Custom sound

This commit is contained in:
stom79 2018-09-16 19:05:54 +02:00
parent 8a5cee5447
commit 1d7bfed1c3
37 changed files with 139 additions and 13 deletions

View File

@ -16,6 +16,9 @@ package fr.gouv.etalab.mastodon.fragments;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.media.RingtoneManager;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.content.ContentUris;
@ -40,6 +43,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
@ -75,6 +79,7 @@ public class SettingsFragment extends Fragment {
private Context context;
private static final int ACTIVITY_CHOOSE_FILE = 411;
private static final int ACTIVITY_CHOOSE_SOUND = 412;
private TextView set_folder;
int count1, count2, count3 = 0;
private EditText your_api_key;
@ -539,6 +544,18 @@ public class SettingsFragment extends Fragment {
});
Button set_notif_sound = rootView.findViewById(R.id.set_notif_sound);
set_notif_sound.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, context.getString(R.string.select_sound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
startActivityForResult(intent, ACTIVITY_CHOOSE_SOUND);
}
});
LinearLayout toot_visibility_container = rootView.findViewById(R.id.toot_visibility_container);
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
@ -751,18 +768,35 @@ public class SettingsFragment extends Fragment {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
if(requestCode == ACTIVITY_CHOOSE_FILE) {
Uri treeUri = data.getData();
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri,
DocumentsContract.getTreeDocumentId(treeUri));
String path = getPath(context, docUri);
if( path == null )
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SET_FOLDER_RECORD, path);
editor.apply();
set_folder.setText(path);
try{
String path = getPath(context, docUri);
if( path == null )
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SET_FOLDER_RECORD, path);
editor.apply();
set_folder.setText(path);
}catch (Exception e){
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
}
}else if (requestCode == ACTIVITY_CHOOSE_SOUND){
try{
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.SET_NOTIF_SOUND, uri.toString());
editor.apply();
}catch (Exception e){
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
}
}
}

View File

@ -28,6 +28,7 @@ import android.graphics.Matrix;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.media.AudioAttributes;
import android.os.CountDownTimer;
import android.provider.MediaStore;
import android.provider.OpenableColumns;
@ -260,6 +261,7 @@ public class Helper {
public static final String SET_FULL_PREVIEW = "set_full_preview";
public static final String SET_COMPACT_MODE = "set_compact_mode";
public static final String SET_SHARE_DETAILS = "set_share_details";
public static final String SET_NOTIF_SOUND = "set_notif_sound";
public static final int S_512KO = 1;
public static final int S_1MO = 2;
public static final int S_2MO = 3;
@ -837,9 +839,15 @@ public class Helper {
channelTitle = context.getString(R.string.channel_notif_boost);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_DEFAULT);
NotificationChannel channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_HIGH);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
assert mNotificationManager != null;
String soundUri =sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"+ R.raw.boop);
channel.setSound(Uri.parse(soundUri), audioAttributes);
mNotificationManager.createNotificationChannel(channel);
}
@ -852,9 +860,9 @@ public class Helper {
.setContentText(message);
if( sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT,false) ) {
notificationBuilder.setVibrate(new long[] { 500, 500, 500});
}else {
String soundUri = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/";
notificationBuilder.setSound(Uri.parse(soundUri + R.raw.boop));
}else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
String soundUri =sharedpreferences.getString(Helper.SET_NOTIF_SOUND, ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() +"/"+ R.raw.boop);
notificationBuilder.setSound(Uri.parse(soundUri));
}
int ledColour = Color.BLUE;

View File

@ -156,6 +156,15 @@
android:layout_height="wrap_content"
android:text="@string/send_crash_report"
/>
<Button
android:id="@+id/set_notif_sound"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:tint="@android:color/white"
android:text="@string/set_notif_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- Resize pictures -->
<LinearLayout
android:layout_marginTop="10dp"

View File

@ -157,6 +157,15 @@
android:text="@string/send_crash_report"
/>
<Button
android:id="@+id/set_notif_sound"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:tint="@android:color/white"
android:text="@string/set_notif_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- Resize pictures -->
<LinearLayout
android:layout_marginTop="10dp"

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -560,6 +560,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>أبدًا</item>
<item>30 دقيقة</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -558,6 +558,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -541,7 +541,9 @@ Die Anwendung <b>nutzt keine Trackingwergzeuge</b>(Zielgruppenbestimmung, Fehler
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string-array name="filter_expire">
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Nie</item>
<item>30 Minuten</item>
<item>1 Stunde</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -547,6 +547,8 @@ Gracias a: </string>
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Nunca</item>
<item>30 minutos</item>

View File

@ -551,6 +551,8 @@ Eskerrik asko Stéphane logoagatik. </string>
<string name="retrieve_remote_account">Urruneko kontua eskuratzen</string>
<string name="expand_image">Automatikoki hedatu ezkutatutako multimedia</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Inoiz ez</item>
<item>30 minutu</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -550,6 +550,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Jamais</item>
<item>30 minutes</item>

View File

@ -558,6 +558,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -551,6 +551,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -551,6 +551,8 @@ https://yandex.ru/legal/confidential/?lang=en
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -552,6 +552,8 @@ Per favore, conferma le notifiche push che vuoi ricevere.
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -541,6 +541,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -549,6 +549,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -544,6 +544,8 @@ Takk til: </string>
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -555,6 +555,8 @@ Podziękowania dla: </string>
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Nigdy</item>
<item>30 minut</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Nunca</item>
<item>30 minutos</item>

View File

@ -552,6 +552,8 @@ Vă mulțumesc:
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -556,6 +556,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -555,6 +555,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Никадa</item>
<item>30 минута</item>

View File

@ -552,6 +552,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -545,6 +545,8 @@ Teşekkürler: </string>
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -548,6 +548,8 @@
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -547,6 +547,8 @@ Cảm ơn bạn: </string>
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -544,6 +544,8 @@ Yandex 有适当的隐私政策可以在这里找到https://yandex.ru/lega
<string name="retrieve_remote_account">Fetching remote account</string>
<string name="expand_image">Automatically expand hidden media</string>
<string name="set_display_follow_instance">Display follow instances button</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>
<item>30 minutes</item>

View File

@ -549,6 +549,8 @@
<string name="retrieve_remote_account">正在擷取遠端帳號</string>
<string name="expand_image">自動展開隱藏的媒體</string>
<string name="set_display_follow_instance">顯示關注實體按鈕</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>永不</item>
<item>30 分鐘</item>

View File

@ -617,6 +617,8 @@
<string name="channel_notif_toot">New Toot</string>
<string name="channel_notif_backup">Toots Backup</string>
<string name="channel_notif_media">Media Download</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>
<string-array name="filter_expire">
<item>Never</item>