diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/android.json | 7 | ||||
| -rw-r--r-- | plugins/com.phonegap.plugins.OrientationLock/LICENSE.md | 21 | ||||
| -rw-r--r-- | plugins/com.phonegap.plugins.OrientationLock/README.md | 29 | ||||
| -rw-r--r-- | plugins/com.phonegap.plugins.OrientationLock/plugin.xml | 35 | ||||
| -rw-r--r-- | plugins/com.phonegap.plugins.OrientationLock/src/com/plugin/phonegap/OrientationLock.java | 65 | ||||
| -rw-r--r-- | plugins/com.phonegap.plugins.OrientationLock/www/orientationLock.js | 18 | ||||
| -rw-r--r-- | plugins/fetch.json | 9 | ||||
| -rw-r--r-- | plugins/ios.json | 3 |
8 files changed, 187 insertions, 0 deletions
diff --git a/plugins/android.json b/plugins/android.json index b284091c..2978230a 100644 --- a/plugins/android.json +++ b/plugins/android.json @@ -55,6 +55,10 @@ { "xml": "<feature name=\"Canvas2ImagePlugin\"><param name=\"android-package\" value=\"org.devgeeks.Canvas2ImagePlugin.Canvas2ImagePlugin\" /></feature>", "count": 1 + }, + { + "xml": "<feature name=\"OrientationLock\"><param name=\"android-package\" value=\"com.plugin.phonegap.OrientationLock\" /></feature>", + "count": 1 } ] } @@ -110,6 +114,9 @@ }, "org.devgeeks.Canvas2ImagePlugin": { "PACKAGE_NAME": "com.pliablepixels.zmninja" + }, + "com.phonegap.plugins.OrientationLock": { + "PACKAGE_NAME": "com.pliablepixels.zmninja" } }, "dependent_plugins": {} diff --git a/plugins/com.phonegap.plugins.OrientationLock/LICENSE.md b/plugins/com.phonegap.plugins.OrientationLock/LICENSE.md new file mode 100644 index 00000000..b5627bb1 --- /dev/null +++ b/plugins/com.phonegap.plugins.OrientationLock/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2012-2014 Emil Varga <emil.varga@gmail.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/plugins/com.phonegap.plugins.OrientationLock/README.md b/plugins/com.phonegap.plugins.OrientationLock/README.md new file mode 100644 index 00000000..6a5899ed --- /dev/null +++ b/plugins/com.phonegap.plugins.OrientationLock/README.md @@ -0,0 +1,29 @@ +# OrientationLock # + +Android Cordova plugin for locking/unlocking the screen orientation from Javascript + +## Calling the plugin ## + +From your JavaScript code call +`window.plugins.orientationLock.unlock()` to unlock orientation, +`window.plugins.orientationLock.lock("portrait")` or `window.plugins.orientationLock.lock("landscape")` +to lock your screen to the specified orientation. + +To start your Cordova application pre-locked place +`setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);` or +`setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);` +in the `onCreate()` of your Cordova activity. + +Once unlocked, you can track orientation changes with the regular `orientationchange` event: + + window.addEventListener("orientationchange", function() { + alert(window.orientation); + }); + +## Adding the Plugin to your project ## + +Using this plugin requires [Apache Cordova for Android](https://github.com/apache/cordova-android). +Within your project, run the following command: + + cordova plugin add https://github.com/cogitor/PhoneGap-OrientationLock.git + diff --git a/plugins/com.phonegap.plugins.OrientationLock/plugin.xml b/plugins/com.phonegap.plugins.OrientationLock/plugin.xml new file mode 100644 index 00000000..8bd114b8 --- /dev/null +++ b/plugins/com.phonegap.plugins.OrientationLock/plugin.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" + xmlns:android="http://schemas.android.com/apk/res/android" + id="com.phonegap.plugins.OrientationLock" + version="0.1"> + + <name>OrientationLock</name> + <author>Emil Varga</author> + + <description> + Android Cordova plugin for locking/unlocking the screen orientation from Javascript. + </description> + + <license>MIT</license> + + <js-module src="www/orientationLock.js" name="OrientationLock"> + <clobbers target="OrientationLock" /> + </js-module> + + <engines> + <engine name="cordova" version=">=3.0.0" /> + </engines> + + <platform name="android"> + + <config-file target="res/xml/config.xml" parent="/*"> + <feature name="OrientationLock" > + <param name="android-package" value="com.plugin.phonegap.OrientationLock"/> + </feature> + </config-file> + + <source-file src="src/com/plugin/phonegap/OrientationLock.java" target-dir="src/com/plugin/phonegap/" /> + + </platform> +</plugin> 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; + } + } +} diff --git a/plugins/com.phonegap.plugins.OrientationLock/www/orientationLock.js b/plugins/com.phonegap.plugins.OrientationLock/www/orientationLock.js new file mode 100644 index 00000000..099a5359 --- /dev/null +++ b/plugins/com.phonegap.plugins.OrientationLock/www/orientationLock.js @@ -0,0 +1,18 @@ +var OrientationLock = function() {} + +OrientationLock.prototype.lock = function(orientation, success, fail) { + return cordova.exec(success, fail, "OrientationLock", "lock", [orientation]) +} + +OrientationLock.prototype.unlock = function(success, fail) { + return cordova.exec(success, fail, "OrientationLock", "unlock", []) +} + +if ( ! window.plugins ) { + window.plugins = {} +} +if ( ! window.plugins.orientationLock ) { + window.plugins.orientationLock = new OrientationLock() +} + +module.exports = OrientationLock diff --git a/plugins/fetch.json b/plugins/fetch.json index 7ffc871a..d4ce0140 100644 --- a/plugins/fetch.json +++ b/plugins/fetch.json @@ -119,5 +119,14 @@ }, "is_top_level": true, "variables": {} + }, + "com.phonegap.plugins.OrientationLock": { + "source": { + "type": "git", + "url": "https://github.com/cogitor/PhoneGap-OrientationLock.git", + "subdir": "." + }, + "is_top_level": true, + "variables": {} } } diff --git a/plugins/ios.json b/plugins/ios.json index fcba2cde..637e10e9 100644 --- a/plugins/ios.json +++ b/plugins/ios.json @@ -132,6 +132,9 @@ }, "org.devgeeks.Canvas2ImagePlugin": { "PACKAGE_NAME": "com.pliablepixels.zmninja" + }, + "com.phonegap.plugins.OrientationLock": { + "PACKAGE_NAME": "com.pliablepixels.zmninja" } }, "dependent_plugins": {} |
