Skip to content

Commit

Permalink
added C2DMErrorEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalczyszyn committed Oct 4, 2011
1 parent 3f3a493 commit b61cf7f
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin
bin-debug
bin-release
.DS_Store
.metadata
10 changes: 5 additions & 5 deletions as3c2dm-example/.actionScriptProperties
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@
<flashCatalyst validateFlashCatalystCompatibility="false"/>
<buildTargets>
<buildTarget airDownloadURL="https://market.android.com/details?id=com.adobe.air" androidSettingsVersion="1" buildTargetName="com.adobe.flexide.multiplatform.android.platform">
<multiPlatformSettings enabled="true" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.android.platform" version="2"/>
<airSettings airCertificatePath="/Users/pwalczys/Projects/cert/my-android-cert.pfx" airTimestamp="true" anePathSet="true" version="1">
<airExcludes/>
<anePaths>
<anePathEntry path="/Users/pwalczys/Projects/as3c2dm/as3c2dm-test/extensions/as3c2dm.ane"/>
<anePathEntry path="/Users/pwalczys/Projects/as3c2dm/as3c2dm-example/extensions/as3c2dm.ane"/>
</anePaths>
</airSettings>
<multiPlatformSettings enabled="true" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.android.platform" version="2"/>
<actionScriptSettings version="1"/>
</buildTarget>
<buildTarget buildTargetName="default">
<multiPlatformSettings enabled="false" includePlatformLibs="false" platformID="default" version="2"/>
<airSettings airCertificatePath="" airTimestamp="true" anePathSet="false" version="1">
<airExcludes/>
<anePaths/>
</airSettings>
<multiPlatformSettings enabled="false" includePlatformLibs="false" platformID="default" version="2"/>
<actionScriptSettings version="1"/>
</buildTarget>
<buildTarget buildTargetName="com.adobe.flexide.multiplatform.ios.platform" iosSettingsVersion="1" provisioningFile="" releasePackageType="">
<multiPlatformSettings enabled="false" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.ios.platform" version="2"/>
<airSettings airCertificatePath="" airTimestamp="true" anePathSet="true" version="1">
<airExcludes/>
<anePaths/>
</airSettings>
<multiPlatformSettings enabled="false" includePlatformLibs="false" platformID="com.adobe.flexide.multiplatform.ios.platform" version="2"/>
<actionScriptSettings version="1"/>
</buildTarget>
<buildTarget buildTargetName="com.qnx.flexide.multiplatform.qnx.platform" extraPackagingOptions="" signBarFile="false">
<multiPlatformSettings enabled="false" includePlatformLibs="false" platformID="com.qnx.flexide.multiplatform.qnx.platform" version="2"/>
<airSettings airCertificatePath="" airTimestamp="true" anePathSet="false" version="1">
<airExcludes/>
<anePaths/>
</airSettings>
<multiPlatformSettings enabled="false" includePlatformLibs="false" platformID="com.qnx.flexide.multiplatform.qnx.platform" version="2"/>
<actionScriptSettings version="1"/>
</buildTarget>
</buildTargets>
Expand Down
14 changes: 14 additions & 0 deletions as3c2dm-example/.fxpProperties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<fxpProperties abbreviated="false" authoringTool="Flex Builder" compiles="true" parentProject="40257871-b911-455d-b0ae-9babddd868be" projectUUID="40257871-b911-455d-b0ae-9babddd868be" pureCatalystProject="false" sdkVersion="4.5.2" uuid="8e85b75c-1431-49cb-aea3-44ff35af329b" version="15">
<projects/>
<src/>
<swc>
<linked location="/extensions/as3c2dm.ane" path="/extensions/as3c2dm.ane" position="2" uuid="8e85b75c-1431-49cb-aea3-44ff35af329b"/>
<linked location="sdkPlaceHolder" path="sdkPlaceHolder" position="0" uuid="8e85b75c-1431-49cb-aea3-44ff35af329b"/>
<linked location="/libs" path="/libs" position="1" uuid="8e85b75c-1431-49cb-aea3-44ff35af329b"/>
<linked location="/extensions/as3c2dm.ane" path="\extensions\as3c2dm.ane" position="2" uuid="8e85b75c-1431-49cb-aea3-44ff35af329b"/>
</swc>
<misc/>
<theme/>
<mxmlFormattingPrefs groupAttributesByState="true" maxLineWidth="100" mxmlAlignAttributes="true" mxmlAttributeOrder="id,userLabel,includeIn,excludeFrom,visible,x,y,z,left,right,top,bottom,width,height,minWidth,minHeight,maxWidth,maxHeight,label" mxmlKeepAttributeValuesOrganized="true"/>
</fxpProperties>
Binary file modified as3c2dm-example/extensions/as3c2dm.ane
Binary file not shown.
11 changes: 6 additions & 5 deletions as3c2dm-example/src/views/HomeView.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<fx:Script>
<![CDATA[
import com.riaspace.c2dm.C2DM;
import com.riaspace.c2dm.events.C2DMErrorEvent;
import com.riaspace.c2dm.events.C2DMRegistrationEvent;
import mx.events.FlexEvent;
Expand All @@ -42,10 +43,10 @@
{
// Using C2DM ANE to register application in C2DM service
c2dm = new C2DM;
// Listening for un/registered event
// Listening for un/registered, error events
c2dm.addEventListener(C2DMRegistrationEvent.REGISTERED, onRegistered);
c2dm.addEventListener(C2DMRegistrationEvent.UNREGISTERED, onUnregistered);
c2dm.addEventListener(C2DMRegistrationEvent.ERROR, onError);
c2dm.addEventListener(C2DMErrorEvent.ERROR, onError);
// Checking if application was already registered in C2DM service
var registrationId:String = persistence.getProperty("registration_id") as String;
Expand All @@ -56,7 +57,7 @@
private function onError(event:C2DMRegistrationEvent):void
{
trace("C2DM error:", event.text);
trace("C2DM error:", event.registrationId);
}
protected function btnRegister_clickHandler(event:MouseEvent):void
Expand All @@ -73,10 +74,10 @@
private function onRegistered(event:C2DMRegistrationEvent):void
{
trace("Registered with registration id:", event.text);
trace("Registered with registration id:", event.registrationId);
// Storing registration id received from C2DM service
persistence.setProperty("registration_id", event.text);
persistence.setProperty("registration_id", event.registrationId);
registered = true;
}
Expand Down
2 changes: 2 additions & 0 deletions as3c2dm/.flexLibProperties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<includeClasses>
<classEntry path="com.riaspace.c2dm.C2DM"/>
<classEntry path="com.riaspace.c2dm.events.C2DMRegistrationEvent"/>
<classEntry path="com.riaspace.c2dm.events.C2DMErrorEvent"/>
<classEntry path="com.riaspace.c2dm.C2DMErrorCodes"/>
</includeClasses>
<includeResources/>
<namespaceManifests/>
Expand Down
Binary file removed as3c2dm/as3c2dm.ane
Binary file not shown.
2 changes: 1 addition & 1 deletion as3c2dm/buildane.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ unzip -o bin/as3c2dm.swc -x catalog.xml

/Applications/Adobe\ Flash\ Builder\ 4.5/sdks/4.5.2/bin/adt -package -storetype pkcs12 -keystore ~/Projects/cert/my-android-cert.pfx -target ane as3c2dm.ane src/extension.xml -swc bin/as3c2dm.swc -platform Android-ARM library.swf as3c2dm.jar

cp as3c2dm.ane ../as3c2dm-test/extensions/
cp as3c2dm.ane ../as3c2dm-example/extensions/

rm library.swf as3c2dm.jar
8 changes: 6 additions & 2 deletions as3c2dm/src/com/riaspace/c2dm/C2DM.as
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

package com.riaspace.c2dm
{
import com.riaspace.c2dm.events.C2DMErrorEvent;
import com.riaspace.c2dm.events.C2DMRegistrationEvent;

import flash.events.EventDispatcher;
import flash.events.StatusEvent;
import flash.external.ExtensionContext;

[Event(name="error", type="com.riaspace.c2dm.events.C2DMErrorEvent")]
[Event(name="registered", type="com.riaspace.c2dm.events.C2DMRegistrationEvent")]
[Event(name="unregistered", type="com.riaspace.c2dm.events.C2DMRegistrationEvent")]
[Event(name="error", type="com.riaspace.c2dm.events.C2DMRegistrationEvent")]

public class C2DM extends EventDispatcher
{
Expand All @@ -52,7 +53,10 @@ package com.riaspace.c2dm
{
if (["registered", "unregistered", "error"].indexOf(event.level) >= 0)
{
dispatchEvent(new C2DMRegistrationEvent(event.level, event.code));
if (event.level == "error")
dispatchEvent(new C2DMErrorEvent(C2DMErrorEvent.ERROR, event.code));
else
dispatchEvent(new C2DMRegistrationEvent(event.level, event.code));
}
else
{
Expand Down
53 changes: 53 additions & 0 deletions as3c2dm/src/com/riaspace/c2dm/C2DMErrorCodes.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2011 Piotr Walczyszyn (http://riaspace.com | @pwalczyszyn)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//////////////////////////////////////////////////////////////////////////////////////

package com.riaspace.c2dm
{
public final class C2DMErrorCodes
{
/**
* The device can't read the response, or there was a 500/503 from the server that can be retried later. The application should use exponential back off and retry.
*/
public static const SERVICE_NOT_AVAILABLE:String = "SERVICE_NOT_AVAILABLE";

/**
* There is no Google account on the phone. The application should ask the user to open the account manager and add a Google account. Fix on the device side.
*/
public static const ACCOUNT_MISSING:String = "ACCOUNT_MISSING";

/**
* Bad password. The application should ask the user to enter his/her password, and let user retry manually later. Fix on the device side.
*/
public static const AUTHENTICATION_FAILED:String = "AUTHENTICATION_FAILED";

/**
* The user has too many applications registered. The application should tell the user to uninstall some other applications, let user retry manually. Fix on the device side.
*/
public static const TOO_MANY_REGISTRATIONS:String = "TOO_MANY_REGISTRATIONS";

/**
* The sender account is not recognized.
*/
public static const INVALID_SENDER:String = "INVALID_SENDER";

/**
* Incorrect phone registration with Google. This phone doesn't currently support C2DM.
*/
public static const PHONE_REGISTRATION_ERROR:String = "PHONE_REGISTRATION_ERROR";
}
}
40 changes: 40 additions & 0 deletions as3c2dm/src/com/riaspace/c2dm/events/C2DMErrorEvent.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2011 Piotr Walczyszyn (http://riaspace.com | @pwalczyszyn)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//////////////////////////////////////////////////////////////////////////////////////

package com.riaspace.c2dm.events
{
import flash.events.Event;

public class C2DMErrorEvent extends Event
{
public static const ERROR:String = "error";

public var errorCode:String;

public function C2DMErrorEvent(type:String, errorCode:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
this.errorCode = errorCode;
super(type, bubbles, cancelable);
}

override public function clone():Event
{
return new C2DMErrorEvent(type, errorCode, bubbles, cancelable);
}
}
}
11 changes: 4 additions & 7 deletions as3c2dm/src/com/riaspace/c2dm/events/C2DMRegistrationEvent.as
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@ package com.riaspace.c2dm.events

public class C2DMRegistrationEvent extends Event
{

public static const REGISTERED:String = "registered";

public static const UNREGISTERED:String = "unregistered";

public static const ERROR:String = "error";

public var text:String;
public var registrationId:String;

public function C2DMRegistrationEvent(type:String, text:String = null, bubbles:Boolean=false, cancelable:Boolean=false)
public function C2DMRegistrationEvent(type:String, registrationId:String = null, bubbles:Boolean=false, cancelable:Boolean=false)
{
this.text = text;
this.registrationId = registrationId;
super(type, bubbles, cancelable);
}

override public function clone():Event
{
return new C2DMRegistrationEvent(type, text, bubbles, cancelable);
return new C2DMRegistrationEvent(type, registrationId, bubbles, cancelable);
}
}
}
2 changes: 1 addition & 1 deletion c2dm-messenger/.actionScriptProperties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<actionScriptProperties analytics="false" mainApplicationPath="C2DMMessenger.mxml" projectUUID="29756dc1-efe1-419b-9699-806dc9fce9d1" version="10">
<compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" flexSDK="Flex 4.5.1" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="false" htmlPlayerVersionCheck="true" includeNetmonSwc="true" outputFolderPath="bin-debug" removeUnusedRSL="true" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="true" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
<compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" flexSDK="Flex 4.5.1 (build 21328)" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="false" htmlPlayerVersionCheck="true" includeNetmonSwc="true" outputFolderPath="bin-debug" removeUnusedRSL="true" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="true" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
<compilerSourcePath/>
<libraryPath defaultLinkType="0">
<libraryPathEntry kind="4" path="">
Expand Down

0 comments on commit b61cf7f

Please sign in to comment.