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/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2012-07-27 23:13:34 -07:00
|
|
|
import android.content.res.Resources;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
2012-09-20 11:04:50 -07:00
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.CheckBox;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.widget.ImageView;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class MenuItemDefault extends LinearLayout
|
|
|
|
implements GeckoMenuItem.Layout {
|
2012-05-31 16:01:50 -07:00
|
|
|
private static final String LOGTAG = "GeckoMenuItemDefault";
|
|
|
|
|
|
|
|
private ImageView mIcon;
|
|
|
|
private TextView mTitle;
|
2012-09-20 11:04:50 -07:00
|
|
|
private CheckBox mCheck;
|
2012-09-27 11:04:02 -07:00
|
|
|
private ImageView mMore;
|
2012-09-20 11:04:50 -07:00
|
|
|
|
|
|
|
private boolean mCheckable;
|
|
|
|
private boolean mChecked;
|
2012-09-27 11:04:02 -07:00
|
|
|
private boolean mHasSubMenu;
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
public MenuItemDefault(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
|
2012-07-27 23:13:34 -07:00
|
|
|
Resources res = context.getResources();
|
2012-09-19 10:32:01 -07:00
|
|
|
setLayoutParams(new AbsListView.LayoutParams((int) (res.getDimension(R.dimen.menu_item_row_width)),
|
|
|
|
(int) (res.getDimension(R.dimen.menu_item_row_height))));
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
inflate(context, R.layout.menu_item, this);
|
|
|
|
mIcon = (ImageView) findViewById(R.id.icon);
|
|
|
|
mTitle = (TextView) findViewById(R.id.title);
|
2012-09-20 11:04:50 -07:00
|
|
|
mCheck = (CheckBox) findViewById(R.id.check);
|
2012-09-27 11:04:02 -07:00
|
|
|
mMore = (ImageView) findViewById(R.id.more);
|
2012-09-20 11:04:50 -07:00
|
|
|
|
|
|
|
mCheckable = false;
|
|
|
|
mChecked = false;
|
2012-09-27 11:04:02 -07:00
|
|
|
mHasSubMenu = false;
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getLayout() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setIcon(Drawable icon) {
|
|
|
|
if (icon != null) {
|
|
|
|
mIcon.setImageDrawable(icon);
|
|
|
|
mIcon.setVisibility(VISIBLE);
|
|
|
|
} else {
|
|
|
|
mIcon.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setIcon(int icon) {
|
|
|
|
if (icon != 0) {
|
|
|
|
mIcon.setImageResource(icon);
|
|
|
|
mIcon.setVisibility(VISIBLE);
|
|
|
|
} else {
|
|
|
|
mIcon.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTitle(CharSequence title) {
|
|
|
|
mTitle.setText(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
mTitle.setEnabled(enabled);
|
|
|
|
mCheck.setEnabled(enabled);
|
|
|
|
mIcon.setColorFilter(enabled ? 0 : 0xFF999999);
|
2012-09-27 11:04:02 -07:00
|
|
|
mMore.setColorFilter(enabled ? 0 : 0xFF999999);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCheckable(boolean checkable) {
|
2012-09-20 11:04:50 -07:00
|
|
|
mCheckable = checkable;
|
2012-09-27 11:04:02 -07:00
|
|
|
mCheck.setVisibility(mCheckable && !mHasSubMenu ? VISIBLE : GONE);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setChecked(boolean checked) {
|
2012-09-20 11:04:50 -07:00
|
|
|
mChecked = checked;
|
|
|
|
mCheck.setChecked(mChecked);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
2012-09-27 11:04:02 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSubMenuIndicator(boolean hasSubMenu) {
|
|
|
|
mHasSubMenu = hasSubMenu;
|
|
|
|
mMore.setVisibility(mHasSubMenu ? VISIBLE : GONE);
|
|
|
|
mCheck.setVisibility(mCheckable && !mHasSubMenu ? VISIBLE : GONE);
|
|
|
|
}
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|