2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2019-2020 Andreas Shimokawa, Cre3per
|
2019-11-23 21:52:46 +01:00
|
|
|
|
|
|
|
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/>. */
|
2019-04-21 21:18:08 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
2019-06-05 14:11:44 +02:00
|
|
|
import android.text.InputType;
|
|
|
|
import android.widget.EditText;
|
2019-04-21 21:18:08 +02:00
|
|
|
|
2019-05-22 00:42:22 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
2019-06-05 14:11:44 +02:00
|
|
|
import androidx.preference.EditTextPreference;
|
2019-05-22 00:42:22 +02:00
|
|
|
import androidx.preference.Preference;
|
2019-04-21 21:18:08 +02:00
|
|
|
import androidx.preference.PreferenceFragmentCompat;
|
|
|
|
|
2019-06-05 16:00:18 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2019-05-22 00:42:22 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2019-11-14 12:33:36 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
2019-10-10 11:32:52 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
|
2019-05-22 10:49:59 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
2019-05-22 00:42:22 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.XTimePreference;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.XTimePreferenceFragment;
|
2019-04-21 21:18:08 +02:00
|
|
|
|
2019-11-14 12:33:36 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SCREEN_ORIENTATION;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION;
|
2019-06-05 16:00:18 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT;
|
2019-05-22 00:42:22 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_START;
|
2019-08-02 00:11:11 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS;
|
2019-06-05 16:00:18 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
|
2019-08-27 11:13:45 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY;
|
2019-08-02 00:11:11 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_LANGUAGE;
|
2019-05-24 23:46:20 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_START;
|
2019-05-23 21:33:35 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
|
2019-06-05 16:00:18 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
|
2019-05-22 10:49:59 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_OFF;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_SCHEDULED;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_START;
|
2019-05-22 00:42:22 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_SWIPE_UNLOCK;
|
|
|
|
|
|
|
|
public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
|
|
|
|
2019-06-05 16:00:18 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DeviceSpecificSettingsFragment.class);
|
|
|
|
|
2019-05-22 00:42:22 +02:00
|
|
|
static final String FRAGMENT_TAG = "DEVICE_SPECIFIC_SETTINGS_FRAGMENT";
|
|
|
|
|
|
|
|
private void setSettingsFileSuffix(String settingsFileSuffix, @NonNull int[] supportedSettings) {
|
2019-04-21 21:18:08 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putString("settingsFileSuffix", settingsFileSuffix);
|
2019-05-22 00:42:22 +02:00
|
|
|
args.putIntArray("supportedSettings", supportedSettings);
|
2019-04-21 21:18:08 +02:00
|
|
|
setArguments(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
2019-05-22 00:42:22 +02:00
|
|
|
Bundle arguments = getArguments();
|
|
|
|
if (arguments == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String settingsFileSuffix = arguments.getString("settingsFileSuffix", null);
|
|
|
|
int[] supportedSettings = arguments.getIntArray("supportedSettings");
|
|
|
|
if (settingsFileSuffix == null || supportedSettings == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-21 21:18:08 +02:00
|
|
|
getPreferenceManager().setSharedPreferencesName("devicesettings_" + settingsFileSuffix);
|
2019-05-22 00:42:22 +02:00
|
|
|
|
|
|
|
if (rootKey == null) {
|
|
|
|
// we are the main preference screen
|
|
|
|
boolean first = true;
|
|
|
|
for (int setting : supportedSettings) {
|
|
|
|
if (first) {
|
|
|
|
setPreferencesFromResource(setting, null);
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
addPreferencesFromResource(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Now, this is ugly: search all the xml files for the rootKey
|
|
|
|
for (int setting : supportedSettings) {
|
|
|
|
try {
|
|
|
|
setPreferencesFromResource(setting, rootKey);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setChangeListener();
|
2019-04-21 21:18:08 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 00:42:22 +02:00
|
|
|
/*
|
|
|
|
* delayed execution so that the preferences are applied first
|
|
|
|
*/
|
|
|
|
private void invokeLater(Runnable runnable) {
|
|
|
|
getListView().post(runnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setChangeListener() {
|
|
|
|
Prefs prefs = new Prefs(getPreferenceManager().getSharedPreferences());
|
2019-05-24 23:46:20 +02:00
|
|
|
String disconnectNotificationState = prefs.getString(PREF_DISCONNECT_NOTIFICATION, PREF_DO_NOT_DISTURB_OFF);
|
|
|
|
boolean disconnectNotificationScheduled = disconnectNotificationState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
2019-05-22 00:42:22 +02:00
|
|
|
|
|
|
|
final Preference disconnectNotificationStart = findPreference(PREF_DISCONNECT_NOTIFICATION_START);
|
|
|
|
if (disconnectNotificationStart != null) {
|
|
|
|
disconnectNotificationStart.setEnabled(disconnectNotificationScheduled);
|
|
|
|
disconnectNotificationStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DISCONNECT_NOTIFICATION_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference disconnectNotificationEnd = findPreference(PREF_DISCONNECT_NOTIFICATION_END);
|
|
|
|
if (disconnectNotificationEnd != null) {
|
|
|
|
disconnectNotificationEnd.setEnabled(disconnectNotificationScheduled);
|
|
|
|
disconnectNotificationEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DISCONNECT_NOTIFICATION_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference disconnectNotification = findPreference(PREF_DISCONNECT_NOTIFICATION);
|
|
|
|
if (disconnectNotification != null) {
|
|
|
|
disconnectNotification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2019-05-24 23:46:20 +02:00
|
|
|
final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
|
2019-05-22 00:42:22 +02:00
|
|
|
|
2019-06-05 16:00:18 +02:00
|
|
|
Objects.requireNonNull(disconnectNotificationStart).setEnabled(scheduled);
|
|
|
|
Objects.requireNonNull(disconnectNotificationEnd).setEnabled(scheduled);
|
2019-05-22 00:42:22 +02:00
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DISCONNECT_NOTIFICATION);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2019-05-22 10:49:59 +02:00
|
|
|
|
|
|
|
String nightModeState = prefs.getString(MiBandConst.PREF_NIGHT_MODE, PREF_NIGHT_MODE_OFF);
|
|
|
|
boolean nightModeScheduled = nightModeState.equals(PREF_NIGHT_MODE_SCHEDULED);
|
|
|
|
|
|
|
|
final Preference nightModeStart = findPreference(PREF_NIGHT_MODE_START);
|
|
|
|
if (nightModeStart != null) {
|
|
|
|
nightModeStart.setEnabled(nightModeScheduled);
|
|
|
|
nightModeStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_NIGHT_MODE_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference nightModeEnd = findPreference(PREF_NIGHT_MODE_END);
|
|
|
|
if (nightModeEnd != null) {
|
|
|
|
nightModeEnd.setEnabled(nightModeScheduled);
|
|
|
|
nightModeEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_NIGHT_MODE_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference nightMode = findPreference(PREF_NIGHT_MODE);
|
|
|
|
if (nightMode != null) {
|
|
|
|
|
|
|
|
nightMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
final boolean scheduled = PREF_NIGHT_MODE_SCHEDULED.equals(newVal.toString());
|
|
|
|
|
2019-06-05 16:00:18 +02:00
|
|
|
Objects.requireNonNull(nightModeStart).setEnabled(scheduled);
|
|
|
|
Objects.requireNonNull(nightModeEnd).setEnabled(scheduled);
|
2019-05-22 10:49:59 +02:00
|
|
|
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_NIGHT_MODE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-24 23:46:20 +02:00
|
|
|
|
|
|
|
String doNotDisturbState = prefs.getString(MiBandConst.PREF_DO_NOT_DISTURB, PREF_DO_NOT_DISTURB_OFF);
|
|
|
|
boolean doNotDisturbScheduled = doNotDisturbState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
|
|
|
|
|
|
|
final Preference doNotDisturbStart = findPreference(PREF_DO_NOT_DISTURB_START);
|
|
|
|
if (doNotDisturbStart != null) {
|
|
|
|
doNotDisturbStart.setEnabled(doNotDisturbScheduled);
|
|
|
|
doNotDisturbStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DO_NOT_DISTURB_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference doNotDisturbEnd = findPreference(PREF_DO_NOT_DISTURB_END);
|
|
|
|
if (doNotDisturbEnd != null) {
|
|
|
|
doNotDisturbEnd.setEnabled(doNotDisturbScheduled);
|
|
|
|
doNotDisturbEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DO_NOT_DISTURB_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference doNotDisturb = findPreference(PREF_DO_NOT_DISTURB);
|
|
|
|
if (doNotDisturb != null) {
|
|
|
|
doNotDisturb.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
|
|
|
|
|
2019-06-05 16:00:18 +02:00
|
|
|
Objects.requireNonNull(doNotDisturbStart).setEnabled(scheduled);
|
|
|
|
Objects.requireNonNull(doNotDisturbEnd).setEnabled(scheduled);
|
2019-05-24 23:46:20 +02:00
|
|
|
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DO_NOT_DISTURB);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-05 12:16:10 +02:00
|
|
|
addPreferenceHandlerFor(PREF_SWIPE_UNLOCK);
|
|
|
|
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
|
2019-08-02 00:11:11 +02:00
|
|
|
addPreferenceHandlerFor(PREF_DATEFORMAT);
|
|
|
|
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
|
|
|
|
addPreferenceHandlerFor(PREF_LANGUAGE);
|
2019-08-27 11:13:45 +02:00
|
|
|
addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY);
|
2019-10-05 22:35:30 +02:00
|
|
|
addPreferenceHandlerFor(PREF_WEARLOCATION);
|
|
|
|
addPreferenceHandlerFor(PREF_SCREEN_ORIENTATION);
|
|
|
|
addPreferenceHandlerFor(PREF_TIMEFORMAT);
|
2019-06-05 14:11:44 +02:00
|
|
|
|
2019-06-05 16:00:18 +02:00
|
|
|
String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
|
|
|
|
boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
|
|
|
|
|
|
|
final Preference rotateWristCycleInfo = findPreference(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
|
|
|
|
if (rotateWristCycleInfo != null) {
|
|
|
|
rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(displayOnLiftState));
|
|
|
|
rotateWristCycleInfo.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference displayOnLiftStart = findPreference(PREF_DISPLAY_ON_LIFT_START);
|
|
|
|
if (displayOnLiftStart != null) {
|
|
|
|
displayOnLiftStart.setEnabled(displayOnLiftScheduled);
|
|
|
|
displayOnLiftStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference displayOnLiftEnd = findPreference(PREF_DISPLAY_ON_LIFT_END);
|
|
|
|
if (displayOnLiftEnd != null) {
|
|
|
|
displayOnLiftEnd.setEnabled(displayOnLiftScheduled);
|
|
|
|
displayOnLiftEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
final Preference displayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
|
|
|
|
if (displayOnLift != null) {
|
|
|
|
displayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
|
|
|
|
Objects.requireNonNull(displayOnLiftStart).setEnabled(scheduled);
|
|
|
|
Objects.requireNonNull(displayOnLiftEnd).setEnabled(scheduled);
|
|
|
|
if (rotateWristCycleInfo != null) {
|
|
|
|
rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(newVal.toString()));
|
|
|
|
}
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_ACTIVATE_DISPLAY_ON_LIFT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-14 12:33:36 +01:00
|
|
|
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_BROADCAST_DELAY, InputType.TYPE_CLASS_NUMBER);
|
|
|
|
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_MAX_INTERVAL, InputType.TYPE_CLASS_NUMBER);
|
|
|
|
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_COUNT, InputType.TYPE_CLASS_NUMBER);
|
|
|
|
setInputTypeFor(MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS, InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
|
|
|
setInputTypeFor(MakibesHR3Constants.PREF_FIND_PHONE_DURATION, InputType.TYPE_CLASS_NUMBER);
|
2019-12-14 23:43:54 +01:00
|
|
|
setInputTypeFor(DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR, InputType.TYPE_CLASS_NUMBER);
|
2019-05-22 00:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings) {
|
|
|
|
DeviceSpecificSettingsFragment fragment = new DeviceSpecificSettingsFragment();
|
|
|
|
fragment.setSettingsFileSuffix(settingsFileSuffix, supportedSettings);
|
|
|
|
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisplayPreferenceDialog(Preference preference) {
|
2019-06-05 16:00:18 +02:00
|
|
|
DialogFragment dialogFragment;
|
2019-05-22 00:42:22 +02:00
|
|
|
if (preference instanceof XTimePreference) {
|
|
|
|
dialogFragment = new XTimePreferenceFragment();
|
|
|
|
Bundle bundle = new Bundle(1);
|
|
|
|
bundle.putString("key", preference.getKey());
|
|
|
|
dialogFragment.setArguments(bundle);
|
|
|
|
dialogFragment.setTargetFragment(this, 0);
|
2019-06-05 16:00:18 +02:00
|
|
|
if (getFragmentManager() != null) {
|
|
|
|
dialogFragment.show(getFragmentManager(), "androidx.preference.PreferenceFragment.DIALOG");
|
|
|
|
}
|
2019-05-22 00:42:22 +02:00
|
|
|
} else {
|
|
|
|
super.onDisplayPreferenceDialog(preference);
|
|
|
|
}
|
|
|
|
}
|
2019-06-05 12:16:10 +02:00
|
|
|
|
|
|
|
private void addPreferenceHandlerFor(final String preferenceKey) {
|
|
|
|
Preference pref = findPreference(preferenceKey);
|
|
|
|
if (pref != null) {
|
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(preferenceKey);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 12:33:36 +01:00
|
|
|
|
|
|
|
private void setInputTypeFor(final String preferenceKey, final int editTypeFlags) {
|
|
|
|
EditTextPreference textPreference = findPreference(preferenceKey);
|
|
|
|
if (textPreference != null) {
|
|
|
|
textPreference.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
|
|
|
|
@Override
|
|
|
|
public void onBindEditText(@NonNull EditText editText) {
|
|
|
|
editText.setInputType(editTypeFlags);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-05-22 00:42:22 +02:00
|
|
|
}
|