Search in sources :

Example 11 with Ringtone

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

the class DockObserver method handleDockStateChange.

private void handleDockStateChange() {
    synchronized (mLock) {
        Slog.i(TAG, "Dock state changed from " + mPreviousDockState + " to " + mReportedDockState);
        final int previousDockState = mPreviousDockState;
        mPreviousDockState = mReportedDockState;
        // Skip the dock intent if not yet provisioned.
        final ContentResolver cr = getContext().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, mReportedDockState);
        boolean dockSoundsEnabled = Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED, 1) == 1;
        boolean dockSoundsEnabledWhenAccessibility = Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, 1) == 1;
        boolean accessibilityEnabled = Settings.Secure.getInt(cr, Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
        // Particularly useful for flaky contact pins...
        if ((dockSoundsEnabled) || (accessibilityEnabled && dockSoundsEnabledWhenAccessibility)) {
            String whichSound = null;
            if (mReportedDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
                if ((previousDockState == Intent.EXTRA_DOCK_STATE_DESK) || (previousDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (previousDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                    whichSound = Settings.Global.DESK_UNDOCK_SOUND;
                } else if (previousDockState == Intent.EXTRA_DOCK_STATE_CAR) {
                    whichSound = Settings.Global.CAR_UNDOCK_SOUND;
                }
            } else {
                if ((mReportedDockState == Intent.EXTRA_DOCK_STATE_DESK) || (mReportedDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (mReportedDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                    whichSound = Settings.Global.DESK_DOCK_SOUND;
                } else if (mReportedDockState == 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(getContext(), 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.
        getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    }
}
Also used : Ringtone(android.media.Ringtone) Intent(android.content.Intent) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 12 with Ringtone

use of android.media.Ringtone in project platform_frameworks_base by android.

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 13 with Ringtone

use of android.media.Ringtone in project platform_frameworks_base by android.

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 14 with Ringtone

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

the class DockObserver method handleDockStateChange.

private void handleDockStateChange() {
    synchronized (mLock) {
        Slog.i(TAG, "Dock state changed from " + mPreviousDockState + " to " + mReportedDockState);
        final int previousDockState = mPreviousDockState;
        mPreviousDockState = mReportedDockState;
        // Skip the dock intent if not yet provisioned.
        final ContentResolver cr = getContext().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, mReportedDockState);
        boolean dockSoundsEnabled = Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED, 1) == 1;
        boolean dockSoundsEnabledWhenAccessibility = Settings.Global.getInt(cr, Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY, 1) == 1;
        boolean accessibilityEnabled = Settings.Secure.getInt(cr, Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
        // Particularly useful for flaky contact pins...
        if ((dockSoundsEnabled) || (accessibilityEnabled && dockSoundsEnabledWhenAccessibility)) {
            String whichSound = null;
            if (mReportedDockState == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
                if ((previousDockState == Intent.EXTRA_DOCK_STATE_DESK) || (previousDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (previousDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                    whichSound = Settings.Global.DESK_UNDOCK_SOUND;
                } else if (previousDockState == Intent.EXTRA_DOCK_STATE_CAR) {
                    whichSound = Settings.Global.CAR_UNDOCK_SOUND;
                }
            } else {
                if ((mReportedDockState == Intent.EXTRA_DOCK_STATE_DESK) || (mReportedDockState == Intent.EXTRA_DOCK_STATE_LE_DESK) || (mReportedDockState == Intent.EXTRA_DOCK_STATE_HE_DESK)) {
                    whichSound = Settings.Global.DESK_DOCK_SOUND;
                } else if (mReportedDockState == 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(getContext(), 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.
        getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    }
}
Also used : Ringtone(android.media.Ringtone) Intent(android.content.Intent) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 15 with Ringtone

use of android.media.Ringtone in project chefly_android by chef-ly.

the class AlarmReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String name = intent.getStringExtra("name");
    Toast.makeText(context, "Alarm!!! " + name, Toast.LENGTH_LONG).show();
    timer.onTimerFinished(name);
    //TODO check if ringtone is null
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    final Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();
    Log.d(TAG, "Alarm Alarm Alarm");
    Handler h = new Handler();
    h.postDelayed(new Runnable() {

        @Override
        public void run() {
            r.stop();
        }
    }, 5000);
}
Also used : Ringtone(android.media.Ringtone) Handler(android.os.Handler) Uri(android.net.Uri)

Aggregations

Ringtone (android.media.Ringtone)27 Uri (android.net.Uri)18 ContentResolver (android.content.ContentResolver)8 Intent (android.content.Intent)6 AudioManager (android.media.AudioManager)4 Handler (android.os.Handler)1 Vibrator (android.os.Vibrator)1 CallNotificationBuilder (org.thoughtcrime.securesms.webrtc.CallNotificationBuilder)1