From 85d78e566bf7ad50317b8f21bafa9d507f317f92 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Sun, 28 Aug 2016 04:23:45 -0700 Subject: [PATCH] Changed ProgressBar to SeekBar --- .../clock2/timers/TimerViewHolder.java | 20 +++++++++++++----- app/src/main/res/layout/item_timer.xml | 21 ++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java b/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java index f4502c4..37b0d20 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimerViewHolder.java @@ -5,7 +5,7 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; -import android.widget.ProgressBar; +import android.widget.SeekBar; import android.widget.TextView; import com.philliphsu.clock2.AsyncTimersTableUpdateHandler; @@ -17,6 +17,7 @@ import com.philliphsu.clock2.util.ProgressBarUtils; import butterknife.Bind; import butterknife.OnClick; +import butterknife.OnTouch; /** * Created by Phillip Hsu on 7/25/2016. @@ -31,7 +32,7 @@ public class TimerViewHolder extends BaseViewHolder { @Bind(R.id.label) TextView mLabel; @Bind(R.id.duration) CountdownChronometer mChronometer; - @Bind(R.id.progress_bar) ProgressBar mProgressBar; + @Bind(R.id.seek_bar) SeekBar mSeekBar; @Bind(R.id.add_one_minute) ImageButton mAddOneMinute; @Bind(R.id.start_pause) ImageButton mStartPause; @Bind(R.id.stop) ImageButton mStop; @@ -70,6 +71,11 @@ public class TimerViewHolder extends BaseViewHolder { mController.stop(); } + @OnTouch(R.id.seek_bar) + boolean captureTouchOnSeekBar() { + return true; // Do nothing when the user touches the seek bar + } + private void bindLabel(String label) { if (!label.isEmpty()) { mLabel.setText(label); @@ -131,11 +137,15 @@ public class TimerViewHolder extends BaseViewHolder { if (!timer.isRunning()) { // If our scale were 1, then casting ratio to an int will ALWAYS // truncate down to zero. - mProgressBar.setMax(100); - mProgressBar.setProgress((int) (100 * ratio)); + mSeekBar.setMax(100); + final int progress = (int) (100 * ratio); + mSeekBar.setProgress(progress); +// mSeekBar.getThumb().mutate().setAlpha(progress == 0 ? 0 : 255); } else { +// mSeekBar.getThumb().mutate().setAlpha(255); mProgressAnimator = ProgressBarUtils.startNewAnimator( - mProgressBar, ratio, timeRemaining); + mSeekBar, ratio, timeRemaining); } + mSeekBar.getThumb().mutate().setAlpha(timeRemaining <= 0 ? 0 : 255); } } diff --git a/app/src/main/res/layout/item_timer.xml b/app/src/main/res/layout/item_timer.xml index 4957108..9fef0c1 100644 --- a/app/src/main/res/layout/item_timer.xml +++ b/app/src/main/res/layout/item_timer.xml @@ -3,6 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginTop="8dp"> @@ -29,13 +30,19 @@ android:layout_centerHorizontal="true" android:textSize="45sp" android:layout_marginBottom="8dp"/> + - + + + android:layout_below="@id/duration" + android:paddingStart="0dp" + android:paddingEnd="0dp" + android:splitTrack="false"/> @@ -53,7 +60,7 @@ android:layout_height="48dp" android:src="@drawable/ic_half_day_1_24dp" android:background="?selectableItemBackground" - android:layout_below="@id/progress_bar" + android:layout_below="@id/seek_bar" android:layout_centerHorizontal="true"/>