diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..53bc614 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md old mode 100644 new mode 100755 index fe7bb0d..fc4a895 --- a/README.md +++ b/README.md @@ -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
+ +## Phonegap build service (config.xml) ## +https://build.phonegap.com/ - Apps - [specific project] - Update code - Zip file including config.xml +```c + +``` + +## Construct2 ## +Download construct2 plugin
+https://dl.dropboxusercontent.com/u/186681453/pluginsforcordova/index.html
+How to install c2 native plugins in xdk, cocoon and cordova cli
+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 # +example/basic/index.html
+example/advanced/index.html + +# Test # + +# Useful links # + +Cordova Plugins
+http://cranberrygame.github.io?referrer=github + +# Credits # diff --git a/example/advanced/index.html b/example/advanced/index.html new file mode 100755 index 0000000..6e0518f --- /dev/null +++ b/example/advanced/index.html @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/example/basic/index.html b/example/basic/index.html new file mode 100755 index 0000000..f901053 --- /dev/null +++ b/example/basic/index.html @@ -0,0 +1,17 @@ + + + + + + + + +

+ + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..c0b257a --- /dev/null +++ b/package.json @@ -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" +} diff --git a/plugin.xml b/plugin.xml new file mode 100755 index 0000000..2eb6c7a --- /dev/null +++ b/plugin.xml @@ -0,0 +1,32 @@ + + + + Cordova NavigationBar plugin + hide and auto hide navigation bar. + Sang Ki Kwon (Cranberrygame) + MIT + cordova, plugin, navigationbar + https://github.com/cranberrygame/cordova-plugin-navigationbar + https://github.com/cranberrygame/cordova-plugin-navigationbar/issues + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/android/NavigationBar.java b/src/android/NavigationBar.java new file mode 100755 index 0000000..9c6e9ec --- /dev/null +++ b/src/android/NavigationBar.java @@ -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 + ); + } +} \ No newline at end of file diff --git a/www/navigationbar.js b/www/navigationbar.js new file mode 100755 index 0000000..d27ff99 --- /dev/null +++ b/www/navigationbar.js @@ -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', + [] + ); + } +};