FileDocCategorySizeDatePackage
InCallMenuItemView.javaAPI DocAndroid 1.5 API6189Wed May 06 22:42:46 BST 2009com.android.phone

InCallMenuItemView

public class InCallMenuItemView extends android.widget.TextView
The View for each item in the {@link InCallMenuView}. Each in-call menu item has a text label, an optional "green LED" on/off indicator below the text, and an optional icon above the text. (It's really just a TextView, using "compound drawables" for the indicator and icon.) Originally modeled after android/widget/IconMenuItemView.java.

Fields Summary
private static final String
LOG_TAG
private static final boolean
DBG
private boolean
mIndicatorVisible
private boolean
mIndicatorState
private android.graphics.drawable.Drawable
mIndicatorDrawable
private android.graphics.drawable.Drawable
mIcon
Constructors Summary
public InCallMenuItemView(android.content.Context context)


       
        super(context);
        if (DBG) log("InCallMenuView constructor...");

        setGravity(Gravity.CENTER);

        TypedArray a =
                context.obtainStyledAttributes(
                        com.android.internal.R.styleable.MenuView);
        int textAppearance = a.getResourceId(com.android.internal.R.styleable.
                                             MenuView_itemTextAppearance, -1);
        // TODO: any other styleable attrs we need from the standard menu item style?
        a.recycle();

        setClickable(true);
        setFocusable(true);
        setTextAppearance(context, textAppearance);

        // These three are needed for marqueeing to look pretty
        setEllipsize(TruncateAt.MARQUEE);
        setHorizontalFadingEdgeEnabled(true);
        setSingleLine(true);

        // Set the padding like the regular menu items do
        setPadding(3, getPaddingTop(), 3, getPaddingBottom());
    
Methods Summary
public booleanisVisible()

        return (getVisibility() == VISIBLE);
    
private voidlog(java.lang.String msg)

        Log.d(LOG_TAG, msg);
    
public voidsetIcon(android.graphics.drawable.Drawable icon)
Sets this item's icon, to be drawn above the text label.

        if (DBG) log("setIcon(" + icon + ")...");
        mIcon = icon;
        updateCompoundDrawables();
    
public voidsetIconResource(int resId)
Sets this item's icon, to be drawn above the text label.

        if (DBG) log("setIconResource(" + resId + ")...");
         Drawable iconDrawable = getResources().getDrawable(resId);
         setIcon(iconDrawable);
    
public voidsetIndicatorState(boolean onoff)
Turns this item's "green LED" state indicator on or off.

        if (DBG) log("setIndicatorState(" + onoff + ")...");
        mIndicatorState = onoff;
        updateIndicator();
        updateCompoundDrawables();
    
public voidsetIndicatorVisible(boolean isVisible)
Sets whether or not this item's "green LED" state indicator should be visible.

        if (DBG) log("setIndicatorVisible(" + isVisible + ")...");
        mIndicatorVisible = isVisible;
        updateIndicator();
        updateCompoundDrawables();
    
public voidsetVisible(boolean isVisible)

        setVisibility(isVisible ? VISIBLE : GONE);
    
public java.lang.StringtoString()

        return "'" + getText() + "' (" + super.toString() + ")";
    
private voidupdateCompoundDrawables()
Installs mIcon and mIndicatorDrawable as our TextView "compound drawables", and does any necessary layout tweaking depending on the presence or absence of the icon or indicator.

        // TODO: There are several hand-tweaked layout constants hardcoded here.
        // If we ever move this widget into the framework (and make it
        // usable from XML), be sure to move these constants to XML too.

        // If the icon is visible, add a bit of negative padding to scoot
        // it down closer to the text.
        if (mIcon != null) {
            setCompoundDrawablePadding(-10);
        }

        // Add some top/bottom padding when the indicator and/or icon are
        // visible (to add a little vertical space between the indicator
        // and the bottom of the item, or the icon and the top of the
        // item.)
        int topPadding = (mIcon != null) ? 5 : 0;
        int bottomPadding = (mIndicatorDrawable != null) ? 5 : 0;
        setPadding(0, topPadding, 0, bottomPadding);

        // TODO: topPadding seems to have no effect here.
        // Regardless of the value I use, the icon image
        // ends up right up against the top edge of the button...
        // (Maybe we're just out of room?)
        // if (DBG) log("updateCompoundDrawables: padding: top " + topPadding
        //              + ", bottom " + bottomPadding);

        setCompoundDrawablesWithIntrinsicBounds(null, mIcon, null, mIndicatorDrawable);
    
private voidupdateIndicator()
Updates mIndicatorDrawable based on mIndicatorVisible and mIndicatorState.

        if (mIndicatorVisible) {
            int resId = mIndicatorState ? android.R.drawable.button_onoff_indicator_on
                    : android.R.drawable.button_onoff_indicator_off;
            mIndicatorDrawable = getResources().getDrawable(resId);
        } else {
            mIndicatorDrawable = null;
        }