Java Code Examples for android.support.v7.widget.Toolbar#getNavigationIcon()

The following examples show how to use android.support.v7.widget.Toolbar#getNavigationIcon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectPictureActivity.java    From FilePicker with MIT License 4 votes vote down vote up
private void initUI() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    Drawable navigationIcon = toolbar.getNavigationIcon();
    TypedArray ta = getTheme().obtainStyledAttributes(new int[]{R.attr.album_element_color});
    int color = ta.getColor(0, 0);
    ta.recycle();
    if (navigationIcon != null) {
        navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    }

    mBuketAdapter = new BuketAdapter(this, null, false);
    ToolbarSpinner spinner = new ToolbarSpinner(this);
    spinner.setSelectedTextView((TextView) findViewById(R.id.selected_folder));
    spinner.setPopupAnchorView(findViewById(R.id.toolbar));
    spinner.setOnItemSelectedListener(this);
    spinner.setAdapter(mBuketAdapter);

    mAlbumCollection.onCreate(this, this);
    mAlbumCollection.load();
    mMediaCollection.onCreate(this, this);

    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
    mRecyclerView.addItemDecoration(new MediaItemDecoration());
    mMediaAdapter = new EssMediaAdapter(new ArrayList<EssFile>());
    mMediaAdapter.setImageResize(UiUtils.getImageResize(this, mRecyclerView));
    mRecyclerView.setAdapter(mMediaAdapter);
    mMediaAdapter.bindToRecyclerView(mRecyclerView);
    mMediaAdapter.setOnItemChildClickListener(this);
    if (SelectOptions.getInstance().isSingle || SelectOptions.getInstance().maxCount == 1) {
        //单选
        mMediaAdapter.setOnItemClickListener(this);
    }
}
 
Example 2
Source File: SelectPictureActivity.java    From AndroidDownload with Apache License 2.0 4 votes vote down vote up
private void initUI() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    Drawable navigationIcon = toolbar.getNavigationIcon();
    TypedArray ta = getTheme().obtainStyledAttributes(new int[]{R.attr.album_element_color});
    int color = ta.getColor(0, 0);
    ta.recycle();
    if (navigationIcon != null) {
        navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    }

    mBuketAdapter = new BuketAdapter(this, null, false);
    ToolbarSpinner spinner = new ToolbarSpinner(this);
    spinner.setSelectedTextView((TextView) findViewById(R.id.selected_folder));
    spinner.setPopupAnchorView(findViewById(R.id.toolbar));
    spinner.setOnItemSelectedListener(this);
    spinner.setAdapter(mBuketAdapter);

    mAlbumCollection.onCreate(this, this);
    mAlbumCollection.load();
    mMediaCollection.onCreate(this, this);

    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
    mRecyclerView.addItemDecoration(new MediaItemDecoration());
    mMediaAdapter = new EssMediaAdapter(new ArrayList<EssFile>());
    mMediaAdapter.setImageResize(UiUtils.getImageResize(this, mRecyclerView));
    mRecyclerView.setAdapter(mMediaAdapter);
    mMediaAdapter.bindToRecyclerView(mRecyclerView);
    mMediaAdapter.setOnItemChildClickListener(this);
    if (SelectOptions.getInstance().isSingle || SelectOptions.getInstance().maxCount == 1) {
        //单选
        mMediaAdapter.setOnItemClickListener(this);
    }
}
 
