Created
July 7, 2011 14:49
-
-
Save m00sey/1069675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ToastPlugin extends Plugin { | |
private static final String TAG = "ToastPlugin"; | |
private static final String LONG_TOAST_ACTION = "show_long"; | |
private static final int TOAST_MESSAGE_INDEX = 0; | |
@Override | |
public PluginResult execute(String action, JSONArray data, String callbackId) { | |
String toastMessage; | |
try { | |
toastMessage = data.getString(TOAST_MESSAGE_INDEX); | |
} catch (JSONException e) { | |
Log.e(TAG, "Required parameter 'Toast Message' missing"); | |
return new PluginResult(Status.ERROR); | |
} | |
if (action.equals(LONG_TOAST_ACTION)) { | |
ctx.runOnUiThread(new RunnableToast(toastMessage, Toast.LENGTH_LONG)); | |
} else { | |
ctx.runOnUiThread(new RunnableToast(toastMessage, Toast.LENGTH_SHORT)); | |
} | |
return new PluginResult(Status.OK); | |
} | |
class RunnableToast implements Runnable { | |
private String message; | |
private int length; | |
public RunnableToast(String message, int length) { | |
this.message = message; | |
this.length = length; | |
} | |
@Override | |
public void run() { | |
Toast.makeText(ctx, message, length).show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment