Move parsing of preference strings to int values to Prefs
This commit is contained in:
parent
0c715a2669
commit
0704915a88
|
@ -7,7 +7,6 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ConfigureAlarms extends GBActivity {
|
||||||
private void updateAlarmsFromPrefs() {
|
private void updateAlarmsFromPrefs() {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
preferencesAlarmListSet = prefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
preferencesAlarmListSet = prefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
||||||
int reservedSlots = Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, "0"));
|
int reservedSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
|
||||||
|
|
||||||
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet, reservedSlots);
|
mGBAlarmListAdapter.setAlarmList(preferencesAlarmListSet, reservedSlots);
|
||||||
mGBAlarmListAdapter.notifyDataSetChanged();
|
mGBAlarmListAdapter.notifyDataSetChanged();
|
||||||
|
|
|
@ -6,11 +6,9 @@ import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
public final class MiBandConst {
|
public final class MiBandConst {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MiBandConst.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MiBandConst.class);
|
||||||
|
|
||||||
|
@ -27,19 +27,12 @@ public final class MiBandConst {
|
||||||
public static final String MI_1A = "1A";
|
public static final String MI_1A = "1A";
|
||||||
public static final String MI_1S = "1S";
|
public static final String MI_1S = "1S";
|
||||||
|
|
||||||
public static int getNotificationPrefIntValue(String pref, String origin, SharedPreferences prefs, int defaultValue) {
|
public static int getNotificationPrefIntValue(String pref, String origin, Prefs prefs, int defaultValue) {
|
||||||
String key = getNotificationPrefKey(pref, origin);
|
String key = getNotificationPrefKey(pref, origin);
|
||||||
String value = null;
|
return prefs.getInt(key, defaultValue);
|
||||||
try {
|
|
||||||
value = prefs.getString(key, String.valueOf(defaultValue));
|
|
||||||
return Integer.valueOf(value);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
LOG.error("Error converting preference value to int: " + key + ": " + value);
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNotificationPrefStringValue(String pref, String origin, SharedPreferences prefs, String defaultValue) {
|
public static String getNotificationPrefStringValue(String pref, String origin, Prefs prefs, String defaultValue) {
|
||||||
String key = getNotificationPrefKey(pref, origin);
|
String key = getNotificationPrefKey(pref, origin);
|
||||||
return prefs.getString(key, defaultValue);
|
return prefs.getString(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MiBandCoordinator.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MiBandCoordinator.class);
|
||||||
|
@ -112,7 +113,7 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||||
*/
|
*/
|
||||||
public static UserInfo getConfiguredUserInfo(String miBandAddress) throws IllegalArgumentException {
|
public static UserInfo getConfiguredUserInfo(String miBandAddress) throws IllegalArgumentException {
|
||||||
ActivityUser activityUser = new ActivityUser();
|
ActivityUser activityUser = new ActivityUser();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
UserInfo info = UserInfo.create(
|
UserInfo info = UserInfo.create(
|
||||||
miBandAddress,
|
miBandAddress,
|
||||||
|
@ -128,7 +129,7 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||||
|
|
||||||
public static int getWearLocation(String miBandAddress) throws IllegalArgumentException {
|
public static int getWearLocation(String miBandAddress) throws IllegalArgumentException {
|
||||||
int location = 0; //left hand
|
int location = 0; //left hand
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
if ("right".equals(prefs.getString(MiBandConst.PREF_MIBAND_WEARSIDE, "left"))) {
|
if ("right".equals(prefs.getString(MiBandConst.PREF_MIBAND_WEARSIDE, "left"))) {
|
||||||
location = 1; // right hand
|
location = 1; // right hand
|
||||||
}
|
}
|
||||||
|
@ -136,17 +137,17 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getHeartrateSleepSupport(String miBandAddress) throws IllegalArgumentException {
|
public static boolean getHeartrateSleepSupport(String miBandAddress) throws IllegalArgumentException {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
return prefs.getBoolean(MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION, false);
|
return prefs.getBoolean(MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFitnessGoal(String miBandAddress) throws IllegalArgumentException {
|
public static int getFitnessGoal(String miBandAddress) throws IllegalArgumentException {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
return Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_FITNESS_GOAL, "10000"));
|
return prefs.getInt(MiBandConst.PREF_MIBAND_FITNESS_GOAL, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getReservedAlarmSlots(String miBandAddress) throws IllegalArgumentException {
|
public static int getReservedAlarmSlots(String miBandAddress) throws IllegalArgumentException {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
return Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, "0"));
|
return prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
|
||||||
|
@ -47,7 +45,7 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
||||||
@Override
|
@Override
|
||||||
public SampleProvider getSampleProvider() {
|
public SampleProvider getSampleProvider() {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
int activityTracker = Integer.parseInt(prefs.getString("pebble_activitytracker", Integer.toString(SampleProvider.PROVIDER_PEBBLE_HEALTH)));
|
int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
|
||||||
switch (activityTracker) {
|
switch (activityTracker) {
|
||||||
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
|
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
|
||||||
return new HealthSampleProvider();
|
return new HealthSampleProvider();
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.impl;
|
package nodomain.freeyourgadget.gadgetbridge.impl;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -12,6 +10,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ALARMS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ALARMS;
|
||||||
|
|
||||||
|
@ -187,8 +186,8 @@ public class GBAlarm implements Alarm {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void store() {
|
public void store() {
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
Set<String> preferencesAlarmListSet = sharedPrefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
Set<String> preferencesAlarmListSet = prefs.getStringSet(PREF_MIBAND_ALARMS, new HashSet<String>());
|
||||||
//the old Set cannot be updated in place see http://developer.android.com/reference/android/content/SharedPreferences.html#getStringSet%28java.lang.String,%20java.util.Set%3Cjava.lang.String%3E%29
|
//the old Set cannot be updated in place see http://developer.android.com/reference/android/content/SharedPreferences.html#getStringSet%28java.lang.String,%20java.util.Set%3Cjava.lang.String%3E%29
|
||||||
Set<String> newPrefs = new HashSet<>(preferencesAlarmListSet);
|
Set<String> newPrefs = new HashSet<>(preferencesAlarmListSet);
|
||||||
|
|
||||||
|
@ -202,7 +201,7 @@ public class GBAlarm implements Alarm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newPrefs.add(this.toPreferences());
|
newPrefs.add(this.toPreferences());
|
||||||
sharedPrefs.edit().putStringSet(PREF_MIBAND_ALARMS, newPrefs).apply();
|
prefs.getPreferences().edit().putStringSet(PREF_MIBAND_ALARMS, newPrefs).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator CREATOR = new Creator() {
|
public static final Creator CREATOR = new Creator() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.preference.PreferenceManager;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class holding the common user information needed by most activity trackers
|
* Class holding the common user information needed by most activity trackers
|
||||||
|
@ -86,11 +87,11 @@ public class ActivityUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchPreferences() {
|
private void fetchPreferences() {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
activityUserGender = Integer.parseInt(prefs.getString(PREF_USER_GENDER, Integer.toString(defaultUserGender)));
|
activityUserGender = prefs.getInt(PREF_USER_GENDER, defaultUserGender);
|
||||||
activityUserHeightCm = Integer.parseInt(prefs.getString(PREF_USER_HEIGHT_CM, Integer.toString(defaultUserHeightCm)));
|
activityUserHeightCm = prefs.getInt(PREF_USER_HEIGHT_CM, defaultUserHeightCm);
|
||||||
activityUserWeightKg = Integer.parseInt(prefs.getString(PREF_USER_WEIGHT_KG, Integer.toString(defaultUserWeightKg)));
|
activityUserWeightKg = prefs.getInt(PREF_USER_WEIGHT_KG, defaultUserWeightKg);
|
||||||
activityUserYearOfBirth = Integer.parseInt(prefs.getString(PREF_USER_YEAR_OF_BIRTH, Integer.toString(defaultUserYearOfBirth)));
|
activityUserYearOfBirth = prefs.getInt(PREF_USER_YEAR_OF_BIRTH, defaultUserYearOfBirth);
|
||||||
activityUserSleepDuration = Integer.parseInt(prefs.getString(PREF_USER_SLEEP_DURATION, Integer.toString(defaultUserSleepDuration)));
|
activityUserSleepDuration = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,9 @@ import android.app.PendingIntent;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
|
|
||||||
|
@ -44,6 +42,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBCallControlReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBCallControlReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBMusicControlReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBMusicControlReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
// TODO: support option for a single reminder notification when notifications could not be delivered?
|
// TODO: support option for a single reminder notification when notifications could not be delivered?
|
||||||
// conditions: app was running and received notifications, but device was not connected.
|
// conditions: app was running and received notifications, but device was not connected.
|
||||||
|
@ -247,8 +246,8 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||||
Intent notificationListenerIntent = new Intent(action);
|
Intent notificationListenerIntent = new Intent(action);
|
||||||
notificationListenerIntent.putExtra("handle", deviceEvent.handle);
|
notificationListenerIntent.putExtra("handle", deviceEvent.handle);
|
||||||
if (deviceEvent.reply != null) {
|
if (deviceEvent.reply != null) {
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
String suffix = sharedPrefs.getString("canned_reply_suffix", null);
|
String suffix = prefs.getString("canned_reply_suffix", null);
|
||||||
if (suffix != null && !Objects.equals(suffix, "")) {
|
if (suffix != null && !Objects.equals(suffix, "")) {
|
||||||
deviceEvent.reply += suffix;
|
deviceEvent.reply += suffix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||||
|
@ -52,6 +53,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.Fe
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.UpdateFirmwareOperation;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.UpdateFirmwareOperation;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
||||||
|
@ -422,7 +424,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
private void performPreferredNotification(String task, String notificationOrigin, BtLEAction extraAction) {
|
private void performPreferredNotification(String task, String notificationOrigin, BtLEAction extraAction) {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized(task);
|
TransactionBuilder builder = performInitialized(task);
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
int vibrateDuration = getPreferredVibrateDuration(notificationOrigin, prefs);
|
int vibrateDuration = getPreferredVibrateDuration(notificationOrigin, prefs);
|
||||||
int vibratePause = getPreferredVibratePause(notificationOrigin, prefs);
|
int vibratePause = getPreferredVibratePause(notificationOrigin, prefs);
|
||||||
short vibrateTimes = getPreferredVibrateCount(notificationOrigin, prefs);
|
short vibrateTimes = getPreferredVibrateCount(notificationOrigin, prefs);
|
||||||
|
@ -441,35 +443,35 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredFlashDuration(String notificationOrigin, SharedPreferences prefs) {
|
private int getPreferredFlashDuration(String notificationOrigin, Prefs prefs) {
|
||||||
return getNotificationPrefIntValue(FLASH_DURATION, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_DURATION);
|
return getNotificationPrefIntValue(FLASH_DURATION, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredOriginalColour(String notificationOrigin, SharedPreferences prefs) {
|
private int getPreferredOriginalColour(String notificationOrigin, Prefs prefs) {
|
||||||
return getNotificationPrefIntValue(FLASH_ORIGINAL_COLOUR, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_ORIGINAL_COLOUR);
|
return getNotificationPrefIntValue(FLASH_ORIGINAL_COLOUR, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_ORIGINAL_COLOUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredFlashColour(String notificationOrigin, SharedPreferences prefs) {
|
private int getPreferredFlashColour(String notificationOrigin, Prefs prefs) {
|
||||||
return getNotificationPrefIntValue(FLASH_COLOUR, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_COLOUR);
|
return getNotificationPrefIntValue(FLASH_COLOUR, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_COLOUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredFlashCount(String notificationOrigin, SharedPreferences prefs) {
|
private int getPreferredFlashCount(String notificationOrigin, Prefs prefs) {
|
||||||
return getNotificationPrefIntValue(FLASH_COUNT, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_COUNT);
|
return getNotificationPrefIntValue(FLASH_COUNT, notificationOrigin, prefs, DEFAULT_VALUE_FLASH_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredVibratePause(String notificationOrigin, SharedPreferences prefs) {
|
private int getPreferredVibratePause(String notificationOrigin, Prefs prefs) {
|
||||||
return getNotificationPrefIntValue(VIBRATION_PAUSE, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_PAUSE);
|
return getNotificationPrefIntValue(VIBRATION_PAUSE, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_PAUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private short getPreferredVibrateCount(String notificationOrigin, SharedPreferences prefs) {
|
private short getPreferredVibrateCount(String notificationOrigin, Prefs prefs) {
|
||||||
return (short) Math.min(Short.MAX_VALUE, getNotificationPrefIntValue(VIBRATION_COUNT, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_COUNT));
|
return (short) Math.min(Short.MAX_VALUE, getNotificationPrefIntValue(VIBRATION_COUNT, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredVibrateDuration(String notificationOrigin, SharedPreferences prefs) {
|
private int getPreferredVibrateDuration(String notificationOrigin, Prefs prefs) {
|
||||||
return getNotificationPrefIntValue(VIBRATION_DURATION, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_DURATION);
|
return getNotificationPrefIntValue(VIBRATION_DURATION, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VibrationProfile getPreferredVibrateProfile(String notificationOrigin, SharedPreferences prefs, short repeat) {
|
private VibrationProfile getPreferredVibrateProfile(String notificationOrigin, Prefs prefs, short repeat) {
|
||||||
String profileId = getNotificationPrefStringValue(VIBRATION_PROFILE, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_PROFILE);
|
String profileId = getNotificationPrefStringValue(VIBRATION_PROFILE, notificationOrigin, prefs, DEFAULT_VALUE_VIBRATION_PROFILE);
|
||||||
return VibrationProfile.getProfile(profileId, repeat);
|
return VibrationProfile.getProfile(profileId, repeat);
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1034,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
int availableSlots = Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, "0"));
|
int availableSlots = prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
|
||||||
|
|
||||||
if (availableSlots > 0) {
|
if (availableSlots > 0) {
|
||||||
CalendarEvents upcomingEvents = new CalendarEvents();
|
CalendarEvents upcomingEvents = new CalendarEvents();
|
||||||
|
|
|
@ -32,6 +32,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAc
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
//import java.util.concurrent.Executors;
|
//import java.util.concurrent.Executors;
|
||||||
//import java.util.concurrent.ScheduledExecutorService;
|
//import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -365,7 +366,7 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
||||||
*/
|
*/
|
||||||
private void sendAckDataTransfer(Calendar time, int bytesTransferred) {
|
private void sendAckDataTransfer(Calendar time, int bytesTransferred) {
|
||||||
byte[] ackTime = MiBandDateConverter.calendarToRawBytes(time);
|
byte[] ackTime = MiBandDateConverter.calendarToRawBytes(time);
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
byte[] ackChecksum = new byte[]{
|
byte[] ackChecksum = new byte[]{
|
||||||
(byte) (bytesTransferred & 0xff),
|
(byte) (bytesTransferred & 0xff),
|
||||||
|
|
|
@ -364,7 +364,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
if (e.getMessage().contains("socket closed")) { //FIXME: this does not feel right
|
||||||
LOG.info(e.getMessage());
|
LOG.info(e.getMessage());
|
||||||
mIsConnected = false;
|
mIsConnected = false;
|
||||||
int reconnectAttempts = Integer.valueOf(prefs.getString("pebble_reconnect_attempts", "10"));
|
int reconnectAttempts = prefs.getInt("pebble_reconnect_attempts", 10);
|
||||||
if (reconnectAttempts > 0) {
|
if (reconnectAttempts > 0) {
|
||||||
gbDevice.setState(GBDevice.State.CONNECTING);
|
gbDevice.setState(GBDevice.State.CONNECTING);
|
||||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
|
|
@ -3,10 +3,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.receivers;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
Loading…
Reference in New Issue