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

The following examples show how to use android.view.View#setOnSystemUiVisibilityChangeListener() . 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 check out the related API usage on the sidebar.
Example 1
Source File: VerticalReaderActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 6 votes vote down vote up
@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
Source File: PhotoViewerFragment.java    From glimmr with 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 3
Source File: ViewImageDetailActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 6 votes vote down vote up
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 File: Wenku8ReaderActivityV1.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: SetupActivity.java    From Speculum-Android with 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);
}
 
Example 6
Source File: ArticleCollectionActivity.java    From aard2-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    Log.d(TAG, "[F] Pause");
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(null);
    prefs().unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 7
Source File: BaseActivity.java    From Slide with 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 8
Source File: NavBarHider.java    From TabletClock with 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 9
Source File: BaseActivity.java    From PHONK with 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 10
Source File: LEDActivity.java    From LEDView with 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 11
Source File: Utils.java    From TubiPlayer with 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 12
Source File: MainActivity.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
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 13
Source File: BobHelper.java    From BobEngine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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
Source File: PlatformActivity.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
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 15
Source File: VenvyUIUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 16
Source File: BasicImmersiveModeFragment.java    From android-BasicImmersiveMode with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: ArticleCollectionActivity.java    From aard2-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "[F] Resume");
    applyFullScreenPref();
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(this);
    prefs().registerOnSharedPreferenceChangeListener(this);
}
 
Example 18
Source File: ImmersiveModeFragment.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
@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 19
Source File: MainActivity.java    From Speculum-Android with 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 20
Source File: Helper.java    From VIA-AI with 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
        }
    });
}