android.support.v7.widget.ActionMenuView Java Examples

The following examples show how to use android.support.v7.widget.ActionMenuView. 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: ToolbarHandler.java    From NightOwl with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(@NonNull View view, @NonNull Object value) {
    Toolbar toolbar = (Toolbar) view;
    int themeId = (int) value;
    try {
        ActionMenuView actionMenuView = (ActionMenuView) sActionMenuViewField.get(toolbar);
        if ( actionMenuView == null ){
            toolbar.getContext().setTheme(themeId);
        } else {
            MenuPresenter presenter = (MenuPresenter) sPresenterField.get(actionMenuView);
            Context context = (Context) sContextField.get(presenter);
            context.setTheme(themeId);
        }

    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    toolbar.setPopupTheme((Integer) value);
}
 
Example #2
Source File: TransitionUtil.java    From android-transition with Apache License 2.0 6 votes vote down vote up
/**
 * Search for a particular menu
 *
 * @param toolbar
 * @param menuId
 * @return the corresponding MenuItem, or null if not found
 */
public static MenuItem getMenuItem(@NonNull Toolbar toolbar, @IdRes int menuId) {
    View v;
    int childCount;
    View innerView;
    MenuItem menuItem;
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        v = toolbar.getChildAt(i);
        if (v instanceof ActionMenuView) {
            childCount = ((ActionMenuView) v).getChildCount();
            for (int j = 0; j < childCount; j++) {
                innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    menuItem = ((ActionMenuItemView) innerView).getItemData();
                    if (menuItem.getItemId() == menuId) {
                        return menuItem;
                    }
                }
            }
        }
    }
    return null;
}
 
Example #3
Source File: TransitionUtil.java    From android-transition with Apache License 2.0 6 votes vote down vote up
/**
 * Get the list of visible MenuItems
 *
 * @param toolbar
 * @return the list of visible MenuItems
 */
public static List<MenuItem> getVisibleMenuItemList(@NonNull Toolbar toolbar) {
    List<MenuItem> list = new ArrayList<>();
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        final View v = toolbar.getChildAt(i);
        if (v instanceof ActionMenuView) {
            int childCount = ((ActionMenuView) v).getChildCount();
            for (int j = 0; j < childCount; j++) {
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    list.add(((ActionMenuItemView) innerView).getItemData());
                }
            }
        }
    }
    return list;
}
 
Example #4
Source File: SecondActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing13_13() {
  // Listing 13-13: Adding a menu to an Action Menu View
  ActionMenuView actionMenuView = findViewById(R.id.menu_view);

  MenuInflater menuInflater = getMenuInflater();
  menuInflater.inflate(R.menu.action_menu, actionMenuView.getMenu());

  actionMenuView.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
    public boolean onMenuItemClick(MenuItem item) {
      switch (item.getItemId()) {
        case (R.id.action_menu_item) :
          // TODO Handle menu clicks.
          return true;
        default: return false;
      }
    }
  });
}
 
Example #5
Source File: ToolbarManager.java    From MDPreference with Apache License 2.0 6 votes vote down vote up
private void onGlobalLayout() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
    else
        mToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(mOnGlobalLayoutListener);

    ActionMenuView menuView = getMenuView();
    for(int i = 0, count = menuView == null ? 0 : menuView.getChildCount(); i < count; i++){
        View child = menuView.getChildAt(i);
        if(mRippleStyle != 0){
            if(child.getBackground() == null || !(child.getBackground() instanceof ToolbarRippleDrawable))
                ViewUtil.setBackground(child, getBackground());
        }
    }

    if(mGroupChanged){
        animateIn();
        mGroupChanged = false;
    }
}
 
Example #6
Source File: ToolbarColorizeHelper.java    From RetroMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            final ActionMenuView overflowViewParent = (ActionMenuView) outViews.get(0).getParent();
            overflowViewParent.getOverflowIcon().setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
Example #7
Source File: BaseActivity.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);
    }
 
