2017-03-10 14:53:19 +01:00
|
|
|
/* Copyright (C) 2015-2017 Andreas Shimokawa, Carsten Pfeiffer, Christian
|
|
|
|
Fischer, Daniele Gobbetti, Szymon Tomasz Stefanek
|
|
|
|
|
|
|
|
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/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
2015-05-07 01:30:40 +02:00
|
|
|
|
2015-05-10 13:08:28 +02:00
|
|
|
import android.content.Intent;
|
2015-05-07 01:30:40 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.Preference;
|
2015-05-10 13:08:28 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-10-09 00:10:53 +02:00
|
|
|
import android.widget.Toast;
|
2015-05-07 01:30:40 +02:00
|
|
|
|
2016-10-11 21:28:28 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2016-04-03 22:38:06 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-05-07 01:30:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
2016-06-18 23:35:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
2017-03-11 11:29:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
2016-10-09 00:10:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2017-07-15 15:01:07 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-05-18 20:56:19 +02:00
|
|
|
|
2017-02-07 23:49:10 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_ALARM_CLOCK;
|
2015-08-03 23:09:49 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL;
|
2016-11-13 21:33:43 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT;
|
2016-11-13 20:47:24 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
|
2017-07-09 16:17:13 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DISPLAY_ITEMS;
|
2017-07-15 15:01:07 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB_OFF;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB_SCHEDULED;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB_START;
|
2017-03-15 00:26:39 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ENABLE_TEXT_NOTIFICATIONS;
|
2017-07-15 00:40:58 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_GOAL_NOTIFICATION;
|
2017-07-15 22:48:26 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_START;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_START;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD;
|
2017-07-09 14:30:03 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
|
2015-08-03 23:09:49 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
2016-06-03 04:43:12 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS;
|
2015-12-17 16:11:35 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
|
2016-04-02 16:09:30 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
|
2015-08-03 23:09:49 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;
|
2015-05-07 01:30:40 +02:00
|
|
|
|
|
|
|
public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
addPreferencesFromResource(R.xml.miband_preferences);
|
2015-05-10 13:08:28 +02:00
|
|
|
|
2016-10-26 00:03:54 +02:00
|
|
|
addTryListeners();
|
|
|
|
|
2017-07-15 15:01:07 +02:00
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
|
2016-10-26 00:03:54 +02:00
|
|
|
final Preference enableHeartrateSleepSupport = findPreference(PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION);
|
|
|
|
enableHeartrateSleepSupport.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
2015-05-10 13:08:28 +02:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2016-10-26 00:03:54 +02:00
|
|
|
GBApplication.deviceService().onEnableHeartRateSleepSupport(Boolean.TRUE.equals(newVal));
|
2015-05-10 13:08:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-11-13 21:33:43 +01:00
|
|
|
|
2017-07-15 00:40:58 +02:00
|
|
|
final Preference goalNotification = findPreference(PREF_MI2_GOAL_NOTIFICATION);
|
|
|
|
goalNotification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_GOAL_NOTIFICATION);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-13 20:47:24 +01:00
|
|
|
final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT);
|
|
|
|
setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2016-11-13 21:33:43 +01:00
|
|
|
invokeLater(new Runnable() {
|
2016-11-13 20:47:24 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
2017-07-09 16:17:13 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference displayPages = findPreference(PREF_MI2_DISPLAY_ITEMS);
|
|
|
|
displayPages.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DISPLAY_ITEMS);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
2016-11-13 20:47:24 +01:00
|
|
|
}
|
|
|
|
});
|
2016-11-13 21:33:43 +01:00
|
|
|
|
|
|
|
final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
|
|
|
|
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-11-24 21:58:32 +01:00
|
|
|
|
2017-07-09 14:30:03 +02:00
|
|
|
final Preference rotateWristCycleInfo = findPreference(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-15 22:48:26 +02:00
|
|
|
final Preference inactivityWarnings = findPreference(PREF_MI2_INACTIVITY_WARNINGS);
|
|
|
|
inactivityWarnings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference inactivityWarningsThreshold = findPreference(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD);
|
|
|
|
inactivityWarningsThreshold.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference inactivityWarningsStart = findPreference(PREF_MI2_INACTIVITY_WARNINGS_START);
|
|
|
|
inactivityWarningsStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference inactivityWarningsEnd = findPreference(PREF_MI2_INACTIVITY_WARNINGS_END);
|
|
|
|
inactivityWarningsEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference inactivityWarningsDnd = findPreference(PREF_MI2_INACTIVITY_WARNINGS_DND);
|
|
|
|
inactivityWarningsDnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_DND);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference inactivityWarningsDndStart = findPreference(PREF_MI2_INACTIVITY_WARNINGS_DND_START);
|
|
|
|
inactivityWarningsDndStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_DND_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference inactivityWarningsDndEnd = findPreference(PREF_MI2_INACTIVITY_WARNINGS_DND_END);
|
|
|
|
inactivityWarningsDndEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_DND_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-15 15:01:07 +02:00
|
|
|
String doNotDisturbState = prefs.getString(MiBandConst.PREF_MI2_DO_NOT_DISTURB, PREF_MI2_DO_NOT_DISTURB_OFF);
|
|
|
|
boolean doNotDisturbScheduled = doNotDisturbState.equals(PREF_MI2_DO_NOT_DISTURB_SCHEDULED);
|
|
|
|
|
|
|
|
final Preference doNotDisturbStart = findPreference(PREF_MI2_DO_NOT_DISTURB_START);
|
|
|
|
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_MI2_DO_NOT_DISTURB_START);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference doNotDisturbEnd = findPreference(PREF_MI2_DO_NOT_DISTURB_END);
|
|
|
|
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_MI2_DO_NOT_DISTURB_END);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference doNotDisturb = findPreference(PREF_MI2_DO_NOT_DISTURB);
|
|
|
|
doNotDisturb.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
final boolean scheduled = PREF_MI2_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
|
|
|
|
|
|
|
|
doNotDisturbStart.setEnabled(scheduled);
|
|
|
|
doNotDisturbEnd.setEnabled(scheduled);
|
|
|
|
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DO_NOT_DISTURB);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-11 11:29:50 +01:00
|
|
|
final Preference fitnessGoal = findPreference(ActivityUser.PREF_USER_STEPS_GOAL);
|
2016-11-24 21:58:32 +01:00
|
|
|
fitnessGoal.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-03-11 11:29:50 +01:00
|
|
|
GBApplication.deviceService().onSendConfiguration(ActivityUser.PREF_USER_STEPS_GOAL);
|
2016-11-24 21:58:32 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-11-13 21:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delayed execution so that the preferences are applied first
|
|
|
|
*/
|
|
|
|
private void invokeLater(Runnable runnable) {
|
|
|
|
getListView().post(runnable);
|
2016-10-26 00:03:54 +02:00
|
|
|
}
|
2015-05-10 13:08:28 +02:00
|
|
|
|
2016-11-13 20:47:24 +01:00
|
|
|
@Override
|
2016-10-26 00:03:54 +02:00
|
|
|
protected void onPostCreate(Bundle savedInstanceState) {
|
|
|
|
super.onPostCreate(savedInstanceState);
|
|
|
|
final Preference developmentMiaddr = findPreference(PREF_MIBAND_ADDRESS);
|
|
|
|
developmentMiaddr.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
2016-04-03 22:38:06 +02:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2016-10-26 00:03:54 +02:00
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
|
|
|
preference.setSummary(newVal.toString());
|
2016-04-03 22:38:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-10-26 00:03:54 +02:00
|
|
|
|
2016-04-03 22:38:06 +02:00
|
|
|
});
|
2015-05-07 01:30:40 +02:00
|
|
|
}
|
|
|
|
|
2016-10-09 00:10:53 +02:00
|
|
|
private void addTryListeners() {
|
|
|
|
for (final NotificationType type : NotificationType.values()) {
|
2016-10-11 17:57:50 +02:00
|
|
|
String prefKey = "mi_try_" + type.getGenericType();
|
2016-10-09 00:10:53 +02:00
|
|
|
final Preference tryPref = findPreference(prefKey);
|
|
|
|
if (tryPref != null) {
|
|
|
|
tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
tryVibration(type);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
GB.toast(getBaseContext(), "Unable to find preference key: " + prefKey + ", trying the vibration won't work", Toast.LENGTH_LONG, GB.WARN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void tryVibration(NotificationType type) {
|
|
|
|
NotificationSpec spec = new NotificationSpec();
|
|
|
|
spec.type = type;
|
|
|
|
GBApplication.deviceService().onNotification(spec);
|
|
|
|
}
|
|
|
|
|
2015-05-07 01:30:40 +02:00
|
|
|
@Override
|
|
|
|
protected String[] getPreferenceKeysWithSummary() {
|
2016-10-11 21:28:28 +02:00
|
|
|
Set<String> prefKeys = new HashSet<>();
|
|
|
|
prefKeys.add(PREF_USER_ALIAS);
|
|
|
|
prefKeys.add(PREF_MIBAND_ADDRESS);
|
2017-03-11 11:29:50 +01:00
|
|
|
prefKeys.add(ActivityUser.PREF_USER_STEPS_GOAL);
|
2016-10-11 21:28:28 +02:00
|
|
|
prefKeys.add(PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR);
|
|
|
|
prefKeys.add(PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS);
|
2017-03-15 00:26:39 +01:00
|
|
|
prefKeys.add(PREF_MI2_ENABLE_TEXT_NOTIFICATIONS);
|
2017-07-15 22:48:26 +02:00
|
|
|
prefKeys.add(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD);
|
2017-02-07 23:49:10 +01:00
|
|
|
prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_ALARM_CLOCK));
|
2016-10-11 21:28:28 +02:00
|
|
|
prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_INCOMING_CALL));
|
|
|
|
|
2016-10-10 22:39:20 +02:00
|
|
|
for (NotificationType type : NotificationType.values()) {
|
2016-10-11 21:35:45 +02:00
|
|
|
String key = type.getGenericType();
|
|
|
|
prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, key));
|
2016-10-10 22:39:20 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 21:28:28 +02:00
|
|
|
return prefKeys.toArray(new String[0]);
|
2015-05-07 01:30:40 +02:00
|
|
|
}
|
|
|
|
}
|