Search in sources :

Example 1 with Ringtone

use of android.media.Ringtone in project Signal-Android by WhisperSystems.

the class MessageNotifier method sendInThreadNotification.

private static void sendInThreadNotification(Context context, Recipients recipients) {
    if (!TextSecurePreferences.isInThreadNotifications(context) || ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        return;
    }
    Uri uri = recipients != null ? recipients.getRingtone() : null;
    if (uri == null) {
        String ringtone = TextSecurePreferences.getNotificationRingtone(context);
        if (ringtone == null) {
            Log.w(TAG, "ringtone preference was null.");
            return;
        }
        uri = Uri.parse(ringtone);
        if (uri == null) {
            Log.w(TAG, "couldn't parse ringtone uri " + ringtone);
            return;
        }
    }
    if (uri.toString().isEmpty()) {
        Log.d(TAG, "ringtone uri is empty");
        return;
    }
    Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
    if (ringtone == null) {
        Log.w(TAG, "ringtone is null");
        return;
    }
    if (Build.VERSION.SDK_INT >= 21) {
        ringtone.setAudioAttributes(new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN).setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    } else {
        ringtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
    }
    ringtone.play();
}
Also used : Ringtone(android.media.Ringtone) CallNotificationBuilder(org.thoughtcrime.securesms.webrtc.CallNotificationBuilder) Uri(android.net.Uri)

Example 2 with Ringtone

use of android.media.Ringtone in project android_frameworks_base by ParanoidAndroid.

the class DockObserver method handleDockStateChange.

private void handleDockStateChange() {
    synchronized (mLock) {
        Slog.i(TAG, "Dock state changed: " + mDockState);
        // Skip the dock intent if not yet provisioned.
        final ContentResolver cr = mContext.getContentResolver();
        if (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) == 0) {
            Slog.i(TAG, "Device not provisioned, skipping dock broadcast");
            return;
        }
        // Pack up the values and broadcast them to everyone
        Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
        intent.putExtra(Intent.EXTRA_DOCK_STATE, mDockState);
        // Particularly useful for flaky contact pins...
        if (Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED, 1) == 1) {
            String whichSound = null;
            if (mDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
                if ((mPreviousDockState == Intent.EXTRA_DOCK_STATE_DESK) || (mPreviousDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (mPreviousDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                    whichSound = Settings.Global.DESK_UNDOCK_SOUND;
                } else if (mPreviousDockState == Intent.EXTRA_DOCK_STATE_CAR) {
                    whichSound = Settings.Global.CAR_UNDOCK_SOUND;
                }
            } else {
                if ((mDockState == Intent.EXTRA_DOCK_STATE_DESK) || (mDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (mDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                    whichSound = Settings.Global.DESK_DOCK_SOUND;
                } else if (mDockState == Intent.EXTRA_DOCK_STATE_CAR) {
                    whichSound = Settings.Global.CAR_DOCK_SOUND;
                }
            }
            if (whichSound != null) {
                final String soundPath = Settings.Global.getString(cr, whichSound);
                if (soundPath != null) {
                    final Uri soundUri = Uri.parse("file://" + soundPath);
                    if (soundUri != null) {
                        final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
                        if (sfx != null) {
                            sfx.setStreamType(AudioManager.STREAM_SYSTEM);
                            sfx.play();
                        }
                    }
                }
            }
        }
        // Send the dock event intent.
        // There are many components in the system watching for this so as to
        // adjust audio routing, screen orientation, etc.
        mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
        // Release the wake lock that was acquired when the message was posted.
        mWakeLock.release();
    }
}
Also used : Ringtone(android.media.Ringtone) Intent(android.content.Intent) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 3 with Ringtone

use of android.media.Ringtone in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method performAuditoryFeedbackForAccessibilityIfNeed.

private void performAuditoryFeedbackForAccessibilityIfNeed() {
    if (!isGlobalAccessibilityGestureEnabled()) {
        return;
    }
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.isSilentMode()) {
        return;
    }
    Ringtone ringTone = RingtoneManager.getRingtone(mContext, Settings.System.DEFAULT_NOTIFICATION_URI);
    ringTone.setStreamType(AudioManager.STREAM_MUSIC);
    ringTone.play();
}
Also used : AudioManager(android.media.AudioManager) Ringtone(android.media.Ringtone)

Example 4 with Ringtone

use of android.media.Ringtone in project android_frameworks_base by ResurrectionRemix.

the class Notifier method playWirelessChargingStartedSound.

private void playWirelessChargingStartedSound() {
    final boolean enabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.CHARGING_SOUNDS_ENABLED, 1) != 0;
    final String soundPath = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.WIRELESS_CHARGING_STARTED_SOUND);
    if (enabled && soundPath != null) {
        final Uri soundUri = Uri.parse("file://" + soundPath);
        if (soundUri != null) {
            final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
            if (sfx != null) {
                sfx.setStreamType(AudioManager.STREAM_SYSTEM);
                sfx.play();
            }
        }
    }
    mSuspendBlocker.release();
}
Also used : Ringtone(android.media.Ringtone) Uri(android.net.Uri)

Example 5 with Ringtone

use of android.media.Ringtone in project android_frameworks_base by DirtyUnicorns.

the class PowerUI method playPowerNotificationSound.

void playPowerNotificationSound() {
    final ContentResolver cr = mContext.getContentResolver();
    final boolean customSound = Settings.Global.getInt(cr, Settings.Global.POWER_NOTIFICATION_CUSTOM_RINGTONE, 0) != 0;
    final String soundPath = customSound ? Settings.Global.getString(cr, Settings.Global.POWER_NOTIFICATIONS_RINGTONE) : Settings.Global.getString(cr, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND);
    if (soundPath != null && !soundPath.equals(POWER_NOTIFICATIONS_SILENT_URI)) {
        Ringtone powerRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(soundPath));
        if (powerRingtone != null) {
            powerRingtone.play();
        }
    }
    if (Settings.Global.getInt(cr, Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) == 1) {
        Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
        if (vibrator != null) {
            vibrator.vibrate(250);
        }
    }
}
Also used : Ringtone(android.media.Ringtone) Vibrator(android.os.Vibrator) ContentResolver(android.content.ContentResolver)

Aggregations

Ringtone (android.media.Ringtone)50 Uri (android.net.Uri)35 ContentResolver (android.content.ContentResolver)8 Intent (android.content.Intent)6 AudioManager (android.media.AudioManager)4 SuppressLint (android.annotation.SuppressLint)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 RingtoneManager (android.media.RingtoneManager)2 Handler (android.os.Handler)2 RingtonePreference (android.preference.RingtonePreference)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 CallNotificationBuilder (org.thoughtcrime.securesms.webrtc.CallNotificationBuilder)2 Activity (android.app.Activity)1 SharedPreferences (android.content.SharedPreferences)1 SQLiteException (android.database.sqlite.SQLiteException)1