2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
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;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.os.Bundle;
|
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;
|
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-03-22 23:01:41 +01:00
|
|
|
import java.io.IOException;
|
2015-09-16 00:53:54 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
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;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
2016-03-22 23:01:41 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2015-05-07 01:30:40 +02:00
|
|
|
|
2016-02-02 17:33:24 +01:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GENDER;
|
|
|
|
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;
|
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 {
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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) {
|
|
|
|
Intent refreshIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
|
|
|
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) {
|
|
|
|
Intent refreshIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@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-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-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,
|
2015-08-19 00:03:52 +02:00
|
|
|
};
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
2015-08-19 00:03:52 +02:00
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|