Example usage for android.app ActionBar.OnMenuVisibilityListener ActionBar.OnMenuVisibilityListener

List of usage examples for android.app ActionBar.OnMenuVisibilityListener ActionBar.OnMenuVisibilityListener

Introduction

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

Prototype

ActionBar.OnMenuVisibilityListener

Source Link

Usage

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    DisplayMetrics metrics = new DisplayMetrics();
    SherlockFragmentActivity activity = getSherlockActivity();

    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    displayPageNumber(-1); // Initializes the pagenumber view properly

    final GestureDetector gestureDetector = new GestureDetector(context,
            new NavGestureDetector(bookView, this, metrics));

    View.OnTouchListener gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

            if (ttsIsRunning()) {
                return false;
            }//from  w  w w  .j a v  a 2s .co  m

            return gestureDetector.onTouchEvent(event);
        }
    };

    this.viewSwitcher.setOnTouchListener(gestureListener);
    this.bookView.setOnTouchListener(gestureListener);
    this.dummyView.setOnTouchListener(gestureListener);

    registerForContextMenu(bookView);
    saveConfigState();

    Intent intent = activity.getIntent();
    String file = null;

    if (intent.getData() != null) {
        file = intent.getData().getPath();
    }

    if (file == null) {
        file = config.getLastOpenedFile();
    }

    updateFromPrefs();
    updateFileName(savedInstanceState, file);

    if ("".equals(fileName) || !new File(fileName).exists()) {

        LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. "
                + "Switching back to the library.");

        Intent newIntent = new Intent(context, LibraryActivity.class);
        startActivity(newIntent);
        activity.finish();
        return;

    } else {

        if (savedInstanceState == null && config.isSyncEnabled()) {
            new DownloadProgressTask().execute();
        } else {
            bookView.restore();
        }
    }

    if (ttsIsRunning()) {
        this.mediaLayout.setVisibility(View.VISIBLE);
        this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this);
        uiHandler.post(progressBarUpdater);
    }

    activity.getSupportActionBar().addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
        @Override
        public void onMenuVisibilityChanged(boolean isVisible) {

            LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible);

            if (isVisible) {
                titleBarLayout.setVisibility(View.VISIBLE);
            } else {
                titleBarLayout.setVisibility(View.GONE);
            }
        }
    });

    /*
    new ShakeListener(getActivity()).setOnShakeListener(new ShakeListener.OnShakeListener() {
    @Override
    public void onShake() {
        if ( ! ttsIsRunning() ) {
            startTextToSpeech();
        }
    }
    });
    */
}