1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 19:36:50 +01:00

Added ringtone preference setting.

This commit is contained in:
Anemograph 2021-09-03 11:01:47 -05:00 committed by vanous
parent e00ee75ad2
commit d088c3d63f
5 changed files with 46 additions and 2 deletions

View File

@ -38,8 +38,11 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
public class FindPhoneActivity extends AbstractGBActivity {
@ -112,7 +115,7 @@ public class FindPhoneActivity extends AbstractGBActivity {
}
mp = new MediaPlayer();
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Uri ringtoneUri = Uri.parse(GBApplication.getPrefs().getString(GBPrefs.PING_TONE, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString()));
try {
mp.setDataSource(this, ringtoneUri);

View File

@ -28,6 +28,8 @@ import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.EditTextPreference;
@ -71,6 +73,8 @@ public class SettingsActivity extends AbstractSettingsActivity {
public static final String PREF_MEASUREMENT_SYSTEM = "measurement_system";
private static final int FILE_REQUEST_CODE = 4711;
private static final int RINGTONE_REQUEST_CODE = 4712;
private static final String DEFAULT_RINGTONE_URI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString();
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -305,6 +309,21 @@ public class SettingsActivity extends AbstractSettingsActivity {
}
});
pref = findPreference(GBPrefs.PING_TONE);
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Set Ping tone");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
startActivityForResult(intent, RINGTONE_REQUEST_CODE);
return true;
}
});
pref.setSummary(RingtoneManager.getRingtone(this, Uri.parse(prefs.getString(GBPrefs.PING_TONE, DEFAULT_RINGTONE_URI))).getTitle(this));
pref = findPreference(GBPrefs.AUTO_EXPORT_LOCATION);
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
@ -436,6 +455,20 @@ public class SettingsActivity extends AbstractSettingsActivity {
.getPrefs().getInt(GBPrefs.AUTO_EXPORT_INTERVAL, 0);
PeriodicExporter.sheduleAlarm(getApplicationContext(), autoExportPeriod, autoExportEnabled);
}
if (requestCode == RINGTONE_REQUEST_CODE && intent != null) {
if(intent.getExtras().getParcelable(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)!= null){
Uri uri = intent.getExtras().getParcelable(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
Ringtone r = RingtoneManager.getRingtone(this ,uri);
findPreference(GBPrefs.PING_TONE).setSummary(r.toString());
PreferenceManager
.getDefaultSharedPreferences(this)
.edit()
.putString(GBPrefs.PING_TONE, uri.toString())
.apply();
findPreference(GBPrefs.PING_TONE).setSummary(r.getTitle(this));
}
}
}
/*

View File

@ -45,6 +45,7 @@ public class GBPrefs {
private static final String AUTO_START = "general_autostartonboot";
public static final String AUTO_EXPORT_ENABLED = "auto_export_enabled";
public static final String AUTO_EXPORT_LOCATION = "auto_export_location";
public static final String PING_TONE = "ping_tone";
public static final String AUTO_EXPORT_INTERVAL = "auto_export_interval";
private static final boolean AUTO_START_DEFAULT = true;
private static final String BG_JS_ENABLED = "pebble_enable_background_javascript";

View File

@ -120,6 +120,7 @@
<string name="pref_title_notifications_repetitions">Repetitions</string>
<string name="pref_title_notifications_call">Phone Calls</string>
<string name="pref_title_support_voip_calls">Enable VoIP app calls</string>
<string name="pref_title_ping_tone">Ping tone</string>
<string name="pref_title_notifications_sms">SMS</string>
<string name="pref_title_notifications_timeout">Minimum time between notifications</string>
<string name="pref_title_notifications_pebblemsg">Pebble Messages</string>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="pref_key_general"
android:title="@string/pref_header_general">
@ -129,6 +130,11 @@
android:key="pref_key_notifications"
android:title="@string/pref_header_notifications">
<Preference
android:id="@+id/preference"
android:key="ping_tone"
android:title="@string/pref_title_ping_tone"
app:summary="%s" />
<ListPreference
android:defaultValue="always"
android:entries="@array/notification_mode_toggle"