michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.menu; michael@0: michael@0: import org.mozilla.gecko.R; michael@0: michael@0: import android.content.Context; michael@0: import android.graphics.drawable.Drawable; michael@0: import android.util.AttributeSet; michael@0: import android.widget.ImageButton; michael@0: michael@0: public class MenuItemActionBar extends ImageButton michael@0: implements GeckoMenuItem.Layout { michael@0: private static final String LOGTAG = "GeckoMenuItemActionBar"; michael@0: michael@0: public MenuItemActionBar(Context context) { michael@0: this(context, null); michael@0: } michael@0: michael@0: public MenuItemActionBar(Context context, AttributeSet attrs) { michael@0: this(context, attrs, R.attr.menuItemActionBarStyle); michael@0: } michael@0: michael@0: public MenuItemActionBar(Context context, AttributeSet attrs, int defStyle) { michael@0: super(context, attrs, defStyle); michael@0: } michael@0: michael@0: @Override michael@0: public void initialize(GeckoMenuItem item) { michael@0: if (item == null) michael@0: return; michael@0: michael@0: setIcon(item.getIcon()); michael@0: setTitle(item.getTitle()); michael@0: setEnabled(item.isEnabled()); michael@0: setId(item.getItemId()); michael@0: } michael@0: michael@0: void setIcon(Drawable icon) { michael@0: if (icon == null) { michael@0: setVisibility(GONE); michael@0: } else { michael@0: setVisibility(VISIBLE); michael@0: setImageDrawable(icon); michael@0: } michael@0: } michael@0: michael@0: void setIcon(int icon) { michael@0: setIcon((icon == 0) ? null : getResources().getDrawable(icon)); michael@0: } michael@0: michael@0: void setTitle(CharSequence title) { michael@0: // set accessibility contentDescription here michael@0: setContentDescription(title); michael@0: } michael@0: michael@0: @Override michael@0: public void setEnabled(boolean enabled) { michael@0: super.setEnabled(enabled); michael@0: setColorFilter(enabled ? 0 : 0xFF999999); michael@0: } michael@0: michael@0: @Override michael@0: public void setShowIcon(boolean show) { michael@0: // Do nothing. michael@0: } michael@0: }