Fixed animations and placement of checkboxes by introducing a checkable image view (checkbox without text)

pull/14/head
Sam Bosley 13 years ago
parent a3b46dec31
commit ea580ffe15

@ -2,17 +2,22 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="10dip" android:paddingTop="10dip"
android:paddingBottom="10dip"
android:paddingLeft="0dip"
android:paddingRight="0dip" android:paddingRight="0dip"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" > android:orientation="horizontal" >
<CheckBox <com.todoroo.astrid.ui.CheckableImageView
android:id="@+id/completeBox" android:id="@+id/completeBox"
android:layout_width="45dip" android:layout_width="45dip"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:gravity="center_vertical" android:layout_marginRight="5dip"
android:button="@drawable/btn_check" /> android:layout_marginLeft="5dip"
android:gravity="center"
android:padding="8dip"
android:src="@drawable/btn_check" />
<com.todoroo.astrid.ui.ErrorCatchingEditText <com.todoroo.astrid.ui.ErrorCatchingEditText
android:id="@+id/title" android:id="@+id/title"

@ -37,12 +37,13 @@
android:paddingBottom="1dip"> android:paddingBottom="1dip">
<CheckBox <com.todoroo.astrid.ui.CheckableImageView
android:id="@+id/completeBox" android:id="@+id/completeBox"
android:layout_width="45dip" android:layout_width="45dip"
android:padding="8dip"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginLeft="10dip" android:layout_marginLeft="2dip"
android:button="@drawable/btn_check" /> android:button="@drawable/btn_check" />
<!-- assignee photo --> <!-- assignee photo -->

@ -43,10 +43,11 @@
android:visibility="gone" > android:visibility="gone" >
</greendroid.widget.AsyncImageView> </greendroid.widget.AsyncImageView>
<CheckBox <com.todoroo.astrid.ui.CheckableImageView
android:id="@+id/completeBox" android:id="@+id/completeBox"
android:layout_width="45dip" android:layout_width="45dip"
android:layout_marginLeft="13dip" android:padding="8dip"
android:layout_marginLeft="5dip"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:minHeight="40dip" android:minHeight="40dip"
android:scaleType="center" android:scaleType="center"

