Messaging: Fix a few android related things

* NotificationBuilder.addPerson(String) -> .addPerson(Person)
* Wearableextenter.addPage deprecated without replacement
* Html.fromHtml(String) -> .fromHtml(String, int)
* Handlers need Loopers
* Resource-IDs are not final by default (if-else instead of switch-case)
* call super.onFinishInflate() in override of onFinishInflate()
* Configuration.locale -> configuration.getLocales().get(0)
* SimpleDateFormat needs localization as well
* AudioAttributes instead of setAudioStreamType()
* isDataEnabled() is a public method, no need for reflection anymore

Change-Id: Icd830768b86edca3e0b44f1edc6c57facc9f731a
This commit is contained in:
Michael W
2024-12-26 15:54:37 +01:00
parent e128bff457
commit d940ab74ad
33 changed files with 313 additions and 388 deletions
@@ -27,7 +27,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.media.AudioManager;
import android.net.Uri;
@@ -45,6 +44,7 @@ import androidx.collection.SimpleArrayMap;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationCompat.WearableExtender;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.Person;
import androidx.core.app.RemoteInput;
import com.android.messaging.Factory;
@@ -649,7 +649,8 @@ public class BugleNotifications {
if (notificationState.mParticipantContactUris != null &&
notificationState.mParticipantContactUris.size() > 0) {
for (final Uri contactUri : notificationState.mParticipantContactUris) {
notificationState.mNotificationBuilder.addPerson(contactUri.toString());
Person p = new Person.Builder().setUri(contactUri.toString()).build();
notificationState.mNotificationBuilder.addPerson(p);
}
}
@@ -727,16 +728,6 @@ public class BugleNotifications {
final WearableExtender wearableExtender = new WearableExtender();
setWearableGroupOptions(notifBuilder, notificationState);
if (avatarHiResBitmap != null) {
wearableExtender.setBackground(avatarHiResBitmap);
} else if (avatarBitmap != null) {
// Nothing to do here; we already set avatarBitmap as the notification icon
} else {
final Bitmap defaultBackground = BitmapFactory.decodeResource(
context.getResources(), R.drawable.bg_sms);
wearableExtender.setBackground(defaultBackground);
}
if (notificationState instanceof MultiMessageNotificationState) {
if (attachmentBitmap != null) {
// When we've got a picture attachment, we do some switcheroo trickery. When
@@ -754,29 +745,8 @@ public class BugleNotifications {
.bigPicture(attachmentBitmap)
.bigLargeIcon(avatarBitmap);
notificationState.mNotificationBuilder.setLargeIcon(smallBitmap);
// Add a wearable page with no visible card so you can more easily see the photo.
String conversationId = notificationState.mConversationIds.first();
String id = NotificationsUtil.DEFAULT_CHANNEL_ID;
if (NotificationsUtil.getNotificationChannel(context, conversationId) != null) {
id = conversationId;
}
final NotificationCompat.Builder photoPageNotifBuilder =
new NotificationCompat.Builder(Factory.get().getApplicationContext(),
NotificationsUtil.DEFAULT_CHANNEL_ID);
final WearableExtender photoPageWearableExtender = new WearableExtender();
photoPageWearableExtender.setHintShowBackgroundOnly(true);
if (attachmentBitmap != null) {
final Bitmap wearBitmap = ImageUtils.scaleCenterCrop(attachmentBitmap,
sWearableImageWidth, sWearableImageHeight);
photoPageWearableExtender.setBackground(wearBitmap);
}
photoPageNotifBuilder.extend(photoPageWearableExtender);
wearableExtender.addPage(photoPageNotifBuilder.build());
}
maybeAddWearableConversationLog(wearableExtender,
(MultiMessageNotificationState) notificationState);
addDownloadMmsAction(notifBuilder, wearableExtender, notificationState);
addWearableVoiceReplyAction(notifBuilder, wearableExtender, notificationState);
}
@@ -804,22 +774,6 @@ public class BugleNotifications {
}
}
private static void maybeAddWearableConversationLog(
final WearableExtender wearableExtender,
final MultiMessageNotificationState notificationState) {
if (!isWearCompanionAppInstalled()) {
return;
}
final String convId = notificationState.mConversationIds.first();
ConversationLineInfo convInfo = notificationState.mConvList.mConvInfos.get(0);
final Notification page = MessageNotificationState.buildConversationPageForWearable(
convId,
convInfo.mParticipantCount);
if (page != null) {
wearableExtender.addPage(page);
}
}
private static void addWearableVoiceReplyAction(final NotificationCompat.Builder notifBuilder,
final WearableExtender wearableExtender, final NotificationState notificationState) {
if (!(notificationState instanceof MultiMessageNotificationState)) {
@@ -1084,7 +1084,7 @@ public abstract class MessageNotificationState extends NotificationState {
}
private static CharSequence convertHtmlAndStripUrls(final String s) {
final Spanned text = Html.fromHtml(s);
final Spanned text = Html.fromHtml(s, Html.FROM_HTML_MODE_LEGACY);
if (text instanceof Spannable) {
stripUrls((Spannable) text);
}
@@ -41,6 +41,7 @@ public class BlockedParticipantListItemView extends LinearLayout {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNameTextView = (TextView) findViewById(R.id.name);
mContactIconView = (ContactIconView) findViewById(R.id.contact_icon);
setOnClickListener(v -> mData.unblock(getContext()));
@@ -39,15 +39,11 @@ public class BlockedParticipantsActivity extends BugleActionBarActivity {
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Treat the home press as back press so that when we go back to
// ConversationActivity, it doesn't lose its original intent (conversation id etc.)
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == android.R.id.home) {// Treat the home press as back press so that when we go back to
// ConversationActivity, it doesn't lose its original intent (conversation id etc.)
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
@@ -203,12 +203,11 @@ public class BugleActionBarActivity extends AppCompatActivity implements ImeUtil
return true;
}
switch (menuItem.getItemId()) {
case android.R.id.home:
if (mActionMode != null) {
dismissActionMode();
return true;
}
if (menuItem.getItemId() == android.R.id.home) {
if (mActionMode != null) {
dismissActionMode();
return true;
}
}
return super.onOptionsItemSelected(menuItem);
}
@@ -24,6 +24,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.provider.Telephony.Sms;
@@ -66,7 +67,7 @@ public class ClassZeroActivity extends Activity {
private ArrayList<ContentValues> mMessageQueue = null;
private final Handler mHandler = new Handler() {
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(final Message msg) {
// Do not handle an invalid message.
@@ -67,6 +67,7 @@ public class PersonItemView extends LinearLayout implements PersonItemDataListen
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNameTextView = (TextView) findViewById(R.id.name);
mDetailsTextView = (TextView) findViewById(R.id.details);
mContactIconView = (ContactIconView) findViewById(R.id.contact_icon);
@@ -56,15 +56,12 @@ public class VCardDetailActivity extends BugleActionBarActivity
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Treat the home press as back press so that when we go back to
// ConversationActivity, it doesn't lose its original intent (conversation id etc.)
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == android.R.id.home) {
// Treat the home press as back press so that when we go back to
// ConversationActivity, it doesn't lose its original intent (conversation id etc.)
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
@@ -125,41 +125,38 @@ public class VCardDetailFragment extends Fragment implements PersonItemDataListe
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_contact:
mBinding.ensureBound();
final Uri vCardUri = mBinding.getData().getVCardUri();
if (item.getItemId() == R.id.action_add_contact) {
mBinding.ensureBound();
final Uri vCardUri = mBinding.getData().getVCardUri();
// We have to do things in the background in case we need to copy the vcard data.
new SafeAsyncTask<Void, Void, Uri>() {
@Override
protected Uri doInBackgroundTimed(final Void... params) {
// We can't delete the persisted vCard file because we don't know when to
// delete it, since the app that uses it (contacts, dialer) may start or
// shut down at any point. Therefore, we rely on the system to clean up
// the cache directory for us.
return mScratchSpaceUri != null ? mScratchSpaceUri :
// We have to do things in the background in case we need to copy the vcard data.
new SafeAsyncTask<Void, Void, Uri>() {
@Override
protected Uri doInBackgroundTimed(final Void... params) {
// We can't delete the persisted vCard file because we don't know when to
// delete it, since the app that uses it (contacts, dialer) may start or
// shut down at any point. Therefore, we rely on the system to clean up
// the cache directory for us.
return mScratchSpaceUri != null ? mScratchSpaceUri :
UriUtil.persistContentToScratchSpace(vCardUri);
}
}
@Override
protected void onPostExecute(final Uri result) {
if (result != null) {
mScratchSpaceUri = result;
if (getActivity() != null) {
MediaScratchFileProvider.addUriToDisplayNameEntry(
result, mBinding.getData().getDisplayName());
UIIntents.get().launchSaveVCardToContactsActivity(getActivity(),
result);
}
@Override
protected void onPostExecute(final Uri result) {
if (result != null) {
mScratchSpaceUri = result;
if (getActivity() != null) {
MediaScratchFileProvider.addUriToDisplayNameEntry(
result, mBinding.getData().getDisplayName());
UIIntents.get().launchSaveVCardToContactsActivity(getActivity(),
result);
}
}
}.executeOnThreadPool();
return true;
default:
return super.onOptionsItemSelected(item);
}
}.executeOnThreadPool();
return true;
}
return super.onOptionsItemSelected(item);
}
public void setVCardUri(final Uri vCardUri) {
@@ -66,11 +66,11 @@ public class ApplicationSettingsActivity extends BugleActionBarActivity {
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_license:
} else if (itemId == R.id.action_license) {
final Intent intent = new Intent(this, LicenseActivity.class);
startActivity(intent);
return true;
@@ -64,8 +64,7 @@ public class PerSubscriptionSettingsActivity extends BugleActionBarActivity {
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (item.getItemId() == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
@@ -75,8 +75,7 @@ public class SettingsActivity extends BugleActionBarActivity {
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (item.getItemId() == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
@@ -87,14 +87,11 @@ public class AttachmentChooserFragment extends Fragment implements DraftMessageD
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_confirm_selection:
confirmSelection();
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.action_confirm_selection) {
confirmSelection();
return true;
}
return super.onOptionsItemSelected(item);
}
@VisibleForTesting
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +65,7 @@ public class ContactListItemView extends LinearLayout implements OnClickListener
@Override
protected void onFinishInflate () {
super.onFinishInflate();
mContactNameTextView = (TextView) findViewById(R.id.contact_name);
mContactDetailsTextView = (TextView) findViewById(R.id.contact_details);
mContactDetailTypeTextView = (TextView) findViewById(R.id.contact_detail_type);
@@ -178,7 +178,7 @@ public class ContactPickerFragment extends Fragment implements ContactPickerData
mCustomHeaderViewPager.setViewHolders(viewHolders);
mCustomHeaderViewPager.setViewPagerTabHeight(CustomHeaderViewPager.DEFAULT_TAB_STRIP_SIZE);
mCustomHeaderViewPager.setBackgroundColor(getResources()
.getColor(R.color.contact_picker_background, getContext().getTheme()));
.getColor(R.color.contact_picker_background, requireActivity().getTheme()));
// The view pager defaults to the frequent contacts page.
mCustomHeaderViewPager.setCurrentItem(0);
@@ -220,32 +220,29 @@ public class ContactPickerFragment extends Fragment implements ContactPickerData
@Override
public boolean onMenuItemClick(final MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_ime_dialpad_toggle:
final int baseInputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE;
if ((mRecipientTextView.getInputType() & InputType.TYPE_CLASS_PHONE) !=
InputType.TYPE_CLASS_PHONE) {
mRecipientTextView.setInputType(baseInputType | InputType.TYPE_CLASS_PHONE);
menuItem.setIcon(R.drawable.ic_ime_light);
} else {
mRecipientTextView.setInputType(baseInputType | InputType.TYPE_CLASS_TEXT);
menuItem.setIcon(R.drawable.ic_numeric_dialpad);
}
ImeUtil.get().showImeKeyboard(getActivity(), mRecipientTextView);
return true;
case R.id.action_add_more_participants:
mHost.onInitiateAddMoreParticipants();
return true;
case R.id.action_confirm_participants:
maybeGetOrCreateConversation();
return true;
case R.id.action_delete_text:
Assert.equals(MODE_PICK_INITIAL_CONTACT, mContactPickingMode);
mRecipientTextView.setText("");
return true;
int itemId = menuItem.getItemId();
if (itemId == R.id.action_ime_dialpad_toggle) {
final int baseInputType = InputType.TYPE_TEXT_FLAG_MULTI_LINE;
if ((mRecipientTextView.getInputType() & InputType.TYPE_CLASS_PHONE) !=
InputType.TYPE_CLASS_PHONE) {
mRecipientTextView.setInputType(baseInputType | InputType.TYPE_CLASS_PHONE);
menuItem.setIcon(R.drawable.ic_ime_light);
} else {
mRecipientTextView.setInputType(baseInputType | InputType.TYPE_CLASS_TEXT);
menuItem.setIcon(R.drawable.ic_numeric_dialpad);
}
ImeUtil.get().showImeKeyboard(requireActivity(), mRecipientTextView);
return true;
} else if (itemId == R.id.action_add_more_participants) {
mHost.onInitiateAddMoreParticipants();
return true;
} else if (itemId == R.id.action_confirm_participants) {
maybeGetOrCreateConversation();
return true;
} else if (itemId == R.id.action_delete_text) {
Assert.equals(MODE_PICK_INITIAL_CONTACT, mContactPickingMode);
mRecipientTextView.setText("");
return true;
}
return false;
}
@@ -40,6 +40,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.binding.Binding;
@@ -190,6 +191,7 @@ public class ComposeMessageView extends LinearLayout
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mComposeEditText = (PlainTextEditText) findViewById(
R.id.compose_message_text);
mComposeEditText.setOnEditorActionListener(this);
@@ -730,7 +732,7 @@ public class ComposeMessageView extends LinearLayout
} else {
mComposeEditText.setHint(Html.fromHtml(getResources().getString(
R.string.compose_message_view_hint_text_multi_sim,
subscriptionListEntry.displayName)));
subscriptionListEntry.displayName), Html.FROM_HTML_MODE_LEGACY));
}
} else {
int type = -1;
@@ -306,67 +306,67 @@ public class ConversationFragment extends Fragment implements ConversationDataLi
public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) {
final ConversationMessageData data = mSelectedMessage.getData();
final String messageId = data.getMessageId();
switch (menuItem.getItemId()) {
case R.id.save_attachment:
if (OsUtil.hasStoragePermission()) {
final SaveAttachmentTask saveAttachmentTask = new SaveAttachmentTask(
getActivity());
for (final MessagePartData part : data.getAttachments()) {
saveAttachmentTask.addAttachmentToSave(part.getContentUri(),
part.getContentType());
}
if (saveAttachmentTask.getAttachmentCount() > 0) {
saveAttachmentTask.executeOnThreadPool();
mHost.dismissActionMode();
}
} else {
getActivity().requestPermissions(
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
int itemId = menuItem.getItemId();
if (itemId == R.id.save_attachment) {
if (OsUtil.hasStoragePermission()) {
final SaveAttachmentTask saveAttachmentTask = new SaveAttachmentTask(
getActivity());
for (final MessagePartData part : data.getAttachments()) {
saveAttachmentTask.addAttachmentToSave(part.getContentUri(),
part.getContentType());
}
return true;
case R.id.action_delete_message:
if (mSelectedMessage != null) {
deleteMessage(messageId);
}
return true;
case R.id.action_download:
if (mSelectedMessage != null) {
retryDownload(messageId);
if (saveAttachmentTask.getAttachmentCount() > 0) {
saveAttachmentTask.executeOnThreadPool();
mHost.dismissActionMode();
}
return true;
case R.id.action_send:
if (mSelectedMessage != null) {
retrySend(messageId);
mHost.dismissActionMode();
}
return true;
case R.id.copy_text:
Assert.isTrue(data.hasText());
final ClipboardManager clipboard = (ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(
ClipData.newPlainText(null /* label */, data.getText()));
} else {
getActivity().requestPermissions(
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
}
return true;
} else if (itemId == R.id.action_delete_message) {
if (mSelectedMessage != null) {
deleteMessage(messageId);
}
return true;
} else if (itemId == R.id.action_download) {
if (mSelectedMessage != null) {
retryDownload(messageId);
mHost.dismissActionMode();
return true;
case R.id.details_menu:
MessageDetailsDialog.show(
getActivity(), data, mBinding.getData().getParticipants(),
mBinding.getData().getSelfParticipantById(data.getSelfParticipantId()));
}
return true;
} else if (itemId == R.id.action_send) {
if (mSelectedMessage != null) {
retrySend(messageId);
mHost.dismissActionMode();
return true;
case R.id.share_message_menu:
shareMessage(data);
mHost.dismissActionMode();
return true;
case R.id.forward_message_menu:
// TODO: Currently we are forwarding one part at a time, instead of
// the entire message. Change this to forwarding the entire message when we
// use message-based cursor in conversation.
final MessageData message = mBinding.getData().createForwardedMessage(data);
UIIntents.get().launchForwardMessageActivity(getActivity(), message);
mHost.dismissActionMode();
return true;
}
return true;
} else if (itemId == R.id.copy_text) {
Assert.isTrue(data.hasText());
final ClipboardManager clipboard = (ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(
ClipData.newPlainText(null /* label */, data.getText()));
mHost.dismissActionMode();
return true;
} else if (itemId == R.id.details_menu) {
MessageDetailsDialog.show(
getActivity(), data, mBinding.getData().getParticipants(),
mBinding.getData().getSelfParticipantById(data.getSelfParticipantId()));
mHost.dismissActionMode();
return true;
} else if (itemId == R.id.share_message_menu) {
shareMessage(data);
mHost.dismissActionMode();
return true;
} else if (itemId == R.id.forward_message_menu) {
// TODO: Currently we are forwarding one part at a time, instead of
// the entire message. Change this to forwarding the entire message when we
// use message-based cursor in conversation.
final MessageData message = mBinding.getData().createForwardedMessage(data);
UIIntents.get().launchForwardMessageActivity(getActivity(), message);
mHost.dismissActionMode();
return true;
}
return false;
}
@@ -774,72 +774,66 @@ public class ConversationFragment extends Fragment implements ConversationDataLi
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.action_people_and_options:
Assert.isTrue(mBinding.getData().getParticipantsLoaded());
UIIntents.get().launchPeopleAndOptionsActivity(getActivity(), mConversationId);
return true;
case R.id.action_call:
final String phoneNumber = mBinding.getData().getParticipantPhoneNumber();
Assert.notNull(phoneNumber);
// Can't make a call to emergency numbers using ACTION_CALL.
if (PhoneNumberUtils.isEmergencyNumber(phoneNumber)) {
UiUtils.showToast(R.string.disallow_emergency_call);
int itemId = item.getItemId();
if (itemId == R.id.action_people_and_options) {
Assert.isTrue(mBinding.getData().getParticipantsLoaded());
UIIntents.get().launchPeopleAndOptionsActivity(getActivity(), mConversationId);
return true;
} else if (itemId == R.id.action_call) {
final String phoneNumber = mBinding.getData().getParticipantPhoneNumber();
Assert.notNull(phoneNumber);
// Can't make a call to emergency numbers using ACTION_CALL.
if (PhoneNumberUtils.isEmergencyNumber(phoneNumber)) {
UiUtils.showToast(R.string.disallow_emergency_call);
} else {
final View targetView = getActivity().findViewById(R.id.action_call);
Point centerPoint;
if (targetView != null) {
final int[] screenLocation = new int[2];
targetView.getLocationOnScreen(screenLocation);
final int centerX = screenLocation[0] + targetView.getWidth() / 2;
final int centerY = screenLocation[1] + targetView.getHeight() / 2;
centerPoint = new Point(centerX, centerY);
} else {
final View targetView = getActivity().findViewById(R.id.action_call);
Point centerPoint;
if (targetView != null) {
final int[] screenLocation = new int[2];
targetView.getLocationOnScreen(screenLocation);
final int centerX = screenLocation[0] + targetView.getWidth() / 2;
final int centerY = screenLocation[1] + targetView.getHeight() / 2;
centerPoint = new Point(centerX, centerY);
} else {
// In the overflow menu, just use the center of the screen.
final Display display =
getActivity().getWindowManager().getDefaultDisplay();
centerPoint = new Point(display.getWidth() / 2, display.getHeight() / 2);
}
UIIntents.get()
.launchPhoneCallActivity(getActivity(), phoneNumber, centerPoint);
// In the overflow menu, just use the center of the screen.
final Display display =
getActivity().getWindowManager().getDefaultDisplay();
centerPoint = new Point(display.getWidth() / 2, display.getHeight() / 2);
}
return true;
case R.id.action_archive:
mBinding.getData().archiveConversation(mBinding);
closeConversation(mConversationId);
return true;
case R.id.action_unarchive:
mBinding.getData().unarchiveConversation(mBinding);
return true;
case R.id.action_settings:
return true;
case R.id.action_add_contact:
final ParticipantData participant = mBinding.getData().getOtherParticipant();
Assert.notNull(participant);
final String destination = participant.getNormalizedDestination();
final Uri avatarUri = AvatarUriUtil.createAvatarUri(participant);
(new AddContactsConfirmationDialog(getActivity(), avatarUri, destination)).show();
return true;
case R.id.action_delete:
if (isReadyForDeleteAction()) {
new AlertDialog.Builder(getActivity())
.setTitle(getResources().getQuantityString(
R.plurals.delete_conversations_confirmation_dialog_title, 1))
.setPositiveButton(R.string.delete_conversation_confirmation_button,
(dialog, button) -> deleteConversation())
.setNegativeButton(R.string.delete_conversation_decline_button, null)
.show();
} else {
warnOfMissingActionConditions(false /*sending*/,
null /*commandToRunAfterActionConditionResolved*/);
}
return true;
UIIntents.get()
.launchPhoneCallActivity(getActivity(), phoneNumber, centerPoint);
}
return true;
} else if (itemId == R.id.action_archive) {
mBinding.getData().archiveConversation(mBinding);
closeConversation(mConversationId);
return true;
} else if (itemId == R.id.action_unarchive) {
mBinding.getData().unarchiveConversation(mBinding);
return true;
} else if (itemId == R.id.action_settings) {
return true;
} else if (itemId == R.id.action_add_contact) {
final ParticipantData participant = mBinding.getData().getOtherParticipant();
Assert.notNull(participant);
final String destination = participant.getNormalizedDestination();
final Uri avatarUri = AvatarUriUtil.createAvatarUri(participant);
(new AddContactsConfirmationDialog(getActivity(), avatarUri, destination)).show();
return true;
} else if (itemId == R.id.action_delete) {
if (isReadyForDeleteAction()) {
new AlertDialog.Builder(getActivity())
.setTitle(getResources().getQuantityString(
R.plurals.delete_conversations_confirmation_dialog_title, 1))
.setPositiveButton(R.string.delete_conversation_confirmation_button,
(dialog, button) -> deleteConversation())
.setNegativeButton(R.string.delete_conversation_decline_button, null)
.show();
} else {
warnOfMissingActionConditions(false /*sending*/,
null /*commandToRunAfterActionConditionResolved*/);
}
return true;
}
return super.onOptionsItemSelected(item);
}
@@ -122,6 +122,7 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mContactIconView = (ContactIconView) findViewById(R.id.conversation_icon);
mContactIconView.setOnLongClickListener(view -> {
ConversationMessageView.this.performLongClick();
@@ -46,6 +46,7 @@ public class SimSelectorItemView extends LinearLayout {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNameTextView = (TextView) findViewById(R.id.name);
mDetailsTextView = (TextView) findViewById(R.id.details);
mSimIconView = (SimIconView) findViewById(R.id.sim_icon);
@@ -64,13 +64,11 @@ public class ArchivedConversationListActivity extends AbstractConversationListAc
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch(menuItem.getItemId()) {
case android.R.id.home:
onActionBarHome();
return true;
default:
return super.onOptionsItemSelected(menuItem);
if (menuItem.getItemId() == android.R.id.home) {
onActionBarHome();
return true;
}
return super.onOptionsItemSelected(menuItem);
}
@Override
@@ -85,19 +85,19 @@ public class ConversationListActivity extends AbstractConversationListActivity i
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem menuItem) {
switch(menuItem.getItemId()) {
case R.id.action_start_new_conversation:
onActionBarStartNewConversation();
return true;
case R.id.action_settings:
onActionBarSettings();
return true;
case R.id.action_show_archived:
onActionBarArchived();
return true;
case R.id.action_show_blocked_contacts:
onActionBarBlockedParticipants();
return true;
int itemId = menuItem.getItemId();
if (itemId == R.id.action_start_new_conversation) {
onActionBarStartNewConversation();
return true;
} else if (itemId == R.id.action_settings) {
onActionBarSettings();
return true;
} else if (itemId == R.id.action_show_archived) {
onActionBarArchived();
return true;
} else if (itemId == R.id.action_show_blocked_contacts) {
onActionBarBlockedParticipants();
return true;
}
return super.onOptionsItemSelected(menuItem);
}
@@ -144,6 +144,7 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mSwipeableContainer = (ViewGroup) findViewById(R.id.swipeableContainer);
mCrossSwipeBackground = (ViewGroup) findViewById(R.id.crossSwipeBackground);
mSwipeableContent = (ViewGroup) findViewById(R.id.swipeableContent);
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,30 +96,29 @@ public class MultiSelectActionModeCallback implements Callback {
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
switch(menuItem.getItemId()) {
case R.id.action_delete:
mListener.onActionBarDelete(mSelectedConversations.values());
return true;
case R.id.action_archive:
mListener.onActionBarArchive(mSelectedConversations.values(), true);
return true;
case R.id.action_unarchive:
mListener.onActionBarArchive(mSelectedConversations.values(), false);
return true;
case R.id.action_add_contact:
Assert.isTrue(mSelectedConversations.size() == 1);
mListener.onActionBarAddContact(mSelectedConversations.valueAt(0));
return true;
case R.id.action_block:
Assert.isTrue(mSelectedConversations.size() == 1);
mListener.onActionBarBlock(mSelectedConversations.valueAt(0));
return true;
case android.R.id.home:
mListener.onActionBarHome();
return true;
default:
return false;
int itemId = menuItem.getItemId();
if (itemId == R.id.action_delete) {
mListener.onActionBarDelete(mSelectedConversations.values());
return true;
} else if (itemId == R.id.action_archive) {
mListener.onActionBarArchive(mSelectedConversations.values(), true);
return true;
} else if (itemId == R.id.action_unarchive) {
mListener.onActionBarArchive(mSelectedConversations.values(), false);
return true;
} else if (itemId == R.id.action_add_contact) {
Assert.isTrue(mSelectedConversations.size() == 1);
mListener.onActionBarAddContact(mSelectedConversations.valueAt(0));
return true;
} else if (itemId == R.id.action_block) {
Assert.isTrue(mSelectedConversations.size() == 1);
mListener.onActionBarBlock(mSelectedConversations.valueAt(0));
return true;
} else if (itemId == android.R.id.home) {
mListener.onActionBarHome();
return true;
}
return false;
}
@Override
@@ -55,15 +55,12 @@ public class PeopleAndOptionsActivity extends BugleActionBarActivity {
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Treat the home press as back press so that when we go back to
// ConversationActivity, it doesn't lose its original intent (conversation id etc.)
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == android.R.id.home) {
// Treat the home press as back press so that when we go back to
// ConversationActivity, it doesn't lose its original intent (conversation id etc.)
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
@@ -123,45 +123,41 @@ public class PeopleAndOptionsFragment extends Fragment
@Override
public void onOptionsItemViewClicked(final PeopleOptionsItemData item) {
switch (item.getItemId()) {
case PeopleOptionsItemData.SETTING_NOTIFICATION:
ArrayList<String> participantsNames = new ArrayList<>();
for (ParticipantData participant : mOtherParticipants) {
participantsNames.add(participant.getDisplayName(true));
}
NotificationsUtil.createNotificationChannelGroup(getActivity(),
NotificationsUtil.CONVERSATION_GROUP_NAME,
R.string.notification_channel_messages_title);
NotificationsUtil.createNotificationChannel(getActivity(),
mBinding.getData().getConversationId(),
String.join(", ", participantsNames),
NotificationManager.IMPORTANCE_DEFAULT,
NotificationsUtil.CONVERSATION_GROUP_NAME);
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
startActivity(intent);
break;
case PeopleOptionsItemData.SETTING_BLOCKED:
if (item.getOtherParticipant().isBlocked()) {
mBinding.getData().setDestinationBlocked(mBinding, false);
break;
}
final Resources res = getResources();
final Activity activity = getActivity();
new AlertDialog.Builder(activity)
.setTitle(res.getString(R.string.block_confirmation_title,
item.getOtherParticipant().getDisplayDestination()))
.setMessage(res.getString(R.string.block_confirmation_message))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (arg0, arg1) -> {
mBinding.getData().setDestinationBlocked(mBinding, true);
activity.setResult(ConversationActivity.FINISH_RESULT_CODE);
activity.finish();
})
.create()
.show();
break;
if (item.getItemId() == PeopleOptionsItemData.SETTING_NOTIFICATION) {
ArrayList<String> participantsNames = new ArrayList<>();
for (ParticipantData participant : mOtherParticipants) {
participantsNames.add(participant.getDisplayName(true));
}
NotificationsUtil.createNotificationChannelGroup(getActivity(),
NotificationsUtil.CONVERSATION_GROUP_NAME,
R.string.notification_channel_messages_title);
NotificationsUtil.createNotificationChannel(getActivity(),
mBinding.getData().getConversationId(),
String.join(", ", participantsNames),
NotificationManager.IMPORTANCE_DEFAULT,
NotificationsUtil.CONVERSATION_GROUP_NAME);
Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
startActivity(intent);
} else if (item.getItemId() == PeopleOptionsItemData.SETTING_BLOCKED) {
if (item.getOtherParticipant().isBlocked()) {
mBinding.getData().setDestinationBlocked(mBinding, false);
return;
}
final Resources res = getResources();
final Activity activity = getActivity();
new AlertDialog.Builder(activity)
.setTitle(res.getString(R.string.block_confirmation_title,
item.getOtherParticipant().getDisplayDestination()))
.setMessage(res.getString(R.string.block_confirmation_message))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (arg0, arg1) -> {
mBinding.getData().setDestinationBlocked(mBinding, true);
activity.setResult(ConversationActivity.FINISH_RESULT_CODE);
activity.finish();
})
.create()
.show();
}
}
@@ -54,6 +54,7 @@ public class PeopleOptionsItemView extends LinearLayout {
@Override
protected void onFinishInflate () {
super.onFinishInflate();
mTitle = (TextView) findViewById(R.id.title);
setOnClickListener(v -> mHostInterface.onOptionsItemViewClicked(mData));
}
@@ -122,16 +122,15 @@ public class AudioRecordView extends FrameLayout implements
mSoundLevels.setLevelSource(mMediaRecorder.getLevelSource());
mRecordButton.setOnTouchListener((v, event) -> {
final int action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN:
onRecordButtonTouchDown();
if (action == MotionEvent.ACTION_DOWN) {
onRecordButtonTouchDown();
// Don't let the record button handle the down event to let it fall through
// so that we can handle it for the entire panel in onTouchEvent(). This is
// done so that: 1) the user taps on the record button to start recording
// 2) the entire panel owns the touch event so we'd keep recording even
// if the user moves outside the button region.
return false;
// Don't let the record button handle the down event to let it fall through
// so that we can handle it for the entire panel in onTouchEvent(). This is
// done so that: 1) the user taps on the record button to start recording
// 2) the entire panel owns the touch event so we'd keep recording even
// if the user moves outside the button region.
return false;
}
return false;
});
@@ -29,6 +29,7 @@ import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
@@ -115,7 +116,7 @@ public class PieRenderer extends OverlayRenderer
private LinearAnimation mFadeIn;
private volatile boolean mFocusCancelled;
private final Handler mHandler = new Handler() {
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
public void handleMessage(Message msg) {
switch(msg.what) {
case MSG_OPEN:
+4 -3
View File
@@ -110,8 +110,8 @@ public class Dates {
flags = FORCE_12_HOUR;
}
return getOlderThanAYearTimestamp(time,
context.getResources().getConfiguration().locale, false /*abbreviated*/,
flags);
context.getResources().getConfiguration().getLocales().get(0),
false /*abbreviated*/, flags);
}
private static CharSequence getTimeString(final long time, final boolean abbreviated,
@@ -124,7 +124,8 @@ public class Dates {
flags = FORCE_12_HOUR;
}
return getTimestamp(time, System.currentTimeMillis(), abbreviated,
context.getResources().getConfiguration().locale, flags, minPeriodToday);
context.getResources().getConfiguration().getLocales().get(0), flags,
minPeriodToday);
}
@VisibleForTesting
+3 -2
View File
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +22,6 @@ import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import com.android.messaging.Factory;
import com.android.messaging.R;
@@ -39,7 +39,8 @@ public class FileUtil {
private static synchronized File getNewFile(File directory, String extension,
String fileNameFormat) throws IOException {
final Date date = new Date(System.currentTimeMillis());
final SimpleDateFormat dateFormat = new SimpleDateFormat(fileNameFormat);
final SimpleDateFormat dateFormat = new SimpleDateFormat(fileNameFormat,
Locale.getDefault(Locale.Category.FORMAT));
final String numberedFileNameFormat = dateFormat.format(date) + "_%02d" + "." + extension;
for (int i = 1; i <= 99; i++) { // Only save 99 of the same file name.
final String newName = String.format(Locale.US, numberedFileNameFormat, i);
@@ -18,6 +18,7 @@ package com.android.messaging.util;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
@@ -37,7 +38,9 @@ public class MediaUtilImpl extends MediaUtil {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
try {
final MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
AudioAttributes.Builder attributes = new AudioAttributes.Builder();
attributes.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayer.setAudioAttributes(attributes.build());
final AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId);
mediaPlayer.setDataSource(
afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
@@ -18,6 +18,7 @@
package com.android.messaging.util;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
@@ -92,7 +93,9 @@ public class NotificationPlayer implements OnCompletionListener {
.getSystemService(Context.AUDIO_SERVICE);
try {
final MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(mCmd.stream);
AudioAttributes.Builder attributes = new AudioAttributes.Builder();
attributes.setLegacyStreamType(mCmd.stream);
player.setAudioAttributes(attributes.build());
player.setDataSource(Factory.get().getApplicationContext(), mCmd.uri);
player.setLooping(mCmd.looping);
player.setVolume(mCmd.volume, mCmd.volume);
+1 -15
View File
@@ -40,13 +40,11 @@ import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.sms.MmsSmsUtils;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -297,19 +295,7 @@ public class PhoneUtils {
* @return true if mobile data is enabled, false otherwise
*/
public boolean isMobileDataEnabled() {
boolean mobileDataEnabled = false;
try {
final Class cmClass = mTelephonyManager.getClass();
final Method method = cmClass.getDeclaredMethod("getDataEnabled", Integer.TYPE);
method.setAccessible(true); // Make the method callable
// get the setting for "mobile data"
mobileDataEnabled = (Boolean) method.invoke(
mTelephonyManager, Integer.valueOf(mSubId));
} catch (final Exception e) {
LogUtil.e(TAG, "PhoneUtil.isMobileDataEnabled: system api not found", e);
}
return mobileDataEnabled;
return mTelephonyManager.createForSubscriptionId(mSubId).isDataEnabled();
}
/**