This commit is contained in:
Michel Jautzy 2017-06-23 16:00:01 +02:00
parent 62471975bd
commit 57afebfa4e
8 changed files with 386 additions and 1 deletions

23
LICENSE Executable file
View File

@ -0,0 +1,23 @@
The MIT License
Copyright (c) 2014 Sang Ki Kwon (Cranberrygame)
Email: cranberrygame@yahoo.com
Homepage: http://www.github.com/cranberrygame
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

71
README.md Normal file → Executable file
View File

@ -1 +1,70 @@
# My project's README
Cordova NavigationBar plugin
====================
# Overview #
Hide and auto hide navigation bar.
[android] [cordova cli] [xdk] [cocoon] [phonegap build service]
This is open source cordova plugin.
You can see Cordova Plugins in one page: http://cranberrygame.github.io?referrer=github
# Change log #
```c
```
# Install plugin #
## Cordova cli ##
https://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface - npm install -g cordova@6.0.0
```c
cordova plugin add cordova-plugin-navigationbar
(when build error, use github url: cordova plugin add https://github.com/cranberrygame/cordova-plugin-navigationbar)
```
## Xdk ##
https://software.intel.com/en-us/intel-xdk - Download XDK - XDK PORJECTS - [specific project] - CORDOVA HYBRID MOBILE APP SETTINGS - Plugin Management - Add Plugins to this Project - Third Party Plugins -
```c
Plugin Source: Cordova plugin registry
Plugin ID: cordova-plugin-navigationbar
## Cocoon ##
https://cocoon.io - Create project - [specific project] - Setting - Plugins - Custom - Git Url: https://github.com/cranberrygame/cordova-plugin-navigationbar.git - INSTALL - Save<br>
## Phonegap build service (config.xml) ##
https://build.phonegap.com/ - Apps - [specific project] - Update code - Zip file including config.xml
```c
<gap:plugin name="cordova-plugin-navigationbar" source="npm" />
```
## Construct2 ##
Download construct2 plugin<br>
https://dl.dropboxusercontent.com/u/186681453/pluginsforcordova/index.html<br>
How to install c2 native plugins in xdk, cocoon and cordova cli<br>
https://plus.google.com/102658703990850475314/posts/XS5jjEApJYV
# Server setting #
```c
```
# API #
```javascript
document.addEventListener("deviceready", function(){
var autoHideNavigationBar = false;
window.navigationbar.setUp(autoHideNavigationBar);
}, false);
window.navigationbar.hide();
```
# Examples #
<a href="https://github.com/cranberrygame/cordova-plugin-navigationbar/blob/master/example/basic/index.html">example/basic/index.html</a><br>
<a href="https://github.com/cranberrygame/cordova-plugin-navigationbar/blob/master/example/advanced/index.html">example/advanced/index.html</a>
# Test #
# Useful links #
Cordova Plugins<br>
http://cranberrygame.github.io?referrer=github
# Credits #

15
example/advanced/index.html Executable file
View File

@ -0,0 +1,15 @@
<html>
<head>
<script type="text/javascript" src="cordova.js"></script>
</head>
<body>
<script>
document.addEventListener("deviceready", function(){
var autoHideNavigationBar = true;
window.navigationbar.setUp(autoHideNavigationBar);
}, false);
</script>
</body>
</html>

17
example/basic/index.html Executable file
View File

@ -0,0 +1,17 @@
<html>
<head>
<script type="text/javascript" src="cordova.js"></script>
</head>
<body>
<script>
document.addEventListener("deviceready", function(){
var autoHideNavigationBar = false;
window.navigationbar.setUp(autoHideNavigationBar);
}, false);
</script>
<p><button onclick="window.navigationbar.hide();">hide</button></p>
</body>
</html>

34
package.json Normal file
View File

@ -0,0 +1,34 @@
{
"name": "cordova-plugin-navigationbar",
"version": "1.0.31",
"description": "hide and auto hide navigation bar.",
"cordova": {
"id": "cordova-plugin-navigationbar",
"platforms": [
"android"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/cranberrygame/cordova-plugin-navigationbar.git"
},
"keywords": [
"cordova",
"plugin",
"navigationbar",
"ecosystem:cordova",
"cordova-android"
],
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"author": "cranberrygame",
"license": "MIT",
"bugs": {
"url": "https://github.com/cranberrygame/cordova-plugin-navigationbar/issues"
},
"homepage": "https://github.com/cranberrygame/cordova-plugin-navigationbar#readme"
}

32
plugin.xml Executable file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-navigationbar"
version="1.0.31">
<name>Cordova NavigationBar plugin</name>
<description>hide and auto hide navigation bar.</description>
<author>Sang Ki Kwon (Cranberrygame)</author>
<license>MIT</license>
<keywords>cordova, plugin, navigationbar</keywords>
<repo>https://github.com/cranberrygame/cordova-plugin-navigationbar</repo>
<issue>https://github.com/cranberrygame/cordova-plugin-navigationbar/issues</issue>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<js-module src="www/navigationbar.js" name="navigationbar">
<clobbers target="window.navigationbar" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="NavigationBar" >
<param name="android-package" value="com.cranberrygame.cordova.plugin.navigationbar.NavigationBar"/>
</feature>
</config-file>
<source-file src="src/android/NavigationBar.java" target-dir="src/com/cranberrygame/cordova/plugin/navigationbar" />
</platform>
</plugin>

174
src/android/NavigationBar.java Executable file
View File

@ -0,0 +1,174 @@
//Copyright (c) 2014 Sang Ki Kwon (Cranberrygame)
//Email: cranberrygame@yahoo.com
//Homepage: http://www.github.com/cranberrygame
//License: MIT (http://opensource.org/licenses/MIT)
package com.cranberrygame.cordova.plugin.navigationbar;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.util.Log;
//
import android.view.View;
import android.os.Handler;
//
import java.lang.reflect.Method;
public class NavigationBar extends CordovaPlugin {
private static final String LOG_TAG = "NavigationBar";
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
}
@Override
public boolean execute(String action, JSONArray args,CallbackContext callbackContext) throws JSONException {
PluginResult result = null;
//args.length()
//args.getString(0)
//args.getString(1)
//args.getInt(0)
//args.getInt(1)
//args.getBoolean(0)
//args.getBoolean(1)
//JSONObject json = args.optJSONObject(0);
//json.optString("adUnit")
//json.optString("adUnitFullScreen")
//JSONObject inJson = json.optJSONObject("inJson");
if (action.equals("setUp")) {
//Activity activity = cordova.getActivity();
//webView
//
final boolean autoHideNavigationBar = args.getBoolean(0);
final CallbackContext delayedCC = callbackContext;
cordova.getActivity().runOnUiThread(new Runnable(){
@Override
public void run() {
_setUp(autoHideNavigationBar);
PluginResult pr = new PluginResult(PluginResult.Status.OK);
//pr.setKeepCallback(true);
delayedCC.sendPluginResult(pr);
//PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
//pr.setKeepCallback(true);
//delayedCC.sendPluginResult(pr);
}
});
return true;
}
else if (action.equals("hideNavigationBar")) {
//Activity activity=cordova.getActivity();
//webView
//
final CallbackContext delayedCC = callbackContext;
cordova.getActivity().runOnUiThread(new Runnable(){
@Override
public void run() {
_hideNavigationBar();
PluginResult pr = new PluginResult(PluginResult.Status.OK);
//pr.setKeepCallback(true);
delayedCC.sendPluginResult(pr);
//PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
//pr.setKeepCallback(true);
//delayedCC.sendPluginResult(pr);
}
});
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
//-------------------------------------
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void _setUp(boolean autoHideNavigationBar){
if (autoHideNavigationBar) {
Activity activity=cordova.getActivity();
//http://stackoverflow.com/questions/21164836/immersive-mode-navigation-becomes-sticky-after-volume-press-or-minimise-restore
//http://www.youtube.com/watch?v=Xw9TIS_JsPM
//https://developer.android.com/training/system-ui/status.html
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
final CordovaInterface cordova_final = cordova;
//http://stackoverflow.com/questions/11762306/listen-for-first-touchevent-when-using-system-ui-flag-hide-navigation
//http://stackoverflow.com/questions/15103339/android-full-screen-modeics-first-touch-shows-the-navigation-bar
//http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html
//webView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener(){//cordova5 build error
getView(webView).setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener(){//fixed cordova5 build error
@Override
public void onSystemUiVisibilityChange(int vis) {
if(vis == 0){
//http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Activity activity=cordova_final.getActivity();
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}, 3000);//after ms
}
}
});
}
}
public static View getView(CordovaWebView webView) {
if(View.class.isAssignableFrom(CordovaWebView.class)) {
return (View) webView;
}
try {
Method getViewMethod = CordovaWebView.class.getMethod("getView", (Class<?>[]) null);
if(getViewMethod != null) {
Object[] args = {};
return (View) getViewMethod.invoke(webView, args);
}
}
catch (Exception e) {
}
return null;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void _hideNavigationBar(){
Activity activity=cordova.getActivity();
activity.getWindow().getDecorView().setSystemUiVisibility(
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
);
}
}

21
www/navigationbar.js Executable file
View File

@ -0,0 +1,21 @@
module.exports = {
setUp: function(autoHideNavigationBar, successCallback, errorCallback) {
cordova.exec(
successCallback,
errorCallback,
'NavigationBar',
'setUp',
[autoHideNavigationBar]
);
},
hideNavigationBar: function(successCallback, errorCallback) {
cordova.exec(
successCallback,
errorCallback,
'NavigationBar',
'hideNavigationBar',
[]
);
}
};