Example usage for android.widget Toolbar setNavigationOnClickListener

List of usage examples for android.widget Toolbar setNavigationOnClickListener

Introduction

In this page you can find the example usage for android.widget Toolbar setNavigationOnClickListener.

Prototype

public void setNavigationOnClickListener(OnClickListener listener) 

Source Link

Document

Set a listener to respond to navigation events.

Usage

From source file:com.example.android.unsplash.DetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_detail);

    postponeEnterTransition();// ww w.j a v a2  s  .  c  om

    TransitionSet transitions = new TransitionSet();
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    transitions.addTransition(slide);
    transitions.addTransition(new Fade());
    getWindow().setEnterTransition(transitions);

    Intent intent = getIntent();
    sharedElementCallback = new DetailSharedElementEnterCallback(intent);
    setEnterSharedElementCallback(sharedElementCallback);
    try {
        initialItem = Integer.parseInt(intent.getData().getLastPathSegment());
    } catch (NumberFormatException e) {
        initialItem = 0;
    }
    PhotoService.getInstance().getPhotosAsync(new PhotoService.PhotoCallback() {
        @Override
        public void success(ArrayList<Photo> photos) {
            setUpViewPager(photos);
            findViewById(android.R.id.empty).setVisibility(View.GONE);
        }

        @Override
        public void error() {
            finishAfterTransition();
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(navigationOnClickListener);

    super.onCreate(savedInstanceState);
}

From source file:org.cyanogenmod.theme.chooser.ChooserActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setActionBar(toolbar);//from   w w w . j av  a2s  .  co m
    toolbar.setNavigationIcon(R.drawable.ic_menu);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (mDrawerLayout.isDrawerOpen(mDrawerContainer)) {
                mDrawerLayout.closeDrawer(mDrawerContainer);
            } else {
                mDrawerLayout.openDrawer(mDrawerContainer);
            }
        }
    });

    initDrawer();

    NotificationHijackingService.ensureEnabled(this);

    if (savedInstanceState == null) {
        handleIntent(getIntent());
    }
}

From source file:am.util.mvp.AMActivity.java

/**
 *  Toolbar//from   w  w  w . ja v  a  2s. c om
 *
 * @param toolbarId Toolbar?ID
 */
@RequiresApi(21)
public final void setActionBar(@IdRes int toolbarId) {
    final View view = findViewById(toolbarId);
    if (view instanceof Toolbar) {
        if (mToolbarListener == null) {
            mToolbarListener = new ToolbarNavigationOnClickListener();
        }
        final Toolbar toolbar = (Toolbar) view;
        setActionBar(toolbar);
        toolbar.setNavigationOnClickListener(mToolbarListener);
    }
}

From source file:com.commonsware.cwac.crossport.v7.app.ActionBarDrawerToggle.java

/**
 * In the future, we can make this constructor public if we want to let developers customize
 * the//from ww w.  ja  v a 2 s .c o  m
 * animation.
 */
