Java Code Examples for android.view.View#setOnSystemUiVisibilityChangeListener()

The following examples show how to use android.view.View#setOnSystemUiVisibilityChangeListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
protected void onResume() {
    super.onResume();
    MobclickAgent.onResume(this);

    // set navigation bar status, remember to disable "setNavigationBarTintEnabled"
    final int flags = 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_IMMERSIVE_STICKY;
    // This work only for android 4.4+
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().getDecorView().setSystemUiVisibility(flags);

        // Code below is to handle presses of Volume up or Volume down.
        // Without this, after pressing volume buttons, the navigation bar will
        // show up and won't hide
        final View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                decorView.setSystemUiVisibility(flags);
            }
        });
    }
}
 
Example 2
private void hideNavigationBar() {
    // This work only for android 4.4+
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // set navigation bar status, remember to disable "setNavigationBarTintEnabled"
        final int flags = 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_IMMERSIVE_STICKY;
        getWindow().getDecorView().setSystemUiVisibility(flags);

        // Code below is to handle presses of Volume up or Volume down.
        // Without this, after pressing volume buttons, the navigation bar will
        // show up and won't hide
        final View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                decorView.setSystemUiVisibility(flags);
            }
        });
    }
}
 
Example 3
private void showNavigationBar() {
    // This work only for android 4.4+
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // set navigation bar status, remember to disable "setNavigationBarTintEnabled"
        final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        getWindow().getDecorView().setSystemUiVisibility(flags);

        // Code below is to handle presses of Volume up or Volume down.
        // Without this, after pressing volume buttons, the navigation bar will
        // show up and won't hide
        final View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                decorView.setSystemUiVisibility(flags);
            }
        });
    }
}
 
Example 4
Source Project: glimmr   File: PhotoViewerFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void initUIVisibilityChangeListener() {
/* if user swipes down from immersive mode we need to know to reshow photo title etc. */
    View decorView = mActivity.getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener
            (new View.OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int visibility) {
                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                        BusProvider.getInstance().post(
                                new PhotoViewerVisibilityChangeEvent(
                                        true, PhotoViewerFragment.this)
                        );
                    }
                }
            });
}
 
Example 5
@Override
protected void onPause() {
    super.onPause();
    Log.d(TAG, "[F] Pause");
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(null);
    prefs().unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 6
Source Project: VIA-AI   File: Helper.java    License: MIT License 5 votes vote down vote up
public void setupAutoHideSystemUI(Window window) {
    final HideSystemUiRunnable runnable = new HideSystemUiRunnable();
    runnable.init(window);

    sHandler = new Handler();
    sHandler.post(runnable); // hide the navigation bar
    final View decorView = window.getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            sHandler.post(runnable); // hide the navigation bar
        }
    });
}
 
Example 7
Source Project: Speculum-Android   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private void hideSystemUI() {
    View mDecorView = getWindow().getDecorView();
    mDecorView.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 // hide nav bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    mDecorView.setOnSystemUiVisibilityChangeListener(this);
}
 
Example 8
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final View decorView = getActivity().getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(
            new View.OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int i) {
                    int height = decorView.getHeight();
                    Log.i(TAG, "Current height: " + height);
                }
            });
}
 
Example 9
@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "[F] Resume");
    applyFullScreenPref();
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(this);
    prefs().registerOnSharedPreferenceChangeListener(this);
}
 
Example 10
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final View decorView = getActivity().getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(
            new View.OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int i) {
                    int height = decorView.getHeight();
                    Log.i(TAG, "Current height: " + height);
                }
            });
}
 
Example 11
/**
 * Set a listener to receive callbacks when the visibility of the system bar changes.
 *
 * @param view    the specific view to set listeners.
 * @param listner The {@link OnSystemUiVisibilityChangeListener} to receive callbacks.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setOnSystemUiVisibilityChangeListener(View view,
                                                         OnSystemUiVisibilityChangeListenerCompact listner) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return;
    }
    if (null == view) {
        throw new IllegalArgumentException("view may not be null.");
    }
    OnSystemUiVisibilityChangeListenerProxy listenerProxy = listner != null ? new OnSystemUiVisibilityChangeListenerProxy(
            listner)
            : null;
    view.setOnSystemUiVisibilityChangeListener(listenerProxy);
}
 
Example 12
private void addFullScreenListener() {
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(
            new View.OnSystemUiVisibilityChangeListener() {
                public void onSystemUiVisibilityChange(int visibility) {
                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                        setFullScreen();
                    }
                }
            });
}
 
Example 13
/**
 * This method creates a listener that will detect when immersive mode is
 * lost and get it back. Needs to be called again in onResume.
 */