Example 3
Source File: MatisseActivity.java    From Matisse with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    // programmatically set theme before super.onCreate()
    mSpec = SelectionSpec.getInstance();
    setTheme(mSpec.themeId);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_matisse);

    if (mSpec.needOrientationRestriction()) {
        setRequestedOrientation(mSpec.orientation);
    }

    if (mSpec.capture) {
        mMediaStoreCompat = new MediaStoreCompat(this);
        if (mSpec.captureStrategy == null)
            throw new RuntimeException("Don't forget to set CaptureStrategy.");
        mMediaStoreCompat.setCaptureStrategy(mSpec.captureStrategy);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    Drawable navigationIcon = toolbar.getNavigationIcon();
    TypedArray ta = getTheme().obtainStyledAttributes(new int[]{R.attr.album_element_color});
    int color = ta.getColor(0, 0);
    ta.recycle();
    navigationIcon.setColorFilter(color, PorterDuff.Mode.SRC_IN);

    mButtonPreview = (TextView) findViewById(R.id.button_preview);
    mButtonApply = (TextView) findViewById(R.id.button_apply);
    mButtonPreview.setOnClickListener(this);
    mButtonApply.setOnClickListener(this);
    mContainer = findViewById(R.id.container);
    mEmptyView = findViewById(R.id.empty_view);
    mOriginalLayout = (LinearLayout) findViewById(R.id.originalLayout);
    mOriginal = (CheckRadioView) findViewById(R.id.original);
    mOriginalLayout.setOnClickListener(this);
    mSelectedCollection.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        mOriginalEnable = savedInstanceState.getBoolean(CHECK_STATE);
    }

    updateBottomToolbar();

    mAlbumsAdapter = new AlbumsAdapter(this, null, false);
    mAlbumsSpinner = new AlbumsSpinner(this);
    mAlbumsSpinner.setOnItemSelectedListener(this);
    mAlbumsSpinner.setSelectedTextView((TextView) findViewById(R.id.selected_album));
    mAlbumsSpinner.setPopupAnchorView(findViewById(R.id.toolbar));
    mAlbumsSpinner.setAdapter(mAlbumsAdapter);
    mAlbumCollection.onCreate(this, this);
    mAlbumCollection.onRestoreInstanceState(savedInstanceState);
    mAlbumCollection.loadAlbums();
}
 
Example 4
Source File: AlbumActivity.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
@Override
public void onSelectorModeEnter() {
    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setActivated(true);
    toolbar.animate().translationY(0.0f).start();

    if (theme.darkStatusBarIconsInSelectorMode()) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    } else {
        Util.setLightStatusBarIcons(findViewById(R.id.root_view));
    }

    if (!pick_photos) {
        ColorFade.fadeBackgroundColor(toolbar, toolbarColor, accentColor);

        ColorFade.fadeToolbarTitleColor(toolbar, accentTextColor, null);

        //fade overflow menu icon
        ColorFade.fadeDrawableColor(toolbar.getOverflowIcon(), textColorSecondary, accentTextColor);

        Drawable selectAll = menu.findItem(R.id.select_all).getIcon();
        selectAll.setAlpha(0);
        ColorFade.fadeDrawableAlpha(selectAll, 255);

        ColorDrawable statusBarOverlay = getStatusBarOverlay();
        if (statusBarOverlay != null) {
            ColorFade.fadeDrawableAlpha(statusBarOverlay, 0);
        }

        Drawable navIcon = toolbar.getNavigationIcon();
        if (navIcon instanceof Animatable) {
            ((Animatable) navIcon).start();
            ColorFade.fadeDrawableColor(navIcon, textColorSecondary, accentTextColor);
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Drawable d;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    AnimatedVectorDrawable drawable = (AnimatedVectorDrawable)
                            ContextCompat.getDrawable(AlbumActivity.this,
                                    R.drawable.cancel_to_back_avd);
                    //mutating avd to reset it
                    drawable.mutate();
                    d = drawable;
                } else {
                    d = ContextCompat.getDrawable(AlbumActivity.this,
                            R.drawable.ic_clear_white);
                }
                d = DrawableCompat.wrap(d);
                DrawableCompat.setTint(d.mutate(), accentTextColor);
                toolbar.setNavigationIcon(d);
            }
        }, navIcon instanceof Animatable ? (int) (500 * Util.getAnimatorSpeed(this)) : 0);
    } else {
        toolbar.setBackgroundColor(accentColor);
        toolbar.setTitleTextColor(accentTextColor);
    }

    handleMenuVisibilityForSelectorMode(true);

    if (!pick_photos) {
        animateFab(true, false);
    }
}
 
