The TimerActivity now lets you choose the break time as well.

This commit is contained in:
Christopher Beckmann 2017-09-08 17:42:29 +02:00
commit b715d442db
4 changed files with 161 additions and 43 deletions

View file

@ -168,9 +168,13 @@ public class ExerciseActivity extends AppCompatActivity implements android.suppo
@Override
public void onLoadFinished(Loader<ExerciseSet> loader, ExerciseSet set) {
this.set = set;
if(set != null) {
this.set = set;
} else {
this.set = new ExerciseSet();
}
if(set.size() > 0) {
if(this.set.size() > 0) {
setExercise(0);
} else {
// TODO IF THERE ARE NO EXERCISES ONLY SHOW TIMER : showTimer();

View file

@ -46,6 +46,9 @@ public class TimerActivity extends BaseActivity implements android.support.v4.ap
private static final String PREF_PICKER_MINUTES = TAG + ".PREF_PICKER_MINUTES";
private static final String PREF_PICKER_HOURS = TAG + ".PREF_PICKER_HOURS";
private static final String PREF_BREAK_PICKER_SECONDS = TAG + "PREF_BREAK_PICKER_SECONDS";
private static final String PREF_BREAK_PICKER_MINUTES = TAG + "PREF_BREAK_PICKER_MINUTES";
// UI
private ProgressBar progressBar;
private TextView timerText;
@ -54,6 +57,8 @@ public class TimerActivity extends BaseActivity implements android.support.v4.ap
private NumberPicker secondsPicker;
private NumberPicker minutesPicker;
private NumberPicker hoursPicker;
private NumberPicker secondsBreakPicker;
private NumberPicker minutesBreakPicker;
private LinearLayout pickerLayout;
private Spinner exerciseSetSpinner;
private ExerciseSetSpinnerAdapter exerciseSetAdapter;
@ -196,24 +201,38 @@ public class TimerActivity extends BaseActivity implements android.support.v4.ap
hoursPicker = (NumberPicker) findViewById(R.id.hours_picker);
pickerLayout = (LinearLayout) findViewById(R.id.picker_layout);
secondsBreakPicker = (NumberPicker) findViewById(R.id.seconds_break_picker);
minutesBreakPicker = (NumberPicker) findViewById(R.id.minutes_break_picker);
secondsPicker.setDisplayedValues(SECONDS_MINUTES);
secondsPicker.setMinValue(0);
secondsPicker.setMaxValue(SECONDS_MINUTES.length - 1);
secondsPicker.setValue(pref.getInt(PREF_PICKER_SECONDS, 0));
secondsBreakPicker.setDisplayedValues(SECONDS_MINUTES);
secondsBreakPicker.setMinValue(0);
secondsBreakPicker.setMaxValue(SECONDS_MINUTES.length - 1);
secondsBreakPicker.setValue(pref.getInt(PREF_BREAK_PICKER_SECONDS, 0));
minutesPicker.setDisplayedValues(SECONDS_MINUTES);
minutesPicker.setMinValue(0);
minutesPicker.setMaxValue(SECONDS_MINUTES.length - 1);
minutesPicker.setValue(pref.getInt(PREF_PICKER_MINUTES, 30));
minutesBreakPicker.setDisplayedValues(SECONDS_MINUTES);
minutesBreakPicker.setMinValue(0);
minutesBreakPicker.setMaxValue(SECONDS_MINUTES.length - 1);
minutesBreakPicker.setValue(pref.getInt(PREF_BREAK_PICKER_MINUTES, 0));
hoursPicker.setDisplayedValues(HOURS);
hoursPicker.setMinValue(0);
hoursPicker.setMaxValue(HOURS.length - 1);
hoursPicker.setValue(pref.getInt(PREF_PICKER_HOURS, 1));
setDividerColor(secondsPicker, R.color.transparent);
setDividerColor(minutesPicker, R.color.transparent);
setDividerColor(hoursPicker, R.color.transparent);
setDividerColor(secondsBreakPicker, R.color.transparent);
setDividerColor(minutesBreakPicker, R.color.transparent);
}
@ -271,6 +290,12 @@ public class TimerActivity extends BaseActivity implements android.support.v4.ap
saveCurrentSetDuration();
mTimerService.startTimer(duration);
progressBar.setMax((int) duration);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
pref.edit()
.putInt(PREF_BREAK_PICKER_SECONDS, secondsBreakPicker.getValue())
.putInt(PREF_BREAK_PICKER_MINUTES, minutesBreakPicker.getValue())
.putLong("PAUSE TIME", getCurrentSetBreakTime()).apply();
}
}
}
@ -289,6 +314,12 @@ public class TimerActivity extends BaseActivity implements android.support.v4.ap
return duration;
}
private long getCurrentSetBreakTime() {
long breakTime = secondsBreakPicker.getValue() * 1000;
breakTime += minutesBreakPicker.getValue() * 1000 * 60;
return breakTime;
}
private void updateUI() {
if(mTimerService != null) {
updateUI(mTimerService.isRunning(), mTimerService.isPaused(), mTimerService.getInitialDuration(), mTimerService.getRemainingDuration());

View file

@ -62,7 +62,7 @@
app:layout_constraintTop_toTopOf="@id/spinner_choose_exercise_set"
app:layout_constraintVertical_bias="0.0" /> -->
<RelativeLayout
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
@ -77,79 +77,152 @@
app:layout_constraintTop_toBottomOf="@+id/spinner_choose_exercise_set">
<LinearLayout
android:id="@+id/picker_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/picker_layout"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:visibility="visible"
android:divider="@color/colorAccent"
android:dividerPadding="4dp"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<NumberPicker
android:id="@+id/hours_picker"
android:layout_width="wrap_content"
android:layout_height="135dp"
android:clickable="false"
android:focusable="false"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textColor="@color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
android:theme="@style/AppTheme.NumberPicker" />
android:text="@string/activity_timer_choose_time"/>
<NumberPicker
android:id="@+id/minutes_picker"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="135dp"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
android:layout_height="wrap_content"
android:divider="@color/colorAccent"
android:dividerPadding="4dp"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<NumberPicker
android:id="@+id/hours_picker"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:clickable="false"
android:focusable="false"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textColor="@color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
android:theme="@style/AppTheme.NumberPicker" />
<NumberPicker
android:id="@+id/minutes_picker"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textColor="@color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
android:theme="@style/AppTheme.NumberPicker" />
<NumberPicker
android:id="@+id/seconds_picker"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:clipChildren="false"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textColor="@color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
android:theme="@style/AppTheme.NumberPicker" />
android:text="@string/activity_timer_choose_break"/>
<NumberPicker
android:id="@+id/seconds_picker"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="135dp"
android:clipChildren="false"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
android:layout_height="wrap_content"
android:divider="@color/colorAccent"
android:dividerPadding="4dp"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<NumberPicker
android:id="@+id/minutes_break_picker"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:clickable="false"
android:focusable="false"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textColor="@color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
android:theme="@style/AppTheme.NumberPicker" />
<NumberPicker
android:id="@+id/seconds_break_picker"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:theme="@style/AppTheme.NumberPicker"
android:descendantFocusability="blocksDescendants" />
</LinearLayout>
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="250dp"
android:layout_alignTop="@+id/timerText"
android:layout_centerHorizontal="true"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:max="100"
android:onClick="onClick"
android:padding="16dp"
android:progress="66"
android:progressDrawable="@drawable/progress_circular"
android:rotation="270"
android:visibility="invisible" />
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/timerText"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
@ -159,10 +232,18 @@
android:textColor="@color/colorPrimaryDark"
android:textSize="36sp"
android:textStyle="bold"
android:visibility="invisible" />
android:visibility="invisible"
app:layout_constraintTop_toTopOf="@+id/progressBar"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="@+id/progressBar"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="@+id/progressBar"
app:layout_constraintBottom_toBottomOf="@+id/progressBar"
android:layout_marginBottom="8dp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
<ImageButton
android:id="@+id/button_reset"

View file

@ -309,6 +309,8 @@
<string name="no">No</string>
<string name="exercise">Exercise</string>
<string name="remaining_time">Time remaining:</string>
<string name="activity_timer_choose_time">Select a work duration:</string>
<string name="activity_timer_choose_break">Select a break duration:</string>
</resources>