类android.view.View.OnSystemUiVisibilityChangeListener源码实例Demo

下面列出了怎么用android.view.View.OnSystemUiVisibilityChangeListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 365browser   文件: WebappActivity.java
/**
 * Sets activity's decor view into an immersive mode.
 * If immersive mode is not supported, this method no-ops.
 */
private void enterImmersiveMode() {
    // Immersive mode is only supported in API 19+.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;

    if (mSetImmersiveRunnable == null) {

        final View decor = getWindow().getDecorView();

        mSetImmersiveRunnable = new Runnable() {
            @Override
            public void run() {
                int currentFlags = decor.getSystemUiVisibility();
                int desiredFlags = currentFlags | IMMERSIVE_MODE_UI_FLAGS;
                if (currentFlags != desiredFlags) {
                    decor.setSystemUiVisibility(desiredFlags);
                }
            }
        };

        // When we enter immersive mode for the first time, register a
        // SystemUiVisibilityChangeListener that restores immersive mode. This is necessary
        // because user actions like focusing a keyboard will break out of immersive mode.
        decor.setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int newFlags) {
                if ((newFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    asyncSetImmersive(RESTORE_IMMERSIVE_MODE_DELAY_MILLIS);
                }
            }
        });
    }

    asyncSetImmersive(0);
}
 
源代码2 项目: Cardboard   文件: CardboardActivity.java
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	requestWindowFeature(1);

	getWindow().addFlags(128);

	this.mMagnetSensor = new MagnetSensor(this);
	this.mMagnetSensor.setOnCardboardTriggerListener(this);

	this.mNfcSensor = NfcSensor.getInstance(this);
	this.mNfcSensor.addOnCardboardNfcListener(this);

	onNfcIntent(getIntent());

	setVolumeKeysMode(2);
	if (Build.VERSION.SDK_INT < 19) {
		final Handler handler = new Handler();
		getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
				new View.OnSystemUiVisibilityChangeListener() {
					public void onSystemUiVisibilityChange(int visibility) {
						if ((visibility & 0x2) == 0) {
							handler.postDelayed(new Runnable() {
								public void run() {
									CardboardActivity.this
											.setFullscreenMode();
								}
							}, 2000L);
						}
					}
				});
	}
}
 
源代码3 项目: VCL-Android   文件: VideoPlayerActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void startPlayback() {
    /* start playback only when audio service and both surfaces are ready */
    if (mPlaybackStarted || mService == null)
        return;

    mPlaybackStarted = true;

    /* Dispatch ActionBar touch events to the Activity */
    mActionBarView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            onTouchEvent(event);
            return true;
        }
    });

    if (AndroidUtil.isICSOrLater())
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        if (visibility == mUiVisibility)
                            return;
                        if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing && !isFinishing()) {
                            showOverlay();
                        }
                        mUiVisibility = visibility;
                    }
                }
        );

    if (AndroidUtil.isHoneycombOrLater()) {
        if (mOnLayoutChangeListener == null) {
            mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
                private final Runnable mRunnable = new Runnable() {
                    @Override
                    public void run() {
                        changeSurfaceLayout();
                    }
                };
                @Override
                public void onLayoutChange(View v, int left, int top, int right,
                                           int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                        /* changeSurfaceLayout need to be called after the layout changed */
                        mHandler.removeCallbacks(mRunnable);
                        mHandler.post(mRunnable);
                    }
                }
            };
        }
        mSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
    }
    changeSurfaceLayout();

    /* Listen for changes to media routes. */
    if (mMediaRouter != null)
        mediaRouterAddCallback(true);

    LibVLC().setOnHardwareAccelerationError(this);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.detachViews();
    if (mPresentation == null) {
        vlcVout.setVideoView(mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mSubtitlesSurfaceView);
    } else {
        vlcVout.setVideoView(mPresentation.mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mPresentation.mSubtitlesSurfaceView);
    }
    mSurfacesAttached = true;
    vlcVout.addCallback(this);
    vlcVout.attachViews();
    mSurfaceView.setKeepScreenOn(true);

    loadMedia();

    // Add any selected subtitle file from the file picker
    if(mSubtitleSelectedFiles.size() > 0) {
        for(String file : mSubtitleSelectedFiles) {
            Log.i(TAG, "Adding user-selected subtitle " + file);
            mService.addSubtitleTrack(file);
        }
    }

    // Set user playback speed
    mService.setRate(mSettings.getFloat(PreferencesActivity.VIDEO_SPEED, 1));
}
 
源代码4 项目: Mizuu   文件: ImageViewer.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (MizLib.hasKitKat()) {
        setTheme(R.style.Mizuu_Theme_Translucent_FullScreen);
    } else {
        setTheme(R.style.Mizuu_Theme_Transparent_FullScreen);
    }

    ViewUtils.setupWindowFlagsForStatusbarOverlay(getWindow(), true);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    ViewUtils.setProperToolbarSize(this, mToolbar);

    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_actionbar));

    mBus = MizuuApplication.getBus();

    mPortraitPhotos = getIntent().getBooleanExtra("portraitPhotos", true);
    mPhotos = getIntent().getStringArrayExtra("photos");

    getSupportActionBar().setTitle((getIntent().getIntExtra("selectedIndex", 0) + 1) + " " + getString(R.string.of) + " " + mPhotos.length);

    mViewPager = (ViewPager) findViewById(R.id.awesomepager);
    mViewPager.setPageMargin(MizLib.convertDpToPixels(getApplicationContext(), 16));
    mViewPager.setAdapter(new ActorPhotosAdapter(getSupportFragmentManager()));
    mViewPager.setOnPageChangeListener(new SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int arg0) {
            getSupportActionBar().setTitle((arg0 + 1) + " " + getString(R.string.of) + " " + mPhotos.length);
        }

    });
    mViewPager.setCurrentItem(getIntent().getIntExtra("selectedIndex", 0));

    View decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            if (visibility == 0) {
                // The UI is visible due to user interaction - let's hide it again after three seconds
                mHandler.postDelayed(mHideSystemUiRunnable, 3000);
            }
        }
    });
}
 
 类所在包
 同包方法