Example 5
Source File: FileExplorerActivity.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
@Override
public void onSelectorModeEnter() {
    fileOpIntent = null;

    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setActivated(true);
    toolbar.animate().translationY(0.0f).start();

    if (theme.darkStatusBarIconsInSelectorMode()) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    } else {
        Util.setLightStatusBarIcons(findViewById(R.id.root_view));
    }

    ColorDrawable statusBarOverlay = getStatusBarOverlay();
    if (statusBarOverlay != null) {
        ColorFade.fadeDrawableAlpha(statusBarOverlay, 0);
    }

    ColorFade.fadeBackgroundColor(toolbar, toolbarColor, accentColor);

    ColorFade.fadeToolbarTitleColor(toolbar, accentTextColor, null);

    //fade overflow menu icon
    ColorFade.fadeDrawableColor(toolbar.getOverflowIcon(),
            textColorSecondary, accentTextColor);

    Drawable navIcon = toolbar.getNavigationIcon();
    if (navIcon instanceof Animatable) {
        ((Animatable) navIcon).start();
        ColorFade.fadeDrawableColor(navIcon,
                textColorSecondary, accentTextColor);
    }
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Drawable d;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                AnimatedVectorDrawable drawable = (AnimatedVectorDrawable)
                        ContextCompat.getDrawable(FileExplorerActivity.this,
                                R.drawable.cancel_to_back_avd);
                //mutating avd to reset it
                drawable.mutate();
                d = drawable;
            } else {
                d = ContextCompat.getDrawable(FileExplorerActivity.this,
                        R.drawable.ic_clear_white);
            }
            d = DrawableCompat.wrap(d);
            DrawableCompat.setTint(d.mutate(), accentTextColor);
            toolbar.setNavigationIcon(d);

            //make menu items visible
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                switch (item.getItemId()) {
                    case R.id.copy:
                    case R.id.move:
                    case R.id.delete:
                        item.setVisible(true);
                        break;
                    default:
                        item.setVisible(false);
                        break;
                }
            }
        }
    }, navIcon instanceof Animatable ? (int) (500 * Util.getAnimatorSpeed(this)) : 0);
}
 
Example 6
Source File: ToolbarContentTintHelper.java    From APlayer with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static void setToolbarContentColor(@NonNull Context context, Toolbar toolbar,
    @Nullable Menu menu, final @ColorInt int toolbarContentColor,
    final @ColorInt int titleTextColor, final @ColorInt int subtitleTextColor,
    final @ColorInt int menuWidgetColor) {
  if (toolbar == null) {
    return;
  }

  if (menu == null) {
    menu = toolbar.getMenu();
  }

  toolbar.setTitleTextColor(titleTextColor);
  toolbar.setSubtitleTextColor(subtitleTextColor);

  if (toolbar.getNavigationIcon() != null) {
    // Tint the toolbar navigation icon (e.g. back, drawer, etc.)
    toolbar.setNavigationIcon(
        TintHelper.createTintedDrawable(toolbar.getNavigationIcon(), toolbarContentColor));
  }

  InternalToolbarContentTintUtil.tintMenu(toolbar, menu, toolbarContentColor);
  InternalToolbarContentTintUtil.applyOverflowMenuTint(context, toolbar, menuWidgetColor);

  if (context instanceof Activity) {
    InternalToolbarContentTintUtil
        .setOverflowButtonColor((Activity) context, toolbarContentColor);
  }

  try {
    // Tint immediate overflow menu items
    final Field menuField = Toolbar.class.getDeclaredField("mMenuBuilderCallback");
    menuField.setAccessible(true);
    final Field presenterField = Toolbar.class.getDeclaredField("mActionMenuPresenterCallback");
    presenterField.setAccessible(true);
    final Field menuViewField = Toolbar.class.getDeclaredField("mMenuView");
    menuViewField.setAccessible(true);

    final MenuPresenter.Callback currentPresenterCb = (MenuPresenter.Callback) presenterField
        .get(toolbar);
    if (!(currentPresenterCb instanceof ATHMenuPresenterCallback)) {
      final ATHMenuPresenterCallback newPresenterCb = new ATHMenuPresenterCallback(context,
          menuWidgetColor, currentPresenterCb, toolbar);
      final MenuBuilder.Callback currentMenuCb = (MenuBuilder.Callback) menuField.get(toolbar);
      toolbar.setMenuCallbacks(newPresenterCb, currentMenuCb);
      ActionMenuView menuView = (ActionMenuView) menuViewField.get(toolbar);
      if (menuView != null) {
        menuView.setMenuCallbacks(newPresenterCb, currentMenuCb);
      }
    }

    // OnMenuItemClickListener to tint submenu items
    final Field menuItemClickListener = Toolbar.class
        .getDeclaredField("mOnMenuItemClickListener");
    menuItemClickListener.setAccessible(true);
    Toolbar.OnMenuItemClickListener currentClickListener = (Toolbar.OnMenuItemClickListener) menuItemClickListener
        .get(toolbar);
    if (!(currentClickListener instanceof ATHOnMenuItemClickListener)) {
      final ATHOnMenuItemClickListener newClickListener = new ATHOnMenuItemClickListener(context,
          menuWidgetColor, currentClickListener, toolbar);
      toolbar.setOnMenuItemClickListener(newClickListener);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 7
Source File: DemoActivity.java    From material-menu with Apache License 2.0 4 votes vote down vote up
private static MaterialMenuDrawable getMaterialMenu(Toolbar toolbar) {
    return (MaterialMenuDrawable) toolbar.getNavigationIcon();
}