mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Support for custom call ringtone selection and per-chat ringtones
This commit is contained in:
parent
35a6ec707f
commit
71c7ef5b5e
@ -963,6 +963,8 @@
|
|||||||
<string name="recipient_preferences__view_safety_number">View safety number</string>
|
<string name="recipient_preferences__view_safety_number">View safety number</string>
|
||||||
<string name="recipient_preferences__chat_settings">Chat settings</string>
|
<string name="recipient_preferences__chat_settings">Chat settings</string>
|
||||||
<string name="recipient_preferences__privacy">Privacy</string>
|
<string name="recipient_preferences__privacy">Privacy</string>
|
||||||
|
<string name="recipient_preferences__call_settings">Call settings</string>
|
||||||
|
<string name="recipient_preferences__ringtone">Ringtone</string>
|
||||||
|
|
||||||
<!--- redphone_call_controls -->
|
<!--- redphone_call_controls -->
|
||||||
<string name="redphone_call_card__signal_call">Signal Call</string>
|
<string name="redphone_call_card__signal_call">Signal Call</string>
|
||||||
@ -1159,6 +1161,8 @@
|
|||||||
<string name="preferences_notifications__events">Events</string>
|
<string name="preferences_notifications__events">Events</string>
|
||||||
<string name="preferences_notifications__in_chat_sounds">In-chat sounds</string>
|
<string name="preferences_notifications__in_chat_sounds">In-chat sounds</string>
|
||||||
<string name="preferences_notifications__show">Show</string>
|
<string name="preferences_notifications__show">Show</string>
|
||||||
|
<string name="preferences_notifications__calls">Calls</string>
|
||||||
|
<string name="preferences_notifications__ringtone">Ringtone</string>
|
||||||
<string name="preferences_chats__show_invitation_prompts">Show invitation prompts</string>
|
<string name="preferences_chats__show_invitation_prompts">Show invitation prompts</string>
|
||||||
<string name="preferences_chats__display_invitation_prompts_for_contacts_without_signal">Display invitation prompts for contacts without Signal</string>
|
<string name="preferences_chats__display_invitation_prompts_for_contacts_without_signal">Display invitation prompts for contacts without Signal</string>
|
||||||
<string name="preferences_chats__message_text_size">Message font size</string>
|
<string name="preferences_chats__message_text_size">Message font size</string>
|
||||||
|
@ -71,6 +71,30 @@
|
|||||||
|
|
||||||
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/preferences_notifications__calls">
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||||
|
android:key="pref_call_notifications"
|
||||||
|
android:title="@string/preferences__notifications"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.preferences.widgets.SignalPreference
|
||||||
|
android:dependency="pref_call_notifications"
|
||||||
|
android:key="pref_call_ringtone"
|
||||||
|
android:title="@string/preferences_notifications__ringtone"
|
||||||
|
android:persistent="false"
|
||||||
|
android:defaultValue="content://settings/system/ringtone" />
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||||
|
android:dependency="pref_call_notifications"
|
||||||
|
android:key="pref_call_vibrate"
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:title="@string/preferences__vibrate"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/preferences_notifications__events">
|
<PreferenceCategory android:title="@string/preferences_notifications__events">
|
||||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||||
android:key="pref_enable_new_contacts_notifications"
|
android:key="pref_enable_new_contacts_notifications"
|
||||||
|
@ -35,6 +35,25 @@
|
|||||||
app:numColumns="5" />
|
app:numColumns="5" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory android:layout="@layout/preference_divider"/>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/recipient_preferences__call_settings">
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.preferences.widgets.SignalPreference
|
||||||
|
android:key="pref_key_recipient_call_ringtone"
|
||||||
|
android:title="@string/recipient_preferences__ringtone"
|
||||||
|
android:persistent="false"/>
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.preferences.widgets.SignalListPreference
|
||||||
|
android:key="pref_key_recipient_call_vibrate"
|
||||||
|
android:title="@string/recipient_preferences__vibrate"
|
||||||
|
android:entries="@array/recipient_vibrate_entries"
|
||||||
|
android:entryValues="@array/recipient_vibrate_values"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:persistent="false"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:key="divider" android:layout="@layout/preference_divider"/>
|
<PreferenceCategory android:key="divider" android:layout="@layout/preference_divider"/>
|
||||||
|
|
||||||
<PreferenceCategory android:key="privacy_settings" android:title="@string/recipient_preferences__privacy">
|
<PreferenceCategory android:key="privacy_settings" android:title="@string/recipient_preferences__privacy">
|
||||||
|
@ -27,6 +27,7 @@ import android.support.v7.preference.Preference;
|
|||||||
import android.support.v7.preference.PreferenceCategory;
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Pair;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@ -74,12 +75,14 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
public static final String ADDRESS_EXTRA = "recipient_address";
|
public static final String ADDRESS_EXTRA = "recipient_address";
|
||||||
public static final String CAN_HAVE_SAFETY_NUMBER_EXTRA = "can_have_safety_number";
|
public static final String CAN_HAVE_SAFETY_NUMBER_EXTRA = "can_have_safety_number";
|
||||||
|
|
||||||
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
||||||
private static final String PREFERENCE_TONE = "pref_key_recipient_ringtone";
|
private static final String PREFERENCE_MESSAGE_TONE = "pref_key_recipient_ringtone";
|
||||||
private static final String PREFERENCE_VIBRATE = "pref_key_recipient_vibrate";
|
private static final String PREFERENCE_CALL_TONE = "pref_key_recipient_call_ringtone";
|
||||||
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
private static final String PREFERENCE_MESSAGE_VIBRATE = "pref_key_recipient_vibrate";
|
||||||
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";
|
private static final String PREFERENCE_CALL_VIBRATE = "pref_key_recipient_call_vibrate";
|
||||||
private static final String PREFERENCE_IDENTITY = "pref_key_recipient_identity";
|
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
||||||
|
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";
|
||||||
|
private static final String PREFERENCE_IDENTITY = "pref_key_recipient_identity";
|
||||||
|
|
||||||
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||||
@ -244,12 +247,18 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
this.canHaveSafetyNumber = getActivity().getIntent()
|
this.canHaveSafetyNumber = getActivity().getIntent()
|
||||||
.getBooleanExtra(RecipientPreferenceActivity.CAN_HAVE_SAFETY_NUMBER_EXTRA, false);
|
.getBooleanExtra(RecipientPreferenceActivity.CAN_HAVE_SAFETY_NUMBER_EXTRA, false);
|
||||||
|
|
||||||
this.findPreference(PREFERENCE_TONE)
|
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
||||||
.setOnPreferenceChangeListener(new RingtoneChangeListener());
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(false));
|
||||||
this.findPreference(PREFERENCE_TONE)
|
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
||||||
.setOnPreferenceClickListener(new RingtoneClickedListener());
|
.setOnPreferenceClickListener(new RingtoneClickedListener(false));
|
||||||
this.findPreference(PREFERENCE_VIBRATE)
|
this.findPreference(PREFERENCE_CALL_TONE)
|
||||||
.setOnPreferenceChangeListener(new VibrateChangeListener());
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(true));
|
||||||
|
this.findPreference(PREFERENCE_CALL_TONE)
|
||||||
|
.setOnPreferenceClickListener(new RingtoneClickedListener(true));
|
||||||
|
this.findPreference(PREFERENCE_MESSAGE_VIBRATE)
|
||||||
|
.setOnPreferenceChangeListener(new VibrateChangeListener(false));
|
||||||
|
this.findPreference(PREFERENCE_CALL_VIBRATE)
|
||||||
|
.setOnPreferenceChangeListener(new VibrateChangeListener(true));
|
||||||
this.findPreference(PREFERENCE_MUTED)
|
this.findPreference(PREFERENCE_MUTED)
|
||||||
.setOnPreferenceClickListener(new MuteClickedListener());
|
.setOnPreferenceClickListener(new MuteClickedListener());
|
||||||
this.findPreference(PREFERENCE_BLOCK)
|
this.findPreference(PREFERENCE_BLOCK)
|
||||||
@ -281,7 +290,11 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
|
if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
|
||||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||||
|
|
||||||
findPreference(PREFERENCE_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_TONE), uri);
|
findPreference(PREFERENCE_MESSAGE_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_MESSAGE_TONE), uri);
|
||||||
|
} else if (requestCode == 2 && resultCode == RESULT_OK && data != null) {
|
||||||
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||||
|
|
||||||
|
findPreference(PREFERENCE_CALL_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_CALL_TONE), uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,41 +304,30 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSummaries(Recipient recipient) {
|
private void setSummaries(Recipient recipient) {
|
||||||
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
|
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
|
||||||
Preference ringtonePreference = this.findPreference(PREFERENCE_TONE);
|
Preference ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE);
|
||||||
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
|
Preference ringtoneCallPreference = this.findPreference(PREFERENCE_CALL_TONE);
|
||||||
ColorPickerPreference colorPreference = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
|
ListPreference vibrateMessagePreference = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE);
|
||||||
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
ListPreference vibrateCallPreference = (ListPreference) this.findPreference(PREFERENCE_CALL_VIBRATE);
|
||||||
Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
|
ColorPickerPreference colorPreference = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
|
||||||
PreferenceCategory privacyCategory = (PreferenceCategory)this.findPreference("privacy_settings");
|
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
||||||
PreferenceCategory divider = (PreferenceCategory)this.findPreference("divider");
|
Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
|
||||||
|
PreferenceCategory privacyCategory = (PreferenceCategory) this.findPreference("privacy_settings");
|
||||||
|
PreferenceCategory divider = (PreferenceCategory) this.findPreference("divider");
|
||||||
|
|
||||||
mutePreference.setChecked(recipient.isMuted());
|
mutePreference.setChecked(recipient.isMuted());
|
||||||
|
|
||||||
final Uri toneUri = recipient.getRingtone();
|
ringtoneMessagePreference.setSummary(getRingtoneSummary(getContext(), recipient.getMessageRingtone()));
|
||||||
|
ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone()));
|
||||||
|
|
||||||
if (toneUri == null) {
|
Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate());
|
||||||
ringtonePreference.setSummary(R.string.preferences__default);
|
Pair<String, Integer> vibrateCallSummary = getVibrateSummary(getContext(), recipient.getCallVibrate());
|
||||||
} else if (toneUri.toString().isEmpty()) {
|
|
||||||
ringtonePreference.setSummary(R.string.preferences__silent);
|
|
||||||
} else {
|
|
||||||
Ringtone tone = RingtoneManager.getRingtone(getActivity(), toneUri);
|
|
||||||
|
|
||||||
if (tone != null) {
|
vibrateMessagePreference.setSummary(vibrateMessageSummary.first);
|
||||||
ringtonePreference.setSummary(tone.getTitle(getActivity()));
|
vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recipient.getVibrate() == VibrateState.DEFAULT) {
|
vibrateCallPreference.setSummary(vibrateCallSummary.first);
|
||||||
vibratePreference.setSummary(R.string.preferences__default);
|
vibrateCallPreference.setValueIndex(vibrateCallSummary.second);
|
||||||
vibratePreference.setValueIndex(0);
|
|
||||||
} else if (recipient.getVibrate() == VibrateState.ENABLED) {
|
|
||||||
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_enabled);
|
|
||||||
vibratePreference.setValueIndex(1);
|
|
||||||
} else {
|
|
||||||
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_disabled);
|
|
||||||
vibratePreference.setValueIndex(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recipient.isGroupRecipient()) {
|
if (recipient.isGroupRecipient()) {
|
||||||
if (colorPreference != null) colorPreference.setVisible(false);
|
if (colorPreference != null) colorPreference.setVisible(false);
|
||||||
@ -362,27 +364,62 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @NonNull String getRingtoneSummary(@NonNull Context context, @Nullable Uri ringtone) {
|
||||||
|
if (ringtone == null) {
|
||||||
|
return context.getString(R.string.preferences__default);
|
||||||
|
} else if (ringtone.toString().isEmpty()) {
|
||||||
|
return context.getString(R.string.preferences__silent);
|
||||||
|
} else {
|
||||||
|
Ringtone tone = RingtoneManager.getRingtone(getActivity(), ringtone);
|
||||||
|
|
||||||
|
if (tone != null) {
|
||||||
|
return tone.getTitle(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return context.getString(R.string.preferences__default);
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NonNull Pair<String, Integer> getVibrateSummary(@NonNull Context context, @NonNull VibrateState vibrateState) {
|
||||||
|
if (vibrateState == VibrateState.DEFAULT) {
|
||||||
|
return new Pair<>(context.getString(R.string.preferences__default), 0);
|
||||||
|
} else if (vibrateState == VibrateState.ENABLED) {
|
||||||
|
return new Pair<>(context.getString(R.string.RecipientPreferenceActivity_enabled), 1);
|
||||||
|
} else {
|
||||||
|
return new Pair<>(context.getString(R.string.RecipientPreferenceActivity_disabled), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModified(final Recipient recipient) {
|
public void onModified(final Recipient recipient) {
|
||||||
Util.runOnMain(() -> setSummaries(recipient));
|
Util.runOnMain(() -> setSummaries(recipient));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener {
|
private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private final boolean calls;
|
||||||
|
|
||||||
|
RingtoneChangeListener(boolean calls) {
|
||||||
|
this.calls = calls;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
Uri value = (Uri)newValue;
|
Uri value = (Uri)newValue;
|
||||||
|
|
||||||
if (TextSecurePreferences.getNotificationRingtone(getContext()).equals(value)) {
|
Uri defaultValue;
|
||||||
value = null;
|
|
||||||
} else if (value == null) {
|
if (calls) defaultValue = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
||||||
value = Uri.EMPTY;
|
else defaultValue = TextSecurePreferences.getNotificationRingtone(getContext());
|
||||||
}
|
|
||||||
|
if (defaultValue.equals(value)) value = null;
|
||||||
|
else if (value == null) value = Uri.EMPTY;
|
||||||
|
|
||||||
new AsyncTask<Uri, Void, Void>() {
|
new AsyncTask<Uri, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Uri... params) {
|
protected Void doInBackground(Uri... params) {
|
||||||
DatabaseFactory.getRecipientDatabase(getActivity())
|
if (calls) DatabaseFactory.getRecipientDatabase(getActivity()).setCallRingtone(recipient, params[0]);
|
||||||
.setRingtone(recipient, params[0]);
|
else DatabaseFactory.getRecipientDatabase(getActivity()).setMessageRingtone(recipient, params[0]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, value);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, value);
|
||||||
@ -393,27 +430,49 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
|
|
||||||
private class RingtoneClickedListener implements Preference.OnPreferenceClickListener {
|
private class RingtoneClickedListener implements Preference.OnPreferenceClickListener {
|
||||||
|
|
||||||
|
private final boolean calls;
|
||||||
|
|
||||||
|
RingtoneClickedListener(boolean calls) {
|
||||||
|
this.calls = calls;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
Uri uri = recipient.getRingtone();
|
Uri current;
|
||||||
|
Uri defaultUri;
|
||||||
|
|
||||||
if (uri == null) uri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
if (calls) {
|
||||||
else if (uri.toString().isEmpty()) uri = null;
|
current = recipient.getCallRingtone();
|
||||||
|
defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
||||||
|
} else {
|
||||||
|
current = recipient.getMessageRingtone();
|
||||||
|
defaultUri = TextSecurePreferences.getNotificationRingtone(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||||
|
else if (current.toString().isEmpty()) current = null;
|
||||||
|
|
||||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
||||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, TextSecurePreferences.getNotificationRingtone(getContext()));
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri);
|
||||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, calls ? RingtoneManager.TYPE_RINGTONE : RingtoneManager.TYPE_NOTIFICATION);
|
||||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
|
||||||
|
|
||||||
startActivityForResult(intent, 1);
|
startActivityForResult(intent, calls ? 2 : 1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class VibrateChangeListener implements Preference.OnPreferenceChangeListener {
|
private class VibrateChangeListener implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private final boolean call;
|
||||||
|
|
||||||
|
VibrateChangeListener(boolean call) {
|
||||||
|
this.call = call;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
int value = Integer.parseInt((String) newValue);
|
int value = Integer.parseInt((String) newValue);
|
||||||
@ -422,8 +481,8 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
|||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
DatabaseFactory.getRecipientDatabase(getActivity())
|
if (call) DatabaseFactory.getRecipientDatabase(getActivity()).setCallVibrate(recipient, vibrateState);
|
||||||
.setVibrate(recipient, vibrateState);
|
else DatabaseFactory.getRecipientDatabase(getActivity()).setMessageVibrate(recipient, vibrateState);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
@ -51,9 +51,11 @@ public class RecipientDatabase extends Database {
|
|||||||
private static final String SIGNAL_PROFILE_NAME = "signal_profile_name";
|
private static final String SIGNAL_PROFILE_NAME = "signal_profile_name";
|
||||||
private static final String SIGNAL_PROFILE_AVATAR = "signal_profile_avatar";
|
private static final String SIGNAL_PROFILE_AVATAR = "signal_profile_avatar";
|
||||||
private static final String PROFILE_SHARING = "profile_sharing_approval";
|
private static final String PROFILE_SHARING = "profile_sharing_approval";
|
||||||
|
private static final String CALL_RINGTONE = "call_ringtone";
|
||||||
|
private static final String CALL_VIBRATE = "call_vibrate";
|
||||||
|
|
||||||
private static final String[] RECIPIENT_PROJECTION = new String[] {
|
private static final String[] RECIPIENT_PROJECTION = new String[] {
|
||||||
BLOCK, NOTIFICATION, VIBRATE, MUTE_UNTIL, COLOR, SEEN_INVITE_REMINDER, DEFAULT_SUBSCRIPTION_ID, EXPIRE_MESSAGES, REGISTERED,
|
BLOCK, NOTIFICATION, CALL_RINGTONE, VIBRATE, CALL_VIBRATE, MUTE_UNTIL, COLOR, SEEN_INVITE_REMINDER, DEFAULT_SUBSCRIPTION_ID, EXPIRE_MESSAGES, REGISTERED,
|
||||||
PROFILE_KEY, SYSTEM_DISPLAY_NAME, SYSTEM_PHOTO_URI, SYSTEM_PHONE_LABEL, SYSTEM_CONTACT_URI,
|
PROFILE_KEY, SYSTEM_DISPLAY_NAME, SYSTEM_PHOTO_URI, SYSTEM_PHONE_LABEL, SYSTEM_CONTACT_URI,
|
||||||
SIGNAL_PROFILE_NAME, SIGNAL_PROFILE_AVATAR, PROFILE_SHARING
|
SIGNAL_PROFILE_NAME, SIGNAL_PROFILE_AVATAR, PROFILE_SHARING
|
||||||
};
|
};
|
||||||
@ -118,7 +120,9 @@ public class RecipientDatabase extends Database {
|
|||||||
PROFILE_KEY + " TEXT DEFAULT NULL, " +
|
PROFILE_KEY + " TEXT DEFAULT NULL, " +
|
||||||
SIGNAL_PROFILE_NAME + " TEXT DEFAULT NULL, " +
|
SIGNAL_PROFILE_NAME + " TEXT DEFAULT NULL, " +
|
||||||
SIGNAL_PROFILE_AVATAR + " TEXT DEFAULT NULL, " +
|
SIGNAL_PROFILE_AVATAR + " TEXT DEFAULT NULL, " +
|
||||||
PROFILE_SHARING + " INTEGER DEFAULT 0);";
|
PROFILE_SHARING + " INTEGER DEFAULT 0, " +
|
||||||
|
CALL_RINGTONE + " TEXT DEFAULT NULL, " +
|
||||||
|
CALL_VIBRATE + " INTEGER DEFAULT " + VibrateState.DEFAULT.getId() + ");";
|
||||||
|
|
||||||
public RecipientDatabase(Context context, SQLCipherOpenHelper databaseHelper) {
|
public RecipientDatabase(Context context, SQLCipherOpenHelper databaseHelper) {
|
||||||
super(context, databaseHelper);
|
super(context, databaseHelper);
|
||||||
@ -155,8 +159,10 @@ public class RecipientDatabase extends Database {
|
|||||||
|
|
||||||
Optional<RecipientSettings> getRecipientSettings(@NonNull Cursor cursor) {
|
Optional<RecipientSettings> getRecipientSettings(@NonNull Cursor cursor) {
|
||||||
boolean blocked = cursor.getInt(cursor.getColumnIndexOrThrow(BLOCK)) == 1;
|
boolean blocked = cursor.getInt(cursor.getColumnIndexOrThrow(BLOCK)) == 1;
|
||||||
String notification = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
|
String messageRingtone = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
|
||||||
int vibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
|
String callRingtone = cursor.getString(cursor.getColumnIndexOrThrow(CALL_RINGTONE));
|
||||||
|
int messageVibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
|
||||||
|
int callVibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(CALL_VIBRATE));
|
||||||
long muteUntil = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
|
long muteUntil = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
|
||||||
String serializedColor = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
|
String serializedColor = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
|
||||||
boolean seenInviteReminder = cursor.getInt(cursor.getColumnIndexOrThrow(SEEN_INVITE_REMINDER)) == 1;
|
boolean seenInviteReminder = cursor.getInt(cursor.getColumnIndexOrThrow(SEEN_INVITE_REMINDER)) == 1;
|
||||||
@ -192,8 +198,10 @@ public class RecipientDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(new RecipientSettings(blocked, muteUntil,
|
return Optional.of(new RecipientSettings(blocked, muteUntil,
|
||||||
VibrateState.fromId(vibrateState),
|
VibrateState.fromId(messageVibrateState),
|
||||||
Util.uri(notification), color, seenInviteReminder,
|
VibrateState.fromId(callVibrateState),
|
||||||
|
Util.uri(messageRingtone), Util.uri(callRingtone),
|
||||||
|
color, seenInviteReminder,
|
||||||
defaultSubscriptionId, expireMessages,
|
defaultSubscriptionId, expireMessages,
|
||||||
RegisteredState.fromId(registeredState),
|
RegisteredState.fromId(registeredState),
|
||||||
profileKey, systemDisplayName, systemContactPhoto,
|
profileKey, systemDisplayName, systemContactPhoto,
|
||||||
@ -237,18 +245,32 @@ public class RecipientDatabase extends Database {
|
|||||||
recipient.resolve().setBlocked(blocked);
|
recipient.resolve().setBlocked(blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRingtone(@NonNull Recipient recipient, @Nullable Uri notification) {
|
public void setMessageRingtone(@NonNull Recipient recipient, @Nullable Uri notification) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(NOTIFICATION, notification == null ? null : notification.toString());
|
values.put(NOTIFICATION, notification == null ? null : notification.toString());
|
||||||
updateOrInsert(recipient.getAddress(), values);
|
updateOrInsert(recipient.getAddress(), values);
|
||||||
recipient.resolve().setRingtone(notification);
|
recipient.resolve().setMessageRingtone(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVibrate(@NonNull Recipient recipient, @NonNull VibrateState enabled) {
|
public void setCallRingtone(@NonNull Recipient recipient, @Nullable Uri ringtone) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(CALL_RINGTONE, ringtone == null ? null : ringtone.toString());
|
||||||
|
updateOrInsert(recipient.getAddress(), values);
|
||||||
|
recipient.resolve().setCallRingtone(ringtone);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageVibrate(@NonNull Recipient recipient, @NonNull VibrateState enabled) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(VIBRATE, enabled.getId());
|
values.put(VIBRATE, enabled.getId());
|
||||||
updateOrInsert(recipient.getAddress(), values);
|
updateOrInsert(recipient.getAddress(), values);
|
||||||
recipient.resolve().setVibrate(enabled);
|
recipient.resolve().setMessageVibrate(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallVibrate(@NonNull Recipient recipient, @NonNull VibrateState enabled) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(CALL_VIBRATE, enabled.getId());
|
||||||
|
updateOrInsert(recipient.getAddress(), values);
|
||||||
|
recipient.resolve().setCallVibrate(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMuted(@NonNull Recipient recipient, long until) {
|
public void setMuted(@NonNull Recipient recipient, long until) {
|
||||||
@ -433,8 +455,10 @@ public class RecipientDatabase extends Database {
|
|||||||
public static class RecipientSettings {
|
public static class RecipientSettings {
|
||||||
private final boolean blocked;
|
private final boolean blocked;
|
||||||
private final long muteUntil;
|
private final long muteUntil;
|
||||||
private final VibrateState vibrateState;
|
private final VibrateState messageVibrateState;
|
||||||
private final Uri notification;
|
private final VibrateState callVibrateState;
|
||||||
|
private final Uri messageRingtone;
|
||||||
|
private final Uri callRingtone;
|
||||||
private final MaterialColor color;
|
private final MaterialColor color;
|
||||||
private final boolean seenInviteReminder;
|
private final boolean seenInviteReminder;
|
||||||
private final int defaultSubscriptionId;
|
private final int defaultSubscriptionId;
|
||||||
@ -450,8 +474,10 @@ public class RecipientDatabase extends Database {
|
|||||||
private final boolean profileSharing;
|
private final boolean profileSharing;
|
||||||
|
|
||||||
RecipientSettings(boolean blocked, long muteUntil,
|
RecipientSettings(boolean blocked, long muteUntil,
|
||||||
@NonNull VibrateState vibrateState,
|
@NonNull VibrateState messageVibrateState,
|
||||||
@Nullable Uri notification,
|
@NonNull VibrateState callVibrateState,
|
||||||
|
@Nullable Uri messageRingtone,
|
||||||
|
@Nullable Uri callRingtone,
|
||||||
@Nullable MaterialColor color,
|
@Nullable MaterialColor color,
|
||||||
boolean seenInviteReminder,
|
boolean seenInviteReminder,
|
||||||
int defaultSubscriptionId,
|
int defaultSubscriptionId,
|
||||||
@ -468,8 +494,10 @@ public class RecipientDatabase extends Database {
|
|||||||
{
|
{
|
||||||
this.blocked = blocked;
|
this.blocked = blocked;
|
||||||
this.muteUntil = muteUntil;
|
this.muteUntil = muteUntil;
|
||||||
this.vibrateState = vibrateState;
|
this.messageVibrateState = messageVibrateState;
|
||||||
this.notification = notification;
|
this.callVibrateState = callVibrateState;
|
||||||
|
this.messageRingtone = messageRingtone;
|
||||||
|
this.callRingtone = callRingtone;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.seenInviteReminder = seenInviteReminder;
|
this.seenInviteReminder = seenInviteReminder;
|
||||||
this.defaultSubscriptionId = defaultSubscriptionId;
|
this.defaultSubscriptionId = defaultSubscriptionId;
|
||||||
@ -497,12 +525,20 @@ public class RecipientDatabase extends Database {
|
|||||||
return muteUntil;
|
return muteUntil;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull VibrateState getVibrateState() {
|
public @NonNull VibrateState getMessageVibrateState() {
|
||||||
return vibrateState;
|
return messageVibrateState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Uri getRingtone() {
|
public @NonNull VibrateState getCallVibrateState() {
|
||||||
return notification;
|
return callVibrateState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Uri getMessageRingtone() {
|
||||||
|
return messageRingtone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Uri getCallRingtone() {
|
||||||
|
return callRingtone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSeenInviteReminder() {
|
public boolean hasSeenInviteReminder() {
|
||||||
|
@ -26,9 +26,12 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|||||||
|
|
||||||
public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private static final String TAG = SQLCipherOpenHelper.class.getSimpleName();
|
private static final String TAG = SQLCipherOpenHelper.class.getSimpleName();
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 1;
|
private static final int RECIPIENT_CALL_RINGTONE_VERSION = 2;
|
||||||
|
|
||||||
|
private static final int DATABASE_VERSION = 2;
|
||||||
private static final String DATABASE_NAME = "signal.db";
|
private static final String DATABASE_NAME = "signal.db";
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@ -89,7 +92,12 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
Log.w(TAG, "Upgrading database: " + oldVersion + ", " + newVersion);
|
||||||
|
|
||||||
|
if (oldVersion < RECIPIENT_CALL_RINGTONE_VERSION) {
|
||||||
|
db.execSQL("ALTER TABLE recipient_preferences ADD COLUMN call_ringtone TEXT DEFAULT NULL");
|
||||||
|
db.execSQL("ALTER TABLE recipient_preferences ADD COLUMN call_vibrate INTEGER DEFAULT " + RecipientDatabase.VibrateState.DEFAULT.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SQLiteDatabase getReadableDatabase() {
|
public SQLiteDatabase getReadableDatabase() {
|
||||||
|
@ -373,7 +373,7 @@ public class MessageNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri uri = recipient != null ? recipient.getRingtone() : null;
|
Uri uri = recipient != null ? recipient.resolve().getMessageRingtone() : null;
|
||||||
|
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
uri = TextSecurePreferences.getNotificationRingtone(context);
|
uri = TextSecurePreferences.getNotificationRingtone(context);
|
||||||
|
@ -48,7 +48,7 @@ public class NotificationState {
|
|||||||
Recipient recipient = notifications.getFirst().getRecipient();
|
Recipient recipient = notifications.getFirst().getRecipient();
|
||||||
|
|
||||||
if (recipient != null) {
|
if (recipient != null) {
|
||||||
return recipient.getRingtone();
|
return recipient.resolve().getMessageRingtone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ public class NotificationState {
|
|||||||
Recipient recipient = notifications.getFirst().getRecipient();
|
Recipient recipient = notifications.getFirst().getRecipient();
|
||||||
|
|
||||||
if (recipient != null) {
|
if (recipient != null) {
|
||||||
return recipient.getVibrate();
|
return recipient.resolve().getMessageVibrate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,11 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
|
import org.thoughtcrime.securesms.preferences.widgets.SignalPreference;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
||||||
@ -42,6 +45,8 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||||||
.setOnPreferenceChangeListener(new NotificationPrivacyListener());
|
.setOnPreferenceChangeListener(new NotificationPrivacyListener());
|
||||||
this.findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF)
|
this.findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF)
|
||||||
.setOnPreferenceChangeListener(new ListSummaryListener());
|
.setOnPreferenceChangeListener(new ListSummaryListener());
|
||||||
|
this.findPreference(TextSecurePreferences.CALL_RINGTONE_PREF)
|
||||||
|
.setOnPreferenceChangeListener(new RingtoneSummaryListener());
|
||||||
|
|
||||||
this.findPreference(TextSecurePreferences.RINGTONE_PREF)
|
this.findPreference(TextSecurePreferences.RINGTONE_PREF)
|
||||||
.setOnPreferenceClickListener(preference -> {
|
.setOnPreferenceClickListener(preference -> {
|
||||||
@ -59,12 +64,31 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.findPreference(TextSecurePreferences.CALL_RINGTONE_PREF)
|
||||||
|
.setOnPreferenceClickListener(preference -> {
|
||||||
|
Uri current = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
||||||
|
|
||||||
|
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||||
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
||||||
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||||
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
|
||||||
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_RINGTONE_URI);
|
||||||
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
|
||||||
|
|
||||||
|
startActivityForResult(intent, 2);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_COLOR_PREF));
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_COLOR_PREF));
|
||||||
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF));
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.LED_BLINK_PREF));
|
||||||
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF));
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.REPEAT_ALERTS_PREF));
|
||||||
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF));
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIVACY_PREF));
|
||||||
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF));
|
initializeListSummary((ListPreference) findPreference(TextSecurePreferences.NOTIFICATION_PRIORITY_PREF));
|
||||||
|
|
||||||
initializeRingtoneSummary(findPreference(TextSecurePreferences.RINGTONE_PREF));
|
initializeRingtoneSummary(findPreference(TextSecurePreferences.RINGTONE_PREF));
|
||||||
|
initializeCallRingtoneSummary(findPreference(TextSecurePreferences.CALL_RINGTONE_PREF));
|
||||||
|
initializeCallVibrateSummary((SwitchPreferenceCompat)findPreference(TextSecurePreferences.CALL_VIBRATE_PREF));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,6 +114,16 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||||||
}
|
}
|
||||||
|
|
||||||
initializeRingtoneSummary(findPreference(TextSecurePreferences.RINGTONE_PREF));
|
initializeRingtoneSummary(findPreference(TextSecurePreferences.RINGTONE_PREF));
|
||||||
|
} else if (requestCode == 2 && resultCode == RESULT_OK && data != null) {
|
||||||
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||||
|
|
||||||
|
if (Settings.System.DEFAULT_RINGTONE_URI.equals(uri)) {
|
||||||
|
TextSecurePreferences.removeCallNotificationRingtone(getContext());
|
||||||
|
} else {
|
||||||
|
TextSecurePreferences.setCallNotificationRingtone(getContext(), uri != null ? uri.toString() : Uri.EMPTY.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeCallRingtoneSummary(findPreference(TextSecurePreferences.CALL_RINGTONE_PREF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +153,17 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||||||
listener.onPreferenceChange(pref, uri);
|
listener.onPreferenceChange(pref, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeCallRingtoneSummary(Preference pref) {
|
||||||
|
RingtoneSummaryListener listener = (RingtoneSummaryListener) pref.getOnPreferenceChangeListener();
|
||||||
|
Uri uri = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
||||||
|
|
||||||
|
listener.onPreferenceChange(pref, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeCallVibrateSummary(SwitchPreferenceCompat pref) {
|
||||||
|
pref.setChecked(TextSecurePreferences.isCallNotificationVibrateEnabled(getContext()));
|
||||||
|
}
|
||||||
|
|
||||||
public static CharSequence getSummary(Context context) {
|
public static CharSequence getSummary(Context context) {
|
||||||
final int onCapsResId = R.string.ApplicationPreferencesActivity_On;
|
final int onCapsResId = R.string.ApplicationPreferencesActivity_On;
|
||||||
final int offCapsResId = R.string.ApplicationPreferencesActivity_Off;
|
final int offCapsResId = R.string.ApplicationPreferencesActivity_Off;
|
||||||
|
@ -74,10 +74,12 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
private @Nullable Uri systemContactPhoto;
|
private @Nullable Uri systemContactPhoto;
|
||||||
private @Nullable Long groupAvatarId;
|
private @Nullable Long groupAvatarId;
|
||||||
private Uri contactUri;
|
private Uri contactUri;
|
||||||
private @Nullable Uri ringtone = null;
|
private @Nullable Uri messageRingtone = null;
|
||||||
|
private @Nullable Uri callRingtone = null;
|
||||||
private long mutedUntil = 0;
|
private long mutedUntil = 0;
|
||||||
private boolean blocked = false;
|
private boolean blocked = false;
|
||||||
private VibrateState vibrate = VibrateState.DEFAULT;
|
private VibrateState messageVibrate = VibrateState.DEFAULT;
|
||||||
|
private VibrateState callVibrate = VibrateState.DEFAULT;
|
||||||
private int expireMessages = 0;
|
private int expireMessages = 0;
|
||||||
private Optional<Integer> defaultSubscriptionId = Optional.absent();
|
private Optional<Integer> defaultSubscriptionId = Optional.absent();
|
||||||
private @NonNull RegisteredState registered = RegisteredState.UNKNOWN;
|
private @NonNull RegisteredState registered = RegisteredState.UNKNOWN;
|
||||||
@ -124,10 +126,12 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
this.groupAvatarId = stale.groupAvatarId;
|
this.groupAvatarId = stale.groupAvatarId;
|
||||||
this.color = stale.color;
|
this.color = stale.color;
|
||||||
this.customLabel = stale.customLabel;
|
this.customLabel = stale.customLabel;
|
||||||
this.ringtone = stale.ringtone;
|
this.messageRingtone = stale.messageRingtone;
|
||||||
|
this.callRingtone = stale.callRingtone;
|
||||||
this.mutedUntil = stale.mutedUntil;
|
this.mutedUntil = stale.mutedUntil;
|
||||||
this.blocked = stale.blocked;
|
this.blocked = stale.blocked;
|
||||||
this.vibrate = stale.vibrate;
|
this.messageVibrate = stale.messageVibrate;
|
||||||
|
this.callVibrate = stale.callVibrate;
|
||||||
this.expireMessages = stale.expireMessages;
|
this.expireMessages = stale.expireMessages;
|
||||||
this.seenInviteReminder = stale.seenInviteReminder;
|
this.seenInviteReminder = stale.seenInviteReminder;
|
||||||
this.defaultSubscriptionId = stale.defaultSubscriptionId;
|
this.defaultSubscriptionId = stale.defaultSubscriptionId;
|
||||||
@ -146,10 +150,12 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
this.systemContactPhoto = details.get().systemContactPhoto;
|
this.systemContactPhoto = details.get().systemContactPhoto;
|
||||||
this.groupAvatarId = details.get().groupAvatarId;
|
this.groupAvatarId = details.get().groupAvatarId;
|
||||||
this.color = details.get().color;
|
this.color = details.get().color;
|
||||||
this.ringtone = details.get().ringtone;
|
this.messageRingtone = details.get().messageRingtone;
|
||||||
|
this.callRingtone = details.get().callRingtone;
|
||||||
this.mutedUntil = details.get().mutedUntil;
|
this.mutedUntil = details.get().mutedUntil;
|
||||||
this.blocked = details.get().blocked;
|
this.blocked = details.get().blocked;
|
||||||
this.vibrate = details.get().vibrateState;
|
this.messageVibrate = details.get().messageVibrateState;
|
||||||
|
this.callVibrate = details.get().callVibrateState;
|
||||||
this.expireMessages = details.get().expireMessages;
|
this.expireMessages = details.get().expireMessages;
|
||||||
this.seenInviteReminder = details.get().seenInviteReminder;
|
this.seenInviteReminder = details.get().seenInviteReminder;
|
||||||
this.defaultSubscriptionId = details.get().defaultSubscriptionId;
|
this.defaultSubscriptionId = details.get().defaultSubscriptionId;
|
||||||
@ -174,10 +180,12 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
Recipient.this.groupAvatarId = result.groupAvatarId;
|
Recipient.this.groupAvatarId = result.groupAvatarId;
|
||||||
Recipient.this.color = result.color;
|
Recipient.this.color = result.color;
|
||||||
Recipient.this.customLabel = result.customLabel;
|
Recipient.this.customLabel = result.customLabel;
|
||||||
Recipient.this.ringtone = result.ringtone;
|
Recipient.this.messageRingtone = result.messageRingtone;
|
||||||
|
Recipient.this.callRingtone = result.callRingtone;
|
||||||
Recipient.this.mutedUntil = result.mutedUntil;
|
Recipient.this.mutedUntil = result.mutedUntil;
|
||||||
Recipient.this.blocked = result.blocked;
|
Recipient.this.blocked = result.blocked;
|
||||||
Recipient.this.vibrate = result.vibrateState;
|
Recipient.this.messageVibrate = result.messageVibrateState;
|
||||||
|
Recipient.this.callVibrate = result.callVibrateState;
|
||||||
Recipient.this.expireMessages = result.expireMessages;
|
Recipient.this.expireMessages = result.expireMessages;
|
||||||
Recipient.this.seenInviteReminder = result.seenInviteReminder;
|
Recipient.this.seenInviteReminder = result.seenInviteReminder;
|
||||||
Recipient.this.defaultSubscriptionId = result.defaultSubscriptionId;
|
Recipient.this.defaultSubscriptionId = result.defaultSubscriptionId;
|
||||||
@ -219,10 +227,12 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
this.groupAvatarId = details.groupAvatarId;
|
this.groupAvatarId = details.groupAvatarId;
|
||||||
this.color = details.color;
|
this.color = details.color;
|
||||||
this.customLabel = details.customLabel;
|
this.customLabel = details.customLabel;
|
||||||
this.ringtone = details.ringtone;
|
this.messageRingtone = details.messageRingtone;
|
||||||
|
this.callRingtone = details.callRingtone;
|
||||||
this.mutedUntil = details.mutedUntil;
|
this.mutedUntil = details.mutedUntil;
|
||||||
this.blocked = details.blocked;
|
this.blocked = details.blocked;
|
||||||
this.vibrate = details.vibrateState;
|
this.messageVibrate = details.messageVibrateState;
|
||||||
|
this.callVibrate = details.callVibrateState;
|
||||||
this.expireMessages = details.expireMessages;
|
this.expireMessages = details.expireMessages;
|
||||||
this.seenInviteReminder = details.seenInviteReminder;
|
this.seenInviteReminder = details.seenInviteReminder;
|
||||||
this.defaultSubscriptionId = details.defaultSubscriptionId;
|
this.defaultSubscriptionId = details.defaultSubscriptionId;
|
||||||
@ -452,17 +462,33 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
if (notify) notifyListeners();
|
if (notify) notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized @Nullable Uri getRingtone() {
|
public synchronized @Nullable Uri getMessageRingtone() {
|
||||||
if (ringtone != null && ringtone.getScheme() != null && ringtone.getScheme().startsWith("file")) {
|
if (messageRingtone != null && messageRingtone.getScheme() != null && messageRingtone.getScheme().startsWith("file")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ringtone;
|
return messageRingtone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRingtone(@Nullable Uri ringtone) {
|
public void setMessageRingtone(@Nullable Uri ringtone) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.ringtone = ringtone;
|
this.messageRingtone = ringtone;
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized @Nullable Uri getCallRingtone() {
|
||||||
|
if (callRingtone != null && callRingtone.getScheme() != null && callRingtone.getScheme().startsWith("file")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return callRingtone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallRingtone(@Nullable Uri ringtone) {
|
||||||
|
synchronized (this) {
|
||||||
|
this.callRingtone = ringtone;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -492,13 +518,25 @@ public class Recipient implements RecipientModifiedListener {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized VibrateState getVibrate() {
|
public synchronized VibrateState getMessageVibrate() {
|
||||||
return vibrate;
|
return messageVibrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVibrate(VibrateState vibrate) {
|
public void setMessageVibrate(VibrateState vibrate) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.vibrate = vibrate;
|
this.messageVibrate = vibrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized VibrateState getCallVibrate() {
|
||||||
|
return callVibrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallVibrate(VibrateState vibrate) {
|
||||||
|
synchronized (this) {
|
||||||
|
this.callVibrate = vibrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -158,9 +158,11 @@ class RecipientProvider {
|
|||||||
@Nullable final Uri contactUri;
|
@Nullable final Uri contactUri;
|
||||||
@Nullable final Long groupAvatarId;
|
@Nullable final Long groupAvatarId;
|
||||||
@Nullable final MaterialColor color;
|
@Nullable final MaterialColor color;
|
||||||
@Nullable final Uri ringtone;
|
@Nullable final Uri messageRingtone;
|
||||||
|
@Nullable final Uri callRingtone;
|
||||||
final long mutedUntil;
|
final long mutedUntil;
|
||||||
@Nullable final VibrateState vibrateState;
|
@Nullable final VibrateState messageVibrateState;
|
||||||
|
@Nullable final VibrateState callVibrateState;
|
||||||
final boolean blocked;
|
final boolean blocked;
|
||||||
final int expireMessages;
|
final int expireMessages;
|
||||||
@NonNull final List<Recipient> participants;
|
@NonNull final List<Recipient> participants;
|
||||||
@ -182,9 +184,11 @@ class RecipientProvider {
|
|||||||
this.customLabel = settings != null ? settings.getSystemPhoneLabel() : null;
|
this.customLabel = settings != null ? settings.getSystemPhoneLabel() : null;
|
||||||
this.contactUri = settings != null ? Util.uri(settings.getSystemContactUri()) : null;
|
this.contactUri = settings != null ? Util.uri(settings.getSystemContactUri()) : null;
|
||||||
this.color = settings != null ? settings.getColor() : null;
|
this.color = settings != null ? settings.getColor() : null;
|
||||||
this.ringtone = settings != null ? settings.getRingtone() : null;
|
this.messageRingtone = settings != null ? settings.getMessageRingtone() : null;
|
||||||
|
this.callRingtone = settings != null ? settings.getCallRingtone() : null;
|
||||||
this.mutedUntil = settings != null ? settings.getMuteUntil() : 0;
|
this.mutedUntil = settings != null ? settings.getMuteUntil() : 0;
|
||||||
this.vibrateState = settings != null ? settings.getVibrateState() : null;
|
this.messageVibrateState = settings != null ? settings.getMessageVibrateState() : null;
|
||||||
|
this.callVibrateState = settings != null ? settings.getCallVibrateState() : null;
|
||||||
this.blocked = settings != null && settings.isBlocked();
|
this.blocked = settings != null && settings.isBlocked();
|
||||||
this.expireMessages = settings != null ? settings.getExpireMessages() : 0;
|
this.expireMessages = settings != null ? settings.getExpireMessages() : 0;
|
||||||
this.participants = participants == null ? new LinkedList<>() : participants;
|
this.participants = participants == null ? new LinkedList<>() : participants;
|
||||||
|
@ -8,6 +8,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -29,6 +30,8 @@ import org.thoughtcrime.securesms.WebRtcCallActivity;
|
|||||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
||||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||||
import org.thoughtcrime.securesms.events.WebRtcViewModel;
|
import org.thoughtcrime.securesms.events.WebRtcViewModel;
|
||||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
@ -540,7 +543,15 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
|
|||||||
sendMessage(WebRtcViewModel.State.CALL_INCOMING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
sendMessage(WebRtcViewModel.State.CALL_INCOMING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
startCallCardActivity();
|
startCallCardActivity();
|
||||||
audioManager.initializeAudioForCall();
|
audioManager.initializeAudioForCall();
|
||||||
audioManager.startIncomingRinger();
|
|
||||||
|
if (TextSecurePreferences.isCallNotificationsEnabled(this)) {
|
||||||
|
Uri ringtone = recipient.resolve().getCallRingtone();
|
||||||
|
VibrateState vibrateState = recipient.resolve().getCallVibrate();
|
||||||
|
|
||||||
|
if (ringtone == null) ringtone = TextSecurePreferences.getCallNotificationRingtone(this);
|
||||||
|
|
||||||
|
audioManager.startIncomingRinger(ringtone, vibrateState == VibrateState.ENABLED || (vibrateState == VibrateState.DEFAULT && TextSecurePreferences.isCallNotificationVibrateEnabled(this)));
|
||||||
|
}
|
||||||
|
|
||||||
registerPowerButtonReceiver();
|
registerPowerButtonReceiver();
|
||||||
|
|
||||||
|
@ -127,6 +127,10 @@ public class TextSecurePreferences {
|
|||||||
private static final String ATTACHMENT_UNENCRYPTED_SECRET = "pref_attachment_unencrypted_secret";
|
private static final String ATTACHMENT_UNENCRYPTED_SECRET = "pref_attachment_unencrypted_secret";
|
||||||
private static final String NEEDS_SQLCIPHER_MIGRATION = "pref_needs_sql_cipher_migration";
|
private static final String NEEDS_SQLCIPHER_MIGRATION = "pref_needs_sql_cipher_migration";
|
||||||
|
|
||||||
|
public static final String CALL_NOTIFICATIONS_PREF = "pref_call_notifications";
|
||||||
|
public static final String CALL_RINGTONE_PREF = "pref_call_ringtone";
|
||||||
|
public static final String CALL_VIBRATE_PREF = "pref_call_vibrate";
|
||||||
|
|
||||||
public static void setNeedsSqlCipherMigration(@NonNull Context context, boolean value) {
|
public static void setNeedsSqlCipherMigration(@NonNull Context context, boolean value) {
|
||||||
setBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, value);
|
setBooleanPreference(context, NEEDS_SQLCIPHER_MIGRATION, value);
|
||||||
EventBus.getDefault().post(new SqlCipherMigrationRequirementProvider.SqlCipherNeedsMigrationEvent());
|
EventBus.getDefault().post(new SqlCipherMigrationRequirementProvider.SqlCipherNeedsMigrationEvent());
|
||||||
@ -684,6 +688,10 @@ public class TextSecurePreferences {
|
|||||||
return getBooleanPreference(context, NOTIFICATION_PREF, true);
|
return getBooleanPreference(context, NOTIFICATION_PREF, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCallNotificationsEnabled(Context context) {
|
||||||
|
return getBooleanPreference(context, CALL_NOTIFICATIONS_PREF, true);
|
||||||
|
}
|
||||||
|
|
||||||
public static @NonNull Uri getNotificationRingtone(Context context) {
|
public static @NonNull Uri getNotificationRingtone(Context context) {
|
||||||
String result = getStringPreference(context, RINGTONE_PREF, Settings.System.DEFAULT_NOTIFICATION_URI.toString());
|
String result = getStringPreference(context, RINGTONE_PREF, Settings.System.DEFAULT_NOTIFICATION_URI.toString());
|
||||||
|
|
||||||
@ -694,18 +702,46 @@ public class TextSecurePreferences {
|
|||||||
return Uri.parse(result);
|
return Uri.parse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NonNull Uri getCallNotificationRingtone(Context context) {
|
||||||
|
String result = getStringPreference(context, CALL_RINGTONE_PREF, Settings.System.DEFAULT_RINGTONE_URI.toString());
|
||||||
|
|
||||||
|
if (result != null && result.startsWith("file:")) {
|
||||||
|
result = Settings.System.DEFAULT_RINGTONE_URI.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Uri.parse(result);
|
||||||
|
}
|
||||||
|
|
||||||
public static void removeNotificationRingtone(Context context) {
|
public static void removeNotificationRingtone(Context context) {
|
||||||
removePreference(context, RINGTONE_PREF);
|
removePreference(context, RINGTONE_PREF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeCallNotificationRingtone(Context context) {
|
||||||
|
removePreference(context, CALL_RINGTONE_PREF);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setNotificationRingtone(Context context, String ringtone) {
|
public static void setNotificationRingtone(Context context, String ringtone) {
|
||||||
setStringPreference(context, RINGTONE_PREF, ringtone);
|
setStringPreference(context, RINGTONE_PREF, ringtone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setCallNotificationRingtone(Context context, String ringtone) {
|
||||||
|
setStringPreference(context, CALL_RINGTONE_PREF, ringtone);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isNotificationVibrateEnabled(Context context) {
|
public static boolean isNotificationVibrateEnabled(Context context) {
|
||||||
return getBooleanPreference(context, VIBRATE_PREF, true);
|
return getBooleanPreference(context, VIBRATE_PREF, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCallNotificationVibrateEnabled(Context context) {
|
||||||
|
boolean defaultValue = true;
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
defaultValue = (Settings.System.getInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 1) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getBooleanPreference(context, CALL_VIBRATE_PREF, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getNotificationLedColor(Context context) {
|
public static String getNotificationLedColor(Context context) {
|
||||||
return getStringPreference(context, LED_COLOR_PREF, "blue");
|
return getStringPreference(context, LED_COLOR_PREF, "blue");
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ import android.annotation.TargetApi;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.RingtoneManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
@ -27,20 +27,20 @@ public class IncomingRinger {
|
|||||||
|
|
||||||
private MediaPlayer player;
|
private MediaPlayer player;
|
||||||
|
|
||||||
public IncomingRinger(Context context) {
|
IncomingRinger(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start(@Nullable Uri uri, boolean vibrate) {
|
||||||
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
|
|
||||||
if (player != null) player.release();
|
if (player != null) player.release();
|
||||||
player = createPlayer();
|
if (uri != null) player = createPlayer(uri);
|
||||||
|
|
||||||
int ringerMode = audioManager.getRingerMode();
|
int ringerMode = audioManager.getRingerMode();
|
||||||
|
|
||||||
if (shouldVibrate(context, player, ringerMode)) {
|
if (shouldVibrate(context, player, ringerMode, vibrate)) {
|
||||||
Log.i(TAG, "Starting vibration");
|
Log.i(TAG, "Starting vibration");
|
||||||
vibrator.vibrate(VIBRATE_PATTERN, 1);
|
vibrator.vibrate(VIBRATE_PATTERN, 1);
|
||||||
}
|
}
|
||||||
@ -74,44 +74,41 @@ public class IncomingRinger {
|
|||||||
vibrator.cancel();
|
vibrator.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldVibrate(Context context, MediaPlayer player, int ringerMode) {
|
private boolean shouldVibrate(Context context, MediaPlayer player, int ringerMode, boolean vibrate) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
return shouldVibrateNew(context, ringerMode);
|
return shouldVibrateNew(context, ringerMode, vibrate);
|
||||||
} else {
|
} else {
|
||||||
return shouldVibrateOld(context);
|
return shouldVibrateOld(context, vibrate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
private boolean shouldVibrateNew(Context context, int ringerMode) {
|
private boolean shouldVibrateNew(Context context, int ringerMode, boolean vibrate) {
|
||||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
if (vibrator == null || !vibrator.hasVibrator()) {
|
if (vibrator == null || !vibrator.hasVibrator()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;
|
if (vibrate) {
|
||||||
|
|
||||||
if (vibrateWhenRinging) {
|
|
||||||
return ringerMode != AudioManager.RINGER_MODE_SILENT;
|
return ringerMode != AudioManager.RINGER_MODE_SILENT;
|
||||||
} else {
|
} else {
|
||||||
return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
|
return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldVibrateOld(Context context) {
|
private boolean shouldVibrateOld(Context context, boolean vibrate) {
|
||||||
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
return audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER);
|
return vibrate && audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MediaPlayer createPlayer() {
|
private MediaPlayer createPlayer(@NonNull Uri ringtoneUri) {
|
||||||
try {
|
try {
|
||||||
MediaPlayer mediaPlayer = new MediaPlayer();
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
||||||
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
|
|
||||||
|
|
||||||
mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
|
mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
|
||||||
mediaPlayer.setDataSource(context, ringtoneUri);
|
mediaPlayer.setDataSource(context, ringtoneUri);
|
||||||
|
@ -4,8 +4,10 @@ package org.thoughtcrime.securesms.webrtc.audio;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.SoundPool;
|
import android.media.SoundPool;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
@ -43,7 +45,7 @@ public class SignalAudioManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startIncomingRinger() {
|
public void startIncomingRinger(@Nullable Uri ringtoneUri, boolean vibrate) {
|
||||||
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
AudioManager audioManager = ServiceUtil.getAudioManager(context);
|
||||||
boolean speaker = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();
|
boolean speaker = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();
|
||||||
|
|
||||||
@ -51,7 +53,7 @@ public class SignalAudioManager {
|
|||||||
audioManager.setMicrophoneMute(false);
|
audioManager.setMicrophoneMute(false);
|
||||||
audioManager.setSpeakerphoneOn(speaker);
|
audioManager.setSpeakerphoneOn(speaker);
|
||||||
|
|
||||||
incomingRinger.start();
|
incomingRinger.start(ringtoneUri, vibrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startOutgoingRinger(OutgoingRinger.Type type) {
|
public void startOutgoingRinger(OutgoingRinger.Type type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user