2018-02-26 14:27:32 +01:00
|
|
|
/* Copyright (C) 2015-2018 0nse, Andreas Shimokawa, Carsten Pfeiffer,
|
|
|
|
Daniele Gobbetti, Felix Konstantin Maurer, Normano64
|
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
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2016-05-26 14:39:54 +02:00
|
|
|
import android.Manifest;
|
|
|
|
import android.content.Context;
|
2015-03-15 21:36:39 +01:00
|
|
|
import android.content.Intent;
|
2015-09-16 00:53:54 +02:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
2018-01-04 15:13:06 +01:00
|
|
|
import android.database.Cursor;
|
2016-05-26 14:39:54 +02:00
|
|
|
import android.location.Criteria;
|
|
|
|
import android.location.Location;
|
2016-07-05 23:52:48 +02:00
|
|
|
import android.location.LocationListener;
|
2016-05-26 14:39:54 +02:00
|
|
|
import android.location.LocationManager;
|
2018-01-04 15:13:06 +01:00
|
|
|
import android.net.Uri;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.os.Bundle;
|
2016-05-26 14:39:54 +02:00
|
|
|
import android.preference.EditTextPreference;
|
2015-09-16 00:53:54 +02:00
|
|
|
import android.preference.ListPreference;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.preference.Preference;
|
2016-05-19 16:34:59 +02:00
|
|
|
import android.preference.PreferenceCategory;
|
2018-01-04 15:13:06 +01:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.provider.DocumentsContract;
|
2016-05-26 14:39:54 +02:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
2015-08-19 00:03:52 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-03-22 23:01:41 +01:00
|
|
|
import android.widget.Toast;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2016-05-26 14:39:54 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2016-03-22 23:01:41 +01:00
|
|
|
import java.io.IOException;
|
2016-06-24 10:25:08 +02:00
|
|
|
import java.util.ArrayList;
|
2015-09-16 00:53:54 +02:00
|
|
|
import java.util.List;
|
2016-05-26 14:39:54 +02:00
|
|
|
import java.util.Locale;
|
2015-09-16 00:53:54 +02:00
|
|
|
|
2017-12-12 22:36:15 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
2016-04-18 00:20:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2018-01-04 15:13:06 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter;
|
2016-06-18 23:35:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
2016-06-24 10:25:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
2018-01-09 08:54:18 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
2016-03-22 23:01:41 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2018-01-07 12:50:59 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
2016-06-24 10:25:08 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-05-07 01:30:40 +02:00
|
|
|
|
2018-08-02 10:55:30 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
|
2018-04-27 09:28:33 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DISPLAY_ITEMS;
|
2018-08-02 10:55:30 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ENABLE_TEXT_NOTIFICATIONS;
|
2016-02-02 17:33:24 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
2016-02-29 21:36:39 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_SLEEP_DURATION;
|
2017-03-11 11:29:50 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
2016-02-02 17:33:24 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
|
2016-02-02 14:32:19 +01:00
|
|
|
|
2015-05-07 01:30:40 +02:00
|
|
|
public class SettingsActivity extends AbstractSettingsActivity {
|
2016-05-26 14:39:54 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(SettingsActivity.class);
|
|
|
|
|
2017-09-30 22:45:45 +02:00
|
|
|
public static final String PREF_MEASUREMENT_SYSTEM = "measurement_system";
|
|
|
|
|
2018-01-04 15:13:06 +01:00
|
|
|
private static final int FILE_REQUEST_CODE = 4711;
|
|
|
|
|
2015-05-07 01:30:40 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
}
|
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
@Override
|
|
|
|
protected void onPostCreate(Bundle savedInstanceState) {
|
|
|
|
super.onPostCreate(savedInstanceState);
|
|
|
|
|
2015-05-12 20:09:35 +02:00
|
|
|
Preference pref = findPreference("notifications_generic");
|
2015-03-15 21:36:39 +01:00
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
|
|
|
startActivity(enableIntent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2015-05-12 20:09:35 +02:00
|
|
|
pref = findPreference("pref_key_miband");
|
2015-05-07 01:30:40 +02:00
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent enableIntent = new Intent(SettingsActivity.this, MiBandPreferencesActivity.class);
|
|
|
|
startActivity(enableIntent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2015-04-19 12:35:23 +02:00
|
|
|
|
2015-09-10 13:48:54 +02:00
|
|
|
pref = findPreference("pref_key_blacklist");
|
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent enableIntent = new Intent(SettingsActivity.this, AppBlacklistActivity.class);
|
|
|
|
startActivity(enableIntent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-18 10:30:19 +02:00
|
|
|
pref = findPreference("pref_key_blacklist_calendars");
|
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent enableIntent = new Intent(SettingsActivity.this, CalBlacklistActivity.class);
|
|
|
|
startActivity(enableIntent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-13 12:03:57 +01:00
|
|
|
pref = findPreference("pebble_emu_addr");
|
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
2015-08-19 00:03:52 +02:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2016-06-18 23:35:34 +02:00
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
2015-08-19 00:03:52 +02:00
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
|
|
|
preference.setSummary(newVal.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-12-13 12:03:57 +01:00
|
|
|
pref = findPreference("pebble_emu_port");
|
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
2015-08-19 00:03:52 +02:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2016-06-18 23:35:34 +02:00
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
2015-08-19 00:03:52 +02:00
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
|
|
|
preference.setSummary(newVal.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2015-09-16 00:53:54 +02:00
|
|
|
|
2016-03-22 23:01:41 +01:00
|
|
|
pref = findPreference("log_to_file");
|
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
2016-04-18 00:20:40 +02:00
|
|
|
boolean doEnable = Boolean.TRUE.equals(newVal);
|
|
|
|
try {
|
|
|
|
if (doEnable) {
|
2016-03-22 23:01:41 +01:00
|
|
|
FileUtils.getExternalFilesDir(); // ensures that it is created
|
|
|
|
}
|
2016-04-18 00:20:40 +02:00
|
|
|
GBApplication.setupLogging(doEnable);
|
|
|
|
} catch (IOException ex) {
|
|
|
|
GB.toast(getApplicationContext(),
|
|
|
|
getString(R.string.error_creating_directory_for_logfiles, ex.getLocalizedMessage()),
|
|
|
|
Toast.LENGTH_LONG,
|
|
|
|
GB.ERROR,
|
|
|
|
ex);
|
2016-03-22 23:01:41 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-07-31 22:49:05 +02:00
|
|
|
pref = findPreference("language");
|
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
String newLang = newVal.toString();
|
|
|
|
try {
|
2017-07-31 23:00:02 +02:00
|
|
|
GBApplication.setLanguage(newLang);
|
2017-09-07 23:26:24 +02:00
|
|
|
recreate();
|
2017-07-31 22:49:05 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
GB.toast(getApplicationContext(),
|
|
|
|
"Error setting language: " + ex.getLocalizedMessage(),
|
|
|
|
Toast.LENGTH_LONG,
|
|
|
|
GB.ERROR,
|
|
|
|
ex);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-09-30 22:45:45 +02:00
|
|
|
final Preference unit = findPreference(PREF_MEASUREMENT_SYSTEM);
|
|
|
|
unit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MEASUREMENT_SYSTEM);
|
|
|
|
}
|
|
|
|
});
|
2017-09-30 23:36:20 +02:00
|
|
|
preference.setSummary(newVal.toString());
|
2017-09-30 22:45:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-19 16:34:59 +02:00
|
|
|
if (!GBApplication.isRunningMarshmallowOrLater()) {
|
|
|
|
pref = findPreference("notification_filter");
|
|
|
|
PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications");
|
|
|
|
category.removePreference(pref);
|
|
|
|
}
|
|
|
|
|
2016-05-26 14:39:54 +02:00
|
|
|
pref = findPreference("location_aquire");
|
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2016-05-26 14:58:36 +02:00
|
|
|
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
2016-05-26 14:39:54 +02:00
|
|
|
ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 0);
|
|
|
|
}
|
2016-05-26 14:58:36 +02:00
|
|
|
|
|
|
|
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
Criteria criteria = new Criteria();
|
2016-05-26 14:39:54 +02:00
|
|
|
String provider = locationManager.getBestProvider(criteria, false);
|
|
|
|
if (provider != null) {
|
|
|
|
Location location = locationManager.getLastKnownLocation(provider);
|
2016-07-03 21:29:02 +02:00
|
|
|
if (location != null) {
|
2016-07-05 23:52:48 +02:00
|
|
|
setLocationPreferences(location);
|
2016-07-03 21:29:02 +02:00
|
|
|
} else {
|
2016-07-05 23:52:48 +02:00
|
|
|
locationManager.requestSingleUpdate(provider, new LocationListener() {
|
|
|
|
@Override
|
|
|
|
public void onLocationChanged(Location location) {
|
|
|
|
setLocationPreferences(location);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
|
|
|
LOG.info("provider status changed to " + status + " (" + provider + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProviderEnabled(String provider) {
|
|
|
|
LOG.info("provider enabled (" + provider + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProviderDisabled(String provider) {
|
|
|
|
LOG.info("provider disabled (" + provider + ")");
|
|
|
|
GB.toast(SettingsActivity.this, getString(R.string.toast_enable_networklocationprovider), 3000, 0);
|
|
|
|
}
|
|
|
|
}, null);
|
2016-07-03 21:29:02 +02:00
|
|
|
}
|
2016-05-26 14:39:54 +02:00
|
|
|
} else {
|
|
|
|
LOG.warn("No location provider found, did you deny location permission?");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-24 10:25:08 +02:00
|
|
|
pref = findPreference("canned_messages_dismisscall_send");
|
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
ArrayList<String> messages = new ArrayList<>();
|
|
|
|
for (int i = 1; i <= 16; i++) {
|
|
|
|
String message = prefs.getString("canned_message_dismisscall_" + i, null);
|
|
|
|
if (message != null && !message.equals("")) {
|
|
|
|
messages.add(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CannedMessagesSpec cannedMessagesSpec = new CannedMessagesSpec();
|
|
|
|
cannedMessagesSpec.type = CannedMessagesSpec.TYPE_MISSEDCALLS;
|
|
|
|
cannedMessagesSpec.cannedMessages = messages.toArray(new String[messages.size()]);
|
|
|
|
GBApplication.deviceService().onSetCannedMessages(cannedMessagesSpec);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-11 19:09:37 +01:00
|
|
|
pref = findPreference("weather_city");
|
2018-01-04 15:13:06 +01:00
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
// reset city id and force a new lookup
|
|
|
|
GBApplication.getPrefs().getPreferences().edit().putString("weather_cityid", null).apply();
|
|
|
|
preference.setSummary(newVal.toString());
|
|
|
|
Intent intent = new Intent("GB_UPDATE_WEATHER");
|
|
|
|
intent.setPackage(BuildConfig.APPLICATION_ID);
|
|
|
|
sendBroadcast(intent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-01-08 11:27:28 +01:00
|
|
|
pref = findPreference(GBPrefs.AUTO_EXPORT_LOCATION);
|
2018-01-04 15:13:06 +01:00
|
|
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent i = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
|
|
|
i.setType("application/x-sqlite3");
|
|
|
|
i.addCategory(Intent.CATEGORY_OPENABLE);
|
2018-01-08 12:07:10 +01:00
|
|
|
i.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
2018-01-08 11:27:28 +01:00
|
|
|
String title = getApplicationContext().getString(R.string.choose_auto_export_location);
|
|
|
|
startActivityForResult(Intent.createChooser(i, title), FILE_REQUEST_CODE);
|
2018-01-04 15:13:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-01-08 11:27:28 +01:00
|
|
|
pref.setSummary(getAutoExportLocationSummary());
|
2018-01-04 15:13:06 +01:00
|
|
|
|
2018-01-08 11:27:28 +01:00
|
|
|
pref = findPreference(GBPrefs.AUTO_EXPORT_INTERVAL);
|
2017-12-11 19:09:37 +01:00
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
2018-01-08 11:27:28 +01:00
|
|
|
public boolean onPreferenceChange(Preference preference, Object autoExportInterval) {
|
|
|
|
String summary = String.format(
|
|
|
|
getApplicationContext().getString(R.string.pref_summary_auto_export_interval),
|
2018-01-24 15:02:25 +01:00
|
|
|
Integer.valueOf((String) autoExportInterval));
|
2018-01-08 11:27:28 +01:00
|
|
|
preference.setSummary(summary);
|
|
|
|
boolean auto_export_enabled = GBApplication.getPrefs().getBoolean(GBPrefs.AUTO_EXPORT_ENABLED, false);
|
2018-01-24 15:02:25 +01:00
|
|
|
PeriodicExporter.sheduleAlarm(getApplicationContext(), Integer.valueOf((String) autoExportInterval), auto_export_enabled);
|
2017-12-11 19:09:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
2018-01-04 15:13:06 +01:00
|
|
|
});
|
2018-01-08 11:27:28 +01:00
|
|
|
int autoExportInterval = GBApplication.getPrefs().getInt(GBPrefs.AUTO_EXPORT_INTERVAL, 0);
|
|
|
|
String summary = String.format(
|
|
|
|
getApplicationContext().getString(R.string.pref_summary_auto_export_interval),
|
|
|
|
(int) autoExportInterval);
|
|
|
|
pref.setSummary(summary);
|
2017-12-11 19:09:37 +01:00
|
|
|
|
2018-01-08 11:27:28 +01:00
|
|
|
findPreference(GBPrefs.AUTO_EXPORT_ENABLED).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
2018-01-04 15:13:06 +01:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object autoExportEnabled) {
|
2018-01-08 11:27:28 +01:00
|
|
|
int autoExportInterval = GBApplication.getPrefs().getInt(GBPrefs.AUTO_EXPORT_INTERVAL, 0);
|
|
|
|
PeriodicExporter.sheduleAlarm(getApplicationContext(), autoExportInterval, (boolean) autoExportEnabled);
|
2018-01-04 15:13:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
2017-12-11 19:09:37 +01:00
|
|
|
});
|
|
|
|
|
2018-06-30 17:32:12 +02:00
|
|
|
pref = findPreference("auto_fetch_interval_limit");
|
|
|
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object autoFetchInterval) {
|
|
|
|
String summary = String.format(
|
|
|
|
getApplicationContext().getString(R.string.pref_auto_fetch_limit_fetches_summary),
|
|
|
|
Integer.valueOf((String) autoFetchInterval));
|
|
|
|
preference.setSummary(summary);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
int autoFetchInterval = GBApplication.getPrefs().getInt("auto_fetch_interval_limit", 0);
|
|
|
|
summary = String.format(
|
|
|
|
getApplicationContext().getString(R.string.pref_auto_fetch_limit_fetches_summary),
|
|
|
|
(int) autoFetchInterval);
|
|
|
|
pref.setSummary(summary);
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-27 09:28:33 +02:00
|
|
|
final Preference displayPages = findPreference("bip_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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-02 10:55:30 +02:00
|
|
|
final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT);
|
|
|
|
setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
|
|
|
invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Preference miBand2DisplayItems = findPreference(PREF_MI2_DISPLAY_ITEMS);
|
|
|
|
miBand2DisplayItems.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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
final Preference miBand3DisplayItems = findPreference("miband3_display_items");
|
|
|
|
miBand3DisplayItems.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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
final Preference corDisplayItems = findPreference("cor_display_items");
|
|
|
|
corDisplayItems.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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-16 00:53:54 +02:00
|
|
|
// Get all receivers of Media Buttons
|
|
|
|
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
|
|
|
|
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
List<ResolveInfo> mediaReceivers = pm.queryBroadcastReceivers(mediaButtonIntent,
|
|
|
|
PackageManager.GET_INTENT_FILTERS | PackageManager.GET_RESOLVED_FILTER);
|
|
|
|
|
|
|
|
|
|
|
|
CharSequence[] newEntries = new CharSequence[mediaReceivers.size() + 1];
|
|
|
|
CharSequence[] newValues = new CharSequence[mediaReceivers.size() + 1];
|
|
|
|
newEntries[0] = getString(R.string.pref_default);
|
|
|
|
newValues[0] = "default";
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
for (ResolveInfo resolveInfo : mediaReceivers) {
|
|
|
|
newEntries[i] = resolveInfo.activityInfo.loadLabel(pm);
|
|
|
|
newValues[i] = resolveInfo.activityInfo.packageName;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
final ListPreference audioPlayer = (ListPreference) findPreference("audio_player");
|
|
|
|
audioPlayer.setEntries(newEntries);
|
|
|
|
audioPlayer.setEntryValues(newValues);
|
2015-09-17 15:30:33 +02:00
|
|
|
audioPlayer.setDefaultValue(newValues[0]);
|
2015-08-19 00:03:52 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 15:13:06 +01:00
|
|
|
@Override
|
2018-01-08 12:07:10 +01:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
if (requestCode == FILE_REQUEST_CODE && intent != null) {
|
|
|
|
Uri uri = intent.getData();
|
|
|
|
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
2018-01-04 15:13:06 +01:00
|
|
|
PreferenceManager
|
2018-01-08 11:27:28 +01:00
|
|
|
.getDefaultSharedPreferences(this)
|
|
|
|
.edit()
|
|
|
|
.putString(GBPrefs.AUTO_EXPORT_LOCATION, uri.toString())
|
|
|
|
.apply();
|
|
|
|
String summary = getAutoExportLocationSummary();
|
|
|
|
findPreference(GBPrefs.AUTO_EXPORT_LOCATION).setSummary(summary);
|
2018-01-04 15:13:06 +01:00
|
|
|
boolean autoExportEnabled = GBApplication
|
2018-01-08 11:27:28 +01:00
|
|
|
.getPrefs().getBoolean(GBPrefs.AUTO_EXPORT_ENABLED, false);
|
2018-01-04 15:13:06 +01:00
|
|
|
int autoExportPeriod = GBApplication
|
2018-01-08 11:27:28 +01:00
|
|
|
.getPrefs().getInt(GBPrefs.AUTO_EXPORT_INTERVAL, 0);
|
2018-01-04 15:13:06 +01:00
|
|
|
PeriodicExporter.sheduleAlarm(getApplicationContext(), autoExportPeriod, autoExportEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 11:27:28 +01:00
|
|
|
/*
|
2018-02-11 14:32:21 +01:00
|
|
|
Either returns the file path of the selected document, or the display name, or an empty string
|
2018-01-08 11:27:28 +01:00
|
|
|
*/
|
|
|
|
private String getAutoExportLocationSummary() {
|
|
|
|
String autoExportLocation = GBApplication.getPrefs().getString(GBPrefs.AUTO_EXPORT_LOCATION, null);
|
|
|
|
if (autoExportLocation == null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
Uri uri = Uri.parse(autoExportLocation);
|
|
|
|
try {
|
2018-02-11 14:32:21 +01:00
|
|
|
return AndroidUtils.getFilePath(getApplicationContext(), uri);
|
|
|
|
} catch (IllegalArgumentException e) {
|
2018-05-15 23:12:18 +02:00
|
|
|
try {
|
|
|
|
Cursor cursor = getContentResolver().query(
|
|
|
|
uri,
|
|
|
|
new String[]{DocumentsContract.Document.COLUMN_DISPLAY_NAME},
|
|
|
|
null, null, null, null
|
|
|
|
);
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
return cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception fdfsdfds) {
|
|
|
|
LOG.warn("fuck");
|
2018-01-08 11:27:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-09-30 22:45:45 +02:00
|
|
|
/*
|
|
|
|
* delayed execution so that the preferences are applied first
|
|
|
|
*/
|
|
|
|
private void invokeLater(Runnable runnable) {
|
|
|
|
getListView().post(runnable);
|
|
|
|
}
|
|
|
|
|
2015-08-19 00:03:52 +02:00
|
|
|
@Override
|
|
|
|
protected String[] getPreferenceKeysWithSummary() {
|
|
|
|
return new String[]{
|
|
|
|
"pebble_emu_addr",
|
2015-09-16 00:53:54 +02:00
|
|
|
"pebble_emu_port",
|
2015-09-17 15:30:33 +02:00
|
|
|
"pebble_reconnect_attempts",
|
2016-05-26 14:39:54 +02:00
|
|
|
"location_latitude",
|
|
|
|
"location_longitude",
|
2016-01-11 15:29:12 +01:00
|
|
|
"canned_reply_suffix",
|
2015-12-13 12:03:57 +01:00
|
|
|
"canned_reply_1",
|
|
|
|
"canned_reply_2",
|
|
|
|
"canned_reply_3",
|
|
|
|
"canned_reply_4",
|
|
|
|
"canned_reply_5",
|
|
|
|
"canned_reply_6",
|
|
|
|
"canned_reply_7",
|
|
|
|
"canned_reply_8",
|
2015-12-17 00:30:55 +01:00
|
|
|
"canned_reply_9",
|
|
|
|
"canned_reply_10",
|
|
|
|
"canned_reply_11",
|
|
|
|
"canned_reply_12",
|
|
|
|
"canned_reply_13",
|
|
|
|
"canned_reply_14",
|
|
|
|
"canned_reply_15",
|
|
|
|
"canned_reply_16",
|
2016-06-24 10:25:08 +02:00
|
|
|
"canned_message_dismisscall_1",
|
|
|
|
"canned_message_dismisscall_2",
|
|
|
|
"canned_message_dismisscall_3",
|
|
|
|
"canned_message_dismisscall_4",
|
|
|
|
"canned_message_dismisscall_5",
|
|
|
|
"canned_message_dismisscall_6",
|
|
|
|
"canned_message_dismisscall_7",
|
|
|
|
"canned_message_dismisscall_8",
|
|
|
|
"canned_message_dismisscall_9",
|
|
|
|
"canned_message_dismisscall_10",
|
|
|
|
"canned_message_dismisscall_11",
|
|
|
|
"canned_message_dismisscall_12",
|
|
|
|
"canned_message_dismisscall_13",
|
|
|
|
"canned_message_dismisscall_14",
|
|
|
|
"canned_message_dismisscall_15",
|
|
|
|
"canned_message_dismisscall_16",
|
2016-02-02 14:32:19 +01:00
|
|
|
PREF_USER_YEAR_OF_BIRTH,
|
|
|
|
PREF_USER_HEIGHT_CM,
|
|
|
|
PREF_USER_WEIGHT_KG,
|
2016-02-29 21:36:39 +01:00
|
|
|
PREF_USER_SLEEP_DURATION,
|
2017-03-11 11:29:50 +01:00
|
|
|
PREF_USER_STEPS_GOAL,
|
2018-08-02 10:55:30 +02:00
|
|
|
PREF_MI2_ENABLE_TEXT_NOTIFICATIONS,
|
2017-12-11 19:09:37 +01:00
|
|
|
"weather_city",
|
2015-08-19 00:03:52 +02:00
|
|
|
};
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
2015-08-19 00:03:52 +02:00
|
|
|
|
2016-07-05 23:52:48 +02:00
|
|
|
private void setLocationPreferences(Location location) {
|
|
|
|
String latitude = String.format(Locale.US, "%.6g", location.getLatitude());
|
|
|
|
String longitude = String.format(Locale.US, "%.6g", location.getLongitude());
|
|
|
|
LOG.info("got location. Lat: " + latitude + " Lng: " + longitude);
|
|
|
|
GB.toast(SettingsActivity.this, getString(R.string.toast_aqurired_networklocation), 2000, 0);
|
|
|
|
EditTextPreference pref_latitude = (EditTextPreference) findPreference("location_latitude");
|
|
|
|
EditTextPreference pref_longitude = (EditTextPreference) findPreference("location_longitude");
|
|
|
|
pref_latitude.setText(latitude);
|
|
|
|
pref_longitude.setText(longitude);
|
|
|
|
pref_latitude.setSummary(latitude);
|
|
|
|
pref_longitude.setSummary(longitude);
|
|
|
|
}
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|