2012-05-31 16:01:50 -07: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 10:41:25 -07:00
|
|
|
package org.mozilla.gecko.menu;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.R;
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class MenuItemActionBar extends ImageButton
|
|
|
|
implements GeckoMenuItem.Layout {
|
2012-05-31 16:01:50 -07:00
|
|
|
private static final String LOGTAG = "GeckoMenuItemActionBar";
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
public MenuItemActionBar(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
public MenuItemActionBar(Context context, AttributeSet attrs) {
|
2013-06-05 15:28:02 -07:00
|
|
|
this(context, attrs, R.attr.menuItemActionBarStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MenuItemActionBar(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
2012-05-31 16:01:50 -07:00
|
|
|
|
2012-07-27 23:13:34 -07:00
|
|
|
int size = (int) (context.getResources().getDimension(R.dimen.browser_toolbar_height));
|
|
|
|
setLayoutParams(new ViewGroup.LayoutParams(size, size));
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2013-02-21 15:02:22 -08:00
|
|
|
@Override
|
2013-06-05 15:28:02 -07:00
|
|
|
public void initialize(GeckoMenuItem item) {
|
|
|
|
if (item == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setIcon(item.getIcon());
|
|
|
|
setTitle(item.getTitle());
|
|
|
|
setEnabled(item.isEnabled());
|
2013-07-03 17:42:47 -07:00
|
|
|
setId(item.getItemId());
|
2013-02-21 15:02:22 -08:00
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
private void setIcon(Drawable icon) {
|
2012-05-31 16:01:50 -07:00
|
|
|
if (icon != null) {
|
|
|
|
setImageDrawable(icon);
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
} else {
|
|
|
|
setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
private void setIcon(int icon) {
|
2012-05-31 16:01:50 -07:00
|
|
|
if (icon != 0) {
|
|
|
|
setImageResource(icon);
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
} else {
|
|
|
|
setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
private void setTitle(CharSequence title) {
|
2012-07-31 03:02:53 -07:00
|
|
|
// set accessibility contentDescription here
|
|
|
|
setContentDescription(title);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
setColorFilter(enabled ? 0 : 0xFF999999);
|
|
|
|
}
|
|
|
|
}
|