2013-05-15 10:55:06 -07:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko.menu;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.R;
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
import android.annotation.TargetApi;
|
2013-05-15 10:55:06 -07:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
|
|
|
public class MenuItemActionView extends LinearLayout
|
|
|
|
implements GeckoMenuItem.Layout {
|
|
|
|
private static final String LOGTAG = "GeckoMenuItemActionView";
|
|
|
|
|
|
|
|
private MenuItemDefault mMenuItem;
|
|
|
|
private ImageButton mActionButton;
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
public MenuItemActionView(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
2013-05-15 10:55:06 -07:00
|
|
|
public MenuItemActionView(Context context, AttributeSet attrs) {
|
2013-06-05 15:28:02 -07:00
|
|
|
this(context, attrs, R.attr.menuItemActionViewStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@TargetApi(11)
|
|
|
|
public MenuItemActionView(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
2013-05-15 10:55:06 -07:00
|
|
|
|
|
|
|
Resources res = context.getResources();
|
|
|
|
int width = res.getDimensionPixelSize(R.dimen.menu_item_row_width);
|
|
|
|
int height = res.getDimensionPixelSize(R.dimen.menu_item_row_height);
|
|
|
|
setMinimumWidth(width);
|
|
|
|
setMinimumHeight(height);
|
|
|
|
|
|
|
|
LayoutInflater.from(context).inflate(R.layout.menu_item_action_view, this);
|
|
|
|
mMenuItem = (MenuItemDefault) findViewById(R.id.menu_item);
|
|
|
|
mActionButton = (ImageButton) findViewById(R.id.action_button);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-05 15:28:02 -07:00
|
|
|
public void initialize(GeckoMenuItem item) {
|
|
|
|
if (item == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setTitle(item.getTitle());
|
|
|
|
setIcon(item.getIcon());
|
|
|
|
setEnabled(item.isEnabled());
|
2013-05-15 10:55:06 -07:00
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
private void setIcon(Drawable icon) {
|
2013-05-15 10:55:06 -07:00
|
|
|
mMenuItem.setIcon(icon);
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
private void setIcon(int icon) {
|
2013-05-15 10:55:06 -07:00
|
|
|
mMenuItem.setIcon(icon);
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
private void setTitle(CharSequence title) {
|
2013-05-15 10:55:06 -07:00
|
|
|
mMenuItem.setTitle(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
mMenuItem.setEnabled(enabled);
|
|
|
|
|
|
|
|
if (mActionButton != null) {
|
|
|
|
mActionButton.setEnabled(enabled);
|
|
|
|
mActionButton.setAlpha(enabled ? 255 : 99);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 15:28:02 -07:00
|
|
|
public void setMenuItemClickListener(View.OnClickListener listener) {
|
|
|
|
mMenuItem.setOnClickListener(listener);
|
2013-05-15 10:55:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setActionButtonClickListener(View.OnClickListener listener) {
|
|
|
|
mActionButton.setOnClickListener(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setActionButton(Drawable drawable) {
|
2013-06-24 15:49:16 -07:00
|
|
|
if (drawable != null) {
|
|
|
|
mActionButton.setImageDrawable(drawable);
|
|
|
|
mActionButton.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mActionButton.setVisibility(View.GONE);
|
|
|
|
}
|
2013-05-15 10:55:06 -07:00
|
|
|
}
|
|
|
|
}
|