2024-01-10 18:54:00 +01:00
|
|
|
/* Copyright (C) 2016-2024 Andreas Shimokawa, Anemograph, Carsten Pfeiffer,
|
|
|
|
Daniel Dakhno, Daniele Gobbetti, Davis Mosenkovs, Dikay900, Felix Konstantin
|
|
|
|
Maurer, José Rebelo, Petr Vaněk
|
2017-03-10 14:53:19 +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
|
2024-01-10 18:54:00 +01:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2016-04-28 23:17:13 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
|
|
|
|
2020-09-30 18:16:25 +02:00
|
|
|
import android.Manifest;
|
|
|
|
import android.content.Context;
|
2022-06-14 18:05:41 +02:00
|
|
|
import android.content.SharedPreferences;
|
2020-09-30 18:16:25 +02:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.location.Criteria;
|
|
|
|
import android.location.Location;
|
|
|
|
import android.location.LocationManager;
|
2020-01-04 23:40:50 +01:00
|
|
|
import android.text.format.DateFormat;
|
2021-09-20 18:18:04 +02:00
|
|
|
import android.util.Log;
|
2020-01-04 23:40:50 +01:00
|
|
|
|
2020-09-30 18:16:25 +02:00
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
2016-05-13 23:47:47 +02:00
|
|
|
import java.text.ParseException;
|
|
|
|
import java.util.Date;
|
|
|
|
|
2020-01-04 23:40:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
2022-06-14 18:05:41 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2020-01-04 23:40:50 +01:00
|
|
|
|
2016-04-28 23:17:13 +02:00
|
|
|
public class GBPrefs {
|
2021-09-20 18:18:04 +02:00
|
|
|
// Since this class must not log to slf4j, we use plain android.util.Log
|
|
|
|
private static final String TAG = "GBPrefs";
|
2020-09-30 18:16:25 +02:00
|
|
|
|
2017-04-22 16:59:55 +02:00
|
|
|
public static final String PACKAGE_BLACKLIST = "package_blacklist";
|
2018-06-18 20:38:37 +02:00
|
|
|
public static final String PACKAGE_PEBBLEMSG_BLACKLIST = "package_pebblemsg_blacklist";
|
2017-08-18 10:30:19 +02:00
|
|
|
public static final String CALENDAR_BLACKLIST = "calendar_blacklist";
|
2022-06-14 18:05:41 +02:00
|
|
|
public static final String DEVICE_AUTO_RECONNECT = "prefs_key_device_auto_reconnect";
|
|
|
|
public static final String DEVICE_CONNECT_BACK = "prefs_key_device_reconnect_on_acl";
|
2017-02-17 23:11:44 +01:00
|
|
|
private static final String AUTO_START = "general_autostartonboot";
|
2018-01-08 11:27:28 +01:00
|
|
|
public static final String AUTO_EXPORT_ENABLED = "auto_export_enabled";
|
|
|
|
public static final String AUTO_EXPORT_LOCATION = "auto_export_location";
|
2021-09-03 18:01:47 +02:00
|
|
|
public static final String PING_TONE = "ping_tone";
|
2018-01-08 11:27:28 +01:00
|
|
|
public static final String AUTO_EXPORT_INTERVAL = "auto_export_interval";
|
2017-02-17 23:11:44 +01:00
|
|
|
private static final boolean AUTO_START_DEFAULT = true;
|
2018-01-14 00:20:13 +01:00
|
|
|
private static final String BG_JS_ENABLED = "pebble_enable_background_javascript";
|
|
|
|
private static final boolean BG_JS_ENABLED_DEFAULT = false;
|
2018-09-05 21:32:06 +02:00
|
|
|
public static final String RTL_SUPPORT = "rtl";
|
|
|
|
public static final String RTL_CONTEXTUAL_ARABIC = "contextualArabic";
|
2016-04-28 23:17:13 +02:00
|
|
|
public static boolean AUTO_RECONNECT_DEFAULT = true;
|
2022-09-04 23:05:57 +02:00
|
|
|
public static final String PREF_ALLOW_INTENT_API = "prefs_key_allow_bluetooth_intent_api";
|
2016-05-13 23:47:47 +02:00
|
|
|
|
2024-02-14 03:25:26 +01:00
|
|
|
public static final String RECONNECT_SCAN_KEY = "prefs_general_key_auto_reconnect_scan";
|
|
|
|
public static final boolean RECONNECT_SCAN_DEFAULT = false;
|
|
|
|
|
2016-05-13 23:47:47 +02:00
|
|
|
public static final String USER_NAME = "mi_user_alias";
|
|
|
|
public static final String USER_NAME_DEFAULT = "gadgetbridge-user";
|
|
|
|
private static final String USER_BIRTHDAY = "";
|
|
|
|
|
2018-08-16 13:13:12 +02:00
|
|
|
public static final String CHART_MAX_HEART_RATE = "chart_max_heart_rate";
|
|
|
|
public static final String CHART_MIN_HEART_RATE = "chart_min_heart_rate";
|
|
|
|
|
2024-01-04 17:48:26 +01:00
|
|
|
public static final String LAST_DEVICE_ADDRESSES = "last_device_addresses";
|
|
|
|
public static final String RECONNECT_ONLY_TO_CONNECTED = "general_reconnectonlytoconnected";
|
|
|
|
|
2016-04-28 23:17:13 +02:00
|
|
|
private final Prefs mPrefs;
|
|
|
|
|
|
|
|
public GBPrefs(Prefs prefs) {
|
|
|
|
mPrefs = prefs;
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
public boolean getAutoReconnect(GBDevice device) {
|
|
|
|
SharedPreferences deviceSpecificPreferences = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress());
|
|
|
|
return deviceSpecificPreferences.getBoolean(DEVICE_AUTO_RECONNECT, AUTO_RECONNECT_DEFAULT);
|
2016-04-28 23:17:13 +02:00
|
|
|
}
|
2016-05-13 23:47:47 +02:00
|
|
|
|
2024-02-14 03:25:26 +01:00
|
|
|
public boolean getAutoReconnectByScan() {
|
|
|
|
return mPrefs.getBoolean(RECONNECT_SCAN_KEY, RECONNECT_SCAN_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2017-02-17 23:11:44 +01:00
|
|
|
public boolean getAutoStart() {
|
|
|
|
return mPrefs.getBoolean(AUTO_START, AUTO_START_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2018-01-14 00:20:13 +01:00
|
|
|
public boolean isBackgroundJsEnabled() {
|
|
|
|
return mPrefs.getBoolean(BG_JS_ENABLED, BG_JS_ENABLED_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:47:47 +02:00
|
|
|
public String getUserName() {
|
|
|
|
return mPrefs.getString(USER_NAME, USER_NAME_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getUserBirthday() {
|
|
|
|
String date = mPrefs.getString(USER_BIRTHDAY, null);
|
|
|
|
if (date == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return DateTimeUtils.dayFromString(date);
|
|
|
|
} catch (ParseException ex) {
|
|
|
|
GB.log("Error parsing date: " + date, GB.ERROR, ex);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 16:59:55 +02:00
|
|
|
public int getUserGender() {
|
2016-05-13 23:47:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-01-04 23:40:50 +01:00
|
|
|
|
|
|
|
public String getTimeFormat() {
|
2022-08-18 23:03:28 +02:00
|
|
|
String timeFormat = mPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO);
|
|
|
|
if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(timeFormat)) {
|
2020-01-04 23:40:50 +01:00
|
|
|
if (DateFormat.is24HourFormat(GBApplication.getContext())) {
|
2022-08-18 23:03:28 +02:00
|
|
|
timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H;
|
2020-01-04 23:40:50 +01:00
|
|
|
} else {
|
2022-08-18 23:03:28 +02:00
|
|
|
timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_12H;
|
2020-01-04 23:40:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return timeFormat;
|
|
|
|
}
|
2020-09-30 18:16:25 +02:00
|
|
|
|
|
|
|
public float[] getLongLat(Context context) {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
|
|
|
|
float latitude = prefs.getFloat("location_latitude", 0);
|
|
|
|
float longitude = prefs.getFloat("location_longitude", 0);
|
2021-09-20 18:18:04 +02:00
|
|
|
Log.i(TAG, "got longitude/latitude from preferences: " + latitude + "/" + longitude);
|
2020-09-30 18:16:25 +02:00
|
|
|
|
|
|
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
|
|
|
prefs.getBoolean("use_updated_location_if_available", false)) {
|
|
|
|
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
Criteria criteria = new Criteria();
|
|
|
|
String provider = locationManager.getBestProvider(criteria, false);
|
|
|
|
if (provider != null) {
|
|
|
|
Location lastKnownLocation = locationManager.getLastKnownLocation(provider);
|
|
|
|
if (lastKnownLocation != null) {
|
|
|
|
latitude = (float) lastKnownLocation.getLatitude();
|
|
|
|
longitude = (float) lastKnownLocation.getLongitude();
|
2021-09-20 18:18:04 +02:00
|
|
|
Log.i(TAG, "got longitude/latitude from last known location: " + latitude + "/" + longitude);
|
2020-09-30 18:16:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new float[]{longitude, latitude};
|
|
|
|
}
|
2016-04-28 23:17:13 +02:00
|
|
|
}
|