Example usage for android.view View SYSTEM_UI_FLAG_IMMERSIVE

List of usage examples for android.view View SYSTEM_UI_FLAG_IMMERSIVE

Introduction

In this page you can find the example usage for android.view View SYSTEM_UI_FLAG_IMMERSIVE.

Prototype

int SYSTEM_UI_FLAG_IMMERSIVE

To view the source code for android.view View SYSTEM_UI_FLAG_IMMERSIVE.

Click Source Link

Document

Flag for #setSystemUiVisibility(int) : View would like to remain interactive when hiding the navigation bar with #SYSTEM_UI_FLAG_HIDE_NAVIGATION .

Usage

From source file:com.example.android.advancedimmersivemode.AdvancedImmersiveModeFragment.java

/**
 * Detects and toggles immersive mode (also known as "hidey bar" mode).
 *//*from ww w.  ja  va 2s . com*/
public void toggleUiFlags() {

    // BEGIN_INCLUDE (get_current_ui_flags)
    // The "Decor View" is the parent view of the Activity.  It's also conveniently the easiest
    // one to find from within a fragment, since there's a handy helper method to pull it, and
    // we don't have to bother with picking a view somewhere deeper in the hierarchy and calling
    // "findViewById" on it.
    View decorView = getActivity().getWindow().getDecorView();
    int uiOptions = decorView.getSystemUiVisibility();
    int newUiOptions = uiOptions;
    // END_INCLUDE (get_current_ui_flags)

    // BEGIN_INCLUDE (toggle_lowprofile_mode)
    // Low profile mode doesn't resize the screen at all, but it covers the nav & status bar
    // icons with black so they're less distracting.  Unlike "full screen" and "hide nav bar,"
    // this mode doesn't interact with immersive mode at all, but it's instructive when running
    // this sample to observe the differences in behavior.
    if (mLowProfileCheckBox.isChecked()) {
        newUiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
    } else {
        newUiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
    }
    // END_INCLUDE (toggle_lowprofile_mode)

    // BEGIN_INCLUDE (toggle_fullscreen_mode)
    // When enabled, this flag hides non-critical UI, such as the status bar,
    // which usually shows notification icons, battery life, etc
    // on phone-sized devices.  The bar reappears when the user swipes it down.  When immersive
    // mode is also enabled, the app-drawable area expands, and when the status bar is swiped
    // down, it appears semi-transparently and slides in over the app, instead of pushing it
    // down.
    if (mHideStatusBarCheckBox.isChecked()) {
        newUiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
    } else {
        newUiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
    }
    // END_INCLUDE (toggle_fullscreen_mode)

    // BEGIN_INCLUDE (toggle_hidenav_mode)
    // When enabled, this flag hides the black nav bar along the bottom,
    // where the home/back buttons are.  The nav bar normally instantly reappears
    // when the user touches the screen.  When immersive mode is also enabled, the nav bar
    // stays hidden until the user swipes it back.
    if (mHideNavCheckbox.isChecked()) {
        newUiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    } else {
        newUiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }
    // END_INCLUDE (toggle_hidenav_mode)

    // BEGIN_INCLUDE (toggle_immersive_mode)
    // Immersive mode doesn't do anything without at least one of the previous flags
    // enabled.  When enabled, it allows the user to swipe the status and/or nav bars
    // off-screen.  When the user swipes the bars back onto the screen, the flags are cleared
    // and immersive mode is automatically disabled.
    if (mImmersiveModeCheckBox.isChecked()) {
        newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
    } else {
        newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE;
    }
    // END_INCLUDE (toggle_immersive_mode)

    // BEGIN_INCLUDE (toggle_immersive_mode_sticky)
    // There's actually two forms of immersive mode, normal and "sticky".  Sticky immersive mode
    // is different in 2 key ways:
    //
    // * Uses semi-transparent bars for the nav and status bars
    // * This UI flag will *not* be cleared when the user interacts with the UI.
    //   When the user swipes, the bars will temporarily appear for a few seconds and then
    //   disappear again.
    if (mImmersiveModeStickyCheckBox.isChecked()) {
        newUiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    } else {
        newUiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    }
    // END_INCLUDE (toggle_immersive_mode_sticky)

    // BEGIN_INCLUDE (set_ui_flags)
    //Set the new UI flags.
    decorView.setSystemUiVisibility(newUiOptions);
    // END_INCLUDE (set_ui_flags)

    dumpFlagStateToLog(uiOptions);
}