@ -79,6 +79,7 @@ import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.taskrabbit.TaskRabbitDataService; import com.todoroo.astrid.taskrabbit.TaskRabbitDataService;
import com.todoroo.astrid.taskrabbit.TaskRabbitTaskContainer; import com.todoroo.astrid.taskrabbit.TaskRabbitTaskContainer;
import com.todoroo.astrid.timers.TimerDecorationExposer; import com.todoroo.astrid.timers.TimerDecorationExposer;
import com.todoroo.astrid.ui.CheckableImageView;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
/** /**
@ -271,7 +272,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
viewHolder.nameView = (TextView)view.findViewById(R.id.title); viewHolder.nameView = (TextView)view.findViewById(R.id.title);
viewHolder.picture = (AsyncImageView)view.findViewById(R.id.picture); viewHolder.picture = (AsyncImageView)view.findViewById(R.id.picture);
viewHolder.pictureBorder = (ImageView)view.findViewById(R.id.pictureBorder); viewHolder.pictureBorder = (ImageView)view.findViewById(R.id.pictureBorder);
viewHolder.completeBox = (CheckBox)view.findViewById(R.id.completeBox); viewHolder.completeBox = (CheckableImageView)view.findViewById(R.id.completeBox);
viewHolder.dueDate = (TextView)view.findViewById(R.id.dueDate); viewHolder.dueDate = (TextView)view.findViewById(R.id.dueDate);
viewHolder.details1 = (TextView)view.findViewById(R.id.details1); viewHolder.details1 = (TextView)view.findViewById(R.id.details1);
viewHolder.details2 = (TextView)view.findViewById(R.id.details2); viewHolder.details2 = (TextView)view.findViewById(R.id.details2);
@ -337,7 +338,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
public ViewGroup rowBody; public ViewGroup rowBody;
public TextView nameView; public TextView nameView;
public View importance; // for legacy importance style public View importance; // for legacy importance style
public CheckBox completeBox; public CheckableImageView completeBox;
public AsyncImageView picture; public AsyncImageView picture;
public ImageView pictureBorder; public ImageView pictureBorder;
public TextView dueDate; public TextView dueDate;
@ -398,7 +399,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
// complete box // complete box
final CheckBox completeBox = viewHolder.completeBox; { final CheckableImageView completeBox = viewHolder.completeBox; {
// show item as completed if it was recently checked // show item as completed if it was recently checked
if(completedItems.get(task.getId()) != null) { if(completedItems.get(task.getId()) != null) {
task.setValue(Task.COMPLETION_DATE, task.setValue(Task.COMPLETION_DATE,
@ -441,7 +442,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
// importance bar // importance bar
final CheckBox checkBoxView = viewHolder.completeBox; { final CheckableImageView checkBoxView = viewHolder.completeBox; {
// Logic for legacy style // Logic for legacy style
boolean useLegacyImportance = Preferences.getBoolean(R.string.p_useLegacyImportanceStyle, false); boolean useLegacyImportance = Preferences.getBoolean(R.string.p_useLegacyImportanceStyle, false);
if (useLegacyImportance) { if (useLegacyImportance) {
@ -454,12 +455,12 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
if (value >= IMPORTANCE_RESOURCES.length) if (value >= IMPORTANCE_RESOURCES.length)
value = IMPORTANCE_RESOURCES.length - 1; value = IMPORTANCE_RESOURCES.length - 1;
if (useLegacyImportance) { if (useLegacyImportance) {
checkBoxView.setButtonDrawable(R.drawable.btn_check); checkBoxView.setImageResource(R.drawable.btn_check);
viewHolder.importance.setBackgroundResource(LEGACY_IMPORTANCE_RESOURCES[value]); viewHolder.importance.setBackgroundResource(LEGACY_IMPORTANCE_RESOURCES[value]);
} else if (!TextUtils.isEmpty(task.getValue(Task.RECURRENCE))) { } else if (!TextUtils.isEmpty(task.getValue(Task.RECURRENCE))) {
checkBoxView.setButtonDrawable(IMPORTANCE_REPEAT_RESOURCES[value]); checkBoxView.setImageResource(IMPORTANCE_REPEAT_RESOURCES[value]);
} else { } else {
checkBoxView.setButtonDrawable(IMPORTANCE_RESOURCES[value]); checkBoxView.setImageResource(IMPORTANCE_RESOURCES[value]);
} }
if (pictureView != null && pictureView.getVisibility() == View.VISIBLE) { if (pictureView != null && pictureView.getVisibility() == View.VISIBLE) {
checkBoxView.setVisibility(View.INVISIBLE); checkBoxView.setVisibility(View.INVISIBLE);

@ -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;
}
/**
* <p>Changes the checked state of this button.</p>
*
* @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();
}
}
}

@ -1,11 +1,10 @@
package com.todoroo.astrid.ui; package com.todoroo.astrid.ui;
import android.app.Activity; import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.ScaleAnimation; import android.view.animation.ScaleAnimation;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText; import android.widget.EditText;
import com.timsu.astrid.R; import com.timsu.astrid.R;
@ -24,7 +23,7 @@ import com.todoroo.astrid.service.TaskService;
public class EditTextControlSet extends TaskEditControlSet { public class EditTextControlSet extends TaskEditControlSet {
private EditText editText; private EditText editText;
private final StringProperty property; private final StringProperty property;
protected CheckBox completeBox; protected CheckableImageView completeBox;
private final int editTextId; private final int editTextId;
@Autowired @Autowired
@ -41,18 +40,17 @@ public class EditTextControlSet extends TaskEditControlSet {
@Override @Override
protected void afterInflate() { protected void afterInflate() {
this.editText = (EditText) getView().findViewById(editTextId); this.editText = (EditText) getView().findViewById(editTextId);
this.completeBox = (CheckBox) getView().findViewById(R.id.completeBox); this.completeBox = (CheckableImageView) getView().findViewById(R.id.completeBox);
} }
@Override @Override
protected void readFromTaskOnInitialize() { protected void readFromTaskOnInitialize() {
editText.setTextKeepState(model.getValue(property)); editText.setTextKeepState(model.getValue(property));
completeBox.setChecked(model.isCompleted()); completeBox.setChecked(model.isCompleted());
completeBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { completeBox.setOnClickListener(new OnClickListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onClick(View v) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1.5f, 1.0f, 1.5f, 1.0f,
ScaleAnimation scaleAnimation = new ScaleAnimation(1.6f, 1.0f, 1.6f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(100); scaleAnimation.setDuration(100);
// set check box to actual action item state // set check box to actual action item state

@ -47,9 +47,9 @@ public class EditTitleControlSet extends EditTextControlSet implements Importanc
valueToUse = TaskAdapter.IMPORTANCE_RESOURCES.length - 1; valueToUse = TaskAdapter.IMPORTANCE_RESOURCES.length - 1;
if(valueToUse < TaskAdapter.IMPORTANCE_RESOURCES.length) { if(valueToUse < TaskAdapter.IMPORTANCE_RESOURCES.length) {
if (isRepeating) { if (isRepeating) {
completeBox.setButtonDrawable(TaskAdapter.IMPORTANCE_REPEAT_RESOURCES[valueToUse]); completeBox.setImageResource(TaskAdapter.IMPORTANCE_REPEAT_RESOURCES[valueToUse]);
} else { } else {
completeBox.setButtonDrawable(TaskAdapter.IMPORTANCE_RESOURCES[valueToUse]); completeBox.setImageResource(TaskAdapter.IMPORTANCE_RESOURCES[valueToUse]);
} }
} }
} }

Loading…
Cancel
Save