mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
Fixed formatting & cleanup
This commit is contained in:
parent
0a927a0d7d
commit
2f7b5ed086
@ -2,7 +2,7 @@
|
|||||||
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="net.yoik.cordova.plugins.screenorientation"
|
id="net.yoik.cordova.plugins.screenorientation"
|
||||||
version="0.0.1">
|
version="0.0.2">
|
||||||
|
|
||||||
<name>YoikScreenOrientation</name>
|
<name>YoikScreenOrientation</name>
|
||||||
<description>Yoik Screen Orientation Plugin</description>
|
<description>Yoik Screen Orientation Plugin</description>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
<clobbers target="cordova.plugins.screenorientation" />
|
<clobbers target="cordova.plugins.screenorientation" />
|
||||||
</js-module>
|
</js-module>
|
||||||
|
|
||||||
<platform name="ios">
|
<platform name="ios">
|
||||||
<config-file target="config.xml" parent="/*">
|
<config-file target="config.xml" parent="/*">
|
||||||
<feature name="YoikScreenOrientation">
|
<feature name="YoikScreenOrientation">
|
||||||
<param name="ios-package" value="YoikScreenOrientation" />
|
<param name="ios-package" value="YoikScreenOrientation" />
|
||||||
@ -24,11 +24,9 @@
|
|||||||
</config-file>
|
</config-file>
|
||||||
<header-file src="src/ios/YoikScreenOrientation.h" />
|
<header-file src="src/ios/YoikScreenOrientation.h" />
|
||||||
<source-file src="src/ios/YoikScreenOrientation.m" />
|
<source-file src="src/ios/YoikScreenOrientation.m" />
|
||||||
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<platform name="android">
|
<platform name="android">
|
||||||
|
|
||||||
<source-file src="src/android/net/yoik/cordova/plugins/screenorientation/YoikScreenOrientation.java" target-dir="src/net/yoik/cordova/plugins/screenorientation/" />
|
<source-file src="src/android/net/yoik/cordova/plugins/screenorientation/YoikScreenOrientation.java" target-dir="src/net/yoik/cordova/plugins/screenorientation/" />
|
||||||
|
|
||||||
<config-file target="res/xml/config.xml" parent="/*">
|
<config-file target="res/xml/config.xml" parent="/*">
|
||||||
@ -36,7 +34,6 @@
|
|||||||
<param name="android-package" value="net.yoik.cordova.plugins.screenorientation.YoikScreenOrientation" />
|
<param name="android-package" value="net.yoik.cordova.plugins.screenorientation.YoikScreenOrientation" />
|
||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
@ -24,8 +24,8 @@ SOFTWARE.
|
|||||||
package net.yoik.cordova.plugins.screenorientation;
|
package net.yoik.cordova.plugins.screenorientation;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
|
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
@ -57,9 +57,6 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
|||||||
private static final String REVERSE_PORTRAIT = "reversePortrait";
|
private static final String REVERSE_PORTRAIT = "reversePortrait";
|
||||||
private static final String FULL_SENSOR = "fullSensor";
|
private static final String FULL_SENSOR = "fullSensor";
|
||||||
|
|
||||||
// an index for the toast message
|
|
||||||
private static final int TOAST_MESSAGE_INDEX = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
||||||
|
|
||||||
@ -87,8 +84,6 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
|||||||
|
|
||||||
Activity activity = cordova.getActivity();
|
Activity activity = cordova.getActivity();
|
||||||
|
|
||||||
Log.d(TAG, "ROUTING SET");
|
|
||||||
|
|
||||||
if (orientation.equals(UNSPECIFIED)) {
|
if (orientation.equals(UNSPECIFIED)) {
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
} else if (orientation.equals(LANDSCAPE)) {
|
} else if (orientation.equals(LANDSCAPE)) {
|
||||||
@ -123,7 +118,6 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
|||||||
callbackContext.error("ScreenOrientation not recognised");
|
callbackContext.error("ScreenOrientation not recognised");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -27,7 +27,6 @@ SOFTWARE.
|
|||||||
|
|
||||||
@interface YoikScreenOrientation : CDVPlugin
|
@interface YoikScreenOrientation : CDVPlugin
|
||||||
|
|
||||||
|
|
||||||
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
||||||
|
|
||||||
@end
|
@end
|
@ -1,24 +1,44 @@
|
|||||||
//
|
/*
|
||||||
// YoikScreenOrientation.m
|
The MIT License (MIT)
|
||||||
// Yoik
|
|
||||||
//
|
|
||||||
// Created by Nick Luo on 14/06/13.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
|
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"
|
#import "YoikScreenOrientation.h"
|
||||||
|
|
||||||
@implementation YoikScreenOrientation
|
@implementation YoikScreenOrientation
|
||||||
|
|
||||||
-(void)screenOrientation:(CDVInvokedUrlCommand *)command
|
-(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.
|
// 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]; }];
|
[self.viewController presentViewController:[UIViewController new] animated:NO completion:^{ [self.viewController dismissViewControllerAnimated:NO completion:nil]; }];
|
||||||
|
|
||||||
// Assume everything went ok
|
// Assume everything went ok
|
||||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
|
// ------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
@ -24,20 +24,20 @@ SOFTWARE.
|
|||||||
var argscheck = require('cordova/argscheck'),
|
var argscheck = require('cordova/argscheck'),
|
||||||
exec = require('cordova/exec'),
|
exec = require('cordova/exec'),
|
||||||
Constants = {
|
Constants = {
|
||||||
Orientation: {
|
Orientation: {
|
||||||
UNSPECIFIED: "unspecified",
|
UNSPECIFIED: "unspecified",
|
||||||
LANDSCAPE: "landscape",
|
LANDSCAPE: "landscape",
|
||||||
PORTRAIT: "portrait",
|
PORTRAIT: "portrait",
|
||||||
USER: "user",
|
USER: "user",
|
||||||
BEHIND: "behind",
|
BEHIND: "behind",
|
||||||
SENSOR: "sensor",
|
SENSOR: "sensor",
|
||||||
NOSENSOR: "nosensor",
|
NOSENSOR: "nosensor",
|
||||||
SENSOR_LANDSCAPE: "sensorLandscape",
|
SENSOR_LANDSCAPE: "sensorLandscape",
|
||||||
SENSOR_PORTRAIT: "sensorPortrait",
|
SENSOR_PORTRAIT: "sensorPortrait",
|
||||||
REVERSE_LANDSCAPE: "reverseLandscape",
|
REVERSE_LANDSCAPE: "reverseLandscape",
|
||||||
REVERSE_PORTRAIT: "reversePortrait",
|
REVERSE_PORTRAIT: "reversePortrait",
|
||||||
FULL_SENSOR: "fullSensor"
|
FULL_SENSOR: "fullSensor"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
currOrientation = Constants.Orientation.UNSPECIFIED;
|
currOrientation = Constants.Orientation.UNSPECIFIED;
|
||||||
|
|
||||||
@ -62,32 +62,32 @@ orientationExports.setOrientation = function(successCallback, errorCallback, ori
|
|||||||
|
|
||||||
// ios orientation callback/hook
|
// ios orientation callback/hook
|
||||||
window.shouldRotateToOrientation = function(orientation) {
|
window.shouldRotateToOrientation = function(orientation) {
|
||||||
var o = Constants.Orientation;
|
var o = Constants.Orientation;
|
||||||
switch (currOrientation) {
|
switch (currOrientation) {
|
||||||
case o.PORTRAIT:
|
case o.PORTRAIT:
|
||||||
case o.SENSOR_PORTRAIT:
|
case o.SENSOR_PORTRAIT:
|
||||||
if (orientation === 0) return true;
|
if (orientation === 0) return true;
|
||||||
break;
|
break;
|
||||||
case o.LANDSCAPE:
|
case o.LANDSCAPE:
|
||||||
case o.SENSOR_LANDSCAPE:
|
case o.SENSOR_LANDSCAPE:
|
||||||
if (orientation === -90) return true;
|
if (orientation === -90) return true;
|
||||||
break;
|
break;
|
||||||
case o.REVERSE_LANDSCAPE:
|
case o.REVERSE_LANDSCAPE:
|
||||||
if (orientation === 90) return true;
|
if (orientation === 90) return true;
|
||||||
break;
|
break;
|
||||||
case o.REVERSE_PORTRAIT:
|
case o.REVERSE_PORTRAIT:
|
||||||
if (orientation === 180) return true;
|
if (orientation === 180) return true;
|
||||||
break;
|
break;
|
||||||
case o.FULL_SENSOR:
|
case o.FULL_SENSOR:
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case o.SENSOR:
|
case o.SENSOR:
|
||||||
case o.UNSPECIFIED:
|
case o.UNSPECIFIED:
|
||||||
if (orientation === -90 || orientation === 90 || orientation === 0) return true;
|
if (orientation === -90 || orientation === 90 || orientation === 0) return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = orientationExports;
|
module.exports = orientationExports;
|
Loading…
x
Reference in New Issue
Block a user