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