Skip to content

Commit

Permalink
Improve alarm and timer views
Browse files Browse the repository at this point in the history
- To be consistent, alarm and timer titles are the same size;
- The padding for timers is adjusted to be identical to the padding for alarms;
- A "0" has been removed from the Add time button when it's not requested;
- For Tablets, the Reset timer button can no longer be hidden by the floating action button;
- For tablets, Play/Pause and Add time buttons are no longer minimized, as is the case with phones in landscape mode;
- For phones in landscape mode, the size of the remaining time has been slightly reduced and timer sizes are longer;
- A ripple effect has been added to the Reset button when it is pressed;
  • Loading branch information
BlackyHawky committed Jun 23, 2024
1 parent 4686a13 commit 697e44b
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 71 deletions.
12 changes: 2 additions & 10 deletions app/src/main/java/com/best/deskclock/data/Timer.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,11 @@ Timer updateAfterTimeSet() {
Timer addCustomTime() {
// Expired and missed timers restart with the time indicated on the add time button.
if (mState == EXPIRED || mState == MISSED) {
if (mButtonTime.isEmpty()) {
return setRemainingTime(0);
} else {
return setRemainingTime(Integer.parseInt(mButtonTime) * MINUTE_IN_MILLIS);
}
return setRemainingTime(Integer.parseInt(mButtonTime) * MINUTE_IN_MILLIS);
}

// Otherwise try to add time indicated on the add time button to the remaining time.
if (mButtonTime.isEmpty()) {
return setRemainingTime(mRemainingTime);
} else {
return setRemainingTime(mRemainingTime + Integer.parseInt(mButtonTime) * MINUTE_IN_MILLIS);
}
return setRemainingTime(mRemainingTime + Integer.parseInt(mButtonTime) * MINUTE_IN_MILLIS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void onDestroyView() {
private void setAddButtonText() {
String addButtonText = Objects.requireNonNull(mAddTimeButtonBox.getText()).toString();

if (mTimerId >= 0) {
if (mTimerId >= 0 && !addButtonText.isEmpty()) {
final Timer timer = DataModel.getDataModel().getTimer(mTimerId);
if (timer != null) {
DataModel.getDataModel().setTimerButtonTime(timer, addButtonText);
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/best/deskclock/timer/TimerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mRecyclerView = view.findViewById(R.id.recycler_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(getLayoutManager(view.getContext()));
// Set a bottom padding for phones to prevent the reset button from being hidden by the FAB
if (!Utils.isTablet(requireContext())) {
final int bottomPadding = Utils.isPortrait(requireContext())
// Set a bottom padding to prevent the reset button from being hidden by the FAB
final int bottomPadding;
if (Utils.isTablet(requireContext())) {
bottomPadding = Utils.toPixel(110, requireContext());
} else {
bottomPadding = Utils.isPortrait(requireContext())
? Utils.toPixel(95, requireContext())
: Utils.toPixel(80, requireContext());
mRecyclerView.setPadding(0, 0, 0, bottomPadding);
mRecyclerView.setClipToPadding(false);
}
mRecyclerView.setPadding(0, 0, 0, bottomPadding);
mRecyclerView.setClipToPadding(false);

mTimersView = view.findViewById(R.id.timer_view);
mCreateTimerView = view.findViewById(R.id.timer_setup);
Expand Down
34 changes: 28 additions & 6 deletions app/src/main/java/com/best/deskclock/timer/TimerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.SystemClock;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
Expand All @@ -32,6 +31,9 @@
import com.google.android.material.button.MaterialButton;
import com.google.android.material.color.MaterialColors;

import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
* This view is a visual representation of a {@link Timer}.
*/
Expand Down Expand Up @@ -111,6 +113,26 @@ protected void onFinishInflate() {
if (!Utils.isTablet(getContext()) && !Utils.isLandscape(getContext())) {
mTimerTotalDurationText = findViewById(R.id.timer_total_duration);
}

// The size of the Play/Pause and add time buttons are reduced for phones in landscape mode
// due to the size of the timers unlike tablets
if (!Utils.isTablet(getContext()) && Utils.isLandscape(getContext())) {
mAddTimeButton.setIncludeFontPadding(false);
mAddTimeButton.setMinHeight(0);
mAddTimeButton.setMinimumHeight(0);
mAddTimeButton.setMinWidth(0);
mAddTimeButton.setMinimumWidth(0);
mAddTimeButton.setPadding(Utils.toPixel(10, getContext()), mAddTimeButton.getPaddingTop(),
Utils.toPixel(10, getContext()), mAddTimeButton.getPaddingBottom());

mPlayPauseButton.setIncludeFontPadding(false);
mPlayPauseButton.setMinHeight(0);
mPlayPauseButton.setMinimumHeight(0);
mPlayPauseButton.setMinWidth(0);
mPlayPauseButton.setMinimumWidth(0);
mPlayPauseButton.setPadding(Utils.toPixel(20, getContext()), mPlayPauseButton.getPaddingTop(),
Utils.toPixel(20, getContext()), mPlayPauseButton.getPaddingBottom());
}
}

/**
Expand Down Expand Up @@ -156,10 +178,10 @@ void update(Timer timer) {

// Update the time to add to timer in the "timer_add_time_button"
String buttonTime = timer.getButtonTime();
mAddTimeButton.setText(getContext().getString(R.string.timer_add_custom_time, buttonTime.isEmpty()
? DateUtils.formatElapsedTime(0)
: DateUtils.formatElapsedTime(Long.parseLong(buttonTime)))
);
long buttonTimeHours = TimeUnit.MINUTES.toHours(Long.parseLong(buttonTime));
long buttonTimeMinutes = TimeUnit.MINUTES.toMinutes(Long.parseLong(buttonTime)) % 60;
String buttonTimeFormatted = String.format(Locale.US, "%01d:%02d", buttonTimeHours, buttonTimeMinutes);
mAddTimeButton.setText(getContext().getString(R.string.timer_add_custom_time, buttonTimeFormatted));

String buttonContentDescription = getContext().getString(R.string.timer_add_custom_time_description, buttonTime);
mAddTimeButton.setContentDescription(buttonContentDescription);
Expand All @@ -175,7 +197,7 @@ void update(Timer timer) {

if (!Utils.isTablet(context) && !Utils.isLandscape(context)) {
final ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mPlayPauseButton.getLayoutParams();
params.topMargin = Utils.toPixel(timer.getState().equals(Timer.State.RESET) ? 20 : 0, context);
params.topMargin = Utils.toPixel(timer.getState().equals(Timer.State.RESET) ? 10 : 0, context);
mPlayPauseButton.setLayoutParams(params);
}

Expand Down
14 changes: 1 addition & 13 deletions app/src/main/java/com/best/deskclock/timer/TimerViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

Expand All @@ -35,8 +34,6 @@ public TimerViewHolder(View view, TimerClickHandler timerClickHandler) {
mTimerItem = (TimerItem) view;
mTimerClickHandler = timerClickHandler;

setLayoutParams(view);

view.findViewById(R.id.reset).setOnClickListener(v -> {
DataModel.getDataModel().resetOrDeleteTimer(getTimer(), R.string.label_deskclock);
Utils.setVibrationTime(context, 10);
Expand Down Expand Up @@ -77,7 +74,7 @@ public TimerViewHolder(View view, TimerClickHandler timerClickHandler) {
};

// If we click on the circular container when the phones (only) are in landscape mode,
// indicating a title for the timers is not feasible so in this case we click on the time text.
// indicating a title for the timers is not possible so in this case we click on the time text.
if (!Utils.isTablet(context) && Utils.isLandscape(context)) {
view.findViewById(R.id.timer_time_text).setOnClickListener(mPlayPauseListener);
} else {
Expand All @@ -97,15 +94,6 @@ public void onBind(int timerId) {
updateTime();
}

private void setLayoutParams(View view) {
if (Utils.isTablet(view.getContext()) && Utils.isLandscape(view.getContext())) {
ViewGroup.LayoutParams lp = view.getLayoutParams();
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
view.setLayoutParams(lp);
}
}

/**
* @return {@code true} if the timer is in a state that requires continuous updates
*/
Expand Down
42 changes: 17 additions & 25 deletions app/src/main/res/layout-land/timer_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="5dp"
android:layout_marginHorizontal="10dp"
android:padding="8dp">
android:paddingHorizontal="12dp"
android:paddingBottom="10dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/close"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintWidth_min="210dp">
app:layout_constraintWidth_min="220dp">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/timer_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
android:background="?attr/selectableItemBackground"
android:drawablePadding="8dp"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="end"
Expand All @@ -48,13 +50,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_close"
android:background="@android:color/transparent"
android:foreground="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/timer_delete"
app:tint="?colorPrimary"
android:scaleType="centerInside"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="@id/timer_label"
app:layout_constraintBottom_toBottomOf="@id/timer_label" />

<!-- Show circle for tablets. See CircleButtonsLayout.java -->
<com.best.deskclock.CircleButtonsLayout
Expand All @@ -63,7 +65,7 @@
android:layout_height="200dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHeight_max="240dp"
app:layout_constraintTop_toBottomOf="@id/close"
app:layout_constraintTop_toBottomOf="@id/timer_label"
app:layout_constraintBottom_toTopOf="@id/play_pause">

<com.best.deskclock.widget.AutoSizingTextView
Expand All @@ -72,11 +74,8 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="40sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/close"
app:layout_constraintBottom_toTopOf="@id/play_pause"
android:includeFontPadding="false"
android:textSize="@dimen/timer_time_text_size"
tools:text="01:23" />

<com.best.deskclock.timer.TimerCircleView
Expand All @@ -88,12 +87,9 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/timer_add_time_button"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:textStyle="bold"
android:paddingHorizontal="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/play_pause"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -103,24 +99,20 @@
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="20dp"
android:src="@drawable/ic_reset"
android:scaleType="centerInside"
android:background="@android:color/transparent"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/timer_reset"
app:tint="?colorPrimary"
app:layout_constraintEnd_toStartOf="@id/play_pause"
app:layout_constraintStart_toEndOf="@+id/timer_add_time_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/play_pause"
app:layout_constraintBottom_toBottomOf="@id/play_pause" />

<com.google.android.material.button.MaterialButton
android:id="@+id/play_pause"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingHorizontal="20dp"
android:contentDescription="@string/timer_start"
android:scaleType="centerInside"
app:iconGravity="textStart"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/alarm_time_collapsed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
app:drawableStartCompat="@drawable/ic_label"
app:drawableTint="@color/md_theme_onSurfaceVariant"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/add_label" />
tools:hint="@string/add_label" />

<include
layout="@layout/alarm_time_summary"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/alarm_time_expanded.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
android:ellipsize="end"
android:gravity="center_vertical"
android:singleLine="true"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
app:drawableStartCompat="@drawable/ic_label"
app:drawableTint="@color/md_theme_onSurfaceVariant"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:textStyle="bold"
tools:hint="@string/add_label" />

<ImageButton
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/res/layout/timer_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
android:layout_height="wrap_content"
android:layout_marginVertical="5dp"
android:layout_marginHorizontal="10dp"
android:padding="8dp">
android:paddingHorizontal="12dp"
android:paddingBottom="10dp">

<com.google.android.material.textview.MaterialTextView
android:id="@+id/timer_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
android:background="?attr/selectableItemBackground"
android:drawablePadding="8dp"
Expand All @@ -41,12 +42,12 @@
android:layout_height="wrap_content"
android:src="@drawable/ic_close"
android:scaleType="centerInside"
android:background="@android:color/transparent"
android:foreground="?attr/selectableItemBackground"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/timer_delete"
app:tint="?colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="@id/timer_label"
app:layout_constraintBottom_toBottomOf="@id/timer_label"/>

<com.best.deskclock.CircleButtonsLayout
android:id="@+id/circle_container"
Expand All @@ -62,6 +63,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:includeFontPadding="false"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -110,11 +112,11 @@
android:layout_height="wrap_content"
android:src="@drawable/ic_reset"
android:scaleType="centerInside"
android:background="@android:color/transparent"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/timer_reset"
app:tint="?colorPrimary"
app:layout_constraintStart_toEndOf="@id/timer_add_time_button"
app:layout_constraintEnd_toStartOf="@id/play_pause"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/play_pause"
app:layout_constraintBottom_toBottomOf="@+id/play_pause" />

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-sw600dp/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<resources>
<dimen name="main_clock_font_size">125sp</dimen>
<dimen name="big_font_size">115sp</dimen>
<dimen name="timer_time_text_size">40sp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<dimen name="main_clock_font_size">64sp</dimen>
<dimen name="big_font_size">32sp</dimen>
<dimen name="analog_clock_size">294dp</dimen>
<dimen name="timer_time_text_size">32sp</dimen>
</resources>

0 comments on commit 697e44b

Please sign in to comment.