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/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2012-07-28 06:13:34 +00:00
|
|
|
import android.content.res.Resources;
|
2012-05-31 23:01:50 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.widget.ImageView;
|
2012-05-31 23:01:50 +00:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.LinearLayout.LayoutParams;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class MenuItemDefault extends LinearLayout
|
|
|
|
implements GeckoMenuItem.Layout {
|
2012-05-31 23:01:50 +00:00
|
|
|
private static final String LOGTAG = "GeckoMenuItemDefault";
|
|
|
|
|
|
|
|
private ImageView mIcon;
|
|
|
|
private TextView mTitle;
|
|
|
|
private ImageView mCheck;
|
|
|
|
|
|
|
|
public MenuItemDefault(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
|
2012-07-28 06:13:34 +00:00
|
|
|
Resources res = context.getResources();
|
|
|
|
setLayoutParams(new LayoutParams((int) (res.getDimension(R.dimen.menu_item_row_width)),
|
|
|
|
(int) (res.getDimension(R.dimen.menu_item_row_height))));
|
2012-05-31 23:01:50 +00:00
|
|
|
setBackgroundResource(R.drawable.menu_item_bg);
|
|
|
|
|
|
|
|
inflate(context, R.layout.menu_item, this);
|
|
|
|
mIcon = (ImageView) findViewById(R.id.icon);
|
|
|
|
mTitle = (TextView) findViewById(R.id.title);
|
|
|
|
mCheck = (ImageView) findViewById(R.id.check);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCheckable(boolean checkable) {
|
|
|
|
mCheck.setVisibility(checkable ? VISIBLE : GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setChecked(boolean checked) {
|
|
|
|
mCheck.setVisibility(checked ? VISIBLE : GONE);
|
|
|
|
}
|
|
|
|
}
|