Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions actionscript/src/com/freshplanet/ane/AirAlert/AirAlert.as
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ package com.freshplanet.ane.AirAlert
{
return Capabilities.manufacturer.indexOf("iOS") != -1 || Capabilities.manufacturer.indexOf("Android") != -1;
}


public function AirAlert()
{
Expand All @@ -62,6 +63,8 @@ package com.freshplanet.ane.AirAlert
return _instance ? _instance : new AirAlert();
}



public function showAlert( title : String, message : String, button1 : String = "OK", callback1 : Function = null, button2 : String = null, callback2 : Function = null ) : void
{
if (!isSupported) return;
Expand All @@ -74,6 +77,20 @@ package com.freshplanet.ane.AirAlert
}



/** Alert skin theme (only android) */
public static const THEME_DARK : String = "DARK";
public static const THEME_LIGHT : String = "LIGHT";

public function setTheme($theme:String) : void
{
if ( Capabilities.manufacturer.indexOf("Android") != -1 )
{
_context.call("AirAlertSetTheme", $theme);
}
}


// --------------------------------------------------------------------------------------//
// //
// PRIVATE API //
Expand Down
2 changes: 1 addition & 1 deletion android/src/com/freshplanet/alert/Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public class Extension implements FREExtension
{
public static ExtensionContext context;
public static String theme = null;

public FREContext createContext(String extId)
{
Expand All @@ -35,7 +36,6 @@ public void initialize() { }

public void dispose()
{
context = null;
}

public static void log(String message)
Expand Down
4 changes: 3 additions & 1 deletion android/src/com/freshplanet/alert/ExtensionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import java.util.Map;

import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.freshplanet.alert.functions.AirAlertSetTheme;
import com.freshplanet.alert.functions.AirAlertShowAlert;

public class ExtensionContext extends FREContext implements OnClickListener, OnCancelListener
Expand All @@ -42,6 +43,7 @@ public Map<String, FREFunction> getFunctions()
Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();

functionMap.put("AirAlertShowAlert", new AirAlertShowAlert());
functionMap.put("AirAlertSetTheme", new AirAlertSetTheme());

return functionMap;
}
Expand Down
34 changes: 34 additions & 0 deletions android/src/com/freshplanet/alert/functions/AirAlertSetTheme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.freshplanet.alert.functions;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;
import com.freshplanet.alert.Extension;

public class AirAlertSetTheme implements FREFunction {

@Override
public FREObject call(FREContext arg0, FREObject[] arg1) {
// TODO Auto-generated method stub
try {
Extension.theme = arg1[0].getAsString();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FRETypeMismatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREInvalidObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREWrongThreadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

}
28 changes: 23 additions & 5 deletions android/src/com/freshplanet/alert/functions/AirAlertShowAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import com.adobe.fre.FREObject;
import com.freshplanet.alert.Extension;

@TargetApi(14)
@TargetApi(18)
public class AirAlertShowAlert implements FREFunction
{
@Override
public FREObject call(FREContext context, FREObject[] args)
{

// Retrieve alert parameters
String title = null;
String message = null;
Expand All @@ -53,19 +54,36 @@ public FREObject call(FREContext context, FREObject[] args)

// Create alert builder with a theme depending on Android version
AlertDialog.Builder alertBuilder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)

int themeDevice;
int themeHold;
if ( "LIGHT".equals ( Extension.theme ) )
{
// Theme "Light"
themeDevice = AlertDialog.THEME_DEVICE_DEFAULT_LIGHT;
themeHold = AlertDialog.THEME_HOLO_LIGHT;
} else {
// Theme "Dark"
themeDevice = AlertDialog.THEME_DEVICE_DEFAULT_DARK;
themeHold = AlertDialog.THEME_HOLO_DARK;
}

if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH )
{
alertBuilder = new AlertDialog.Builder(context.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_DARK);
alertBuilder = new AlertDialog.Builder(context.getActivity(), themeDevice);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
else if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
{
alertBuilder = new AlertDialog.Builder(context.getActivity(), AlertDialog.THEME_HOLO_DARK);
alertBuilder = new AlertDialog.Builder(context.getActivity(), themeHold);
}
else
{
alertBuilder = new AlertDialog.Builder(context.getActivity());
}




// Setup and show the alert
alertBuilder.setTitle(title).setMessage(message).setNeutralButton(button1, Extension.context).setOnCancelListener(Extension.context);
if (button2 != null)
Expand Down