Initial commit

This commit is contained in:
2018-09-22 10:44:38 +08:00
commit eacb95c18a
723 changed files with 100993 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
Copyright (c) 2014, Mesmotronic Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,99 @@
Full Screen Plugin for Cordova
==============================
Plugin for Cordova (or PhoneGap) 3.0+ to enable true full screen on Android devices using lean and immersive modes, ported from our popular [ANE for Adobe AIR](https://github.com/mesmotronic/air-ane-fullscreen).
Released under BSD license; see LICENSE for details.
How does it work?
-----------------
This plugin enables developers to offer users a true full screen experience in their Cordova and PhoneGap apps for Android.
Using Android 4.0+, you can use true full screen in "lean mode", the way you see in apps like YouTube, expanding the app right to the edges of the screen, hiding the status and navigation bars until the user next interacts. This is ideally suited to video or cut-scene content.
In Android 4.4+, however, you can now enter true full screen, fully interactive immersive mode. In this mode, your app will remain in true full screen until you choose otherwise; users can swipe down from the top of the screen to temporarily display the system UI.
If you find that the plugin doesn't work as you might like on a specific device or Android configuration you're using, don't forget that this project is open source, so feel free to fork the project and adapt it to work in any way you like!
Installation
------------
**Cordova**
`cordova plugin add cordova-plugin-fullscreen`
**PhoneGap**
`phonegap local plugin add cordova-plugin-fullscreen`
Notes
-----
From version 1.0.2, the plugin ID has changed to `cordova-plugin-fullscreen` in line with the official Cordova plugin naming coventions following the switch to NPM. We therefore recommend that any previous version be uninstalled before upgrading to this release.
Since the release of `android@5.0.0`, setting `<preference name="Fullscreen" value="true" />` in `config.xml` will use immersive mode, where available, even without this plugin.
Code example
------------
Using the plugin in your app couldn't be easier:
```js
function successFunction()
{
console.info("It worked!");
}
function errorFunction(error)
{
console.error(error);
}
function trace(value)
{
console.log(value);
}
// Is this plugin supported?
AndroidFullScreen.isSupported(supportedFunction, errorFunction);
// Is immersive mode supported?
AndroidFullScreen.isImmersiveModeSupported(successFunction, errorFunction);
// The width of the screen in immersive mode
AndroidFullScreen.immersiveWidth(trace, errorFunction);
// The height of the screen in immersive mode
AndroidFullScreen.immersiveHeight(trace, errorFunction);
// Hide system UI until user interacts
AndroidFullScreen.leanMode(successFunction, errorFunction);
// Show system UI
AndroidFullScreen.showSystemUI(successFunction, errorFunction);
// Extend your app underneath the status bar (Android 4.4+ only)
AndroidFullScreen.showUnderStatusBar(successFunction, errorFunction);
// Extend your app underneath the system UI (Android 4.4+ only)
AndroidFullScreen.showUnderSystemUI(successFunction, errorFunction);
// Hide system UI and keep it hidden (Android 4.4+ only)
AndroidFullScreen.immersiveMode(successFunction, errorFunction);
// Custom full screen mode
// See https://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)
AndroidFullScreen.setSystemUiVisibility(AndroidFullScreen.SYSTEM_UI_FLAG_FULLSCREEN | AndroidFullScreen.SYSTEM_UI_FLAG_LOW_PROFILE, successFunction, errorFunction);
```
All methods will call the successFunction callback if the action was successful and the errorFunction if it wasn't (or isn't supported); if you're using the plugin in an app for a platform other than Android, all methods will fail.
The `immersiveWidth` and `immersiveHeight` properties return the screen width and height available in immersive mode (or with the system UI hidden), where supported.
Getting the immersive screen size
---------------------------------
You can use the `immersiveWidth` and `immersiveHeight` methods to find out the dimensions of the screen with the system UI hidden, regardless of the current screen state.
@@ -0,0 +1 @@
You need to install the plugin before running the example.
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.mesmotronic.fullscreen.test" version="0.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Cordova Full Screen Test</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<!-- <preference name="Fullscreen" value="false" /> -->
</widget>
@@ -0,0 +1,83 @@
<!--
#
# 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.
#
-->
# Cordova Hooks
This directory may contain scripts used to customize cordova commands. This
directory used to exist at `.cordova/hooks`, but has now been moved to the
project root. Any scripts you add to these directories will be executed before
and after the commands corresponding to the directory name. Useful for
integrating your own build systems or integrating with version control systems.
__Remember__: Make your scripts executable.
## Hook Directories
The following subdirectories will be used for hooks:
after_build/
after_compile/
after_docs/
after_emulate/
after_platform_add/
after_platform_rm/
after_platform_ls/
after_plugin_add/
after_plugin_ls/
after_plugin_rm/
after_plugin_search/
after_prepare/
after_run/
after_serve/
before_build/
before_compile/
before_docs/
before_emulate/
before_platform_add/
before_platform_rm/
before_platform_ls/
before_plugin_add/
before_plugin_ls/
before_plugin_rm/
before_plugin_search/
before_prepare/
before_run/
before_serve/
pre_package/ <-- Windows 8 and Windows Phone only.
## Script Interface
All scripts are run from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
* CORDOVA_VERSION - The version of the Cordova-CLI.
* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
* CORDOVA_HOOK - Path to the hook that is being executed.
* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
If a script returns a non-zero exit code, then the parent cordova command will be aborted.
## Writing hooks
We highly recommend writting your hooks using Node.js so that they are
cross-platform. Some good examples are shown here:
[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
@@ -0,0 +1,92 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<meta name="msapplication-tap-highlight" content="no" />
<title>Full Screen Example</title>
<style type="text/css">
body, html
{
margin: 4px;
padding: 0;
position: relative;
}
button
{
display: block;
width: 100%;
height: 42px;
margin-bottom: 4px;
font-size: 18px;
}
</style>
</head>
<body>
<h1>Android 4.0+</h1>
<button id="leanModeButton">Lean Mode</button>
<button id="showUiButton">Show UI</button>
<button id="customButton">Custom Mode</button>
<h1>Android 4.4+</h1>
<button id="immersiveModeButton">Immersive Mode</button>
<button id="showUnderUiButton">Show Under UI</button>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
function successFunction()
{
console.log("It worked!");
}
function errorFunction(error)
{
console.error(error);
}
function leanMode()
{
AndroidFullScreen.leanMode(successFunction, errorFunction);
}
function immersiveMode()
{
AndroidFullScreen.immersiveMode(successFunction, errorFunction);
}
function showUnderSystemUI()
{
AndroidFullScreen.showUnderSystemUI(successFunction, errorFunction);
}
function showSystemUI()
{
AndroidFullScreen.showSystemUI(successFunction, errorFunction);
}
function setSystemUiVisibility()
{
AndroidFullScreen.setSystemUiVisibility(AndroidFullScreen.SYSTEM_UI_FLAG_FULLSCREEN | AndroidFullScreen.SYSTEM_UI_FLAG_LOW_PROFILE, successFunction, errorFunction);
}
function deviceReady()
{
document.getElementById('leanModeButton').addEventListener('click', leanMode);
document.getElementById('immersiveModeButton').addEventListener('click', immersiveMode)
document.getElementById('showUnderUiButton').addEventListener('click', showUnderSystemUI);
document.getElementById('showUiButton').addEventListener('click', showSystemUI);
document.getElementById('customButton').addEventListener('click', setSystemUiVisibility);
}
document.addEventListener('deviceready', deviceReady);
</script>
</body>
</html>
@@ -0,0 +1,101 @@
{
"_args": [
[
{
"raw": "cordova-plugin-fullscreen",
"scope": null,
"escapedName": "cordova-plugin-fullscreen",
"name": "cordova-plugin-fullscreen",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"D:\\pWork\\yunkong2.vis.cordova\\node_modules"
]
],
"_from": "cordova-plugin-fullscreen@latest",
"_id": "cordova-plugin-fullscreen@1.2.0",
"_inCache": true,
"_location": "/cordova-plugin-fullscreen",
"_nodeVersion": "6.11.2",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/cordova-plugin-fullscreen-1.2.0.tgz_1502480881540_0.3836044427007437"
},
"_npmUser": {
"name": "mesmotronic",
"email": "npm.support@mesmotronic.com"
},
"_npmVersion": "5.3.0",
"_phantomChildren": {},
"_requested": {
"raw": "cordova-plugin-fullscreen",
"scope": null,
"escapedName": "cordova-plugin-fullscreen",
"name": "cordova-plugin-fullscreen",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#USER"
],
"_resolved": "https://registry.npmjs.org/cordova-plugin-fullscreen/-/cordova-plugin-fullscreen-1.2.0.tgz",
"_shasum": "482b38e881715e1fc812d6c35bea1072efb424a7",
"_shrinkwrap": null,
"_spec": "cordova-plugin-fullscreen",
"_where": "D:\\pWork\\yunkong2.vis.cordova\\node_modules",
"author": {
"name": "Neil Rackett"
},
"bugs": {
"url": "https://github.com/mesmotronic/cordova-fullscreen-plugin/issues"
},
"cordova": {
"id": "cordova-plugin-fullscreen",
"platforms": [
"android"
]
},
"dependencies": {},
"description": "Plugin for Cordova (or PhoneGap) 3.0+ to enable true full screen on Android devices using lean and immersive modes",
"devDependencies": {},
"directories": {},
"dist": {
"integrity": "sha512-cl8mE1MoTjv4JlwV6dw3nOc7Qj18WuNJLf2jHWUmRTYzCI/SW9ym/ghSVvonTVnaoECuHrOpmAfUoFzbb8kf2Q==",
"shasum": "482b38e881715e1fc812d6c35bea1072efb424a7",
"tarball": "https://registry.npmjs.org/cordova-plugin-fullscreen/-/cordova-plugin-fullscreen-1.2.0.tgz"
},
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"gitHead": "c17032965a56c59ae9d4f5fdbccd85406ebec605",
"homepage": "https://github.com/mesmotronic/cordova-fullscreen-plugin#readme",
"keywords": [
"cordova",
"android",
"fullscreen",
"lean",
"immersive",
"ecosystem:cordova",
"cordova-android"
],
"license": "BSD",
"maintainers": [
{
"name": "mesmotronic",
"email": "npm.support@mesmotronic.com"
}
],
"name": "cordova-plugin-fullscreen",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/mesmotronic/cordova-fullscreen-plugin.git"
},
"version": "1.2.0"
}
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015, Mesmotronic Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the organization nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-fullscreen"
version="1.1.0"
>
<name>cordova-plugin-fullscreen</name>
<description>Plugin for Cordova (or PhoneGap) 3.0+ to enable true full screen on Android devices using lean and immersive modes</description>
<keywords>cordova,android,fullscreen,lean,immersive,statusbar</keywords>
<repo>https://github.com/mesmotronic/cordova-fullscreen-plugin.git</repo>
<license>BSD</license>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<js-module
src="www/AndroidFullScreen.js"
name="AndroidFullScreen"
>
<clobbers target="AndroidFullScreen" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="AndroidFullScreen">
<param
name="android-package"
value="com.mesmotronic.plugins.FullScreenPlugin"
/>
</feature>
</config-file>
<source-file
src="src/android/com/mesmotronic/plugins/FullScreenPlugin.java"
target-dir="src/com/mesmotronic/plugins"
/>
</platform>
</plugin>
@@ -0,0 +1,503 @@
package com.mesmotronic.plugins;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.graphics.Point;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.graphics.Color;
import android.os.Handler;
public class FullScreenPlugin extends CordovaPlugin
{
public static final String ACTION_IS_SUPPORTED = "isSupported";
public static final String ACTION_IS_IMMERSIVE_MODE_SUPPORTED = "isImmersiveModeSupported";
public static final String ACTION_IMMERSIVE_WIDTH = "immersiveWidth";
public static final String ACTION_IMMERSIVE_HEIGHT = "immersiveHeight";
public static final String ACTION_LEAN_MODE = "leanMode";
public static final String ACTION_SHOW_SYSTEM_UI = "showSystemUI";
public static final String ACTION_SHOW_UNDER_STATUS_BAR = "showUnderStatusBar";
public static final String ACTION_SHOW_UNDER_SYSTEM_UI = "showUnderSystemUI";
public static final String ACTION_IMMERSIVE_MODE = "immersiveMode";
public static final String ACTION_SET_SYSTEM_UI_VISIBILITY = "setSystemUiVisibility";
private CallbackContext context;
private Activity activity;
private Window window;
private View decorView;
private int mLastSystemUIVisibility = 0;
private final Handler mLeanBackHandler = new Handler();
private final Runnable mEnterLeanback = new Runnable() {
@Override
public void run() {
leanMode();
}
};
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param cordova The context of the main Activity.
* @param webView The CordovaWebView Cordova is running in.
*/
@Override
public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
super.initialize(cordova, webView);
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
// by the Cordova.
Window window = cordova.getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
}
});
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException
{
context = callbackContext;
activity = cordova.getActivity();
window = activity.getWindow();
decorView = window.getDecorView();
if (ACTION_IS_SUPPORTED.equals(action))
return isSupported();
else if (ACTION_IS_IMMERSIVE_MODE_SUPPORTED.equals(action))
return isImmersiveModeSupported();
else if (ACTION_IMMERSIVE_WIDTH.equals(action))
return immersiveWidth();
else if (ACTION_IMMERSIVE_HEIGHT.equals(action))
return immersiveHeight();
else if (ACTION_LEAN_MODE.equals(action))
return leanMode();
else if (ACTION_SHOW_SYSTEM_UI.equals(action))
return showSystemUI();
else if (ACTION_SHOW_UNDER_STATUS_BAR.equals(action))
return showUnderStatusBar();
else if (ACTION_SHOW_UNDER_SYSTEM_UI.equals(action))
return showUnderSystemUI();
else if (ACTION_IMMERSIVE_MODE.equals(action))
return immersiveMode();
else if (ACTION_SET_SYSTEM_UI_VISIBILITY.equals(action))
return setSystemUiVisibility(args.getInt(0));
return false;
}
protected void resetWindow()
{
decorView.setOnFocusChangeListener(null);
decorView.setOnSystemUiVisibilityChangeListener(null);
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
/**
* Are any of the features of this plugin supported?
*/
protected boolean isSupported()
{
boolean supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
PluginResult res = new PluginResult(PluginResult.Status.OK, supported);
context.sendPluginResult(res);
return supported;
}
/**
* Is immersive mode supported?
*/
protected boolean isImmersiveModeSupported()
{
boolean supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
PluginResult res = new PluginResult(PluginResult.Status.OK, supported);
context.sendPluginResult(res);
return supported;
}
/**
* The width of the screen in immersive mode
*/
protected boolean immersiveWidth()
{
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
Point outSize = new Point();
decorView.getDisplay().getRealSize(outSize);
PluginResult res = new PluginResult(PluginResult.Status.OK, outSize.x);
context.sendPluginResult(res);
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
/**
* The height of the screen in immersive mode
*/
protected boolean immersiveHeight()
{
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
Point outSize = new Point();
decorView.getDisplay().getRealSize(outSize);
PluginResult res = new PluginResult(PluginResult.Status.OK, outSize.y);
context.sendPluginResult(res);
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
/**
* Hide system UI until user interacts
*/
protected boolean leanMode()
{
if (!isSupported())
{
context.error("Not supported");
return false;
}
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
resetWindow();
int uiOptions =
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
mLastSystemUIVisibility = uiOptions;
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility)
{
if((mLastSystemUIVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
&& (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
resetHideTimer();
}
mLastSystemUIVisibility = visibility;
}
});
decorView.setSystemUiVisibility(uiOptions);
context.success();
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
private void resetHideTimer() {
// First cancel any queued events - i.e. resetting the countdown clock
mLeanBackHandler.removeCallbacks(mEnterLeanback);
// And fire the event in 3s time
mLeanBackHandler.postDelayed(mEnterLeanback, 3000);
}
/**
* Show system UI
*/
protected boolean showSystemUI()
{
if (!isSupported())
{
context.error("Not supported");
return false;
}
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
resetWindow();
// Remove translucent theme from bars
window.clearFlags
(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
);
// Update system UI
decorView.setOnSystemUiVisibilityChangeListener(null);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
PluginResult res = new PluginResult(PluginResult.Status.OK, true);
context.sendPluginResult(res);
context.success();
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
/**
* Extend your app underneath the status bar (Android 4.4+ only)
*/
protected boolean showUnderStatusBar()
{
if (!isImmersiveModeSupported())
{
context.error("Not supported");
return false;
}
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
resetWindow();
// Make the status bar translucent
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// Extend view underneath status bar
int uiOptions =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
context.success();
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
/**
* Extend your app underneath the system UI (Android 4.4+ only)
*/
protected boolean showUnderSystemUI()
{
if (!isImmersiveModeSupported())
{
context.error("Not supported");
return false;
}
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
resetWindow();
// Make the status and nav bars translucent
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// Extend view underneath status and nav bars
int uiOptions =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
context.success();
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
/**
* Hide system UI and switch to immersive mode (Android 4.4+ only)
*/
protected boolean immersiveMode()
{
if (!isImmersiveModeSupported())
{
context.error("Not supported");
return false;
}
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
resetWindow();
final int uiOptions =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
decorView.setSystemUiVisibility(uiOptions);
decorView.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus)
{
decorView.setSystemUiVisibility(uiOptions);
}
}
});
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility)
{
decorView.setSystemUiVisibility(uiOptions);
}
});
context.success();
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
protected boolean setSystemUiVisibility(final int visibility)
{
if (!isSupported())
{
context.error("Not supported");
return false;
}
activity.runOnUiThread(new Runnable()
{
@Override
public void run()
{
try
{
resetWindow();
decorView.setSystemUiVisibility(visibility);
context.success();
}
catch (Exception e)
{
context.error(e.getMessage());
}
}
});
return true;
}
private void setStatusBarBackgroundColor(final String colorPref) {
if (Build.VERSION.SDK_INT >= 21) {
if (colorPref != null && !colorPref.isEmpty()) {
final Window window = cordova.getActivity().getWindow();
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
try {
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref));
} catch (IllegalArgumentException ignore) {
} catch (Exception ignore) {
}
}
}
}
}
@@ -0,0 +1,79 @@
(function(window, undefined)
{
'use strict';
var AndroidFullScreen =
{
SYSTEM_UI_FLAG_FULLSCREEN: 4,
SYSTEM_UI_FLAG_HIDE_NAVIGATION: 2,
SYSTEM_UI_FLAG_IMMERSIVE: 2048,
SYSTEM_UI_FLAG_IMMERSIVE_STICKY: 4096,
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: 1024,
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION: 512,
SYSTEM_UI_FLAG_LAYOUT_STABLE: 256,
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR: 8192,
SYSTEM_UI_FLAG_LOW_PROFILE: 1,
SYSTEM_UI_FLAG_VISIBLE: 0,
isSupported: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'isSupported', []);
},
isImmersiveModeSupported: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'isImmersiveModeSupported', []);
},
immersiveWidth: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'immersiveWidth', []);
},
immersiveHeight: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'immersiveHeight', []);
},
leanMode: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'leanMode', []);
},
showSystemUI: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'showSystemUI', []);
},
showUnderStatusBar: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'showUnderStatusBar', []);
},
showUnderSystemUI: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'showUnderSystemUI', []);
},
immersiveMode: function(successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'immersiveMode', []);
},
/**
* @see https://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)
*/
setSystemUiVisibility: function(visibility, successFunction, errorFunction)
{
cordova.exec(successFunction, errorFunction, 'AndroidFullScreen', 'setSystemUiVisibility', [visibility || 0]);
}
};
cordova.addConstructor(function()
{
window.AndroidFullScreen = AndroidFullScreen;
return window.AndroidFullScreen;
});
})(window);