summaryrefslogtreecommitdiff
path: root/library/main/src/com/android/setupwizardlib/items/ButtonItem.java
diff options
context:
space:
mode:
Diffstat (limited to 'library/main/src/com/android/setupwizardlib/items/ButtonItem.java')
-rw-r--r--library/main/src/com/android/setupwizardlib/items/ButtonItem.java244
1 files changed, 119 insertions, 125 deletions
diff --git a/library/main/src/com/android/setupwizardlib/items/ButtonItem.java b/library/main/src/com/android/setupwizardlib/items/ButtonItem.java
index 07802ae..b398f4d 100644
--- a/library/main/src/com/android/setupwizardlib/items/ButtonItem.java
+++ b/library/main/src/com/android/setupwizardlib/items/ButtonItem.java
@@ -25,7 +25,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-
import com.android.setupwizardlib.R;
/**
@@ -34,128 +33,123 @@ import com.android.setupwizardlib.R;
*/
public class ButtonItem extends AbstractItem implements View.OnClickListener {
- public interface OnClickListener {
- void onClick(ButtonItem item);
- }
-
- private boolean mEnabled = true;
- private CharSequence mText;
- private int mTheme = R.style.SuwButtonItem;
- private OnClickListener mListener;
-
- private Button mButton;
-
- public ButtonItem() {
- super();
- }
-
- public ButtonItem(Context context, AttributeSet attrs) {
- super(context, attrs);
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuwButtonItem);
- mEnabled = a.getBoolean(R.styleable.SuwButtonItem_android_enabled, true);
- mText = a.getText(R.styleable.SuwButtonItem_android_text);
- mTheme = a.getResourceId(R.styleable.SuwButtonItem_android_theme, R.style.SuwButtonItem);
- a.recycle();
- }
-
- public void setOnClickListener(OnClickListener listener) {
- mListener = listener;
- }
-
- public void setText(CharSequence text) {
- mText = text;
- }
-
- public CharSequence getText() {
- return mText;
- }
-
- /**
- * The theme to use for this button. This can be used to create button of a particular style
- * (e.g. a colored or borderless button). Typically {@code android:buttonStyle} will be set in
- * the theme to change the style applied by the button.
- *
- * @param theme Resource ID of the theme
- */
- public void setTheme(int theme) {
- mTheme = theme;
- mButton = null;
- }
-
- /**
- * @return Resource ID of the theme used by this button.
- */
- public int getTheme() {
- return mTheme;
- }
-
- public void setEnabled(boolean enabled) {
- mEnabled = enabled;
- }
-
- @Override
- public int getCount() {
- return 0;
- }
-
- @Override
- public boolean isEnabled() {
- return mEnabled;
- }
-
- @Override
- public int getLayoutResource() {
- return 0;
- }
-
- /**
- * Do not use this since ButtonItem is not directly part of a list.
- */
- @Override
- public final void onBindView(View view) {
- throw new UnsupportedOperationException("Cannot bind to ButtonItem's view");
- }
-
- /**
- * Create a button according to this button item.
- *
- * @param parent The parent of the button, used to retrieve the theme and context for this
- * button.
- * @return A button that can be added to the parent.
- */
- protected Button createButton(ViewGroup parent) {
- if (mButton == null) {
- Context context = parent.getContext();
- if (mTheme != 0) {
- context = new ContextThemeWrapper(context, mTheme);
- }
- mButton = createButton(context);
- mButton.setOnClickListener(this);
- } else {
- if (mButton.getParent() instanceof ViewGroup) {
- // A view cannot be added to a different parent if one already exists. Remove this
- // button from its parent before returning.
- ((ViewGroup) mButton.getParent()).removeView(mButton);
- }
- }
- mButton.setEnabled(mEnabled);
- mButton.setText(mText);
- mButton.setId(getViewId());
- return mButton;
- }
-
- @Override
- public void onClick(View v) {
- if (mListener != null) {
- mListener.onClick(this);
- }
- }
-
- @SuppressLint("InflateParams") // This is used similar to Button(Context), so it's OK to not
- // specify the parent.
- private Button createButton(Context context) {
- // Inflate a single button from XML, so that when using support lib, it will take advantage
- // of the injected layout inflater and give us AppCompatButton instead.
- return (Button) LayoutInflater.from(context).inflate(R.layout.suw_button, null, false);
- }
+ public interface OnClickListener {
+ void onClick(ButtonItem item);
+ }
+
+ private boolean enabled = true;
+ private CharSequence text;
+ private int theme = R.style.SuwButtonItem;
+ private OnClickListener listener;
+
+ private Button button;
+
+ public ButtonItem() {
+ super();
+ }
+
+ public ButtonItem(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuwButtonItem);
+ enabled = a.getBoolean(R.styleable.SuwButtonItem_android_enabled, true);
+ text = a.getText(R.styleable.SuwButtonItem_android_text);
+ theme = a.getResourceId(R.styleable.SuwButtonItem_android_theme, R.style.SuwButtonItem);
+ a.recycle();
+ }
+
+ public void setOnClickListener(OnClickListener listener) {
+ this.listener = listener;
+ }
+
+ public void setText(CharSequence text) {
+ this.text = text;
+ }
+
+ public CharSequence getText() {
+ return text;
+ }
+
+ /**
+ * The theme to use for this button. This can be used to create button of a particular style (e.g.
+ * a colored or borderless button). Typically {@code android:buttonStyle} will be set in the theme
+ * to change the style applied by the button.
+ *
+ * @param theme Resource ID of the theme
+ */
+ public void setTheme(int theme) {
+ this.theme = theme;
+ button = null;
+ }
+
+ /** @return Resource ID of the theme used by this button. */
+ public int getTheme() {
+ return theme;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public int getCount() {
+ return 0;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public int getLayoutResource() {
+ return 0;
+ }
+
+ /** Do not use this since ButtonItem is not directly part of a list. */
+ @Override
+ public final void onBindView(View view) {
+ throw new UnsupportedOperationException("Cannot bind to ButtonItem's view");
+ }
+
+ /**
+ * Create a button according to this button item.
+ *
+ * @param parent The parent of the button, used to retrieve the theme and context for this button.
+ * @return A button that can be added to the parent.
+ */
+ protected Button createButton(ViewGroup parent) {
+ if (button == null) {
+ Context context = parent.getContext();
+ if (theme != 0) {
+ context = new ContextThemeWrapper(context, theme);
+ }
+ button = createButton(context);
+ button.setOnClickListener(this);
+ } else {
+ if (button.getParent() instanceof ViewGroup) {
+ // A view cannot be added to a different parent if one already exists. Remove this
+ // button from its parent before returning.
+ ((ViewGroup) button.getParent()).removeView(button);
+ }
+ }
+ button.setEnabled(enabled);
+ button.setText(text);
+ button.setId(getViewId());
+ return button;
+ }
+
+ @SuppressLint("InflateParams") // This is used similar to Button(Context), so it's OK to not
+ // specify the parent.
+ private Button createButton(Context context) {
+ // Inflate a single button from XML, so that when using support lib, it will take advantage
+ // of the injected layout inflater and give us AppCompatButton instead.
+ return (Button) LayoutInflater.from(context).inflate(R.layout.suw_button, null, false);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (listener != null) {
+ listener.onClick(this);
+ }
+ }
}