1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-26 01:27:33 +01:00

Add alarm title and description field to alarm configuation

Wire it up and enable for Fossil Hybrid HR
This commit is contained in:
Andreas Shimokawa 2020-04-24 10:39:32 +02:00
parent ca5d177608
commit fa2d954552
6 changed files with 158 additions and 96 deletions

View File

@ -22,6 +22,7 @@ import android.text.format.DateFormat;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.CheckedTextView; import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.TimePicker; import android.widget.TimePicker;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -46,6 +47,8 @@ public class AlarmDetails extends AbstractGBActivity {
private CheckedTextView cbFriday; private CheckedTextView cbFriday;
private CheckedTextView cbSaturday; private CheckedTextView cbSaturday;
private CheckedTextView cbSunday; private CheckedTextView cbSunday;
private EditText title;
private EditText description;
private GBDevice device; private GBDevice device;
@Override @Override
@ -56,6 +59,9 @@ public class AlarmDetails extends AbstractGBActivity {
alarm = (Alarm) getIntent().getSerializableExtra(nodomain.freeyourgadget.gadgetbridge.model.Alarm.EXTRA_ALARM); alarm = (Alarm) getIntent().getSerializableExtra(nodomain.freeyourgadget.gadgetbridge.model.Alarm.EXTRA_ALARM);
device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE); device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
title = findViewById(R.id.alarm_title);
description = findViewById(R.id.alarm_description);
timePicker = findViewById(R.id.alarm_time_picker); timePicker = findViewById(R.id.alarm_time_picker);
cbSmartWakeup = findViewById(R.id.alarm_cb_smart_wakeup); cbSmartWakeup = findViewById(R.id.alarm_cb_smart_wakeup);
cbSnooze = findViewById(R.id.alarm_cb_snooze); cbSnooze = findViewById(R.id.alarm_cb_snooze);
@ -126,6 +132,12 @@ public class AlarmDetails extends AbstractGBActivity {
int snoozeVisibility = supportsSnoozing() ? View.VISIBLE : View.GONE; int snoozeVisibility = supportsSnoozing() ? View.VISIBLE : View.GONE;
cbSnooze.setVisibility(snoozeVisibility); cbSnooze.setVisibility(snoozeVisibility);
int descriptionVisibility = supportsDescription() ? View.VISIBLE : View.GONE;
title.setVisibility(descriptionVisibility);
title.setText(alarm.getTitle());
description.setVisibility(descriptionVisibility);
description.setText(alarm.getDescription());
cbMonday.setChecked(alarm.getRepetition(Alarm.ALARM_MON)); cbMonday.setChecked(alarm.getRepetition(Alarm.ALARM_MON));
cbTuesday.setChecked(alarm.getRepetition(Alarm.ALARM_TUE)); cbTuesday.setChecked(alarm.getRepetition(Alarm.ALARM_TUE));
cbWednesday.setChecked(alarm.getRepetition(Alarm.ALARM_WED)); cbWednesday.setChecked(alarm.getRepetition(Alarm.ALARM_WED));
@ -144,6 +156,14 @@ public class AlarmDetails extends AbstractGBActivity {
return false; return false;
} }
private boolean supportsDescription() {
if (device != null) {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
return coordinator.supportsAlarmDescription(device);
}
return false;
}
private boolean supportsSnoozing() { private boolean supportsSnoozing() {
if (device != null) { if (device != null) {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device); DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
@ -170,6 +190,8 @@ public class AlarmDetails extends AbstractGBActivity {
alarm.setRepetition(repetitionMask); alarm.setRepetition(repetitionMask);
alarm.setHour(timePicker.getCurrentHour()); alarm.setHour(timePicker.getCurrentHour());
alarm.setMinute(timePicker.getCurrentMinute()); alarm.setMinute(timePicker.getCurrentMinute());
alarm.setTitle(title.getText().toString());
alarm.setDescription(description.getText().toString());
DBHelper.store(alarm); DBHelper.store(alarm);
} }

View File

@ -152,6 +152,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return false; return false;
} }
@Override
public boolean supportsAlarmDescription(GBDevice device) {
return false;
}
@Override @Override
public boolean supportsMusicInfo() { public boolean supportsMusicInfo() {
return false; return false;

View File

@ -207,6 +207,12 @@ public interface DeviceCoordinator {
*/ */
boolean supportsAlarmSnoozing(); boolean supportsAlarmSnoozing();
/**
* Returns true if this device/coordinator supports alarm descriptions
* @return
*/
boolean supportsAlarmDescription(GBDevice device);
/** /**
* Returns true if the given device supports heart rate measurements. * Returns true if the given device supports heart rate measurements.
* @return * @return

View File

@ -125,6 +125,11 @@ public class QHybridCoordinator extends AbstractDeviceCoordinator {
return this.supportsAlarmConfiguration() ? 5 : 0; return this.supportsAlarmConfiguration() ? 5 : 0;
} }
@Override
public boolean supportsAlarmDescription(GBDevice device) {
return isHybridHR();
}
@Override @Override
public boolean supportsSmartWakeup(GBDevice device) { public boolean supportsSmartWakeup(GBDevice device) {
return false; return false;

View File

@ -52,4 +52,8 @@ public interface Alarm extends Serializable {
int getHour(); int getHour();
int getMinute(); int getMinute();
String getTitle();
String getDescription();
} }

View File

@ -9,133 +9,153 @@
android:id="@+id/scrollView" android:id="@+id/scrollView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_alignParentTop="true"> android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"> android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_smart_wakeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:drawableStart="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_smart_wakeup"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:drawableStart="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_snooze"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TimePicker
android:id="@+id/alarm_time_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleX="1"
android:scaleY="1"
android:layout_marginBottom="20dp" />
<LinearLayout
android:id="@+id/dowSelector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatCheckedTextView <androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_monday" android:id="@+id/alarm_cb_smart_wakeup"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_weight="1" android:drawableStart="?android:attr/listChoiceIndicatorMultiple"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center" android:gravity="center"
android:text="@string/alarm_mon_short" android:text="@string/alarm_smart_wakeup"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView <androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_tuesday" android:id="@+id/alarm_cb_snooze"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_weight="1" android:drawableStart="?android:attr/listChoiceIndicatorMultiple"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center" android:gravity="center"
android:text="@string/alarm_tue_short" android:text="@string/alarm_snooze"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView <EditText
android:id="@+id/alarm_cb_wednesday" android:id="@+id/alarm_title"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:ems="10"
android:layout_weight="1" android:hint="Title"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple" android:inputType="text"
android:gravity="center" android:maxLength="32" />
android:text="@string/alarm_wed_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView <EditText
android:id="@+id/alarm_cb_thursday" android:id="@+id/alarm_description"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:ems="10"
android:layout_weight="1" android:gravity="start|top"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple" android:hint="Description"
android:gravity="center" android:inputType="textMultiLine"
android:text="@string/alarm_thu_short" android:maxLength="256"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:singleLine="false" />
<androidx.appcompat.widget.AppCompatCheckedTextView <TimePicker
android:id="@+id/alarm_cb_friday" android:id="@+id/alarm_time_picker"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginBottom="20dp"
android:layout_weight="1" android:scaleX="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple" android:scaleY="1" />
android:gravity="center"
android:text="@string/alarm_fri_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView <LinearLayout
android:id="@+id/alarm_cb_saturday" android:id="@+id/dowSelector"
android:layout_width="wrap_content" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:baselineAligned="false"
android:layout_weight="1" android:orientation="horizontal">
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_sat_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView <androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_sunday" android:id="@+id/alarm_cb_monday"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_weight="1" android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple" android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center" android:gravity="center"
android:text="@string/alarm_sun_short" android:text="@string/alarm_mon_short"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout> <androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_tuesday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_tue_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_wednesday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_wed_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_thursday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_thu_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_friday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_fri_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_saturday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_sat_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
<androidx.appcompat.widget.AppCompatCheckedTextView
android:id="@+id/alarm_cb_sunday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:drawableTop="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center"
android:text="@string/alarm_sun_short"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>