Example usage for android.app ActionBar addOnMenuVisibilityListener

List of usage examples for android.app ActionBar addOnMenuVisibilityListener

Introduction

In this page you can find the example usage for android.app ActionBar addOnMenuVisibilityListener.

Prototype

public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);

Source Link

Document

Add a listener that will respond to menu visibility change events.

Usage

From source file:com.ultramegatech.ey.PeriodicTableActivity.java

/**
 * Set up immersive full screen mode for supported devices.
 *///from  w ww.  jav  a 2 s. c  o  m
private void setupImmersiveMode() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mImmersiveModeCallback = new Runnable() {
            @Override
            public void run() {
                hideSystemUi();
            }
        };

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().getDecorView()
                .setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        mHandler.removeCallbacks(mImmersiveModeCallback);
                        if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
                            mHandler.postDelayed(mImmersiveModeCallback, IMMERSIVE_MODE_DELAY);
                        }
                    }
                });

        final ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
                @Override
                public void onMenuVisibilityChanged(boolean isVisible) {
                    if (isVisible) {
                        mHandler.removeCallbacks(mImmersiveModeCallback);
                    } else {
                        mHandler.postDelayed(mImmersiveModeCallback, IMMERSIVE_MODE_DELAY);
                    }
                }
            });
        }
    }
}

From source file:com.android.ex.photo.PhotoViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final ActivityManager mgr = (ActivityManager) getApplicationContext()
            .getSystemService(Activity.ACTIVITY_SERVICE);
    sMemoryClass = mgr.getMemoryClass();

    Intent mIntent = getIntent();//from w ww. j  a va 2  s .  co m

    int currentItem = -1;
    if (savedInstanceState != null) {
        currentItem = savedInstanceState.getInt(STATE_ITEM_KEY, -1);
        mFullScreen = savedInstanceState.getBoolean(STATE_FULLSCREEN_KEY, false);
    }

    // uri of the photos to view; optional
    if (mIntent.hasExtra(Intents.EXTRA_PHOTOS_URI)) {
        mPhotosUri = mIntent.getStringExtra(Intents.EXTRA_PHOTOS_URI);
    }

    // projection for the query; optional
    // I.f not set, the default projection is used.
    // This projection must include the columns from the default projection.
    if (mIntent.hasExtra(Intents.EXTRA_PROJECTION)) {
        mProjection = mIntent.getStringArrayExtra(Intents.EXTRA_PROJECTION);
    } else {
        mProjection = null;
    }

    // Set the current item from the intent if wasn't in the saved instance
    if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) {
        currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1);
    }
    mPhotoIndex = currentItem;

    setContentView(R.layout.photo_activity_view);

    // Create the adapter and add the view pager
    mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null);

    mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOnInterceptTouchListener(this);

    // Kick off the loader
    getLoaderManager().initLoader(LOADER_PHOTO_LIST, null, this);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    mActionBarHideDelayTime = getResources().getInteger(R.integer.action_bar_delay_time_in_millis);
    actionBar.addOnMenuVisibilityListener(this);
    actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
}