setOnSystemUiVisibilityChangeListener ( )源码实例Demo

android.view.View#setOnSystemUiVisibilityChangeListener ( )源码实例Demo

下面列出了android.view.View#setOnSystemUiVisibilityChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
            }
        });
    }
}
 
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);
            }
        });
    }
}
 
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);
            }
        });
    }
}
 
源代码4 项目: glimmr   文件: PhotoViewerFragment.java
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)
                        );
                    }
                }
            });
}
 
源代码5 项目: aard2-android   文件: ArticleCollectionActivity.java
@Override
protected void onPause() {
    super.onPause();
    Log.d(TAG, "[F] Pause");
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(null);
    prefs().unregisterOnSharedPreferenceChangeListener(this);
}
 
源代码6 项目: VIA-AI   文件: Helper.java
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
        }
    });
}
 
源代码7 项目: Speculum-Android   文件: MainActivity.java
@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);
}
 
@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);
                }
            });
}
 
源代码9 项目: aard2-android   文件: ArticleCollectionActivity.java
@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "[F] Resume");
    applyFullScreenPref();
    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(this);
    prefs().registerOnSharedPreferenceChangeListener(this);
}
 
@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);
                }
            });
}
 
源代码11 项目: VideoOS-Android-SDK   文件: VenvyUIUtil.java
/**
 * 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);
}
 
源代码12 项目: FirefoxReality   文件: PlatformActivity.java
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();
                    }
                }
            });
}
 
源代码13 项目: BobEngine   文件: BobHelper.java
/**
 * 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);
			}
		}
	});
}
 
源代码14 项目: GLEXP-Team-onebillion   文件: MainActivity.java
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);
}
 
源代码15 项目: TubiPlayer   文件: Utils.java
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);
}
 
源代码16 项目: LEDView   文件: LEDActivity.java
@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 {
            }
        }
    });
}
 
源代码17 项目: PHONK   文件: BaseActivity.java
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);
    });
}
 
源代码18 项目: TabletClock   文件: NavBarHider.java
@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();
					}
				}
			});
}
 
源代码19 项目: Slide   文件: BaseActivity.java
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) {
    }
}
 
源代码20 项目: Speculum-Android   文件: SetupActivity.java
@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);
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类
 同类方法