1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 14:32:54 +01:00

Fossil Hybrid HR: Move watchface settings to proper settings screen

This commit is contained in:
Arjan Schrijver 2021-11-16 14:25:58 +01:00 committed by Gitea
parent 91c317fda2
commit 1d9eb9f332
5 changed files with 235 additions and 39 deletions

View File

@ -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" />
<activity
android:name=".devices.qhybrid.HybridHRWatchfaceSettingsActivity"
android:label="@string/watchface_dialog_title_settings"
android:parentActivityName=".devices.qhybrid.HybridHRWatchfaceDesignerActivity" />
<activity
android:name=".devices.um25.Activity.DataActivity"
android:exported="true" />

View File

@ -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() {

View File

@ -16,7 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
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;

View File

@ -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 <http://www.gnu.org/licenses/>. */
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;
}
}
}
}

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/watchface_setting_title_display_refresh_timeout">
<EditTextPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_refresh_full"
android:title="@string/watchface_setting_display_refresh_full" />
<EditTextPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_refresh_partial"
android:title="@string/watchface_setting_display_refresh_partial" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/watchface_setting_title_wrist_flick">
<Preference
android:selectable="false"
android:enabled="false"
android:singleLineTitle="false"
android:title="@string/watchface_setting_desc_wrist_flick" />
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_wrist_flick_relative"
android:title="@string/watchface_setting_wrist_flick_move_relative"
android:singleLineTitle="false" />
<EditTextPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_wrist_flick_hour_hand"
android:title="@string/watchface_setting_wrist_flick_hour" />
<EditTextPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_wrist_flick_minute_hand"
android:title="@string/watchface_setting_wrist_flick_minute" />
<EditTextPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_wrist_flick_duration"
android:title="@string/watchface_setting_wrist_flick_duration" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/watchface_setting_title_power_saving">
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_power_saving_display"
android:title="@string/watchface_setting_power_saving_display"
android:singleLineTitle="false" />
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_power_saving_hands"
android:title="@string/watchface_setting_power_saving_hands"
android:singleLineTitle="false" />
</PreferenceCategory>
</PreferenceScreen>