|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 package org.mozilla.gecko.menu; |
|
6 |
|
7 import org.mozilla.gecko.R; |
|
8 |
|
9 import android.content.Context; |
|
10 import android.graphics.drawable.Drawable; |
|
11 import android.util.AttributeSet; |
|
12 import android.widget.ImageButton; |
|
13 |
|
14 public class MenuItemActionBar extends ImageButton |
|
15 implements GeckoMenuItem.Layout { |
|
16 private static final String LOGTAG = "GeckoMenuItemActionBar"; |
|
17 |
|
18 public MenuItemActionBar(Context context) { |
|
19 this(context, null); |
|
20 } |
|
21 |
|
22 public MenuItemActionBar(Context context, AttributeSet attrs) { |
|
23 this(context, attrs, R.attr.menuItemActionBarStyle); |
|
24 } |
|
25 |
|
26 public MenuItemActionBar(Context context, AttributeSet attrs, int defStyle) { |
|
27 super(context, attrs, defStyle); |
|
28 } |
|
29 |
|
30 @Override |
|
31 public void initialize(GeckoMenuItem item) { |
|
32 if (item == null) |
|
33 return; |
|
34 |
|
35 setIcon(item.getIcon()); |
|
36 setTitle(item.getTitle()); |
|
37 setEnabled(item.isEnabled()); |
|
38 setId(item.getItemId()); |
|
39 } |
|
40 |
|
41 void setIcon(Drawable icon) { |
|
42 if (icon == null) { |
|
43 setVisibility(GONE); |
|
44 } else { |
|
45 setVisibility(VISIBLE); |
|
46 setImageDrawable(icon); |
|
47 } |
|
48 } |
|
49 |
|
50 void setIcon(int icon) { |
|
51 setIcon((icon == 0) ? null : getResources().getDrawable(icon)); |
|
52 } |
|
53 |
|
54 void setTitle(CharSequence title) { |
|
55 // set accessibility contentDescription here |
|
56 setContentDescription(title); |
|
57 } |
|
58 |
|
59 @Override |
|
60 public void setEnabled(boolean enabled) { |
|
61 super.setEnabled(enabled); |
|
62 setColorFilter(enabled ? 0 : 0xFF999999); |
|
63 } |
|
64 |
|
65 @Override |
|
66 public void setShowIcon(boolean show) { |
|
67 // Do nothing. |
|
68 } |
|
69 } |