mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
One js file for ios, android and windows
This commit is contained in:
parent
4b7a573f53
commit
2d8500f6a5
43
plugin.xml
43
plugin.xml
@ -14,7 +14,7 @@
|
|||||||
KIND, either express or implied. See the License for the
|
KIND, either express or implied. See the License for the
|
||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
id="cordova-plugin-screen-orientation"
|
id="cordova-plugin-screen-orientation"
|
||||||
@ -34,30 +34,25 @@
|
|||||||
|
|
||||||
<platform name="ios">
|
<platform name="ios">
|
||||||
<config-file target="config.xml" parent="/*">
|
<config-file target="config.xml" parent="/*">
|
||||||
<feature name="YoikScreenOrientation">
|
<feature name="CDVOrientation">
|
||||||
<param name="ios-package" value="YoikScreenOrientation" />
|
<param name="ios-package" value="CDVOrientation" />
|
||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
<js-module src="www/screenorientation.ios.js" name="screenorientation.ios">
|
|
||||||
<merges target="cordova.plugins.screenorientation" />
|
<header-file src="src/ios/CDVOrientation.h" />
|
||||||
</js-module>
|
<source-file src="src/ios/CDVOrientation.m" />
|
||||||
<header-file src="src/ios/YoikScreenOrientation.h" />
|
|
||||||
<source-file src="src/ios/YoikScreenOrientation.m" />
|
|
||||||
<header-file src="src/ios/CDVViewController+UpdateSupportedOrientations.h" />
|
|
||||||
<source-file src="src/ios/CDVViewController+UpdateSupportedOrientations.m" />
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<platform name="android">
|
<platform name="android">
|
||||||
<source-file src="src/android/YoikScreenOrientation.java" target-dir="src/net/yoik/cordova/plugins/screenorientation/" />
|
<source-file src="src/android/CDVOrientation.java" target-dir="src/cordova/plugins/screenorientation/" />
|
||||||
|
|
||||||
<config-file target="res/xml/config.xml" parent="/*">
|
<config-file target="res/xml/config.xml" parent="/*">
|
||||||
<feature name="YoikScreenOrientation">
|
<feature name="CDVOrientation">
|
||||||
<param name="android-package" value="net.yoik.cordova.plugins.screenorientation.YoikScreenOrientation" />
|
<param name="android-package" value="cordova.plugins.screenorientation.CDVOrientation" />
|
||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
<js-module src="www/screenorientation.android.js" name="screenorientation.android">
|
|
||||||
<merges target="cordova.plugins.screenorientation" />
|
|
||||||
</js-module>
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<platform name="blackberry10">
|
<platform name="blackberry10">
|
||||||
@ -70,21 +65,11 @@
|
|||||||
</js-module>
|
</js-module>
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<platform name="wp8">
|
|
||||||
<config-file target="config.xml" parent="/*">
|
|
||||||
<feature name="YoikScreenOrientation">
|
|
||||||
<param name="wp-package" value="YoikScreenOrientation"/>
|
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
<js-module src="www/screenorientation.wp8.js" name="screenorientation.wp8">
|
|
||||||
<merges target="cordova.plugins.screenorientation" />
|
|
||||||
</js-module>
|
|
||||||
<source-file src="src/wp/YoikScreenOrientation.cs" />
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<platform name="windows">
|
<platform name="windows">
|
||||||
<js-module src="www/screenorientation.windows.js" name="screenorientation.windows">
|
<js-module src="src/windows/CDVOrientationProxy.js" name="CDVOrientationProxy">
|
||||||
<merges target="cordova.plugins.screenorientation" />
|
<merges target="" />
|
||||||
</js-module>
|
</js-module>
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
|
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/android/.DS_Store
vendored
Normal file
BIN
src/android/.DS_Store
vendored
Normal file
Binary file not shown.
@ -17,9 +17,9 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.yoik.cordova.plugins.screenorientation;
|
package cordova.plugins.screenorientation;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
@ -31,7 +31,7 @@ import android.app.Activity;
|
|||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class YoikScreenOrientation extends CordovaPlugin {
|
public class CDVOrientation extends CordovaPlugin {
|
||||||
|
|
||||||
private static final String TAG = "YoikScreenOrientation";
|
private static final String TAG = "YoikScreenOrientation";
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
|||||||
|
|
||||||
String action = args.optString(0);
|
String action = args.optString(0);
|
||||||
|
|
||||||
if (action.equals("set")) {
|
|
||||||
|
|
||||||
String orientation = args.optString(1);
|
String orientation = args.optString(1);
|
||||||
|
|
||||||
@ -93,9 +93,6 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
|||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
|
||||||
callbackContext.error("ScreenOrientation not recognised");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
src/ios/.DS_Store
vendored
Normal file
BIN
src/ios/.DS_Store
vendored
Normal file
Binary file not shown.
@ -17,12 +17,15 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#import <Cordova/CDVPlugin.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
#import <Cordova/CDVViewController.h>
|
#import <Cordova/CDVViewController.h>
|
||||||
|
|
||||||
@interface CDVViewController (UpdateSupportedOrientations)
|
@interface CDVOrientation : CDVPlugin
|
||||||
|
{}
|
||||||
|
|
||||||
- (void)updateSupportedOrientations:(NSArray *)orientations;
|
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
||||||
|
|
||||||
@end
|
@end
|
65
src/ios/CDVOrientation.m
Normal file
65
src/ios/CDVOrientation.m
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "CDVOrientation.h"
|
||||||
|
#import <Cordova/CDVViewController.h>
|
||||||
|
#import <objc/message.h>
|
||||||
|
|
||||||
|
@interface CDVOrientation () {}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation CDVOrientation
|
||||||
|
|
||||||
|
-(void)screenOrientation:(CDVInvokedUrlCommand *)command
|
||||||
|
{
|
||||||
|
CDVPluginResult* pluginResult;
|
||||||
|
NSInteger orientationMask = [[command argumentAtIndex:0] integerValue];
|
||||||
|
CDVViewController* vc = (CDVViewController*)self.viewController;
|
||||||
|
NSMutableArray* result = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
if(orientationMask & 1) {
|
||||||
|
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortrait]];
|
||||||
|
}
|
||||||
|
if(orientationMask & 2) {
|
||||||
|
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]];
|
||||||
|
}
|
||||||
|
if(orientationMask & 4) {
|
||||||
|
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]];
|
||||||
|
}
|
||||||
|
if(orientationMask & 8) {
|
||||||
|
[result addObject:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]];
|
||||||
|
}
|
||||||
|
|
||||||
|
SEL selector = NSSelectorFromString(@"setSupportedOrientations:");
|
||||||
|
|
||||||
|
if([vc respondsToSelector:selector]) {
|
||||||
|
((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
|
||||||
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_INVALID_ACTION messageAsString:@"Error calling to set supported orientations"];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import "CDVViewController+UpdateSupportedOrientations.h"
|
|
||||||
|
|
||||||
@implementation CDVViewController (UpdateSupportedOrientations)
|
|
||||||
|
|
||||||
- (void)updateSupportedOrientations:(NSArray *)orientations {
|
|
||||||
|
|
||||||
[self setValue:orientations forKey:@"supportedOrientations"];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import <Cordova/CDVPlugin.h>
|
|
||||||
#import <Cordova/CDVViewController.h>
|
|
||||||
|
|
||||||
@interface YoikScreenOrientation : CDVPlugin
|
|
||||||
|
|
||||||
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
|
||||||
@property (strong, nonatomic) NSArray *originalSupportedOrientations;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface ForcedViewController : UIViewController
|
|
||||||
|
|
||||||
@property (strong, nonatomic) NSString *calledWith;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import "YoikScreenOrientation.h"
|
|
||||||
#import "CDVViewController+UpdateSupportedOrientations.h"
|
|
||||||
|
|
||||||
@implementation YoikScreenOrientation
|
|
||||||
|
|
||||||
-(void)screenOrientation:(CDVInvokedUrlCommand *)command
|
|
||||||
{
|
|
||||||
[self.commandDelegate runInBackground:^{
|
|
||||||
|
|
||||||
if(self.originalSupportedOrientations == nil) {
|
|
||||||
self.originalSupportedOrientations = [self.viewController valueForKey:@"supportedOrientations"];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSArray* arguments = command.arguments;
|
|
||||||
NSString* orientationIn = [arguments objectAtIndex:1];
|
|
||||||
|
|
||||||
if ([orientationIn isEqual: @"unlocked"]) {
|
|
||||||
[(CDVViewController*)self.viewController updateSupportedOrientations:self.originalSupportedOrientations];
|
|
||||||
self.originalSupportedOrientations = nil;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// grab the device orientation so we can pass it back to the js side.
|
|
||||||
NSString *orientation;
|
|
||||||
switch ([[UIDevice currentDevice] orientation]) {
|
|
||||||
case UIDeviceOrientationLandscapeLeft:
|
|
||||||
orientation = @"landscape-secondary";
|
|
||||||
break;
|
|
||||||
case UIDeviceOrientationLandscapeRight:
|
|
||||||
orientation = @"landscape-primary";
|
|
||||||
break;
|
|
||||||
case UIDeviceOrientationPortrait:
|
|
||||||
orientation = @"portrait-primary";
|
|
||||||
break;
|
|
||||||
case UIDeviceOrientationPortraitUpsideDown:
|
|
||||||
orientation = @"portrait-secondary";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
orientation = @"portait";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we send the result prior to the view controller presentation so that the JS side
|
|
||||||
// is ready for the unlock call.
|
|
||||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
||||||
messageAsDictionary:@{@"device":orientation}];
|
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
||||||
|
|
||||||
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
|
|
||||||
// HACK: Force rotate by changing the view hierarchy.
|
|
||||||
ForcedViewController *vc = [[ForcedViewController alloc] init];
|
|
||||||
vc.calledWith = orientationIn;
|
|
||||||
|
|
||||||
// backgound should be transparent as it is briefly visible
|
|
||||||
// prior to closing.
|
|
||||||
vc.view.backgroundColor = [UIColor clearColor];
|
|
||||||
// vc.view.alpha = 0.0;
|
|
||||||
vc.view.opaque = YES;
|
|
||||||
|
|
||||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
|
|
||||||
// This stops us getting the black application background flash, iOS8
|
|
||||||
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
[self.viewController presentViewController:vc animated:NO completion:nil];
|
|
||||||
});
|
|
||||||
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation ForcedViewController
|
|
||||||
|
|
||||||
-(void) viewDidAppear:(BOOL)animated {
|
|
||||||
CDVViewController *presenter = (CDVViewController*)self.presentingViewController;
|
|
||||||
|
|
||||||
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {
|
|
||||||
[presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationPortrait]]];
|
|
||||||
|
|
||||||
} else if([self.calledWith rangeOfString:@"landscape"].location != NSNotFound) {
|
|
||||||
[presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]]];
|
|
||||||
} else {
|
|
||||||
[presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], [NSNumber numberWithInt:UIInterfaceOrientationPortrait]]];
|
|
||||||
}
|
|
||||||
[presenter dismissViewControllerAnimated:NO completion:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (UIInterfaceOrientationMask) supportedInterfaceOrientations
|
|
||||||
{
|
|
||||||
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {
|
|
||||||
return UIInterfaceOrientationMaskPortrait;
|
|
||||||
} else if([self.calledWith rangeOfString:@"landscape"].location != NSNotFound) {
|
|
||||||
return UIInterfaceOrientationMaskLandscape;
|
|
||||||
}
|
|
||||||
return UIInterfaceOrientationMaskAll;
|
|
||||||
}
|
|
||||||
@end
|
|
BIN
src/windows/.DS_Store
vendored
Normal file
BIN
src/windows/.DS_Store
vendored
Normal file
Binary file not shown.
58
src/windows/CDVOrientation.cs
Normal file
58
src/windows/CDVOrientation.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
var DisplayInfo = Windows.Graphics.Display.DisplayInformation;
|
||||||
|
var Orientations = Windows.Graphics.Display.DisplayOrientations;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
setAllowedOrientations: function (win, fail, args) {
|
||||||
|
//console.log("setAllowedOrientations proxy called with " + args);
|
||||||
|
|
||||||
|
try {
|
||||||
|
var prefOrients = args[0];
|
||||||
|
var winPrefs = 0;
|
||||||
|
|
||||||
|
if (prefOrients & 1) { // UIInterfaceOrientationPortrait
|
||||||
|
winPrefs = winPrefs | Orientations.portrait;
|
||||||
|
}
|
||||||
|
if (prefOrients & 2) { // UIInterfaceOrientationPortraitUpsideDown
|
||||||
|
winPrefs = winPrefs | Orientations.portraitFlipped;
|
||||||
|
}
|
||||||
|
if(prefOrients & 4) { // UIInterfaceOrientationLandscapeLeft
|
||||||
|
winPrefs = winPrefs | Orientations.landscape;
|
||||||
|
}
|
||||||
|
if (prefOrients & 8) { // UIInterfaceOrientationLandscapeRight
|
||||||
|
winPrefs = winPrefs | Orientations.landscapeFlipped;
|
||||||
|
}
|
||||||
|
setTimeout(function () {
|
||||||
|
DisplayInfo.autoRotationPreferences = winPrefs;
|
||||||
|
win();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log("error :: " + err);
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require("cordova/exec/proxy").add("CDVOrientation", module.exports);
|
@ -1,140 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Net;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.Phone.Controls;
|
|
||||||
using Microsoft.Phone.Notification;
|
|
||||||
using Microsoft.Phone.Shell;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Ink;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using System.Windows.Threading;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
using WPCordovaClassLib.Cordova;
|
|
||||||
using WPCordovaClassLib.Cordova.Commands;
|
|
||||||
using WPCordovaClassLib.Cordova.JSON;
|
|
||||||
|
|
||||||
|
|
||||||
namespace WPCordovaClassLib.Cordova.Commands
|
|
||||||
{
|
|
||||||
public class YoikScreenOrientation : BaseCommand
|
|
||||||
{
|
|
||||||
#region Static members
|
|
||||||
private const string UNLOCKED = "unlocked";
|
|
||||||
|
|
||||||
private const string PORTRAIT = "portrait";
|
|
||||||
private const string PORTRAIT_PRIMARY = "portrait-primary";
|
|
||||||
private const string PORTRAIT_SECONDARY = "portrait-secondary";
|
|
||||||
|
|
||||||
private const string LANDSCAPE = "landscape";
|
|
||||||
private const string LANDSCAPE_PRIMARY = "landscape-primary";
|
|
||||||
private const string LANDSCAPE_SECONDARY = "landscape-secondary";
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Current orientation
|
|
||||||
/// </summary>
|
|
||||||
private string currentOrientation;
|
|
||||||
|
|
||||||
public YoikScreenOrientation()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Changes the orientation
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
public void screenOrientation(string options)
|
|
||||||
{
|
|
||||||
string orientation = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
orientation = JSON.JsonHelper.Deserialize<string[]>(options)[0];
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(orientation))
|
|
||||||
{
|
|
||||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.currentOrientation != orientation) // Might prevent flickering
|
|
||||||
{
|
|
||||||
|
|
||||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
|
||||||
{
|
|
||||||
PhoneApplicationFrame frame;
|
|
||||||
PhoneApplicationPage page;
|
|
||||||
if (TryCast(Application.Current.RootVisual, out frame) &&
|
|
||||||
TryCast(frame.Content, out page))
|
|
||||||
{
|
|
||||||
if (orientation == PORTRAIT || orientation == PORTRAIT_PRIMARY || orientation == PORTRAIT_SECONDARY)
|
|
||||||
{
|
|
||||||
page.SupportedOrientations = SupportedPageOrientation.Portrait;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (orientation == LANDSCAPE || orientation == LANDSCAPE_PRIMARY || orientation == LANDSCAPE_SECONDARY)
|
|
||||||
{
|
|
||||||
page.SupportedOrientations = SupportedPageOrientation.Landscape;
|
|
||||||
}
|
|
||||||
else if (orientation == UNLOCKED)
|
|
||||||
{
|
|
||||||
page.SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Screen orientation not detected."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.currentOrientation = orientation;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.DispatchCommandResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool TryCast<T>(object obj, out T result) where T : class
|
|
||||||
{
|
|
||||||
result = obj as T;
|
|
||||||
return result != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
BIN
www/.DS_Store
vendored
Normal file
BIN
www/.DS_Store
vendored
Normal file
Binary file not shown.
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
var exec = require('cordova/exec'),
|
|
||||||
screenOrientation = {};
|
|
||||||
|
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
|
||||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
var exec = require('cordova/exec'),
|
|
||||||
screenOrientation = {},
|
|
||||||
iosOrientation = 'unlocked',
|
|
||||||
orientationMap = {
|
|
||||||
'portrait': [0,180],
|
|
||||||
'portrait-primary': [0],
|
|
||||||
'portrait-secondary': [180],
|
|
||||||
'landscape': [-90,90],
|
|
||||||
'landscape-primary': [-90],
|
|
||||||
'landscape-secondary': [90],
|
|
||||||
'default': [-90,90,0,180]
|
|
||||||
};
|
|
||||||
|
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
|
||||||
iosOrientation = orientation;
|
|
||||||
|
|
||||||
var success = function(res) {
|
|
||||||
if (orientation === 'unlocked' && res.device) {
|
|
||||||
iosOrientation = res.device;
|
|
||||||
setTimeout(function() {
|
|
||||||
iosOrientation = 'unlocked';
|
|
||||||
},300);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
exec(success, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
|
||||||
|
|
||||||
// ios orientation callback/hook
|
|
||||||
window.shouldRotateToOrientation = function(orientation) {
|
|
||||||
var map = orientationMap[iosOrientation] || orientationMap['default'];
|
|
||||||
return map.indexOf(orientation) >= 0;
|
|
||||||
};
|
|
@ -17,9 +17,9 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var screenOrientation = {},
|
var screenOrientation = {},
|
||||||
Orientations = [
|
Orientations = [
|
||||||
'portrait-primary',
|
'portrait-primary',
|
||||||
// The orientation is in the primary portrait mode.
|
// The orientation is in the primary portrait mode.
|
||||||
@ -35,15 +35,38 @@ var screenOrientation = {},
|
|||||||
// The orientation is either landscape-primary or landscape-secondary.
|
// The orientation is either landscape-primary or landscape-secondary.
|
||||||
];
|
];
|
||||||
|
|
||||||
screenOrientation.Orientations = Orientations;
|
screenOrientation.Orientations = Orientations;
|
||||||
screenOrientation.currOrientation = 'unlocked';
|
screenOrientation.currOrientation = 'natural';
|
||||||
|
var orientationMask = 0;
|
||||||
|
screenOrientation.setOrientation = function(orientation) {
|
||||||
|
if(orientation == 'portrait-primary'){
|
||||||
|
orientationMask = 1;
|
||||||
|
}
|
||||||
|
else if(orientation == 'portrait-secondary'){
|
||||||
|
orientationMask = 2;
|
||||||
|
}
|
||||||
|
else if(orientation == 'landscape-primary'){
|
||||||
|
orientationMask = 4;
|
||||||
|
}
|
||||||
|
else if(orientation == 'landscape-secondary'){
|
||||||
|
orientationMask = 8;
|
||||||
|
}
|
||||||
|
else if(orientation == 'portrait'){
|
||||||
|
orientationMask = 3;
|
||||||
|
}
|
||||||
|
else if(orientation == 'landscape'){
|
||||||
|
orientationMask = 12;
|
||||||
|
}
|
||||||
|
else if(orientation == 'natural'){
|
||||||
|
orientationMask = 15;
|
||||||
|
}
|
||||||
|
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
|
||||||
//platform specific files override this function
|
|
||||||
console.log('setOrientation not supported on device');
|
|
||||||
};
|
|
||||||
|
|
||||||
function addScreenOrientationApi(screenObject) {
|
cordova.exec(null, null, "CDVOrientation", "screenOrientation", [orientationMask, orientation]);
|
||||||
|
//console.log('setOrientation not supported on device');
|
||||||
|
};
|
||||||
|
|
||||||
|
function addScreenOrientationApi(screenObject) {
|
||||||
if (screenObject.unlockOrientation || screenObject.lockOrientation) {
|
if (screenObject.unlockOrientation || screenObject.lockOrientation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,15 +81,15 @@ function addScreenOrientationApi(screenObject) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
screenObject.unlockOrientation = function() {
|
screenObject.unlockOrientation = function() {
|
||||||
screenOrientation.currOrientation = screenObject.orientation = 'unlocked';
|
screenOrientation.currOrientation = screenObject.orientation = 'natural';
|
||||||
screenOrientation.setOrientation('unlocked');
|
screenOrientation.setOrientation('natural');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
addScreenOrientationApi(screen);
|
addScreenOrientationApi(screen);
|
||||||
orientationChange();
|
orientationChange();
|
||||||
|
|
||||||
function orientationChange() {
|
function orientationChange() {
|
||||||
var orientation;
|
var orientation;
|
||||||
|
|
||||||
switch (window.orientation) {
|
switch (window.orientation) {
|
||||||
@ -87,8 +110,8 @@ function orientationChange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screen.orientation = orientation;
|
screen.orientation = orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("orientationchange", orientationChange, true);
|
window.addEventListener("orientationchange", orientationChange, true);
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
module.exports = screenOrientation;
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
var screenOrientation = {};
|
|
||||||
|
|
||||||
screenOrientation.setOrientation = function (orientation) {
|
|
||||||
var orientationNumber;
|
|
||||||
switch (orientation) {
|
|
||||||
case 'landscape':
|
|
||||||
orientationNumber = 5;
|
|
||||||
break;
|
|
||||||
case 'portrait':
|
|
||||||
orientationNumber = 10;
|
|
||||||
break;
|
|
||||||
case 'landscape-primary':
|
|
||||||
orientationNumber = 1;
|
|
||||||
break;
|
|
||||||
case 'landscape-secondary':
|
|
||||||
orientationNumber = 4;
|
|
||||||
break;
|
|
||||||
case 'portrait-primary':
|
|
||||||
orientationNumber = 2;
|
|
||||||
break;
|
|
||||||
case 'portrait-secondary':
|
|
||||||
orientationNumber = 8;
|
|
||||||
break;
|
|
||||||
case 'unlocked':
|
|
||||||
orientationNumber = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Windows.Graphics.Display.DisplayInformation.autoRotationPreferences = orientationNumber;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
var exec = require('cordova/exec'),
|
|
||||||
screenOrientation = {};
|
|
||||||
|
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
|
||||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", [orientation]);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
|
Loading…
x
Reference in New Issue
Block a user