1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/menu/MenuItemActionBar.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.menu; 1.9 + 1.10 +import org.mozilla.gecko.R; 1.11 + 1.12 +import android.content.Context; 1.13 +import android.graphics.drawable.Drawable; 1.14 +import android.util.AttributeSet; 1.15 +import android.widget.ImageButton; 1.16 + 1.17 +public class MenuItemActionBar extends ImageButton 1.18 + implements GeckoMenuItem.Layout { 1.19 + private static final String LOGTAG = "GeckoMenuItemActionBar"; 1.20 + 1.21 + public MenuItemActionBar(Context context) { 1.22 + this(context, null); 1.23 + } 1.24 + 1.25 + public MenuItemActionBar(Context context, AttributeSet attrs) { 1.26 + this(context, attrs, R.attr.menuItemActionBarStyle); 1.27 + } 1.28 + 1.29 + public MenuItemActionBar(Context context, AttributeSet attrs, int defStyle) { 1.30 + super(context, attrs, defStyle); 1.31 + } 1.32 + 1.33 + @Override 1.34 + public void initialize(GeckoMenuItem item) { 1.35 + if (item == null) 1.36 + return; 1.37 + 1.38 + setIcon(item.getIcon()); 1.39 + setTitle(item.getTitle()); 1.40 + setEnabled(item.isEnabled()); 1.41 + setId(item.getItemId()); 1.42 + } 1.43 + 1.44 + void setIcon(Drawable icon) { 1.45 + if (icon == null) { 1.46 + setVisibility(GONE); 1.47 + } else { 1.48 + setVisibility(VISIBLE); 1.49 + setImageDrawable(icon); 1.50 + } 1.51 + } 1.52 + 1.53 + void setIcon(int icon) { 1.54 + setIcon((icon == 0) ? null : getResources().getDrawable(icon)); 1.55 + } 1.56 + 1.57 + void setTitle(CharSequence title) { 1.58 + // set accessibility contentDescription here 1.59 + setContentDescription(title); 1.60 + } 1.61 + 1.62 + @Override 1.63 + public void setEnabled(boolean enabled) { 1.64 + super.setEnabled(enabled); 1.65 + setColorFilter(enabled ? 0 : 0xFF999999); 1.66 + } 1.67 + 1.68 + @Override 1.69 + public void setShowIcon(boolean show) { 1.70 + // Do nothing. 1.71 + } 1.72 +}