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.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
|
|
|
}
|
|
|
|
|
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-12-18 18:49:48 -08:00
|
|
|
void setIcon(Drawable icon) {
|
2013-12-20 14:51:53 -08:00
|
|
|
if (icon == null) {
|
2012-05-31 16:01:50 -07:00
|
|
|
setVisibility(GONE);
|
2013-12-20 14:51:53 -08:00
|
|
|
} else {
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
setImageDrawable(icon);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 18:49:48 -08:00
|
|
|
void setIcon(int icon) {
|
2013-12-20 14:51:53 -08:00
|
|
|
setIcon((icon == 0) ? null : getResources().getDrawable(icon));
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2013-12-18 18:49:48 -08:00
|
|
|
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);
|
|
|
|
}
|
2013-12-18 18:49:53 -08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setShowIcon(boolean show) {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|