package com.wpc.library.videocomponents;
|
|
import android.annotation.SuppressLint;
|
import android.app.ActionBar;
|
import android.os.Build;
|
import android.os.Handler;
|
import android.view.View;
|
|
public abstract class NavHiderCompat {
|
|
public static NavHiderCompat getInstance(View view) {
|
NavHiderCompat navHider;
|
final int version = Build.VERSION.SDK_INT;
|
if (version >= Build.VERSION_CODES.HONEYCOMB) {
|
navHider = new NavHiderCompatHC(view);
|
} else {
|
navHider = null;
|
}
|
return navHider;
|
}
|
|
abstract public void setNavVisibility(boolean visible);
|
|
@SuppressLint("NewApi")
|
static class NavHiderCompatHC extends NavHiderCompat implements
|
View.OnSystemUiVisibilityChangeListener, ActionBar.OnMenuVisibilityListener {
|
|
private int mLastSystemUiVis;
|
|
private View mView;
|
|
public NavHiderCompatHC(View view) {
|
super();
|
mView = view;
|
mView.setOnSystemUiVisibilityChangeListener(this);
|
}
|
|
@Override
|
public void onMenuVisibilityChanged(boolean isVisible) {
|
setNavVisibility(true);
|
}
|
|
@Override
|
public void onSystemUiVisibilityChange(int visibility) {
|
// Detect when we go out of nav-hidden mode, to clear our state
|
// back to having the full UI chrome up. Only do this when
|
// the state is changing and nav is no longer hidden.
|
int diff = mLastSystemUiVis ^ visibility;
|
mLastSystemUiVis = visibility;
|
if ((diff & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
|
&& (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
|
setNavVisibility(true);
|
}
|
}
|
|
@Override
|
public void setNavVisibility(boolean visible) {
|
int newVis = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
if (!visible) {
|
newVis |= View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
}
|
|
// If we are now visible, schedule a timer for us to go invisible.
|
if (visible) {
|
Handler h = mView.getHandler();
|
if (h != null) {
|
// h.removeCallbacks(mNavHider);
|
// if (!mMenusOpen && !mPaused) {
|
// // If the menus are open or play is paused, we will not auto-hide.
|
// h.postDelayed(mNavHider, 3000);
|
// }
|
}
|
}
|
|
// Set the new desired visibility.
|
mView.setSystemUiVisibility(newVis);
|
// mNavVisible = visible;
|
}
|
}
|
}
|