Back to project page Resonos-Android-Framework.
The source code is released under:
Apache License
If you think the Android project Resonos-Android-Framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.resonos.apps.library; /* ww w .ja va 2 s . c om*/ import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.view.View; import com.resonos.apps.library.util.AppUtils; /** * This class denotes a menu item for the action bar, or for the custom toolbar widget * @author Chris Newhouse */ public class Action { // constants public static final int ICON_BITMAP = -1; public static final int ICON_NONE = 0; public static final int ALPHA_DISABLED = 100; // global vars private static int counter = 0; // data public String text; public int icon; public int id; private Bitmap bmp; public boolean wt, over; public Enum<?> tag; public boolean nonPressable = false, disabled = false, pressed = false; public View customControl = null; public boolean customControlFill = false; public boolean newRow = false; public boolean priority = true; // public ActionProvider actionProvider = null; /** * * Construct a new Action for an ActionBar or ToolBar using a resource for image * @param Title * @param i, the icon resource id, or 0 for none * @param true to show text instead of tooltip * @param true to put into the overflow menu (ActionBar only) * @param this is the tag of the action from the enum for this toolbar/actionbar */ public Action(String t, int i, boolean withText, boolean overflow, Enum<?> tg) { text = t; icon = i; wt = withText; over = overflow; id = counter++; tag = tg; } /** * Construct a new Action for an ActionBar or ToolBar using a bitmap * @param Title * @param The bitmap to use * @param true to show text instead of tooltip * @param true to put into the overflow menu (ActionBar only) * @param this is the tag of the action from the enum for this toolbar/actionbar */ public Action(String t, Bitmap bmp, boolean withText, boolean overflow, Enum<?> tg) { text = t; icon = ICON_BITMAP; this.bmp = bmp; wt = withText; over = overflow; id = counter++; tag = tg; } /** * set this action to be not pressable (toolbar only) * @return this action for chaining */ public Action setNonPressable() { nonPressable = true; return this; } /** * set this action to forced in the actionbar or not * @return true = forced, false = if room */ public Action setPriority(boolean high) { priority = high; return this; } /** * Set this action to be disabled * @return this action for chaining */ public Action setDisabled() { disabled = true; return this; } /** * Set this action to be not pressable (toolbar only) * @return this action for chaining */ public Action setPressed(boolean p) { pressed = p; return this; } // commented out because ActionBarSherlock is not at a state where // the ShareActionProvider is actually bug free // it just causes random crashes to occur in my experience // /** // * Adds an Action Provider to this button (ActionBar only) // * @return this action for chaining // */ // public Action actionProvider(ActionProvider ap) { // actionProvider = ap; // return this; // } /** * Set this action to be on a new row (toolbar only). * All subsequent actions will be on this row. * @return this action for chaining */ public Action newRow() { newRow = true; return this; } /** * Add a custom View in this Action (toolbar only) * @param the custom view * @param true if you want this control to fill the rest of the row * @return this action for chaining */ public Action customControl(View v, boolean fill) { customControl = v; customControlFill = fill; nonPressable = true; return this; } /** * Gets the drawable for the icon in this button, whether it is a bitmap or resource * @param Context to access resources * @return the drawable, or null if there is none */ public Drawable getDrawable(Context mCX) { if (icon == Action.ICON_BITMAP) return new BitmapDrawable(mCX.getResources(), bmp); else if (icon != Action.ICON_NONE) { if (disabled) { Drawable d = AppUtils.getMutableDrawable(mCX, icon); d.setAlpha(ALPHA_DISABLED); return d; } else return mCX.getResources().getDrawable(icon); } else return null; } }