diff --git a/astrid/res/layout/control_set_title.xml b/astrid/res/layout/control_set_title.xml index 143148dc9..0e74064d8 100644 --- a/astrid/res/layout/control_set_title.xml +++ b/astrid/res/layout/control_set_title.xml @@ -2,17 +2,22 @@ - + - diff --git a/astrid/res/layout/task_adapter_row.xml b/astrid/res/layout/task_adapter_row.xml index 62154cb32..34b0413d9 100644 --- a/astrid/res/layout/task_adapter_row.xml +++ b/astrid/res/layout/task_adapter_row.xml @@ -43,10 +43,11 @@ android:visibility="gone" > - = IMPORTANCE_RESOURCES.length) value = IMPORTANCE_RESOURCES.length - 1; if (useLegacyImportance) { - checkBoxView.setButtonDrawable(R.drawable.btn_check); + checkBoxView.setImageResource(R.drawable.btn_check); viewHolder.importance.setBackgroundResource(LEGACY_IMPORTANCE_RESOURCES[value]); } else if (!TextUtils.isEmpty(task.getValue(Task.RECURRENCE))) { - checkBoxView.setButtonDrawable(IMPORTANCE_REPEAT_RESOURCES[value]); + checkBoxView.setImageResource(IMPORTANCE_REPEAT_RESOURCES[value]); } else { - checkBoxView.setButtonDrawable(IMPORTANCE_RESOURCES[value]); + checkBoxView.setImageResource(IMPORTANCE_RESOURCES[value]); } if (pictureView != null && pictureView.getVisibility() == View.VISIBLE) { checkBoxView.setVisibility(View.INVISIBLE); diff --git a/astrid/src/com/todoroo/astrid/ui/CheckableImageView.java b/astrid/src/com/todoroo/astrid/ui/CheckableImageView.java new file mode 100644 index 000000000..4baff1815 --- /dev/null +++ b/astrid/src/com/todoroo/astrid/ui/CheckableImageView.java @@ -0,0 +1,98 @@ +package com.todoroo.astrid.ui; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.ViewDebug; +import android.widget.Checkable; +import android.widget.ImageView; + +public class CheckableImageView extends ImageView implements Checkable { + + private static final int[] CHECKED_STATE_SET = { + android.R.attr.state_checked + }; + + public CheckableImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public static interface OnCheckedChangeListener { + public void onCheckedChanged(Checkable c, boolean isChecked); + } + + @Override + public boolean performClick() { + toggle(); + return super.performClick(); + } + + private boolean mChecked; + private boolean mBroadcasting; + private OnCheckedChangeListener mOnCheckedChangeListener; + + public void toggle() { + setChecked(!mChecked); + } + + @ViewDebug.ExportedProperty + public boolean isChecked() { + return mChecked; + } + + /** + *

Changes the checked state of this button.

+ * + * @param checked true to check the button, false to uncheck it + */ + public void setChecked(boolean checked) { + if (mChecked != checked) { + mChecked = checked; + refreshDrawableState(); + + // Avoid infinite recursions if setChecked() is called from a listener + if (mBroadcasting) { + return; + } + + mBroadcasting = true; + if (mOnCheckedChangeListener != null) { + mOnCheckedChangeListener.onCheckedChanged(this, mChecked); + } + + mBroadcasting = false; + } + } + + /** + * Register a callback to be invoked when the checked state of this button + * changes. + * + * @param listener the callback to call on checked state change + */ + public void setOnCheckedChangeListener(OnCheckedChangeListener listener) { + mOnCheckedChangeListener = listener; + } + + @Override + public int[] onCreateDrawableState(int extraSpace) { + final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); + if (isChecked()) { + mergeDrawableStates(drawableState, CHECKED_STATE_SET); + } + return drawableState; + } + + @Override + protected void drawableStateChanged() { + super.drawableStateChanged(); + + if (getDrawable() != null) { + int[] myDrawableState = getDrawableState(); + + // Set the state of the Drawable + getDrawable().setState(myDrawableState); + + invalidate(); + } + } +} diff --git a/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java b/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java index 2ed86e67d..b13d7bc15 100644 --- a/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java @@ -1,11 +1,10 @@ package com.todoroo.astrid.ui; import android.app.Activity; +import android.view.View; +import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import com.timsu.astrid.R; @@ -24,7 +23,7 @@ import com.todoroo.astrid.service.TaskService; public class EditTextControlSet extends TaskEditControlSet { private EditText editText; private final StringProperty property; - protected CheckBox completeBox; + protected CheckableImageView completeBox; private final int editTextId; @Autowired @@ -41,18 +40,17 @@ public class EditTextControlSet extends TaskEditControlSet { @Override protected void afterInflate() { this.editText = (EditText) getView().findViewById(editTextId); - this.completeBox = (CheckBox) getView().findViewById(R.id.completeBox); + this.completeBox = (CheckableImageView) getView().findViewById(R.id.completeBox); } @Override protected void readFromTaskOnInitialize() { editText.setTextKeepState(model.getValue(property)); completeBox.setChecked(model.isCompleted()); - completeBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { + completeBox.setOnClickListener(new OnClickListener() { @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - - ScaleAnimation scaleAnimation = new ScaleAnimation(1.6f, 1.0f, 1.6f, 1.0f, + public void onClick(View v) { + ScaleAnimation scaleAnimation = new ScaleAnimation(1.5f, 1.0f, 1.5f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(100); // set check box to actual action item state diff --git a/astrid/src/com/todoroo/astrid/ui/EditTitleControlSet.java b/astrid/src/com/todoroo/astrid/ui/EditTitleControlSet.java index cc65ca62d..d6b1e539f 100644 --- a/astrid/src/com/todoroo/astrid/ui/EditTitleControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/EditTitleControlSet.java @@ -47,9 +47,9 @@ public class EditTitleControlSet extends EditTextControlSet implements Importanc valueToUse = TaskAdapter.IMPORTANCE_RESOURCES.length - 1; if(valueToUse < TaskAdapter.IMPORTANCE_RESOURCES.length) { if (isRepeating) { - completeBox.setButtonDrawable(TaskAdapter.IMPORTANCE_REPEAT_RESOURCES[valueToUse]); + completeBox.setImageResource(TaskAdapter.IMPORTANCE_REPEAT_RESOURCES[valueToUse]); } else { - completeBox.setButtonDrawable(TaskAdapter.IMPORTANCE_RESOURCES[valueToUse]); + completeBox.setImageResource(TaskAdapter.IMPORTANCE_RESOURCES[valueToUse]); } } }