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

Upgrade discovery and pairing preferences to androidx

This commit is contained in:
José Rebelo 2023-07-25 12:24:42 +01:00
parent 1b281c7c62
commit cac92fdc26
2 changed files with 58 additions and 57 deletions

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Lem Dulfo,
vanous
/* Copyright (C) 2015-2023 Andreas Shimokawa, Carsten Pfeiffer, Lem Dulfo,
vanous, José Rebelo
This file is part of Gadgetbridge.
@ -18,36 +18,36 @@
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.os.Bundle;
import android.preference.Preference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import androidx.fragment.app.Fragment;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.AbstractPreferenceFragment;
public class DiscoveryPairingPreferenceActivity extends AbstractSettingsActivity {
private static final Logger LOG = LoggerFactory.getLogger(AbstractSettingsActivity.class);
public class DiscoveryPairingPreferenceActivity extends AbstractGBActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_settings);
if (savedInstanceState == null) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(DiscoveryPairingPreferenceFragment.FRAGMENT_TAG);
if (fragment == null) {
fragment = new DiscoveryPairingPreferenceFragment();
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings_container, fragment, DiscoveryPairingPreferenceFragment.FRAGMENT_TAG)
.commit();
}
}
public static class DiscoveryPairingPreferenceFragment extends AbstractPreferenceFragment {
static final String FRAGMENT_TAG = "DISCOVERY_PAIRING_PREFERENCES_FRAGMENT";
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.discovery_pairing_preferences);
final Prefs prefs = GBApplication.getPrefs();
final Preference pref = findPreference("scanning_intensity");
pref.setSummary(String.valueOf(prefs.getInt("scanning_intensity", 1)));
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
preference.setSummary(newVal.toString());
return true;
}
});
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
}
}
}

View File

@ -1,38 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="pref_discovery_pairing"
android:title="@string/activity_prefs_discovery_pairing">
<CheckBoxPreference
<SwitchPreference
android:defaultValue="true"
android:key="ignore_bonded_devices"
android:layout="@layout/preference_checkbox"
android:summary="@string/ignore_bonded_devices_description"
android:title="@string/ignore_bonded_devices" />
<CheckBoxPreference
android:title="@string/ignore_bonded_devices"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="enable_companiondevice_pairing"
android:layout="@layout/preference_checkbox"
android:summary="@string/companiondevice_pairing_details"
android:title="@string/companiondevice_pairing" />
<CheckBoxPreference
android:title="@string/companiondevice_pairing"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="discover_unsupported_devices"
android:layout="@layout/preference_checkbox"
android:summary="@string/discover_unsupported_devices_description"
android:title="@string/discover_unsupported_devices" />
android:title="@string/discover_unsupported_devices"
app:iconSpaceReserved="false" />
<SeekBarPreference
android:defaultValue="1"
android:key="scanning_intensity"
android:max="3"
android:min="0"
android:title="@string/discovery_scanning_intensity"
android:defaultValue="1"
app:iconSpaceReserved="false"
app:showSeekBarValue="true" />
<Preference
android:selectable="false"
android:persistent="false"
android:summary="@string/discovery_scanning_intensity_warning" />
</PreferenceCategory>
android:selectable="false"
android:summary="@string/discovery_scanning_intensity_warning"
app:iconSpaceReserved="false" />
</PreferenceScreen>