Example #8
Source File: RatingsAdapter.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
public HeaderHolder(View v, MenuInflater menuInflater) {
	super(v);
	avatarImage = (ImageView) v.findViewById(R.id.avatar_image);
	userNameText = (TextView) v.findViewById(R.id.user_name_text);
	userCountText = (TextView) v.findViewById(R.id.user_count_text);
	refreshMenu = (ActionMenuView) v.findViewById(R.id.refresh_menu);
	menuInflater.inflate(R.menu.menu_refresh, refreshMenu.getMenu());
}
 
Example #9
Source File: ToolbarContentTintHelper.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
public static void applyOverflowMenuTint(final @NonNull Context context, final Toolbar toolbar,
    final @ColorInt int color) {
  if (toolbar == null) {
    return;
  }
  toolbar.post(new Runnable() {
    @Override
    public void run() {
      try {
        Field f1 = Toolbar.class.getDeclaredField("mMenuView");
        f1.setAccessible(true);
        ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
        Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
        f2.setAccessible(true);

        // Actually ActionMenuPresenter
        BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
        Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
        f3.setAccessible(true);
        MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
        setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color);

        Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
        f4.setAccessible(true);
        MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
        setTintForMenuPopupHelper(context, subMenuPopupHelper, color);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  });
}
 
Example #10
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
public FloatingSearchView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    if (isInEditMode()) {
        mActivity = null;
    } else {
        mActivity = getActivity();
    }

    setFocusable(true);
    setFocusableInTouchMode(true);

    inflate(getContext(), R.layout.fsv_floating_search_layout, this);

    mSearchInput = (LogoEditText)findViewById(R.id.fsv_search_text);
    mNavButtonView = (ImageView) findViewById(R.id.fsv_search_action_navigation);
    mRecyclerView = (RecyclerView) findViewById(R.id.fsv_suggestions_list);
    mDivider = findViewById(R.id.fsv_suggestions_divider);
    mSearchContainer = (ViewGroup) findViewById(R.id.fsv_search_container);
    mActionMenu = (ActionMenuView) findViewById(R.id.fsv_search_action_menu);

    //TODO: move elevation parameters to XML attributes
    mSearchBackground = new RoundRectDrawableWithShadow(
            DEFAULT_CONTENT_COLOR, ViewUtils.dpToPx(DEFAULT_RADIUS),
            ViewUtils.dpToPx(DEFAULT_ELEVATION),
            ViewUtils.dpToPx(DEFAULT_MAX_ELEVATION));
    mSearchBackground.setAddPaddingForCorners(true);

    mCardDecorator = new SuggestionItemDecorator(mSearchBackground.mutate());

    applyXmlAttributes(attrs, defStyleAttr, 0);
    setupViews();
}
 
Example #11
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
public FloatingSearchView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    if (isInEditMode()) {
        mActivity = null;
    } else {
        mActivity = getActivity();
    }

    setFocusable(true);
    setFocusableInTouchMode(true);

    inflate(getContext(), R.layout.fsv_floating_search_layout, this);

    mSearchInput = (LogoEditText)findViewById(R.id.fsv_search_text);
    mNavButtonView = (ImageView) findViewById(R.id.fsv_search_action_navigation);
    mRecyclerView = (RecyclerView) findViewById(R.id.fsv_suggestions_list);
    mDivider = findViewById(R.id.fsv_suggestions_divider);
    mSearchContainer = (ViewGroup) findViewById(R.id.fsv_search_container);
    mActionMenu = (ActionMenuView) findViewById(R.id.fsv_search_action_menu);

    //TODO: move elevation parameters to XML attributes
    mSearchBackground = new RoundRectDrawableWithShadow(
            DEFAULT_CONTENT_COLOR, ViewUtils.dpToPx(DEFAULT_RADIUS),
            ViewUtils.dpToPx(DEFAULT_ELEVATION),
            ViewUtils.dpToPx(DEFAULT_MAX_ELEVATION));
    mSearchBackground.setAddPaddingForCorners(true);

    mCardDecorator = new SuggestionItemDecorator(mSearchBackground.mutate());

    applyXmlAttributes(attrs, defStyleAttr, 0);
    setupViews();
}
 
