Show larger ripple when toggling check marks

Closes #78
pull/84/merge
Alinson S. Xavier 10 years ago
parent 677a643e5b
commit 4db7a6e89c

@ -330,17 +330,18 @@ public class ListHabitsFragment extends Fragment
private void toggleCheck(View v) private void toggleCheck(View v)
{ {
Long tag = (Long) v.getTag(R.string.habit_key); Long id = helper.getHabitIdFromCheckmarkView(v);
Integer offset = (Integer) v.getTag(R.string.offset_key); Habit habit = loader.habits.get(id);
long timestamp = DateHelper.getStartOfDay(
DateHelper.getLocalTime() - offset * DateHelper.millisecondsInOneDay);
Habit habit = loader.habits.get(tag);
if(habit == null) return; if(habit == null) return;
listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); float x = v.getX() + v.getWidth() / 2.0f + ((View) v.getParent()).getX();
float y = v.getY() + v.getHeight() / 2.0f + ((View) v.getParent()).getY();
helper.triggerRipple((View) v.getParent().getParent(), x, y);
listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
helper.toggleCheckmarkView(v, habit); helper.toggleCheckmarkView(v, habit);
long timestamp = helper.getTimestampFromCheckmarkView(v);
executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId()); executeCommand(new ToggleRepetitionCommand(habit, timestamp), habit.getId());
} }

@ -21,6 +21,7 @@ package org.isoron.uhabits.helpers;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -241,6 +242,36 @@ public class ListHabitsHelper
updateCheckmark(androidColor, (TextView) v, 2); updateCheckmark(androidColor, (TextView) v, 2);
} }
public Long getHabitIdFromCheckmarkView(View v)
{
return (Long) v.getTag(R.string.habit_key);
}
public long getTimestampFromCheckmarkView(View v)
{
Integer offset = (Integer) v.getTag(R.string.offset_key);
return DateHelper.getStartOfDay(DateHelper.getLocalTime() -
offset * DateHelper.millisecondsInOneDay);
}
public void triggerRipple(View v, final float x, final float y)
{
final Drawable background = v.getBackground();
if (android.os.Build.VERSION.SDK_INT >= 21)
background.setHotspot(x, y);
background.setState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled});
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
background.setState(new int[]{});
}
}, 25);
}
private static class HotspotTouchListener implements View.OnTouchListener private static class HotspotTouchListener implements View.OnTouchListener
{ {
@Override @Override

@ -28,8 +28,4 @@
<item name="android:layout_alignParentTop">true</item> <item name="android:layout_alignParentTop">true</item>
<item name="android:paddingRight">4dp</item> <item name="android:paddingRight">4dp</item>
</style> </style>
<style name="ListHabits.Checkmark" parent="ListHabits.CheckmarkCommon">
<item name="android:background">@drawable/ripple_transparent</item>
</style>
</resources> </resources>

@ -72,17 +72,13 @@
<item name="android:gravity">center_vertical</item> <item name="android:gravity">center_vertical</item>
</style> </style>
<style name="ListHabits.CheckmarkCommon"> <style name="ListHabits.Checkmark">
<item name="android:focusable">false</item> <item name="android:focusable">false</item>
<item name="android:minHeight">@dimen/checkmarkHeight</item> <item name="android:minHeight">@dimen/checkmarkHeight</item>
<item name="android:width">@dimen/checkmarkWidth</item> <item name="android:width">@dimen/checkmarkWidth</item>
<item name="android:gravity">center</item> <item name="android:gravity">center</item>
</style> </style>
<style name="ListHabits.Checkmark" parent="ListHabits.CheckmarkCommon">
</style>
<style name="ListHabits.EmptyState"> <style name="ListHabits.EmptyState">
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>

Loading…
Cancel
Save