From 1d9eb9f3325c4ca6a96a448d6f5477422a2a512a Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Tue, 16 Nov 2021 14:25:58 +0100 Subject: [PATCH] Fossil Hybrid HR: Move watchface settings to proper settings screen --- app/src/main/AndroidManifest.xml | 6 + .../HybridHRWatchfaceDesignerActivity.java | 48 ++---- .../qhybrid/HybridHRWatchfaceSettings.java | 4 +- .../HybridHRWatchfaceSettingsActivity.java | 154 ++++++++++++++++++ .../res/xml/fossil_hr_watchface_settings.xml | 62 +++++++ 5 files changed, 235 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java create mode 100644 app/src/main/res/xml/fossil_hr_watchface_settings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c962a80df..cab98550f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -627,7 +627,13 @@ android:name=".devices.qhybrid.HybridHRWatchfaceDesignerActivity" android:label="@string/qhybrid_title_watchface_designer" android:screenOrientation="portrait" + android:launchMode="singleTop" android:parentActivityName=".activities.appmanager.AppManagerActivity" /> + + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java index d57a8d657..62770c206 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java @@ -44,7 +44,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; -import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; @@ -99,6 +98,9 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem private int defaultWidgetColor = HybridHRWatchfaceWidget.COLOR_WHITE; private boolean readyToCloseActivity = false; + private final int CHILD_ACTIVITY_IMAGE_CHOOSER = 0; + private final int CHILD_ACTIVITY_SETTINGS = 1; + BroadcastReceiver fileUploadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -163,7 +165,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem @Override public void onActivityResult(int requestCode, int resultCode, Intent resultData) { super.onActivityResult(requestCode, resultCode, resultData); - if (requestCode == 42 && resultCode == Activity.RESULT_OK) { + if (requestCode == CHILD_ACTIVITY_IMAGE_CHOOSER && resultCode == Activity.RESULT_OK) { Uri imageUri = resultData.getData(); if (imageUri == null) { LOG.warn("No image selected"); @@ -176,6 +178,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem return; } renderWatchfacePreview(); + } else if (requestCode == CHILD_ACTIVITY_SETTINGS && resultCode == Activity.RESULT_OK && resultData != null) { + watchfaceSettings = (HybridHRWatchfaceSettings) resultData.getSerializableExtra("watchfaceSettings"); } } @@ -233,7 +237,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); - startActivityForResult(intent, 42); + startActivityForResult(intent, CHILD_ACTIVITY_IMAGE_CHOOSER); } else if (v.getId() == R.id.button_add_widget) { showWidgetEditPopup(-1); } else if (v.getId() == R.id.button_watchface_settings) { @@ -655,41 +659,9 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem } private void showWatchfaceSettingsPopup() { - View layout = getLayoutInflater().inflate(R.layout.dialog_hybridhr_watchface_settings, null); - final EditText displayTimeoutFullInput = layout.findViewById(R.id.watchface_setting_display_full); - displayTimeoutFullInput.setText(String.valueOf(watchfaceSettings.getDisplayTimeoutFull())); - final EditText displayTimeoutPartialInput = layout.findViewById(R.id.watchface_setting_display_partial); - displayTimeoutPartialInput.setText(String.valueOf(watchfaceSettings.getDisplayTimeoutPartial())); - final CheckBox wristFlickHandsMoveRelativeInput = layout.findViewById(R.id.watchface_setting_flick_relative); - wristFlickHandsMoveRelativeInput.setChecked(watchfaceSettings.isWristFlickHandsMoveRelative()); - final EditText wristFlickDurationInput = layout.findViewById(R.id.watchface_setting_flick_timeout); - wristFlickDurationInput.setText(String.valueOf(watchfaceSettings.getWristFlickDuration())); - final EditText wristFlickMoveHourInput = layout.findViewById(R.id.watchface_setting_flick_hour); - wristFlickMoveHourInput.setText(String.valueOf(watchfaceSettings.getWristFlickMoveHour())); - final EditText wristFlickMoveMinuteInput = layout.findViewById(R.id.watchface_setting_flick_minute); - wristFlickMoveMinuteInput.setText(String.valueOf(watchfaceSettings.getWristFlickMoveMinute())); - final CheckBox powersaveDisplayInput = layout.findViewById(R.id.watchface_setting_powersave_display); - powersaveDisplayInput.setChecked(watchfaceSettings.getPowersaveDisplay()); - final CheckBox powersaveHandsInput = layout.findViewById(R.id.watchface_setting_powersave_hands); - powersaveHandsInput.setChecked(watchfaceSettings.getPowersaveHands()); - new AlertDialog.Builder(this) - .setView(layout) - .setNegativeButton(R.string.fossil_hr_new_action_cancel, null) - .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - watchfaceSettings.setDisplayTimeoutFull(Integer.parseInt(displayTimeoutFullInput.getText().toString())); - watchfaceSettings.setDisplayTimeoutPartial(Integer.parseInt(displayTimeoutPartialInput.getText().toString())); - watchfaceSettings.setWristFlickHandsMoveRelative(wristFlickHandsMoveRelativeInput.isChecked()); - watchfaceSettings.setWristFlickDuration(Integer.parseInt(wristFlickDurationInput.getText().toString())); - watchfaceSettings.setWristFlickMoveHour(Integer.parseInt(wristFlickMoveHourInput.getText().toString())); - watchfaceSettings.setWristFlickMoveMinute(Integer.parseInt(wristFlickMoveMinuteInput.getText().toString())); - watchfaceSettings.setPowersaveDisplay(powersaveDisplayInput.isChecked()); - watchfaceSettings.setPowersaveHands(powersaveHandsInput.isChecked()); - } - }) - .setTitle(R.string.watchface_dialog_title_settings) - .show(); + Intent intent = new Intent(this, HybridHRWatchfaceSettingsActivity.class); + intent.putExtra("watchfaceSettings", watchfaceSettings); + startActivityForResult(intent, CHILD_ACTIVITY_SETTINGS); } private void calculateDisplayImageSize() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettings.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettings.java index b70034086..cd402da3e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettings.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettings.java @@ -16,7 +16,9 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; -public class HybridHRWatchfaceSettings { +import java.io.Serializable; + +public class HybridHRWatchfaceSettings implements Serializable { private int displayTimeoutFull = 60; private int displayTimeoutPartial = 15; private boolean wristFlickHandsMoveRelative = true; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java new file mode 100644 index 000000000..2fb1a9725 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceSettingsActivity.java @@ -0,0 +1,154 @@ +/* Copyright (C) 2021 Arjan Schrijver + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; + +import android.content.Intent; +import android.os.Bundle; +import android.preference.EditTextPreference; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.SwitchPreference; +import android.view.MenuItem; + +import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity; + +public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivity { + static HybridHRWatchfaceSettings settings; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + if (bundle != null) { + settings = (HybridHRWatchfaceSettings) bundle.getSerializable("watchfaceSettings"); + } else { + throw new IllegalArgumentException("Must provide a settings object when invoking this activity"); + } + + getFragmentManager().beginTransaction().replace(android.R.id.content, new HybridHRWatchfaceSettingsFragment()).commit(); + } + + @Override + public void onBackPressed() { + // Hardware back button + Intent output = new Intent(); + output.putExtra("watchfaceSettings", settings); + setResult(RESULT_OK, output); + finish(); + super.onBackPressed(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + // Action bar back button + Intent output = new Intent(); + output.putExtra("watchfaceSettings", settings); + setResult(RESULT_OK, output); + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + public static class HybridHRWatchfaceSettingsFragment extends PreferenceFragment + { + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.fossil_hr_watchface_settings); + + EditTextPreference refresh_full = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_full"); + refresh_full.setOnPreferenceChangeListener(new PreferenceChangeListener()); + refresh_full.setText(Integer.toString(settings.getDisplayTimeoutFull())); + refresh_full.setSummary(Integer.toString(settings.getDisplayTimeoutFull())); + + EditTextPreference refresh_partial = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_partial"); + refresh_partial.setOnPreferenceChangeListener(new PreferenceChangeListener()); + refresh_partial.setText(Integer.toString(settings.getDisplayTimeoutPartial())); + refresh_partial.setSummary(Integer.toString(settings.getDisplayTimeoutPartial())); + + SwitchPreference wrist_flick_relative = (SwitchPreference) findPreference("pref_hybridhr_watchface_wrist_flick_relative"); + wrist_flick_relative.setOnPreferenceChangeListener(new PreferenceChangeListener()); + wrist_flick_relative.setChecked(settings.isWristFlickHandsMoveRelative()); + + EditTextPreference wrist_flick_hour_hand = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_hour_hand"); + wrist_flick_hour_hand.setOnPreferenceChangeListener(new PreferenceChangeListener()); + wrist_flick_hour_hand.setText(Integer.toString(settings.getWristFlickMoveHour())); + wrist_flick_hour_hand.setSummary(Integer.toString(settings.getWristFlickMoveHour())); + + EditTextPreference wrist_flick_minute_hand = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_minute_hand"); + wrist_flick_minute_hand.setOnPreferenceChangeListener(new PreferenceChangeListener()); + wrist_flick_minute_hand.setText(Integer.toString(settings.getWristFlickMoveMinute())); + wrist_flick_minute_hand.setSummary(Integer.toString(settings.getWristFlickMoveMinute())); + + EditTextPreference wrist_flick_duration = (EditTextPreference) findPreference("pref_hybridhr_watchface_wrist_flick_duration"); + wrist_flick_duration.setOnPreferenceChangeListener(new PreferenceChangeListener()); + wrist_flick_duration.setText(Integer.toString(settings.getWristFlickDuration())); + wrist_flick_duration.setSummary(Integer.toString(settings.getWristFlickDuration())); + + SwitchPreference power_saving_display = (SwitchPreference) findPreference("pref_hybridhr_watchface_power_saving_display"); + power_saving_display.setOnPreferenceChangeListener(new PreferenceChangeListener()); + power_saving_display.setChecked(settings.getPowersaveDisplay()); + + SwitchPreference power_saving_hands = (SwitchPreference) findPreference("pref_hybridhr_watchface_power_saving_hands"); + power_saving_hands.setOnPreferenceChangeListener(new PreferenceChangeListener()); + power_saving_hands.setChecked(settings.getPowersaveHands()); + } + + private static class PreferenceChangeListener implements Preference.OnPreferenceChangeListener { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + switch (preference.getKey()) { + case "pref_hybridhr_watchface_refresh_full": + settings.setDisplayTimeoutFull(Integer.parseInt(newValue.toString())); + preference.setSummary(newValue.toString()); + break; + case "pref_hybridhr_watchface_refresh_partial": + settings.setDisplayTimeoutPartial(Integer.parseInt(newValue.toString())); + preference.setSummary(newValue.toString()); + break; + case "pref_hybridhr_watchface_wrist_flick_relative": + settings.setWristFlickHandsMoveRelative((boolean) newValue); + break; + case "pref_hybridhr_watchface_wrist_flick_hour_hand": + settings.setWristFlickMoveHour(Integer.parseInt(newValue.toString())); + preference.setSummary(newValue.toString()); + break; + case "pref_hybridhr_watchface_wrist_flick_minute_hand": + settings.setWristFlickMoveMinute(Integer.parseInt(newValue.toString())); + preference.setSummary(newValue.toString()); + break; + case "pref_hybridhr_watchface_wrist_flick_duration": + settings.setWristFlickDuration(Integer.parseInt(newValue.toString())); + preference.setSummary(newValue.toString()); + break; + case "pref_hybridhr_watchface_power_saving_display": + settings.setPowersaveDisplay((boolean) newValue); + break; + case "pref_hybridhr_watchface_power_saving_hands": + settings.setPowersaveHands((boolean) newValue); + break; + } + return true; + } + } + } +} diff --git a/app/src/main/res/xml/fossil_hr_watchface_settings.xml b/app/src/main/res/xml/fossil_hr_watchface_settings.xml new file mode 100644 index 000000000..ae6f157bf --- /dev/null +++ b/app/src/main/res/xml/fossil_hr_watchface_settings.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file