Example #12
Source File: ToolbarManager.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
private void animateIn(){
    ActionMenuView menuView = getMenuView();

    for(int i = 0, count = menuView == null ? 0 : menuView.getChildCount(); i < count; i++){
        View child = menuView.getChildAt(i);
        Animation anim = mAnimator.getInAnimation(child, i);
        if(anim != null)
            child.startAnimation(anim);
    }
}
 
Example #13
Source File: BaseActivity.java    From WheelViewDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);
    }
 
Example #14
Source File: BaseActivity.java    From CameraMaskDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);
    }
 
Example #15
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 4 votes vote down vote up
public void setOnMenuItemClickListener(ActionMenuView.OnMenuItemClickListener listener) {
    mActionMenu.setOnMenuItemClickListener(listener);
}
 
Example #16
Source File: ActorToolbar.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void doColorizing(View v, final ColorFilter colorFilter, int toolbarIconsColor) {
        if (v instanceof ImageButton) {
            ((ImageButton) v).getDrawable().setAlpha(255);
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }

        if (v instanceof ImageView && !(v instanceof AvatarView)) {
            ((ImageView) v).getDrawable().setAlpha(255);
            ((ImageView) v).getDrawable().setColorFilter(colorFilter);
        }

        if (v instanceof AutoCompleteTextView) {
            ((AutoCompleteTextView) v).setTextColor(toolbarIconsColor);
        }

        if (v instanceof TextView) {
            ((TextView) v).setTextColor(toolbarIconsColor);
        }

        if (v instanceof EditText) {
            ((EditText) v).setTextColor(toolbarIconsColor);
        }

        if (v instanceof ViewGroup) {
            for (int lli = 0; lli < ((ViewGroup) v).getChildCount(); lli++) {
                doColorizing(((ViewGroup) v).getChildAt(lli), colorFilter, toolbarIconsColor);
            }
        }

        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that
                //are not back button, nor text, nor overflow menu icon.
                final View innerView = ((ActionMenuView) v).getChildAt(j);

                if (innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView) innerView).getCompoundDrawables().length;
                    for (int k = 0; k < drawablesCount; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread,
                            //by adding it to the message queue
                            //Won't work otherwise.
                            //Works fine for my case but needs more testing

                            ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);

//                              innerView.post(new Runnable() {
//                                  @Override
//                                  public void run() {
//                                      ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
//                                  }
//                              });
                        }
                    }
                }
            }
        }
    }
 
Example #17
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static BaseDSL.ViewClassResult actionMenuView() {
  return BaseDSL.v(ActionMenuView.class);
}
 
Example #18
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void actionMenuView(Anvil.Renderable r) {
  return BaseDSL.v(ActionMenuView.class, r);
}
 
Example #19
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onMenuItemClick(ActionMenuView.OnMenuItemClickListener arg) {
  return BaseDSL.attr("onMenuItemClick", arg);
}
 
