diff --git a/actionscript/src/com/freshplanet/ane/AirAlert/AirAlert.as b/actionscript/src/com/freshplanet/ane/AirAlert/AirAlert.as index 010475c..42013ce 100644 --- a/actionscript/src/com/freshplanet/ane/AirAlert/AirAlert.as +++ b/actionscript/src/com/freshplanet/ane/AirAlert/AirAlert.as @@ -36,6 +36,7 @@ package com.freshplanet.ane.AirAlert { return Capabilities.manufacturer.indexOf("iOS") != -1 || Capabilities.manufacturer.indexOf("Android") != -1; } + public function AirAlert() { @@ -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; @@ -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 // diff --git a/android/src/com/freshplanet/alert/Extension.java b/android/src/com/freshplanet/alert/Extension.java index 97ccaa2..24c34b6 100644 --- a/android/src/com/freshplanet/alert/Extension.java +++ b/android/src/com/freshplanet/alert/Extension.java @@ -24,6 +24,7 @@ public class Extension implements FREExtension { public static ExtensionContext context; + public static String theme = null; public FREContext createContext(String extId) { @@ -35,7 +36,6 @@ public void initialize() { } public void dispose() { - context = null; } public static void log(String message) diff --git a/android/src/com/freshplanet/alert/ExtensionContext.java b/android/src/com/freshplanet/alert/ExtensionContext.java index 59518ce..377da1d 100644 --- a/android/src/com/freshplanet/alert/ExtensionContext.java +++ b/android/src/com/freshplanet/alert/ExtensionContext.java @@ -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 @@ -42,6 +43,7 @@ public Map getFunctions() Map functionMap = new HashMap(); functionMap.put("AirAlertShowAlert", new AirAlertShowAlert()); + functionMap.put("AirAlertSetTheme", new AirAlertSetTheme()); return functionMap; } diff --git a/android/src/com/freshplanet/alert/functions/AirAlertSetTheme.java b/android/src/com/freshplanet/alert/functions/AirAlertSetTheme.java new file mode 100644 index 0000000..a386d9e --- /dev/null +++ b/android/src/com/freshplanet/alert/functions/AirAlertSetTheme.java @@ -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; + } + +} diff --git a/android/src/com/freshplanet/alert/functions/AirAlertShowAlert.java b/android/src/com/freshplanet/alert/functions/AirAlertShowAlert.java index 509581c..e3799aa 100644 --- a/android/src/com/freshplanet/alert/functions/AirAlertShowAlert.java +++ b/android/src/com/freshplanet/alert/functions/AirAlertShowAlert.java @@ -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; @@ -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)