[Android] Ask confirmation to set a track as ringtone
Geoffrey Métais
git at videolan.org
Fri Jan 25 15:59:04 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 25 15:58:35 2019 +0100| [e498ce6a36b665939488d6a7418127f0868bb53e] | committer: Geoffrey Métais
Ask confirmation to set a track as ringtone
> https://code.videolan.org/videolan/vlc-android/commit/e498ce6a36b665939488d6a7418127f0868bb53e
---
vlc-android/res/values/strings.xml | 1 +
.../org/videolan/vlc/gui/helpers/AudioUtil.java | 95 ++++++++++++----------
2 files changed, 51 insertions(+), 45 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 4bb2bdb43..677f6186a 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -52,6 +52,7 @@
<string name="delete">Delete</string>
<string name="remove">Remove</string>
<string name="set_song">Set as ringtone</string>
+ <string name="set_song_question">Set \'%1$s\' as ringtone?</string>
<string name="info">Information</string>
<string name="confirm_delete">Delete the file \'%1$s\'?</string>
<string name="confirm_delete_folder">Delete the folder \'%1$s\' and all its contents?</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
index 0c7c37d1d..d91dcb49d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.java
@@ -99,55 +99,60 @@ public class AudioUtil {
Permissions.checkWriteSettingsPermission(context, Permissions.PERMISSION_SYSTEM_RINGTONE);
return;
}
- WorkersKt.runIO(new Runnable() {
+ UiTools.snackerConfirm(context.getWindow().getDecorView(), context.getString(R.string.set_song_question, song.getTitle()), new Runnable() {
@Override
public void run() {
- final File newRingtone = AndroidUtil.UriToFile(song.getUri());
- if (!newRingtone.exists()) {
- Toast.makeText(context.getApplicationContext(),context.getString(R.string.ringtone_error), Toast.LENGTH_SHORT).show();
- return;
- }
-
- final ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.DATA, newRingtone.getAbsolutePath());
- values.put(MediaStore.MediaColumns.TITLE, song.getTitle());
- values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
- values.put(MediaStore.Audio.Media.ARTIST, song.getArtist());
- values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
- values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
- values.put(MediaStore.Audio.Media.IS_ALARM, false);
- values.put(MediaStore.Audio.Media.IS_MUSIC, false);
-
- final Uri uri = MediaStore.Audio.Media.getContentUriForPath(newRingtone.getAbsolutePath());
- final Uri newUri;
- try {
- context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newRingtone.getAbsolutePath() + "\"", null);
- newUri = context.getContentResolver().insert(uri, values);
- RingtoneManager.setActualDefaultRingtoneUri(
- context.getApplicationContext(),
- RingtoneManager.TYPE_RINGTONE,
- newUri
- );
- } catch(Exception e) {
- Log.e(TAG, "error setting ringtone", e);
- WorkersKt.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(context.getApplicationContext(),
- context.getString(R.string.ringtone_error),
- Toast.LENGTH_SHORT).show();
- }
- });
- return;
- }
- WorkersKt.runOnMainThread(new Runnable() {
+ WorkersKt.runIO(new Runnable() {
@Override
public void run() {
- Toast.makeText(
- context.getApplicationContext(),
- context.getString(R.string.ringtone_set, song.getTitle()),
- Toast.LENGTH_SHORT)
- .show();
+ final File newRingtone = AndroidUtil.UriToFile(song.getUri());
+ if (!newRingtone.exists()) {
+ Toast.makeText(context.getApplicationContext(),context.getString(R.string.ringtone_error), Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ final ContentValues values = new ContentValues();
+ values.put(MediaStore.MediaColumns.DATA, newRingtone.getAbsolutePath());
+ values.put(MediaStore.MediaColumns.TITLE, song.getTitle());
+ values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
+ values.put(MediaStore.Audio.Media.ARTIST, song.getArtist());
+ values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
+ values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
+ values.put(MediaStore.Audio.Media.IS_ALARM, false);
+ values.put(MediaStore.Audio.Media.IS_MUSIC, false);
+
+ final Uri uri = MediaStore.Audio.Media.getContentUriForPath(newRingtone.getAbsolutePath());
+ final Uri newUri;
+ try {
+ context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newRingtone.getAbsolutePath() + "\"", null);
+ newUri = context.getContentResolver().insert(uri, values);
+ RingtoneManager.setActualDefaultRingtoneUri(
+ context.getApplicationContext(),
+ RingtoneManager.TYPE_RINGTONE,
+ newUri
+ );
+ } catch(Exception e) {
+ Log.e(TAG, "error setting ringtone", e);
+ WorkersKt.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(context.getApplicationContext(),
+ context.getString(R.string.ringtone_error),
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ return;
+ }
+ WorkersKt.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(
+ context.getApplicationContext(),
+ context.getString(R.string.ringtone_set, song.getTitle()),
+ Toast.LENGTH_SHORT)
+ .show();
+ }
+ });
}
});
}
More information about the Android
mailing list