1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Upgrade Q-Hybrid watchface settings to androidx

This commit is contained in:
José Rebelo 2023-07-25 20:50:20 +01:00
parent bac1d35479
commit 69ae0817cf
4 changed files with 166 additions and 105 deletions

View File

@ -18,22 +18,25 @@ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
import android.content.Intent;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import android.view.MenuItem;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
import androidx.fragment.app.Fragment;
public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivity {
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment;
public class HybridHRWatchfaceSettingsActivity extends AbstractGBActivity {
static HybridHRWatchfaceSettings settings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_settings);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
@ -43,7 +46,16 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivity
throw new IllegalArgumentException("Must provide a settings object when invoking this activity");
}
getFragmentManager().beginTransaction().replace(android.R.id.content, new HybridHRWatchfaceSettingsFragment()).commit();
if (savedInstanceState == null) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(HybridHRWatchfaceSettingsFragment.FRAGMENT_TAG);
if (fragment == null) {
fragment = new HybridHRWatchfaceSettingsFragment();
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_container, fragment, HybridHRWatchfaceSettingsFragment.FRAGMENT_TAG)
.commit();
}
}
@Override
@ -69,11 +81,11 @@ public class HybridHRWatchfaceSettingsActivity extends AbstractSettingsActivity
return super.onOptionsItemSelected(item);
}
public static class HybridHRWatchfaceSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener
{
public static class HybridHRWatchfaceSettingsFragment extends AbstractPreferenceFragment implements Preference.OnPreferenceChangeListener {
static final String FRAGMENT_TAG = "HYBRID_HR_WATCHFACE_SETTINGS_FRAGMENT";
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.fossil_hr_watchface_settings);
EditTextPreference refresh_full = (EditTextPreference) findPreference("pref_hybridhr_watchface_refresh_full");

View File

@ -18,21 +18,26 @@ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
import android.content.Intent;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreference;
import android.view.MenuItem;
import androidx.fragment.app.Fragment;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.TimeZone;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment;
public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivity {
public class HybridHRWatchfaceWidgetActivity extends AbstractGBActivity {
private static int widgetIndex;
private static HybridHRWatchfaceWidget widget;
@ -48,6 +53,7 @@ public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_settings);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
@ -58,7 +64,16 @@ public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivity {
throw new IllegalArgumentException("Must provide a widget object when invoking this activity");
}
getFragmentManager().beginTransaction().replace(android.R.id.content, new HybridHRWatchfaceWidgetFragment()).commit();
if (savedInstanceState == null) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(HybridHRWatchfaceWidgetFragment.FRAGMENT_TAG);
if (fragment == null) {
fragment = new HybridHRWatchfaceWidgetFragment();
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_container, fragment, HybridHRWatchfaceWidgetFragment.FRAGMENT_TAG)
.commit();
}
}
@Override
@ -86,14 +101,14 @@ public class HybridHRWatchfaceWidgetActivity extends AbstractSettingsActivity {
return super.onOptionsItemSelected(item);
}
public static class HybridHRWatchfaceWidgetFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener
{
public static class HybridHRWatchfaceWidgetFragment extends AbstractPreferenceFragment implements Preference.OnPreferenceChangeListener {
static final String FRAGMENT_TAG = "HYBRID_HR_WATCHFACE_WIDGET_FRAGMENT";
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.fossil_hr_widget_settings);
widgetTypes = HybridHRWatchfaceWidget.getAvailableWidgetTypes(getActivity().getBaseContext());
widgetTypes = HybridHRWatchfaceWidget.getAvailableWidgetTypes(requireActivity().getBaseContext());
ListPreference widgetType = (ListPreference) findPreference("pref_hybridhr_widget_type");
widgetType.setOnPreferenceChangeListener(this);
widgetType.setEntries(widgetTypes.values().toArray(new String[0]));

View File

@ -1,97 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:title="@string/watchface_setting_title_display_refresh_timeout">
android:title="@string/watchface_setting_title_display_refresh_timeout"
app:iconSpaceReserved="false">
<EditTextPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_refresh_full"
android:title="@string/watchface_setting_display_refresh_full" />
<EditTextPreference
android:persistent="false"
android:title="@string/watchface_setting_display_refresh_full"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="pref_hybridhr_watchface_refresh_partial"
android:title="@string/watchface_setting_display_refresh_partial" />
android:persistent="false"
android:title="@string/watchface_setting_display_refresh_partial"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/watchface_setting_title_wrist_flick">
android:title="@string/watchface_setting_title_wrist_flick"
app:iconSpaceReserved="false">
<Preference
android:selectable="false"
android:enabled="false"
android:selectable="false"
android:singleLineTitle="false"
android:title="@string/watchface_setting_desc_wrist_flick" />
android:title="@string/watchface_setting_desc_wrist_flick"
app:iconSpaceReserved="false" />
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_wrist_flick_relative"
android:persistent="false"
android:singleLineTitle="false"
android:title="@string/watchface_setting_wrist_flick_move_relative"
android:singleLineTitle="false" />
app:iconSpaceReserved="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:title="@string/watchface_setting_wrist_flick_hour"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="pref_hybridhr_watchface_wrist_flick_minute_hand"
android:title="@string/watchface_setting_wrist_flick_minute" />
<EditTextPreference
android:persistent="false"
android:title="@string/watchface_setting_wrist_flick_minute"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="pref_hybridhr_watchface_wrist_flick_duration"
android:title="@string/watchface_setting_wrist_flick_duration" />
android:persistent="false"
android:title="@string/watchface_setting_wrist_flick_duration"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/watchface_setting_title_custom_events">
android:title="@string/watchface_setting_title_custom_events"
app:iconSpaceReserved="false">
<ListPreference
android:dialogTitle="@string/watchface_setting_button_toggle_widgets"
android:entries="@array/pref_hybridhr_watchface_events_items"
android:entryValues="@array/pref_hybridhr_watchface_events_values"
android:key="pref_hybridhr_watchface_toggle_widgets"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_setting_button_toggle_widgets"
android:key="pref_hybridhr_watchface_toggle_widgets"
app:iconSpaceReserved="false" />
<ListPreference
android:dialogTitle="@string/watchface_setting_button_toggle_backlight"
android:entries="@array/pref_hybridhr_watchface_events_items"
android:entryValues="@array/pref_hybridhr_watchface_events_values"
android:dialogTitle="@string/watchface_setting_button_toggle_widgets"
android:negativeButtonText="@string/Cancel"/>
<ListPreference
android:key="pref_hybridhr_watchface_toggle_backlight"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_setting_button_toggle_backlight"
android:key="pref_hybridhr_watchface_toggle_backlight"
app:iconSpaceReserved="false" />
<ListPreference
android:dialogTitle="@string/watchface_setting_button_move_hands"
android:entries="@array/pref_hybridhr_watchface_events_items"
android:entryValues="@array/pref_hybridhr_watchface_events_values"
android:dialogTitle="@string/watchface_setting_button_toggle_backlight"
android:negativeButtonText="@string/Cancel"/>
<ListPreference
android:key="pref_hybridhr_watchface_move_hands"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_setting_button_move_hands"
android:key="pref_hybridhr_watchface_move_hands"
android:entries="@array/pref_hybridhr_watchface_events_items"
android:entryValues="@array/pref_hybridhr_watchface_events_values"
android:dialogTitle="@string/watchface_setting_button_move_hands"
android:negativeButtonText="@string/Cancel"/>
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/watchface_setting_title_power_saving">
android:title="@string/watchface_setting_title_power_saving"
app:iconSpaceReserved="false">
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_power_saving_display"
android:persistent="false"
android:singleLineTitle="false"
android:title="@string/watchface_setting_power_saving_display"
android:singleLineTitle="false" />
app:iconSpaceReserved="false" />
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_watchface_power_saving_hands"
android:title="@string/watchface_setting_power_saving_hands"
android:singleLineTitle="false" />
<SwitchPreference
android:persistent="false"
android:singleLineTitle="false"
android:title="@string/watchface_setting_power_saving_hands"
app:iconSpaceReserved="false" />
<SwitchPreference
android:key="pref_hybridhr_watchface_light_up_on_notification"
android:persistent="false"
android:singleLineTitle="false"
android:title="@string/watchface_setting_light_up_on_notification"
android:singleLineTitle="false" />
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -1,92 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="widget_pref_category_generic"
android:title="@string/watchface_dialog_widget_cat_generic">
android:title="@string/watchface_dialog_widget_cat_generic"
app:iconSpaceReserved="false">
<ListPreference
android:dialogTitle="@string/watchface_dialog_widget_type"
android:key="pref_hybridhr_widget_type"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_dialog_widget_type"
android:key="pref_hybridhr_widget_type"
android:dialogTitle="@string/watchface_dialog_widget_type"
android:negativeButtonText="@string/Cancel"/>
app:iconSpaceReserved="false" />
<ListPreference
android:dialogTitle="@string/watchface_dialog_widget_color"
android:key="pref_hybridhr_widget_color"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_dialog_widget_color"
android:key="pref_hybridhr_widget_color"
android:dialogTitle="@string/watchface_dialog_widget_color"
android:negativeButtonText="@string/Cancel"/>
app:iconSpaceReserved="false" />
<ListPreference
android:persistent="false"
android:title="@string/watchface_dialog_widget_background"
android:key="pref_hybridhr_widget_background"
android:dialogTitle="@string/watchface_dialog_widget_background"
android:entries="@array/pref_hybridhr_widgetbackgrounds_items"
android:entryValues="@array/pref_hybridhr_widgetbackgrounds_values"
android:negativeButtonText="@string/Cancel"/>
android:key="pref_hybridhr_widget_background"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_dialog_widget_background"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:key="widget_pref_category_position"
android:title="@string/watchface_dialog_widget_cat_position">
android:title="@string/watchface_dialog_widget_cat_position"
app:iconSpaceReserved="false">
<EditTextPreference
android:persistent="false"
android:inputType="numberDecimal"
android:key="pref_hybridhr_widget_pos_x"
android:title="@string/watchface_dialog_widget_x_coordinate"
android:inputType="numberDecimal" />
<EditTextPreference
android:persistent="false"
android:title="@string/watchface_dialog_widget_x_coordinate"
app:iconSpaceReserved="false" />
<EditTextPreference
android:inputType="numberDecimal"
android:key="pref_hybridhr_widget_pos_y"
android:persistent="false"
android:title="@string/watchface_dialog_widget_y_coordinate"
android:inputType="numberDecimal" />
app:iconSpaceReserved="false" />
<ListPreference
android:dialogTitle="@string/watchface_dialog_widget_presets"
android:key="pref_hybridhr_widget_pos_preset"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_dialog_widget_presets"
android:key="pref_hybridhr_widget_pos_preset"
android:dialogTitle="@string/watchface_dialog_widget_presets"
android:negativeButtonText="@string/Cancel"/>
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory
android:key="widget_pref_category_2nd_tz_widget"
android:title="@string/watchface_dialog_widget_cat_2nd_tz_widget">
android:title="@string/watchface_dialog_widget_cat_2nd_tz_widget"
app:iconSpaceReserved="false">
<ListPreference
android:dialogTitle="@string/watchface_dialog_widget_timezone"
android:key="pref_hybridhr_widget_timezone"
android:negativeButtonText="@string/Cancel"
android:persistent="false"
android:title="@string/watchface_dialog_widget_timezone"
android:key="pref_hybridhr_widget_timezone"
android:dialogTitle="@string/watchface_dialog_widget_timezone"
android:negativeButtonText="@string/Cancel"/>
app:iconSpaceReserved="false" />
<EditTextPreference
android:persistent="false"
android:inputType="numberDecimal"
android:key="pref_hybridhr_widget_timezone_timeout"
android:persistent="false"
android:title="@string/watchface_dialog_widget_timezone_duration"
android:inputType="numberDecimal" />
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:key="widget_pref_category_custom_widget"
android:title="@string/watchface_dialog_widget_cat_custom_widget">
android:title="@string/watchface_dialog_widget_cat_custom_widget"
app:iconSpaceReserved="false">
<EditTextPreference
android:persistent="false"
android:inputType="numberDecimal"
android:key="pref_hybridhr_widget_width"
android:persistent="false"
android:title="@string/watchface_dialog_widget_width"
android:inputType="numberDecimal" />
app:iconSpaceReserved="false" />
<EditTextPreference
android:persistent="false"
android:inputType="numberDecimal"
android:key="pref_hybridhr_widget_custom_timeout"
android:persistent="false"
android:title="@string/watchface_dialog_widget_update_timeout"
android:inputType="numberDecimal" />
app:iconSpaceReserved="false" />
<SwitchPreference
android:persistent="false"
android:key="pref_hybridhr_widget_custom_hide_text"
android:title="@string/watchface_dialog_widget_timeout_hide_text"
android:singleLineTitle="false" />
<SwitchPreference
android:persistent="false"
android:singleLineTitle="false"
android:title="@string/watchface_dialog_widget_timeout_hide_text"
app:iconSpaceReserved="false" />
<SwitchPreference
android:key="pref_hybridhr_widget_custom_show_circle"
android:persistent="false"
android:singleLineTitle="false"
android:title="@string/watchface_dialog_widget_timeout_show_circle"
android:singleLineTitle="false" />
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>