2012-05-31 23:01:50 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-05-15 17:41:25 +00:00
|
|
|
package org.mozilla.gecko.menu;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.R;
|
2012-05-31 23:01:50 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class MenuItemActionBar extends ImageButton
|
|
|
|
implements GeckoMenuItem.Layout {
|
2012-05-31 23:01:50 +00:00
|
|
|
private static final String LOGTAG = "GeckoMenuItemActionBar";
|
|
|
|
|
2013-06-05 22:28:02 +00:00
|
|
|
public MenuItemActionBar(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
2012-05-31 23:01:50 +00:00
|
|
|
public MenuItemActionBar(Context context, AttributeSet attrs) {
|
2013-06-05 22:28:02 +00:00
|
|
|
this(context, attrs, R.attr.menuItemActionBarStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MenuItemActionBar(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
2012-05-31 23:01:50 +00:00
|
|
|
|
2012-07-28 06:13:34 +00:00
|
|
|
int size = (int) (context.getResources().getDimension(R.dimen.browser_toolbar_height));
|
|
|
|
setLayoutParams(new ViewGroup.LayoutParams(size, size));
|
2012-05-31 23:01:50 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 23:02:22 +00:00
|
|
|
@Override
|
2013-06-05 22:28:02 +00:00
|
|
|
public void initialize(GeckoMenuItem item) {
|
|
|
|
if (item == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setIcon(item.getIcon());
|
|
|
|
setTitle(item.getTitle());
|
|
|
|
setEnabled(item.isEnabled());
|
2013-07-04 00:42:47 +00:00
|
|
|
setId(item.getItemId());
|
2013-02-21 23:02:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-05 22:28:02 +00:00
|
|
|
private void setIcon(Drawable icon) {
|
2012-05-31 23:01:50 +00:00
|
|
|
if (icon != null) {
|
|
|
|
setImageDrawable(icon);
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
} else {
|
|
|
|
setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 22:28:02 +00:00
|
|
|
private void setIcon(int icon) {
|
2012-05-31 23:01:50 +00:00
|
|
|
if (icon != 0) {
|
|
|
|
setImageResource(icon);
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
} else {
|
|
|
|
setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 22:28:02 +00:00
|
|
|
private void setTitle(CharSequence title) {
|
2012-07-31 10:02:53 +00:00
|
|
|
// set accessibility contentDescription here
|
|
|
|
setContentDescription(title);
|
2012-05-31 23:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
setColorFilter(enabled ? 0 : 0xFF999999);
|
|
|
|
}
|
|
|
|
}
|