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
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
import com.adobe.fre.FREFunction;
import com.freshplanet.ane.AirAlert.functions.ShowAlertFunction;

import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnCancelListener;
import java.util.HashMap;
import java.util.Map;

public class AirAlertExtensionContext extends FREContext implements OnClickListener, OnCancelListener {
public class AirAlertExtensionContext extends FREContext {
@Override
public void dispose()
{
Expand All @@ -39,15 +36,4 @@ public Map<String, FREFunction> getFunctions() {
functions.put("showAlert", new ShowAlertFunction());
return functions;
}

public void onClick(DialogInterface dialog, int which) {
String buttonIndex = (which == DialogInterface.BUTTON_POSITIVE) ? "1" : "0";
dispatchStatusEventAsync("CLICK", buttonIndex);
}

public void onCancel(DialogInterface dialog)
{
dispatchStatusEventAsync("CLICK", "0");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,47 @@
import com.adobe.fre.FREObject;
import com.freshplanet.ane.AirAlert.AirAlertExtension;

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


public class ShowAlertFunction extends BaseFunction {
public FREObject call(FREContext context, FREObject[] args) {
public FREObject call(final FREContext context, FREObject[] args) {
super.call(context, args);

String title = getStringFromFREObject(args[0]);
String message = getStringFromFREObject(args[1]);
String button1 = getStringFromFREObject(args[2]);
String button2 = args.length > 3 ? getStringFromFREObject(args[3]) : null;
final boolean hasButton2 = args.length > 3;
String button2 = hasButton2 ? getStringFromFREObject(args[3]) : null;

// Create alert builder with a theme depending on Android version
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context.getActivity());

// Setup and show the alert
alertBuilder.setTitle(title).setMessage(message).setNeutralButton(button1, AirAlertExtension.context).setOnCancelListener(AirAlertExtension.context);
alertBuilder.setTitle(title).setMessage(message).setNeutralButton(button1, new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
context.dispatchStatusEventAsync("CLICK", "0");
}
}).setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
context.dispatchStatusEventAsync("CLICK", hasButton2?"1":"0");
}
});
if (button2 != null) {
alertBuilder.setPositiveButton(button2, AirAlertExtension.context);
alertBuilder.setPositiveButton(button2, new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
context.dispatchStatusEventAsync("CLICK", "1");
}
});
}

AlertDialog alertDialog = alertBuilder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();

return null;

}

}