use of android.media.AudioAttributes in project android_packages_apps_Dialer by MoKee.
the class StatusBarNotifier method buildAndSendNotification.
/**
* Sets up the main Ui for the notification
*/
private void buildAndSendNotification(Call originalCall, ContactCacheEntry contactInfo) {
// This can get called to update an existing notification after contact information has come
// back. However, it can happen much later. Before we continue, we need to make sure that
// the call being passed in is still the one we want to show in the notification.
final Call call = getCallToShow(CallList.getInstance());
if (call == null || !call.getId().equals(originalCall.getId())) {
return;
}
final int callState = call.getState();
// Check if data has changed; if nothing is different, don't issue another notification.
final int iconResId;
Bitmap largeIcon = getLargeIconToDisplay(contactInfo, call);
String content = getContentString(call, contactInfo.userType);
int wifiQualityValue = call.getWifiQuality();
if (wifiQualityValue != QtiCallConstants.VOWIFI_QUALITY_NONE) {
iconResId = getVoWiFiQualityIcon(wifiQualityValue);
content += " " + getVoWiFiQualityText(wifiQualityValue);
} else {
iconResId = getIconToDisplay(call);
}
final String contentTitle = getContentTitle(contactInfo, call);
final boolean isVideoUpgradeRequest = call.getSessionModificationState() == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST;
final Call pendingAccountSelectionCall = CallList.getInstance().getWaitingForAccountCall();
final int notificationType;
if ((callState == Call.State.INCOMING || callState == Call.State.CALL_WAITING || isVideoUpgradeRequest) && (!InCallPresenter.getInstance().isShowingInCallUi() || pendingAccountSelectionCall != null)) {
notificationType = NOTIFICATION_INCOMING_CALL;
} else {
notificationType = NOTIFICATION_IN_CALL;
}
if (!checkForChangeAndSaveData(iconResId, content, largeIcon, contentTitle, callState, call.getVideoState(), notificationType, contactInfo.contactRingtoneUri)) {
return;
}
if (largeIcon != null) {
largeIcon = getRoundedIcon(largeIcon);
}
// set the content
boolean isMultiSimDevice = mTelephonyManager.isMultiSimEnabled();
if (isMultiSimDevice) {
SubscriptionInfo info = SubscriptionManager.from(mContext).getActiveSubscriptionInfo(call.getSubId());
if (info != null) {
content += " (" + info.getDisplayName() + ")";
}
}
/*
* This builder is used for the notification shown when the device is locked and the user
* has set their notification settings to 'hide sensitive content'
* {@see Notification.Builder#setPublicVersion}.
*/
Notification.Builder publicBuilder = new Notification.Builder(mContext);
publicBuilder.setSmallIcon(iconResId).setColor(mContext.getResources().getColor(R.color.dialer_theme_color)).setContentTitle(getContentString(call, ContactsUtils.USER_TYPE_CURRENT));
setNotificationWhen(call, callState, publicBuilder);
/*
* Builder for the notification shown when the device is unlocked or the user has set their
* notification settings to 'show all notification content'.
*/
final Notification.Builder builder = getNotificationBuilder();
builder.setPublicVersion(publicBuilder.build());
// Set up the main intent to send the user to the in-call screen
final PendingIntent inCallPendingIntent = createLaunchPendingIntent();
builder.setContentIntent(inCallPendingIntent);
// Set the intent as a full screen intent as well if a call is incoming
if (notificationType == NOTIFICATION_INCOMING_CALL && (!InCallPresenter.getInstance().isShowingInCallUi() || (pendingAccountSelectionCall != null))) {
configureFullScreenIntent(builder, inCallPendingIntent, call);
// Set the notification category for incoming calls
builder.setCategory(Notification.CATEGORY_CALL);
}
// Set the content
builder.setContentText(content);
builder.setSmallIcon(iconResId);
builder.setContentTitle(contentTitle);
builder.setLargeIcon(largeIcon);
builder.setColor(mContext.getResources().getColor(R.color.dialer_theme_color));
if (isVideoUpgradeRequest) {
builder.setUsesChronometer(false);
addDismissUpgradeRequestAction(builder);
addAcceptUpgradeRequestAction(builder);
} else {
createIncomingCallNotification(call, callState, builder);
}
addPersonReference(builder, contactInfo, call);
/*
* Fire off the notification
*/
Notification notification = builder.build();
if (mDialerRingtoneManager.shouldPlayRingtone(callState, contactInfo.contactRingtoneUri)) {
notification.flags |= Notification.FLAG_INSISTENT;
notification.sound = contactInfo.contactRingtoneUri;
AudioAttributes.Builder audioAttributes = new AudioAttributes.Builder();
audioAttributes.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
audioAttributes.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE);
notification.audioAttributes = audioAttributes.build();
if (mDialerRingtoneManager.shouldVibrate(mContext.getContentResolver())) {
notification.vibrate = VIBRATE_PATTERN;
}
}
if (mDialerRingtoneManager.shouldPlayCallWaitingTone(callState)) {
Log.v(this, "Playing call waiting tone");
mDialerRingtoneManager.playCallWaitingTone();
}
if (mCurrentNotification != notificationType && mCurrentNotification != NOTIFICATION_NONE) {
Log.i(this, "Previous notification already showing - cancelling " + mCurrentNotification);
mNotificationManager.cancel(mCurrentNotification);
}
Log.i(this, "Displaying notification for " + notificationType);
mNotificationManager.notify(notificationType, notification);
mCurrentNotification = notificationType;
}
use of android.media.AudioAttributes in project OpenCamera by ageback.
the class MainActivity method initSound.
@SuppressWarnings("deprecation")
private void initSound() {
if (sound_pool == null) {
if (MyDebug.LOG)
Log.d(TAG, "create new sound_pool");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes audio_attributes = new AudioAttributes.Builder().setLegacyStreamType(AudioManager.STREAM_SYSTEM).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
sound_pool = new SoundPool.Builder().setMaxStreams(1).setAudioAttributes(audio_attributes).build();
} else {
sound_pool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
}
sound_ids = new SparseIntArray();
}
}
use of android.media.AudioAttributes in project xabber-android by redsolution.
the class ChatFragment method playMessageSound.
public void playMessageSound() {
if (!SettingsManager.eventsInChatSounds())
return;
final MediaPlayer mp;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes attr = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN).setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build();
mp = MediaPlayer.create(getActivity(), R.raw.message_alert, attr, AudioManager.AUDIO_SESSION_ID_GENERATE);
} else {
mp = MediaPlayer.create(getActivity(), R.raw.message_alert);
mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
}
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mp.release();
}
});
}
use of android.media.AudioAttributes in project xabber-android by redsolution.
the class NotificationChannelUtils method updateMessageChannel.
@RequiresApi(api = Build.VERSION_CODES.O)
public static String updateMessageChannel(NotificationManager notifManager, ChannelType type, Uri newSound, long[] newVibro, AudioAttributes newAudioAttrs) {
// settings
NotificationChannel channel = getMessageChannel(notifManager, type);
Uri sound = (newSound != null) ? newSound : channel.getSound();
long[] vibro = (newVibro != null) ? newVibro : channel.getVibrationPattern();
AudioAttributes audioAttrs = (newAudioAttrs != null) ? newAudioAttrs : channel.getAudioAttributes();
// delete old channel
notifManager.deleteNotificationChannel(getChannelID(type));
// need to change channel settings
updateChannelID(type);
return createMessageChannel(notifManager, type, sound, vibro, audioAttrs);
}
use of android.media.AudioAttributes in project xabber-android by redsolution.
the class NotificationChannelUtils method updateCustomChannel.
@RequiresApi(api = Build.VERSION_CODES.O)
public static String updateCustomChannel(NotificationManager notifManager, String channelID, Uri newSound, long[] newVibro, AudioAttributes newAudioAttrs) {
// settings
NotificationChannel channel = notifManager.getNotificationChannel(channelID);
Uri sound = (newSound != null) ? newSound : channel.getSound();
long[] vibro = (newVibro != null) ? newVibro : channel.getVibrationPattern();
AudioAttributes audioAttrs = (newAudioAttrs != null) ? newAudioAttrs : channel.getAudioAttributes();
CharSequence name = channel.getName();
String description = channel.getDescription();
// delete old channel
notifManager.deleteNotificationChannel(channelID);
// need to change channel settings
return createCustomChannel(notifManager, name, description, sound, vibro, audioAttrs);
}
Aggregations