Added explicit sent sound

pull/207/head
M66B 3 years ago
parent 75f57a215f
commit 0e521c35f2

@ -133,16 +133,17 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
private static final int KEY_ITERATIONS = 65536;
private static final int KEY_LENGTH = 256;
static final int REQUEST_SOUND = 1;
static final int REQUEST_EXPORT = 2;
static final int REQUEST_IMPORT = 3;
static final int REQUEST_CHOOSE_ACCOUNT = 4;
static final int REQUEST_DONE = 5;
static final int REQUEST_IMPORT_CERTIFICATE = 6;
static final int REQUEST_OAUTH = 7;
static final int REQUEST_STILL = 8;
static final int REQUEST_DELETE_ACCOUNT = 9;
static final int REQUEST_IMPORT_PROVIDERS = 10;
static final int REQUEST_SOUND_INBOUND = 1;
static final int REQUEST_SOUND_OUTBOUND = 2;
static final int REQUEST_EXPORT = 3;
static final int REQUEST_IMPORT = 4;
static final int REQUEST_CHOOSE_ACCOUNT = 5;
static final int REQUEST_DONE = 6;
static final int REQUEST_IMPORT_CERTIFICATE = 7;
static final int REQUEST_OAUTH = 8;
static final int REQUEST_STILL = 9;
static final int REQUEST_DELETE_ACCOUNT = 10;
static final int REQUEST_IMPORT_PROVIDERS = 11;
static final int PI_MISC = 1;

@ -987,18 +987,7 @@ public class EntityRule {
message.ui_silent = true;
db.message().setMessageUiSilent(message.id, message.ui_silent);
executor.submit(new Runnable() {
@Override
public void run() {
try {
if (MediaPlayerHelper.isInCall(context))
return;
MediaPlayerHelper.play(context, uri, alarm, duration);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
MediaPlayerHelper.queue(context, uri, alarm, duration);
return true;
}

@ -414,7 +414,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, sound == null ? null : Uri.parse(sound));
startActivityForResult(Helper.getChooser(getContext(), intent), ActivitySetup.REQUEST_SOUND);
startActivityForResult(Helper.getChooser(getContext(), intent), ActivitySetup.REQUEST_SOUND_INBOUND);
}
});
@ -703,7 +703,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
try {
switch (requestCode) {
case ActivitySetup.REQUEST_SOUND:
case ActivitySetup.REQUEST_SOUND_INBOUND:
if (resultCode == RESULT_OK && data != null)
onSelectSound(data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI));
break;

@ -19,8 +19,12 @@ package eu.faircode.email;
Copyright 2018-2022 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
@ -67,6 +71,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swAttachNew;
private Spinner spAnswerAction;
private SwitchCompat swSendPending;
private Button btnSound;
private Spinner spComposeFont;
private SwitchCompat swSeparateReply;
@ -98,7 +103,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
"suggest_names", "suggest_sent", "suggested_received", "suggest_frequently",
"alt_re", "alt_fwd",
"send_reminders", "send_chips", "send_delayed",
"attach_new", "answer_action", "send_pending",
"attach_new", "answer_action", "send_pending", "sound_sent",
"compose_font", "prefix_once", "prefix_count", "separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit", "resize_reply",
"signature_location", "signature_new", "signature_reply", "signature_forward",
"discard_delete", "reply_move",
@ -133,6 +138,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swAttachNew = view.findViewById(R.id.swAttachNew);
spAnswerAction = view.findViewById(R.id.spAnswerAction);
swSendPending = view.findViewById(R.id.swSendPending);
btnSound = view.findViewById(R.id.btnSound);
spComposeFont = view.findViewById(R.id.spComposeFont);
swSeparateReply = view.findViewById(R.id.swSeparateReply);
@ -316,6 +322,20 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
}
});
btnSound.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String sound = prefs.getString("sound_sent", null);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.title_advanced_sound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, sound == null ? null : Uri.parse(sound));
startActivityForResult(Helper.getChooser(getContext(), intent), ActivitySetup.REQUEST_SOUND_OUTBOUND);
}
});
spComposeFont.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
@ -635,4 +655,35 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false));
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case ActivitySetup.REQUEST_SOUND_OUTBOUND:
if (resultCode == RESULT_OK && data != null)
onSelectSound(data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI));
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onSelectSound(Uri uri) {
Log.i("Selected ringtone=" + uri);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (uri == null) // no/silent sound
prefs.edit().remove("sound_sent").apply();
else {
if ("content".equals(uri.getScheme()))
prefs.edit().putString("sound_sent", uri.toString()).apply();
else
prefs.edit().remove("sound_sent").apply();
}
}
}

