changes
This commit is contained in:
parent
57afebfa4e
commit
294299aa97
|
@ -16,6 +16,8 @@ import android.annotation.TargetApi;
|
|||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.content.Context;
|
||||
|
||||
//
|
||||
import android.view.View;
|
||||
import android.os.Handler;
|
||||
|
@ -23,152 +25,182 @@ import android.os.Handler;
|
|||
import java.lang.reflect.Method;
|
||||
|
||||
public class NavigationBar extends CordovaPlugin {
|
||||
private static final String LOG_TAG = "NavigationBar";
|
||||
private static final String LOG_TAG = "NavigationBar";
|
||||
public int pixelHeight = 0;
|
||||
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
super.initialize(cordova, webView);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args,CallbackContext callbackContext) throws JSONException {
|
||||
PluginResult result = null;
|
||||
@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");
|
||||
//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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
});
|
||||
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
|
||||
//
|
||||
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();
|
||||
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);
|
||||
}
|
||||
});
|
||||
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 true;
|
||||
}
|
||||
else if (action.equals("softNavigationHeight")) {
|
||||
|
||||
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;
|
||||
}
|
||||
final CallbackContext delayedCC = callbackContext;
|
||||
cordova.getActivity().runOnUiThread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
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;
|
||||
}
|
||||
Activity mikeActivity=cordova.getActivity();
|
||||
Context context=mikeActivity.getApplicationContext();
|
||||
int resourceId = mikeActivity.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
|
||||
@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
|
||||
);
|
||||
}
|
||||
|
||||
int pixelHeight = 0;
|
||||
if (resourceId > 0) {
|
||||
pixelHeight = mikeActivity.getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
PluginResult pr = new PluginResult(PluginResult.Status.OK, pixelHeight);
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,5 +17,15 @@ module.exports = {
|
|||
'hideNavigationBar',
|
||||
[]
|
||||
);
|
||||
},
|
||||
softNavigationHeight: function(successCallback, errorCallback) {
|
||||
cordova.exec(
|
||||
successCallback,
|
||||
errorCallback,
|
||||
'NavigationBar',
|
||||
'softNavigationHeight',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Reference in New Issue