From source file:com.example.nitish.welcomapp.activitypt.PeriodicTableActivity.java

/**
 * Enable immersive full screen mode./* w  w w  .ja  v a2 s.c om*/
 */
private void hideSystemUi() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().getDecorView().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
                        | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);

        findViewById(R.id.touchFrame).setVisibility(View.VISIBLE);
    }
}

From source file:io.jari.geenstijl.Blog.java

@SuppressLint("NewApi")
void enableImmersive(boolean immersive, View view) {
    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("hide_actionbar", true))
        return;//from   w ww . j ava  2s. c  o  m

    if (immersive && !forceNoImmersive) {
        if (Build.VERSION.SDK_INT >= 19) {
            tintManager.setStatusBarAlpha(0.5f);
            view.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 | View.SYSTEM_UI_FLAG_IMMERSIVE);
        }
        actionBar.hide();
    } else {
        if (Build.VERSION.SDK_INT >= 19) {
            tintManager.setStatusBarAlpha(1f);
            view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }

        actionBar.show();
    }
}

From source file:com.nagravision.mediaplayer.FullscreenActivity.java

/**
 *
 *///  w  w  w. ja  va 2s .c  o  m
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle inBundle) {
    Log.v(LOG_TAG, "FullscreenActivity::onCreate - Enter\n");
    super.onCreate(inBundle);

    getApplication().registerActivityLifecycleCallbacks(this);

    if (Build.VERSION.SDK_INT < 16) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_fullscreen);
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mMoviesList = (ListView) findViewById(R.id.start_drawer);
    mUrlsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, MOVIES_ARR);
    mMoviesList.setAdapter(mUrlsAdapter);
    mVideoHolder = (VideoView) findViewById(R.id.fullscreen_content);

    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_FULLSCREEN;
    if (Build.VERSION.SDK_INT >= 19) {
        uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
    }
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.hide();

    mNotifBuilder = new Notification.Builder(this);
    mNotifMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mExplicitIntent = new Intent(Intent.ACTION_VIEW);
    mExplicitIntent.setClass(this, this.getClass());
    mDefaultIntent = PendingIntent.getActivity(this, REQUEST_DISPLAY, mExplicitIntent,
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_DEBUG_LOG_RESOLUTION);
    mInfosActionIntent = new Intent();
    mInfosActionIntent.setAction("com.nagravision.mediaplayer.VIDEO_INFOS");
    mInfosActionIntent.addCategory(Intent.CATEGORY_DEFAULT);
    mInfosActionIntent.addCategory(Intent.CATEGORY_INFO);
    mInfosIntent = PendingIntent.getActivity(this, REQUEST_INFOS, mInfosActionIntent,
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_DEBUG_LOG_RESOLUTION);

    if (Build.VERSION.SDK_INT >= 19) {
        mVideoHolder.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);
    } else {
        mVideoHolder.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
    OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
        public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View v, int position,
                long id) {
            Log.v(LOG_TAG, "FullscreenActivity.onCreate.OnItemClickListener::onItemClick - Enter\n");
            ClickItem(position, 0);
        }
    };

    mMoviesList.setOnItemClickListener(mMessageClickedHandler);

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    mControlsView = new MediaController(this, true);
    mControlsView.setPrevNextListeners(new View.OnClickListener() {
        /*
         * Next listener
         */
        @Override
        public void onClick(View view) {
            Log.v(LOG_TAG, "FullscreenActivity.onCreate.OnClickListener::onClick(next) - Enter\n");
            mVideoHolder.stopPlayback();
            int position = 0;
            if (mLastPosition > 0)
                position = mLastPosition + 1;
            if (position >= MOVIES_URLS.length)
                position = 0;
            ClickItem(position, 0);

            String toaststr = getResources().getString(R.string.next_movie_toast_string) + MOVIES_ARR[position];
            Toast.makeText(FullscreenActivity.this, toaststr, Toast.LENGTH_LONG).show();
        }
    }, new View.OnClickListener() {
        /*
         * Prev listener
         */
        @Override
        public void onClick(View view) {
            Log.v(LOG_TAG, "FullscreenActivity.onCreate.OnClickListener::onClick(prev) - Enter\n");
            mVideoHolder.stopPlayback();
            int position = 0;
            if (mLastPosition > 0)
                position = mLastPosition - 1;
            if (position < 0)
                position = MOVIES_URLS.length - 1;
            ClickItem(position, 0);

            String toaststr = getResources().getString(R.string.prev_movie_toast_string) + MOVIES_ARR[position];
            Toast.makeText(FullscreenActivity.this, toaststr, Toast.LENGTH_LONG).show();
        }
    });
    mVideoHolder.setMediaController(mControlsView);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, mVideoHolder, HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
        // Cached values.
        int mControlsHeight;
        int mShortAnimTime;

        @Override
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
        public void onVisibilityChange(boolean visible) {
            Log.v(LOG_TAG, "FullscreenActivity.OnVisibilityChangeListener::onVisibilityChange - Enter\n");

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                if (mControlsHeight == 0)
                    mControlsHeight = mControlsView.getHeight();
                if (mShortAnimTime == 0)
                    mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
                mControlsView.animate().translationY(visible ? 0 : mControlsHeight).setDuration(mShortAnimTime);
            } else
                mControlsView.setVisibility(visible ? View.VISIBLE : View.GONE);

            if (visible && AUTO_HIDE)
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
        }
    });

    // Set up the user interaction to manually show or hide the system UI.
    mVideoHolder.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (TOGGLE_ON_CLICK) {
                mSystemUiHider.toggle();
            } else {
                mSystemUiHider.show();
            }
        }
    });

    mDrawer.openDrawer(mMoviesList);
}

