mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
Resolve merge conflicts
This commit is contained in:
commit
ab23405417
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
#If ignorance is bliss, then somebody knock the smile off my face
|
||||
|
||||
*.csproj.user
|
||||
*.suo
|
||||
*.cache
|
||||
Thumbs.db
|
||||
*.DS_Store
|
||||
|
||||
*.bak
|
||||
*.cache
|
||||
*.log
|
||||
*.swp
|
||||
*.user
|
||||
|
||||
demo/hooks/
|
||||
demo/platforms/
|
||||
demo/plugins/
|
||||
|
||||
.vscode/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
.npmignore
Normal file
2
.npmignore
Normal file
@ -0,0 +1,2 @@
|
||||
demo/
|
||||
tests/
|
42
README.md
42
README.md
@ -19,7 +19,7 @@
|
||||
|
||||
# Cordova Screen Orientation Plugin
|
||||
|
||||
Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on an early version of [Screen Orientation API](http://www.w3.org/TR/screen-orientation/) so the api does not currently match the current spec.
|
||||
Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on [Screen Orientation API](http://www.w3.org/TR/screen-orientation/) so the api matches the current spec.
|
||||
|
||||
The plugin adds the following to the screen object (`window.screen`):
|
||||
|
||||
@ -36,12 +36,6 @@ The plugin adds the following to the screen object (`window.screen`):
|
||||
|
||||
## Install
|
||||
|
||||
_cordova < 4_
|
||||
|
||||
```bash
|
||||
cordova plugin add net.yoik.cordova.plugins.screenorientation
|
||||
```
|
||||
_cordova > 4_
|
||||
|
||||
```bash
|
||||
cordova plugin add cordova-plugin-screen-orientation
|
||||
@ -67,6 +61,9 @@ cordova plugin add cordova-plugin-screen-orientation
|
||||
#### landscape
|
||||
> The orientation is either landscape-primary or landscape-secondary (sensor).
|
||||
|
||||
#### any
|
||||
> orientation is unlocked - all orientations are supported.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
@ -85,9 +82,6 @@ console.log('Orientation is ' + screen.orientation);
|
||||
Both android and iOS will fire the orientationchange event on the window object.
|
||||
For this version of the plugin use the window object if you require notification.
|
||||
|
||||
For this plugin to follow the full API events should be fired on the screen object.
|
||||
iOS and BB10 do not currently support events on the _screen_ object so custom event
|
||||
handling will need to be added (Suggestions welcome!).
|
||||
|
||||
### Example usage
|
||||
|
||||
@ -101,28 +95,11 @@ window.addEventListener("orientationchange", function(){
|
||||
|
||||
The __screen.orientation__ property will not update when the phone is [rotated 180 degrees](http://www.quirksmode.org/dom/events/orientationchange.html).
|
||||
|
||||
## iOS Notes
|
||||
|
||||
The iOS version is a combination of the cordova JS callback _window.shouldRotateToOrientation_ and the workaround to recheck the orientation as implemented in https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation.
|
||||
|
||||
__If you have a custom implementation of the _window.shouldRotateToOrientation_ it will have to be removed for the plugin to function as expected.__
|
||||
|
||||
#### iOS6
|
||||
|
||||
There has been a few cases where the rotation does not change the width of the viewport
|
||||
|
||||
Issue [#1](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/1) @dokterbob
|
||||
|
||||
>It seems to be related to having width=device-width, height=device-height in the meta viewport (which is part of the boilerplate phonegap/cordova app). It can be solved by updating the viewport with width=device-height, height=device-width or simply removing width and height altogether.
|
||||
|
||||
#### iOS8
|
||||
|
||||
Versions prior to 1.2.0 will cause an application crash in iOS8 due to a change in presentViewController timing.
|
||||
|
||||
## BB10 Notes
|
||||
|
||||
Wraps the com.blackberry.app plugin functions, auto installed as a dependancy.
|
||||
|
||||
<<<<<<< HEAD
|
||||
## WP8 Notes
|
||||
|
||||
Windows phone does not support specification or primary and secondary orientations. If called with a specific orientation the plugin will just apply the landscape or portait orientation.
|
||||
@ -134,6 +111,15 @@ Windows 8.1 Applicaitons (runtime/metro applications) will only display orientat
|
||||
# Legacy Changelog
|
||||
|
||||
See [RELEASENOTES.md](RELEASENOTES.md) for the automated changelog.
|
||||
=======
|
||||
# Changelog
|
||||
|
||||
## 2.0.0
|
||||
* Common javascript for iOS, Android and Windows.
|
||||
|
||||
## 1.4.2
|
||||
* [#101](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/pull/101) make iOS rotate as needed when lockOrientation is called
|
||||
>>>>>>> f2f2dbde729b9d3ac5884de6ee80ae354a3bf5ef
|
||||
|
||||
## 1.4.1
|
||||
* [#89](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/pull/89) Fix for cordova >= 3.6.3
|
||||
|
26
demo/config.xml
Normal file
26
demo/config.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<widget id="com.cordova.screenorientationdemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
|
||||
<name>ScreenOrientationDemo</name>
|
||||
<description>
|
||||
A sample Apache Cordova application that showcases the Screenorientation plugin.
|
||||
</description>
|
||||
<author email="dev@cordova.apache.org" href="http://cordova.io">
|
||||
Apache Cordova Team
|
||||
</author>
|
||||
<content src="index.html" />
|
||||
<plugin name="cordova-plugin-whitelist" spec="1" />
|
||||
<access origin="*" />
|
||||
<allow-intent href="http://*/*" />
|
||||
<allow-intent href="https://*/*" />
|
||||
<allow-intent href="tel:*" />
|
||||
<allow-intent href="sms:*" />
|
||||
<allow-intent href="mailto:*" />
|
||||
<allow-intent href="geo:*" />
|
||||
<platform name="android">
|
||||
<allow-intent href="market:*" />
|
||||
</platform>
|
||||
<platform name="ios">
|
||||
<allow-intent href="itms:*" />
|
||||
<allow-intent href="itms-apps:*" />
|
||||
</platform>
|
||||
</widget>
|
115
demo/www/css/index.css
Normal file
115
demo/www/css/index.css
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
* {
|
||||
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
|
||||
}
|
||||
|
||||
body {
|
||||
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
|
||||
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
|
||||
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
|
||||
background-color:#E4E4E4;
|
||||
background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
|
||||
background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
|
||||
background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
|
||||
background-image:-webkit-gradient(
|
||||
linear,
|
||||
left top,
|
||||
left bottom,
|
||||
color-stop(0, #A7A7A7),
|
||||
color-stop(0.51, #E4E4E4)
|
||||
);
|
||||
background-attachment:fixed;
|
||||
font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
|
||||
font-size:12px;
|
||||
height:100%;
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
text-transform:uppercase;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
/* Portrait layout (default) */
|
||||
.app {
|
||||
background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */
|
||||
position:absolute; /* position in the center of the screen */
|
||||
left:50%;
|
||||
top:50%;
|
||||
height:50px; /* text area height */
|
||||
width:225px; /* text area width */
|
||||
text-align:center;
|
||||
padding:180px 0px 0px 0px; /* image height is 200px (bottom 20px are overlapped with text) */
|
||||
margin:-115px 0px 0px -112px; /* offset vertical: half of image height and text area height */
|
||||
/* offset horizontal: half of text area width */
|
||||
}
|
||||
|
||||
/* Landscape layout (with min-width) */
|
||||
@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {
|
||||
.app {
|
||||
background-position:left center;
|
||||
padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */
|
||||
margin:-90px 0px 0px -198px; /* offset vertical: half of image height */
|
||||
/* offset horizontal: half of image width and text area width */
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size:24px;
|
||||
font-weight:normal;
|
||||
margin:0px;
|
||||
overflow:visible;
|
||||
padding:0px;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.event {
|
||||
border-radius:4px;
|
||||
-webkit-border-radius:4px;
|
||||
color:#FFFFFF;
|
||||
font-size:12px;
|
||||
margin:0px 30px;
|
||||
padding:2px 0px;
|
||||
}
|
||||
|
||||
.event.listening {
|
||||
background-color:#333333;
|
||||
display:block;
|
||||
}
|
||||
|
||||
.event.received {
|
||||
background-color:#4B946A;
|
||||
display:none;
|
||||
}
|
||||
|
||||
@keyframes fade {
|
||||
from { opacity: 1.0; }
|
||||
50% { opacity: 0.4; }
|
||||
to { opacity: 1.0; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes fade {
|
||||
from { opacity: 1.0; }
|
||||
50% { opacity: 0.4; }
|
||||
to { opacity: 1.0; }
|
||||
}
|
||||
|
||||
.blink {
|
||||
animation:fade 3000ms infinite;
|
||||
-webkit-animation:fade 3000ms infinite;
|
||||
}
|
BIN
demo/www/img/logo.png
Normal file
BIN
demo/www/img/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
58
demo/www/index.html
Normal file
58
demo/www/index.html
Normal file
@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
Customize this policy to fit your own app's needs. For more guidance, see:
|
||||
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
|
||||
Some notes:
|
||||
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
|
||||
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
|
||||
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
|
||||
* Enable inline JS: add 'unsafe-inline' to default-src
|
||||
-->
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<link rel="stylesheet" type="text/css" href="css/index.css">
|
||||
<title>Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="app">
|
||||
<h1>Apache Cordova</h1>
|
||||
<div id="deviceready" class="blink">
|
||||
<p class="event listening">Connecting to Device</p>
|
||||
<p class="event received">Device is Ready</p>
|
||||
</div>
|
||||
<div>
|
||||
<button id="btnPortrait">Portrait</button>
|
||||
<button id="btnLandscape">Landscape</button>
|
||||
</div>
|
||||
<div>
|
||||
<button id="btnPortPrimary">Portrait - Primary</button>
|
||||
<button id="btnLandPrimary">Landscape - Primary</button>
|
||||
</div>
|
||||
<button id="btnAny">Any</button>
|
||||
</div>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
96
demo/www/js/index.js
Normal file
96
demo/www/js/index.js
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 app = {
|
||||
// Application Constructor
|
||||
initialize: function() {
|
||||
this.bindEvents();
|
||||
},
|
||||
// Bind Event Listeners
|
||||
//
|
||||
// Bind any events that are required on startup. Common events are:
|
||||
// 'load', 'deviceready', 'offline', and 'online'.
|
||||
bindEvents: function() {
|
||||
document.addEventListener('deviceready', this.onDeviceReady, false);
|
||||
|
||||
},
|
||||
// deviceready Event Handler
|
||||
//
|
||||
// The scope of 'this' is the event. In order to call the 'receivedEvent'
|
||||
// function, we must explicitly call 'app.receivedEvent(...);'
|
||||
onDeviceReady: function() {
|
||||
app.receivedEvent('deviceready');
|
||||
btnPortrait.addEventListener("click", function() {
|
||||
// alert('Orientation is ' + screen.orientation);
|
||||
screen.lockOrientation('portrait').then(function(obj) {
|
||||
console.log(obj);
|
||||
}).catch(function(obj) {
|
||||
console.log(obj);
|
||||
});
|
||||
});
|
||||
btnLandscape.addEventListener("click", function() {
|
||||
// alert('Orientation is ' + screen.orientation);
|
||||
screen.lockOrientation('landscape').then(function(obj) {
|
||||
console.log(obj);
|
||||
}).catch(function(obj) {
|
||||
console.log(obj);
|
||||
});
|
||||
});
|
||||
btnPortPrimary.addEventListener("click", function() {
|
||||
// alert('Orientation is ' + screen.orientation);
|
||||
screen.lockOrientation('portrait-primary').then(function(obj) {
|
||||
console.log(obj);
|
||||
}).catch(function(obj) {
|
||||
console.log(obj);
|
||||
});
|
||||
});
|
||||
btnLandPrimary.addEventListener("click", function() {
|
||||
// alert('Orientation is ' + screen.orientation);
|
||||
screen.lockOrientation('landscape-primary').then(function(obj) {
|
||||
console.log(obj);
|
||||
}).catch(function(obj) {
|
||||
console.log(obj);
|
||||
});
|
||||
});
|
||||
btnAny.addEventListener("click", function() {
|
||||
// alert('Orientation is ' + screen.orientation);
|
||||
screen.lockOrientation('any').then(function(obj) {
|
||||
console.log(obj);
|
||||
}).catch(function(obj) {
|
||||
console.log(obj);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
// Update DOM on a Received Event
|
||||
receivedEvent: function(id) {
|
||||
var parentElement = document.getElementById(id);
|
||||
var listeningElement = parentElement.querySelector('.listening');
|
||||
var receivedElement = parentElement.querySelector('.received');
|
||||
|
||||
listeningElement.setAttribute('style', 'display:none;');
|
||||
receivedElement.setAttribute('style', 'display:block;');
|
||||
|
||||
console.log('Received Event: ' + id);
|
||||
}
|
||||
};
|
||||
|
||||
app.initialize();
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-screen-orientation",
|
||||
"version": "1.4.3-dev",
|
||||
"version": "2.0.0-dev",
|
||||
"description": "Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS, WP8, W8.1, and BB10.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
46
plugin.xml
46
plugin.xml
@ -14,12 +14,11 @@
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
-->
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-screen-orientation"
|
||||
version="1.4.3-dev">
|
||||
|
||||
version="2.0.0-dev">
|
||||
<name>Screen Orientation</name>
|
||||
<description>Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS, WP8, W8.1, and BB10.</description>
|
||||
<license>MIT</license>
|
||||
@ -34,30 +33,25 @@
|
||||
|
||||
<platform name="ios">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="YoikScreenOrientation">
|
||||
<param name="ios-package" value="YoikScreenOrientation" />
|
||||
<feature name="CDVOrientation">
|
||||
<param name="ios-package" value="CDVOrientation" />
|
||||
</feature>
|
||||
</config-file>
|
||||
<js-module src="www/screenorientation.ios.js" name="screenorientation.ios">
|
||||
<merges target="cordova.plugins.screenorientation" />
|
||||
</js-module>
|
||||
<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" />
|
||||
|
||||
<header-file src="src/ios/CDVOrientation.h" />
|
||||
<source-file src="src/ios/CDVOrientation.m" />
|
||||
|
||||
</platform>
|
||||
|
||||
<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="/*">
|
||||
<feature name="YoikScreenOrientation">
|
||||
<param name="android-package" value="net.yoik.cordova.plugins.screenorientation.YoikScreenOrientation" />
|
||||
<feature name="CDVOrientation">
|
||||
<param name="android-package" value="cordova.plugins.screenorientation.CDVOrientation" />
|
||||
</feature>
|
||||
</config-file>
|
||||
<js-module src="www/screenorientation.android.js" name="screenorientation.android">
|
||||
<merges target="cordova.plugins.screenorientation" />
|
||||
</js-module>
|
||||
|
||||
</platform>
|
||||
|
||||
<platform name="blackberry10">
|
||||
@ -70,21 +64,11 @@
|
||||
</js-module>
|
||||
</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">
|
||||
<js-module src="www/screenorientation.windows.js" name="screenorientation.windows">
|
||||
<merges target="cordova.plugins.screenorientation" />
|
||||
<js-module src="src/windows/CDVOrientationProxy.js" name="CDVOrientationProxy">
|
||||
<merges target="" />
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
|
@ -17,9 +17,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
package net.yoik.cordova.plugins.screenorientation;
|
||||
package cordova.plugins.screenorientation;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
@ -31,15 +31,14 @@ import android.app.Activity;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.util.Log;
|
||||
|
||||
public class YoikScreenOrientation extends CordovaPlugin {
|
||||
public class CDVOrientation extends CordovaPlugin {
|
||||
|
||||
private static final String TAG = "YoikScreenOrientation";
|
||||
|
||||
/**
|
||||
* Screen Orientation Constants
|
||||
*/
|
||||
|
||||
private static final String UNLOCKED = "unlocked";
|
||||
private static final String ANY = "any";
|
||||
private static final String PORTRAIT_PRIMARY = "portrait-primary";
|
||||
private static final String PORTRAIT_SECONDARY = "portrait-secondary";
|
||||
private static final String LANDSCAPE_PRIMARY = "landscape-primary";
|
||||
@ -66,7 +65,7 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
||||
|
||||
String action = args.optString(0);
|
||||
|
||||
if (action.equals("set")) {
|
||||
|
||||
|
||||
String orientation = args.optString(1);
|
||||
|
||||
@ -74,7 +73,7 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
||||
|
||||
Activity activity = cordova.getActivity();
|
||||
|
||||
if (orientation.equals(UNLOCKED)) {
|
||||
if (orientation.equals(ANY)) {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
} else if (orientation.equals(LANDSCAPE_PRIMARY)) {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
@ -93,9 +92,6 @@ public class YoikScreenOrientation extends CordovaPlugin {
|
||||
callbackContext.success();
|
||||
return true;
|
||||
|
||||
} else {
|
||||
callbackContext.error("ScreenOrientation not recognised");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -17,12 +17,15 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Cordova/CDVViewController.h>
|
||||
|
||||
@interface CDVViewController (UpdateSupportedOrientations)
|
||||
@interface CDVOrientation : CDVPlugin
|
||||
{}
|
||||
|
||||
- (void)updateSupportedOrientations:(NSArray *)orientations;
|
||||
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
||||
|
||||
@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
|
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;
|
||||
}
|
||||
}
|
||||
}
|
31
tests/plugin.xml
Normal file
31
tests/plugin.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:rim="http://www.blackberry.com/ns/widgets"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cordova-plugin-device-tests"
|
||||
version="1.0.0-dev">
|
||||
<name>Cordova Screen Orientation Plugin Tests</name>
|
||||
<license>Apache 2.0</license>
|
||||
|
||||
<js-module src="tests.js" name="tests">
|
||||
</js-module>
|
||||
</plugin>
|
@ -19,11 +19,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec'),
|
||||
screenOrientation = {};
|
||||
/* jshint jasmine: true */
|
||||
|
||||
screenOrientation.setOrientation = function(orientation) {
|
||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
||||
exports.defineAutoTests = function() {
|
||||
describe('Orientation Information (window.orientation)', function () {
|
||||
it("should exist", function() {
|
||||
expect(window.orientation).toBeDefined();
|
||||
});
|
||||
|
||||
it("should contain a platform specification that is a string", function() {
|
||||
expect(window.orientation).toBeDefined();
|
||||
expect((String(window.orientation.type)).length > 0).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
@ -1,3 +1,4 @@
|
||||
cordova.define("cordova-plugin-screen-orientation.screenorientation", function(require, exports, module) {
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
@ -17,9 +18,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
var screenOrientation = {},
|
||||
var screenOrientation = {},
|
||||
Orientations = [
|
||||
'portrait-primary',
|
||||
// The orientation is in the primary portrait mode.
|
||||
@ -31,42 +32,79 @@ var screenOrientation = {},
|
||||
// The orientation is in the secondary landscape mode.
|
||||
'portrait',
|
||||
// The orientation is either portrait-primary or portrait-secondary.
|
||||
'landscape'
|
||||
'landscape',
|
||||
// The orientation is either landscape-primary or landscape-secondary.
|
||||
'any'
|
||||
// All orientations are supported (unlocked orientation)
|
||||
];
|
||||
|
||||
screenOrientation.Orientations = Orientations;
|
||||
screenOrientation.currOrientation = 'unlocked';
|
||||
screenOrientation.Orientations = Orientations;
|
||||
screenOrientation.currOrientation = 'any';
|
||||
var orientationMask = 0;
|
||||
screenOrientation.setOrientation = function(orientation) {
|
||||
if(orientation == Orientations[0]){
|
||||
orientationMask = 1;
|
||||
}
|
||||
else if(orientation == Orientations[1]){
|
||||
orientationMask = 2;
|
||||
}
|
||||
else if(orientation == Orientations[2]){
|
||||
orientationMask = 4;
|
||||
}
|
||||
else if(orientation == Orientations[3]){
|
||||
orientationMask = 8;
|
||||
}
|
||||
else if(orientation == Orientations[4]){
|
||||
orientationMask = 3;
|
||||
}
|
||||
else if(orientation == Orientations[5]){
|
||||
orientationMask = 12;
|
||||
}
|
||||
else if(orientation == Orientations[6]){
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
screenObject.lockOrientation = function(orientation) {
|
||||
|
||||
var p = new Promise(function(resolve,reject){
|
||||
if (Orientations.indexOf(orientation) == -1) {
|
||||
console.log('INVALID ORIENTATION', orientation);
|
||||
return;
|
||||
var err = new Error();
|
||||
err.name = "NotSupportedError";
|
||||
|
||||
reject(err);//"cannot change orientation");
|
||||
|
||||
}
|
||||
else {
|
||||
screenOrientation.currOrientation = screenObject.orientation = orientation;
|
||||
screenOrientation.setOrientation(orientation);
|
||||
resolve("Orientation set"); // orientation change successful
|
||||
}
|
||||
});
|
||||
return p;
|
||||
|
||||
|
||||
};
|
||||
|
||||
screenObject.unlockOrientation = function() {
|
||||
screenOrientation.currOrientation = screenObject.orientation = 'unlocked';
|
||||
screenOrientation.setOrientation('unlocked');
|
||||
screenOrientation.currOrientation = screenObject.orientation = 'any';
|
||||
screenOrientation.setOrientation('any');
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
addScreenOrientationApi(screen);
|
||||
orientationChange();
|
||||
addScreenOrientationApi(screen);
|
||||
orientationChange();
|
||||
|
||||
function orientationChange() {
|
||||
function orientationChange() {
|
||||
var orientation;
|
||||
|
||||
switch (window.orientation) {
|
||||
@ -83,12 +121,14 @@ function orientationChange() {
|
||||
orientation = 'landscape-secondary';
|
||||
break;
|
||||
default:
|
||||
orientation = 'unknown';
|
||||
orientation = 'any';
|
||||
}
|
||||
|
||||
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