Example #20
Source File: ToolbarColorizeHelper.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        //Step 1 : Changing the color of back button (or open drawer button).
        if (v instanceof ImageButton) {
            //Action Bar back button
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }


        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
                //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread, by adding it to the message queue
                            //Won't work otherwise.
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
Example #21
Source File: OverlayContentLayout.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
private void refreshToolbar(Menu menu) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    menu.findItem(R.id.resync_action).setVisible(getLyrics().isLRC());
    menu.findItem(R.id.convert_action).setVisible(getLyrics().isLRC());
    menu.findItem(R.id.save_action).setVisible(!sharedPreferences.getBoolean("pref_auto_save", true));
    menu.findItem(R.id.action_vote).setVisible("user-submission".equals(getLyrics().getSource()));
    MenuItem romanizeMenuItem = menu.findItem(R.id.romanize_action); // .setVisible(RomanizeUtil.detectIdeographic(getLyrics().getText()));

    if (romanizeMenuItem != null && getLyrics() != null && getLyrics().getText() != null && getLyrics().getFlag() == Lyrics.POSITIVE_RESULT) {
        boolean isIdeographic = RomanizeUtil.detectIdeographic(getLyrics().getText());
        Lyrics storedLyrics = null;
        if (!isIdeographic) {
            storedLyrics = getLyrics() == null ? null :
                    DatabaseHelper.getInstance(getContext()).get(new String[]{
                            getLyrics().getArtist(),
                            getLyrics().getTitle(),
                            getLyrics().getOriginalArtist(),
                            getLyrics().getOriginalTitle()});
        }
        romanizeMenuItem.setVisible(isIdeographic ||
                (storedLyrics != null && RomanizeUtil.detectIdeographic(storedLyrics.getText())));
        romanizeMenuItem.setTitle(isIdeographic ? R.string.romanize : R.string.reset);

        if (getLyrics().getFlag() == Lyrics.POSITIVE_RESULT
                && sharedPreferences.getBoolean("pref_auto_save", true)) {
            if (storedLyrics == null || (getLyrics().isLRC() && !getLyrics().isLRC())) {
                lyricsPresentInDB = true;
                new WriteToDatabaseTask().execute(this, menu.findItem(R.id.save_action), getLyrics());
            }
            menu.findItem(R.id.save_action).setVisible(false);
        }
    } else {
        romanizeMenuItem.setVisible(false);
    }

    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View toolbarChild = toolbar.getChildAt(i);
        if (toolbarChild instanceof ActionMenuView) {
            ViewGroup actionBarContainer = (ViewGroup) toolbarChild;
            for (int j = 0; j < actionBarContainer.getChildCount(); j++) {
                View v = actionBarContainer.getChildAt(j);
                v.setOnLongClickListener(menuItemLongClickListener);
            }
            break;
        }
    }
}
 
Example #22
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 #23
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 4 votes vote down vote up
public void setOnMenuItemClickListener(ActionMenuView.OnMenuItemClickListener listener) {
    mActionMenu.setOnMenuItemClickListener(listener);
}
 
Example #24
Source File: ToolbarColorizeHelper.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        //Step 1 : Changing the color of back button (or open drawer button).
        if (v instanceof ImageButton) {
            //Action Bar back button
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }


        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
                //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread, by adding it to the message queue
                            //Won't work otherwise.
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
Example #25
Source File: ToolbarColorizeHelper.java    From IdeaTrackerPlus with MIT License 4 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        //Step 1 : Changing the color of back button (or open drawer button).
        if (v instanceof ImageButton) {
            //Action Bar back button
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }


        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
                //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread, by adding it to the message queue
                            //Won't work otherwise.
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
Example #26
Source File: EmptyFragmentActivity.java    From WheelViewDemo with Apache License 2.0 4 votes vote down vote up
@Override
    public void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        //You can initialize custom action bar here.
        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        TextView tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ImageView ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        ActionMenuView actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
    }
 
Example #27
Source File: BaseActivity.java    From WheelViewDemo with Apache License 2.0 4 votes vote down vote up
public ActionMenuView getActionMenuView() {
    return actionMenuView;
}
 
Example #28
Source File: EmptyFragmentActivity.java    From CameraMaskDemo with Apache License 2.0 4 votes vote down vote up
@Override
    public void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        //You can initialize custom action bar here.
        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        TextView tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ImageView ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        ActionMenuView actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
    }
 
Example #29
Source File: BaseActivity.java    From CameraMaskDemo with Apache License 2.0 4 votes vote down vote up
public ActionMenuView getActionMenuView() {
    return actionMenuView;
}
 
Example #30
Source File: EmptyFragmentActivity.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
@Override
    public void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        //You can initialize custom action bar here.
        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        TextView tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ImageView ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        ActionMenuView actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
    }