From source file:de.spiritcroc.modular_remote.MainActivity.java

private int getHideSystemUIFlags() {
    int flags;//from ww w.j a v  a2s.c o m
    if (Build.VERSION.SDK_INT >= 19) {
        flags = View.SYSTEM_UI_FLAG_IMMERSIVE;
    } else {
        flags = 0;
    }
    if (Build.VERSION.SDK_INT >= 16) {
        if (fullscreen) {
            flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN;
        }
        if (hideNavigationBar) {
            flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }
        if (hideActionBar) {
            flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        }
    }
    return flags;
}

From source file:com.free.searcher.MainFragment.java

void setNavVisibility(boolean visible) {
    int newVis = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    if (!visible) {
        container.setVisibility(View.INVISIBLE);
        newVis = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE
        //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        ;//from   ww w . j  a  v  a 2s .c o  m
    } else if (showFind) {
        container.setVisibility(View.VISIBLE);
        actionBar.show();
    } else {
        actionBar.show();
    }
    Log.d("newVis", newVis + "");
    // Set the new desired visibility.
    statusView.setSystemUiVisibility(newVis);
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Activates full-screen mode - hides status bar, system navigation and the Action Bar.
 *//*from   ww w.  ja  v a 2  s . com*/
@SuppressLint("InlinedApi") // Android versions not supporting Immersive Fullscreen ignore unsupported flags.
public void activateFullscreen(boolean setFlags) {

    // Hide action bar and activate fullscreen flags.
    fullscreenMode = true;
    getActionBar().hide();

    if (setFlags) {
        // Android 4.0 and before have a different mechanism for fullscreen:
        if (Build.VERSION.SDK_INT < 16) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        // Android 4.1 JellyBean and newer:
        else {
            // Set basic fullscreen flags
            int flags = View.SYSTEM_UI_FLAG_FULLSCREEN; // Hides the status bar

            // Set flags for devices with support for immersive fullscreen.
            if (Build.VERSION.SDK_INT >= 19) {
                // The last two flags make for a smoother transition between states.
                flags = flags | View.SYSTEM_UI_FLAG_IMMERSIVE // Ensures that no touch events won't cancel fullscreen mode.
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Hides the system navigation
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // Ensures more seamless transition.
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; // Ensures more seamless transition.
            }

            decorView.setSystemUiVisibility(flags);
        }
    }

    // Signal to the Governor that a runtime change has occurred.
    governor.onRuntimeChange();
}

From source file:com.google.android.apps.muzei.ArtDetailFragment.java

private void showHideChrome(boolean show) {
    int flags = show ? 0 : View.SYSTEM_UI_FLAG_LOW_PROFILE;
    flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    if (!show) {/*from  w w w  . j a v  a  2  s.c om*/
        flags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE;
    }
    mContainerView.setSystemUiVisibility(flags);
}

From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java

private void hideSystemUI() {
    // Set the IMMERSIVE flag.m
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    getWindow().getDecorView().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);
}

From source file:org.fossasia.phimpme.leafpic.activities.PlayerActivity.java

private void hideSystemBars() {
    toolbar.animate().translationY(-toolbar.getHeight()).setInterpolator(new AccelerateInterpolator())
            .setDuration(200).start();//from ww w .j ava2s.c o m

    getWindow().getDecorView().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);
}