From 2f7b5ed0863b88569bd6391d4ae4a3b911a4818d Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Thu, 8 May 2014 07:56:40 +1000 Subject: [PATCH] Fixed formatting & cleanup --- plugin.xml | 7 +- .../YoikScreenOrientation.java | 8 +- src/ios/YoikScreenOrientation.h | 1 - src/ios/YoikScreenOrientation.m | 38 +++++++--- www/screenorientation.js | 74 +++++++++---------- 5 files changed, 69 insertions(+), 59 deletions(-) diff --git a/plugin.xml b/plugin.xml index 546d6c8..ccdccd1 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.0.2"> YoikScreenOrientation Yoik Screen Orientation Plugin @@ -16,7 +16,7 @@ - + @@ -24,11 +24,9 @@ - - @@ -36,7 +34,6 @@ - \ No newline at end of file diff --git a/src/android/net/yoik/cordova/plugins/screenorientation/YoikScreenOrientation.java b/src/android/net/yoik/cordova/plugins/screenorientation/YoikScreenOrientation.java index 13a2115..efe36f1 100644 --- a/src/android/net/yoik/cordova/plugins/screenorientation/YoikScreenOrientation.java +++ b/src/android/net/yoik/cordova/plugins/screenorientation/YoikScreenOrientation.java @@ -24,8 +24,8 @@ SOFTWARE. package net.yoik.cordova.plugins.screenorientation; import org.apache.cordova.CallbackContext; - import org.apache.cordova.CordovaPlugin; + import org.json.JSONArray; import org.json.JSONException; @@ -57,9 +57,6 @@ public class YoikScreenOrientation extends CordovaPlugin { private static final String REVERSE_PORTRAIT = "reversePortrait"; private static final String FULL_SENSOR = "fullSensor"; - // an index for the toast message - private static final int TOAST_MESSAGE_INDEX = 0; - @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { @@ -87,8 +84,6 @@ public class YoikScreenOrientation extends CordovaPlugin { Activity activity = cordova.getActivity(); - Log.d(TAG, "ROUTING SET"); - if (orientation.equals(UNSPECIFIED)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } else if (orientation.equals(LANDSCAPE)) { @@ -123,7 +118,6 @@ public class YoikScreenOrientation extends CordovaPlugin { callbackContext.error("ScreenOrientation not recognised"); return false; } - } } \ No newline at end of file diff --git a/src/ios/YoikScreenOrientation.h b/src/ios/YoikScreenOrientation.h index 0d6d5b4..4ec730d 100644 --- a/src/ios/YoikScreenOrientation.h +++ b/src/ios/YoikScreenOrientation.h @@ -27,7 +27,6 @@ SOFTWARE. @interface YoikScreenOrientation : CDVPlugin - - (void)screenOrientation:(CDVInvokedUrlCommand *)command; @end \ No newline at end of file diff --git a/src/ios/YoikScreenOrientation.m b/src/ios/YoikScreenOrientation.m index 094ac97..34d5fda 100644 --- a/src/ios/YoikScreenOrientation.m +++ b/src/ios/YoikScreenOrientation.m @@ -1,24 +1,44 @@ -// -// YoikScreenOrientation.m -// Yoik -// -// Created by Nick Luo on 14/06/13. -// -// +/* +The MIT License (MIT) +Copyright (c) 2014 + +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. + */ #import "YoikScreenOrientation.h" @implementation YoikScreenOrientation -(void)screenOrientation:(CDVInvokedUrlCommand *)command { + // this method does not control the orientation, it is set in the .js file. + + // SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation + // ------------------ + // HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately. [self.viewController presentViewController:[UIViewController new] animated:NO completion:^{ [self.viewController dismissViewControllerAnimated:NO completion:nil]; }]; // Assume everything went ok CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - + // ------------------ } -@end +@end \ No newline at end of file diff --git a/www/screenorientation.js b/www/screenorientation.js index 1df403b..1614453 100644 --- a/www/screenorientation.js +++ b/www/screenorientation.js @@ -24,20 +24,20 @@ SOFTWARE. var argscheck = require('cordova/argscheck'), exec = require('cordova/exec'), Constants = { - Orientation: { + Orientation: { UNSPECIFIED: "unspecified", - LANDSCAPE: "landscape", - PORTRAIT: "portrait", - USER: "user", - BEHIND: "behind", - SENSOR: "sensor", - NOSENSOR: "nosensor", - SENSOR_LANDSCAPE: "sensorLandscape", - SENSOR_PORTRAIT: "sensorPortrait", - REVERSE_LANDSCAPE: "reverseLandscape", - REVERSE_PORTRAIT: "reversePortrait", - FULL_SENSOR: "fullSensor" - } + LANDSCAPE: "landscape", + PORTRAIT: "portrait", + USER: "user", + BEHIND: "behind", + SENSOR: "sensor", + NOSENSOR: "nosensor", + SENSOR_LANDSCAPE: "sensorLandscape", + SENSOR_PORTRAIT: "sensorPortrait", + REVERSE_LANDSCAPE: "reverseLandscape", + REVERSE_PORTRAIT: "reversePortrait", + FULL_SENSOR: "fullSensor" + } }, currOrientation = Constants.Orientation.UNSPECIFIED; @@ -62,32 +62,32 @@ orientationExports.setOrientation = function(successCallback, errorCallback, ori // ios orientation callback/hook window.shouldRotateToOrientation = function(orientation) { - var o = Constants.Orientation; - switch (currOrientation) { - case o.PORTRAIT: - case o.SENSOR_PORTRAIT: - if (orientation === 0) return true; - break; - case o.LANDSCAPE: - case o.SENSOR_LANDSCAPE: - if (orientation === -90) return true; - break; - case o.REVERSE_LANDSCAPE: - if (orientation === 90) return true; - break; - case o.REVERSE_PORTRAIT: - if (orientation === 180) return true; - break; - case o.FULL_SENSOR: - return true; - break; + var o = Constants.Orientation; + switch (currOrientation) { + case o.PORTRAIT: + case o.SENSOR_PORTRAIT: + if (orientation === 0) return true; + break; + case o.LANDSCAPE: + case o.SENSOR_LANDSCAPE: + if (orientation === -90) return true; + break; + case o.REVERSE_LANDSCAPE: + if (orientation === 90) return true; + break; + case o.REVERSE_PORTRAIT: + if (orientation === 180) return true; + break; + case o.FULL_SENSOR: + return true; + break; case o.SENSOR: - case o.UNSPECIFIED: - if (orientation === -90 || orientation === 90 || orientation === 0) return true; - break; - } + case o.UNSPECIFIED: + if (orientation === -90 || orientation === 90 || orientation === 0) return true; + break; + } - return false; + return false; } module.exports = orientationExports; \ No newline at end of file