diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-07-24 15:48:01 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-07-24 15:48:01 -0400 |
| commit | 83400033a3b7a91ad072a5d306355c9cd5a80d82 (patch) | |
| tree | b84d23a607523249554dc97ed26f000ca03d0abd /plugins/com.phonegap.plugins.OrientationLock/src | |
| parent | 89640e9b0212a2525ea132b1d11bb8962f5444dd (diff) | |
integrated event scrubbing with direct image access - need to clean up code
Diffstat (limited to 'plugins/com.phonegap.plugins.OrientationLock/src')
| -rw-r--r-- | plugins/com.phonegap.plugins.OrientationLock/src/com/plugin/phonegap/OrientationLock.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/plugins/com.phonegap.plugins.OrientationLock/src/com/plugin/phonegap/OrientationLock.java b/plugins/com.phonegap.plugins.OrientationLock/src/com/plugin/phonegap/OrientationLock.java new file mode 100644 index 00000000..063fb900 --- /dev/null +++ b/plugins/com.phonegap.plugins.OrientationLock/src/com/plugin/phonegap/OrientationLock.java @@ -0,0 +1,65 @@ +package com.plugin.phonegap; + +import org.json.JSONArray; +import org.json.JSONException; + +import android.content.pm.ActivityInfo; + +import org.apache.cordova.CallbackContext; +import org.apache.cordova.CordovaInterface; +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaWebView; + +/** + * + * Android Phonegap Plugin for locking/unlocking the orientation from JS code + * + */ +public class OrientationLock extends CordovaPlugin { + + private static final String LANSCAPE = "landscape"; + private static final String PORTRAIT = "portrait"; + + public OrientationLock() { + } + + public void unlock() { + this.cordova.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } + + public void lock(String orientation) { + if (orientation.equals(PORTRAIT)) + this.cordova.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + else + this.cordova.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + + @Override + public boolean execute(String action, JSONArray arguments, CallbackContext callbackContext) { + if (action.equals("lock")) { + + try { + String orientation = arguments.getString(0); + + if (orientation!=null && (orientation.equals(LANSCAPE) || orientation.equals(PORTRAIT))) { + this.lock(orientation); + callbackContext.success(); + return true; + } else { + return false; + } + } catch (JSONException e) { + callbackContext.error("JSON_EXCEPTION"); + return true; + } + + } else if (action.equals("unlock")) { + this.unlock(); + callbackContext.success(); + return true; + + } else { + return false; + } + } +} |