@ -7,13 +7,42 @@ import android.media.MediaPlayer;
import android.net.Uri;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class MediaPlayerHelper {
static final int DEFAULT_SOUND_DURATION = 30; // seconds
static final int DEFAULT_ALARM_DURATION = 30; // seconds
static void play(Context context, Uri uri, boolean alarm, int duration) throws IOException {
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "media");
static void queue(Context context, String uri) {
try {
queue(context, Uri.parse(uri), false, DEFAULT_SOUND_DURATION);
} catch (Throwable ex) {
Log.e(ex);
}
}
static void queue(Context context, Uri uri, boolean alarm, int duration) {
Log.i("Queuing sound=" + uri);
executor.submit(new Runnable() {
@Override
public void run() {
try {
if (MediaPlayerHelper.isInCall(context))
return;
MediaPlayerHelper.play(context, uri, alarm, duration);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
private static void play(Context context, Uri uri, boolean alarm, int duration) throws IOException {
Semaphore sem = new Semaphore(0);
AudioAttributes attrs = new AudioAttributes.Builder()

@ -90,7 +90,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
EntityLog.log(this, "Service send create");
super.onCreate();
startForeground(NotificationHelper.NOTIFICATION_SEND,
getNotificationService(false).build());
getNotificationService().build());
owner = new TwoStateOwner(this, "send");
@ -110,7 +110,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
NotificationManager nm =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SEND,
getNotificationService(false).build());
getNotificationService().build());
} catch (Throwable ex) {
Log.w(ex);
}
@ -205,7 +205,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
startForeground(NotificationHelper.NOTIFICATION_SEND,
getNotificationService(false).build());
getNotificationService().build());
Log.i("Send intent=" + intent);
Log.logExtras(intent);
@ -213,7 +213,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
return START_STICKY;
}
NotificationCompat.Builder getNotificationService(boolean alert) {
NotificationCompat.Builder getNotificationService() {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, "send")
.setSmallIcon(R.drawable.baseline_send_white_24)
@ -221,7 +221,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
.setContentIntent(getPendingIntent(this))
.setAutoCancel(false)
.setShowWhen(true)
.setOnlyAlertOnce(!alert)
.setOnlyAlertOnce(true)
.setDefaults(0) // disable sound on pre Android 8
.setLocalOnly(true)
.setPriority(NotificationCompat.PRIORITY_MIN)
@ -334,7 +334,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
NotificationManager nm =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SEND,
getNotificationService(false).build());
getNotificationService().build());
} catch (Throwable ex) {
Log.w(ex);
}
@ -521,7 +521,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
NotificationManager nm =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(true).build());
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService().build());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean reply_move = prefs.getBoolean("reply_move", false);
@ -735,7 +735,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
if (now > last + PROGRESS_UPDATE_INTERVAL) {
last = now;
lastProgress = progress;
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false).build());
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService().build());
}
}
}
@ -776,7 +776,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
iservice.close();
if (lastProgress >= 0) {
lastProgress = -1;
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false).build());
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService().build());
}
db.identity().setIdentityState(ident.id, null);
}
@ -827,6 +827,11 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
nm.cancel("send:" + message.id, NotificationHelper.NOTIFICATION_TAGGED);
// Play sent sound
String sound = prefs.getString("sound_sent", null);
if (!TextUtils.isEmpty(sound))
MediaPlayerHelper.queue(ServiceSend.this, sound);
// Check sent message
if (sid != null) {
try {

@ -378,6 +378,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spAnswerAction"
app:switchPadding="12dp" />
<Button
android:id="@+id/btnSound"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_audiotrack_24"
android:drawablePadding="6dp"
android:text="@string/title_advanced_sound"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSendPending" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

Loading…
Cancel
Save