ActionBarDrawerToggle(Activity activity, Toolbar toolbar, DrawerLayout drawerLayout, DrawerArrowDrawable slider,
        @StringRes int openDrawerContentDescRes, @StringRes int closeDrawerContentDescRes) {
    if (toolbar != null) {
        mActivityImpl = new ToolbarCompatDelegate(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDrawerIndicatorEnabled) {
                    toggle();
                } else if (mToolbarNavigationClickListener != null) {
                    mToolbarNavigationClickListener.onClick(v);
                }
            }
        });
    } else if (activity instanceof DelegateProvider) { // Allow the Activity to provide an impl
        mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        mActivityImpl = new JellybeanMr2Delegate(activity);
    } /*else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      mActivityImpl = new IcsDelegate(activity);
      } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      mActivityImpl = new HoneycombDelegate(activity);
      }*/ else {
        mActivityImpl = new DummyDelegate(activity);
    }

    mDrawerLayout = drawerLayout;
    mOpenDrawerContentDescRes = openDrawerContentDescRes;
    mCloseDrawerContentDescRes = closeDrawerContentDescRes;
    if (slider == null) {
        mSlider = new DrawerArrowDrawable(mActivityImpl.getActionBarThemedContext());
    } else {
        mSlider = slider;
    }

    mHomeAsUpIndicator = getThemeUpIndicator();
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);

    DesignerNewsViewModelFactory factory = InjectionKt.provideViewModelFactory(this);
    viewModel = ViewModelProviders.of(this, factory).get(StoryViewModel.class);

    commentsUseCase = Injection.provideCommentsUseCase(this);

    bindResources();/*from w  w w . jav  a 2 s  .  c o  m*/

    story = getIntent().getParcelableExtra(Activities.DesignerNews.Story.EXTRA_STORY);

    commentsUseCase.getComments(story.getLinks().getComments(), result -> {
        if (result instanceof Result.Success) {
            Result.Success<List<Comment>> success = (Result.Success<List<Comment>>) result;
            List<Comment> data = success.getData();
            setupComments(data);
        }
        return Unit.INSTANCE;
    });

    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
    markdown = new Bypass(getResources().getDisplayMetrics(), new Bypass.Options()
            .setBlockQuoteLineColor(ContextCompat.getColor(this, io.plaidapp.R.color.designer_news_quote_line))
            .setBlockQuoteLineWidth(2) // dps
            .setBlockQuoteLineIndent(8) // dps
            .setPreImageLinebreakHeight(4) //dps
            .setBlockQuoteIndentSize(TypedValue.COMPLEX_UNIT_DIP, 2f)
            .setBlockQuoteTextColor(ContextCompat.getColor(this, io.plaidapp.R.color.designer_news_quote)));
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(new CommentAnimator(
            getResources().getInteger(io.plaidapp.R.integer.comment_expand_collapse_duration)));
    header = getLayoutInflater().inflate(R.layout.designer_news_story_description, commentsList, false);
    bindDescription();

    // setup title/toolbar
    if (collapsingToolbar != null) { // narrow device: collapsing toolbar
        collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
        collapsingToolbar.setTitle(story.getTitle());
        final Toolbar toolbar = findViewById(R.id.story_toolbar);
        toolbar.setNavigationOnClickListener(backClick);
        commentsList.addOnScrollListener(headerScrollListener);

        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
                    List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(getIntent(), collapsingToolbar);
            }

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                    List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(collapsingToolbar);
            }
        });

    } else { // w600dp configuration: content card scrolls over title bar
        final TextView title = findViewById(R.id.story_title);
        title.setText(story.getTitle());
        findViewById(R.id.back).setOnClickListener(backClick);
    }

    enterCommentView = setupCommentField();
    commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<>(0), enterCommentView);
    commentsList.setAdapter(commentsAdapter);

    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);
    ButterKnife.bind(this);

    story = getIntent().getParcelableExtra(EXTRA_STORY);
    fab.setOnClickListener(fabClick);//  w ww  . ja  v  a  2s  .  c  o  m
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
    markdown = new Bypass(this,
            new Bypass.Options()
                    .setBlockQuoteLineColor(ContextCompat.getColor(this, R.color.designer_news_quote_line))
                    .setBlockQuoteLineWidth(2) // dps
                    .setBlockQuoteLineIndent(8) // dps
                    .setPreImageLinebreakHeight(4) //dps
                    .setBlockQuoteIndentSize(TypedValue.COMPLEX_UNIT_DIP, 2f)
                    .setBlockQuoteTextColor(ContextCompat.getColor(this, R.color.designer_news_quote)));
    circleTransform = new CircleTransform(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(
            new CommentAnimator(getResources().getInteger(R.integer.comment_expand_collapse_duration)));
    header = getLayoutInflater().inflate(R.layout.designer_news_story_description, commentsList, false);
    bindDescription();

    // setup title/toolbar
    if (collapsingToolbar != null) { // narrow device: collapsing toolbar
        collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
        collapsingToolbar.setTitle(story.title);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.story_toolbar);
        toolbar.setNavigationOnClickListener(backClick);
        commentsList.addOnScrollListener(headerScrollListener);

        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
                    List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(getIntent(), collapsingToolbar);
            }

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                    List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(collapsingToolbar);
            }
        });

    } else { // w600dp configuration: content card scrolls over title bar
        final TextView title = (TextView) findViewById(R.id.story_title);
        title.setText(story.title);
        findViewById(R.id.back).setOnClickListener(backClick);
    }

    final View enterCommentView = setupCommentField();
    if (story.comment_count > 0) {
        // flatten the comments from a nested structure {@see Comment#comments} to a
        // list appropriate for our adapter (using the depth attribute).
        List<Comment> flattened = new ArrayList<>(story.comment_count);
        unnestComments(story.comments, flattened);
        commentsAdapter = new DesignerNewsCommentsAdapter(header, flattened, enterCommentView);
        commentsList.setAdapter(commentsAdapter);

    } else {
        commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<Comment>(0), enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    }
    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);
    ButterKnife.bind(this);
    getWindow().getSharedElementReturnTransition().addListener(returnHomeListener);

    story = getIntent().getParcelableExtra(EXTRA_STORY);
    fab.setOnClickListener(fabClick);/*from  w  w w.jav  a2 s  .  c o  m*/

    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(getWindow()) {
        @Override
        public void onDragDismissed() {
            finishAfterTransition();
        }
    };

    markdown = new Bypass(this,
            new Bypass.Options()
                    .setBlockQuoteLineColor(ContextCompat.getColor(this, R.color.designer_news_quote_line))
                    .setBlockQuoteLineWidth(2) // dps
                    .setBlockQuoteLineIndent(8) // dps
                    .setPreImageLinebreakHeight(4) //dps
                    .setBlockQuoteIndentSize(TypedValue.COMPLEX_UNIT_DIP, 2f)
                    .setBlockQuoteTextColor(ContextCompat.getColor(this, R.color.designer_news_quote)));
    circleTransform = new CircleTransform(this);

    designerNewsPrefs = DesignerNewsPrefs.get(this);
    createDesignerNewsApi();

    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(new CommentAnimator());

    header = getLayoutInflater().inflate(R.layout.designer_news_story_description, commentsList, false);
    bindDescription();

    // setup toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.story_toolbar);
    if (collapsingToolbar != null) { // portrait: collapsing toolbar
        collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
        collapsingToolbar.setTitle(story.title);
    } else { // landscape: scroll toolbar with content
        toolbar = (Toolbar) header.findViewById(R.id.story_toolbar);
        FontTextView title = (FontTextView) toolbar.findViewById(R.id.story_title);
        title.setText(story.title);
    }
    commentsList.addOnScrollListener(headerScrollListener);

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finishAfterTransition();
        }
    });

    View enterCommentView = setupCommentField();

    if (story.comment_count > 0) {
        // flatten the comments from a nested structure {@see Comment#comments} to a
        // list appropriate for our adapter (using the depth attribute).
        List<Comment> flattened = new ArrayList<>(story.comment_count);
        unnestComments(story.comments, flattened);
        commentsAdapter = new DesignerNewsCommentsAdapter(header, flattened, enterCommentView);
        commentsList.setAdapter(commentsAdapter);

    } else {
        commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<Comment>(0), enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    }
    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}