@SuppressLint("NewApi")
private void UIChangeListener() {
	final View decorView = activity.getWindow().getDecorView();

	decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
		@Override
		public void onSystemUiVisibilityChange(int visibility) {
			if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
				decorView.setSystemUiVisibility(VISIBILITY);
			}
		}
	});
}
 
Example 14
public void setupWindowVisibilityFlags()
{
    final int flags = 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;
    //
    final View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
    {

        @Override
        public void onSystemUiVisibilityChange (int visibility)
        {
            if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
            {
                decorView.setSystemUiVisibility(flags);
            }
        }
    });
    //
    decorView.setSystemUiVisibility(flags);
    //
    // disable the lock screen when the app is running
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
 
Example 15
Source Project: TubiPlayer   File: Utils.java    License: MIT License 5 votes vote down vote up
public static void hideSystemUI(@NonNull final Activity activity, final boolean immediate, final int delayMs) {
    View decorView = activity.getWindow().getDecorView();
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    int uiState = 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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN; // hide status bar
    if (Util.SDK_INT > 18) {
        uiState |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_IMMERSIVE;
    } else {
        final Handler handler = new Handler();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if (visibility == View.VISIBLE) {
                    Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                            hideSystemUI(activity, false);
                        }
                    };
                    if (immediate) {
                        handler.post(runnable);
                    } else {
                        handler.postDelayed(runnable, delayMs);
                    }
                }
            }
        });
    }
    decorView.setSystemUiVisibility(uiState);
}
 
Example 16
Source Project: LEDView   File: LEDActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    fetchLEDData();
    PowerManager pm = (PowerManager)getSystemService(
            Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK,
            "led");
    mWakeLock.acquire();

    final View decorView = getWindow().getDecorView();
    final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int i) {
            if ((i & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        decorView.setSystemUiVisibility(uiOptions);
                    }
                },1000);

            } else {
            }
        }
    });
}
 
Example 17
Source Project: PHONK   File: BaseActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void lightsOutMode() {
    lightsOutMode = true;
    final View rootView = getWindow().getDecorView();
    rootView.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
    rootView.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);

    rootView.setOnSystemUiVisibilityChangeListener(visibility -> {
        MLog.d(TAG, "" + visibility);
        rootView.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
        rootView.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
    });
}
 
Example 18
Source Project: TabletClock   File: NavBarHider.java    License: MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
public NavBarHider(Activity activity, final View rootView) {
	mActivity = activity;

	if (android.os.Build.VERSION.SDK_INT >= 11) {
		rootView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
			@Override
			public void onSystemUiVisibilityChange(int visibility) {
				if (!isRunning
						|| (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {
					return;
				}
				hide(RESTORE_HIDE_TIMEOUT_MS);
			}
		});
	}
	rootView.getViewTreeObserver().addOnGlobalLayoutListener(
			new ViewTreeObserver.OnGlobalLayoutListener() {
				private final View content = rootView;

				@SuppressWarnings("deprecation")
				@Override
				public void onGlobalLayout() {
					if (android.os.Build.VERSION.SDK_INT >= 16) {
						content.getViewTreeObserver()
								.removeOnGlobalLayoutListener(this);
					} else {
						content.getViewTreeObserver()
								.removeGlobalOnLayoutListener(this);
					}
					hasNavigationBar = content.getHeight() < Style
							.getDisplayMetrics().heightPixels;
					if (hasNavigationBar && isRunning) {
						hide();
					}
				}
			});
}
 
Example 19
Source Project: Slide   File: BaseActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void showDecor() {
    try {
        if (!SettingValues.immersiveMode) {
            final View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
            decorView.setOnSystemUiVisibilityChangeListener(null);
        }
    } catch (Exception ignored) {
    }
}
 
Example 20
Source Project: Speculum-Android   File: SetupActivity.java    License: MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private void hideSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.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 // hide nav bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    decorView.setOnSystemUiVisibilityChangeListener(this);
}