From ce6bc0e203c42529c1c48df398da102e99e3f2b0 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 25 Jun 2018 10:47:13 +0200 Subject: Allow per-call account selection. Change-Id: Ieac27294f4069b2cff17bb39a0954f74320ad943 --- .../dialer/app/AccountSelectionActivity.java | 101 +++++++++++++++++++++ java/com/android/dialer/app/AndroidManifest.xml | 4 + java/com/android/dialer/app/DialtactsActivity.java | 7 +- .../dialer/app/calllog/CallLogActivity.java | 7 +- .../app/calllog/CallLogListItemViewHolder.java | 18 +++- .../android/dialer/app/calllog/IntentProvider.java | 36 +++++--- .../android/dialer/app/res/values/cm_strings.xml | 3 + java/com/android/dialer/app/res/values/styles.xml | 10 ++ .../calldetails/CallDetailsHeaderViewHolder.java | 21 ++++- .../dialer/dialpadview/DialpadFragment.java | 45 ++++++++- .../dialpadview/res/menu/dialpad_options.xml | 6 +- .../dialer/main/impl/OldMainActivityPeer.java | 2 +- java/com/android/dialer/util/CallUtil.java | 21 +++++ 13 files changed, 257 insertions(+), 24 deletions(-) create mode 100644 java/com/android/dialer/app/AccountSelectionActivity.java (limited to 'java') diff --git a/java/com/android/dialer/app/AccountSelectionActivity.java b/java/com/android/dialer/app/AccountSelectionActivity.java new file mode 100644 index 000000000..de84a36b9 --- /dev/null +++ b/java/com/android/dialer/app/AccountSelectionActivity.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.app; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.text.TextUtils; + +import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; +import com.android.contacts.common.widget.SelectPhoneAccountDialogOptions; +import com.android.contacts.common.widget.SelectPhoneAccountDialogOptionsUtil; +import com.android.dialer.callintent.CallInitiationType; +import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.util.CallUtil; + +import java.util.ArrayList; +import java.util.List; + +public class AccountSelectionActivity extends AppCompatActivity { + public static Intent createIntent(Context context, String number, + CallInitiationType.Type initiationType) { + if (TextUtils.isEmpty(number)) { + return null; + } + + List accounts = + CallUtil.getCallCapablePhoneAccounts(context, PhoneAccount.SCHEME_TEL); + if (accounts == null || accounts.size() <= 1) { + return null; + } + ArrayList accountHandles = new ArrayList<>(); + for (PhoneAccount account : accounts) { + accountHandles.add(account.getAccountHandle()); + } + + return new Intent(context, AccountSelectionActivity.class) + .putExtra("number", number) + .putExtra("accountHandles", accountHandles) + .putExtra("type", initiationType.ordinal()); + } + + private String number; + private CallInitiationType.Type initiationType; + + private SelectPhoneAccountDialogFragment.SelectPhoneAccountListener listener = + new SelectPhoneAccountDialogFragment.SelectPhoneAccountListener() { + @Override + public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, + boolean setDefault, String callId) { + Intent intent = new CallIntentBuilder(number, initiationType) + .setPhoneAccountHandle(selectedAccountHandle) + .build(); + startActivity(intent); + finish(); + } + + @Override + public void onDialogDismissed(String callId) { + finish(); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + number = getIntent().getStringExtra("number"); + initiationType = CallInitiationType.Type.values()[getIntent().getIntExtra("type", 0)]; + + if (getFragmentManager().findFragmentByTag("dialog") == null) { + List handles = getIntent().getParcelableArrayListExtra("accountHandles"); + SelectPhoneAccountDialogOptions options = SelectPhoneAccountDialogOptionsUtil + .builderWithAccounts(handles) + .setTitle(R.string.call_via_dialog_title) + .setCanSetDefault(false) + .build(); + SelectPhoneAccountDialogFragment dialog = + SelectPhoneAccountDialogFragment.newInstance(options, listener); + + dialog.show(getFragmentManager(), "dialog"); + } + } +} diff --git a/java/com/android/dialer/app/AndroidManifest.xml b/java/com/android/dialer/app/AndroidManifest.xml index 190f098a5..78b50b668 100644 --- a/java/com/android/dialer/app/AndroidManifest.xml +++ b/java/com/android/dialer/app/AndroidManifest.xml @@ -78,6 +78,10 @@ android:theme="@style/DialtactsTheme"> + + diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index 25a69564d..318f9a138 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -769,9 +769,10 @@ public class DialtactsActivity extends TransactionSafeActivity String number = data.getStringExtra(OldCallDetailsActivity.EXTRA_PHONE_NUMBER); int snackbarDurationMillis = 5_000; Snackbar.make(parentLayout, getString(R.string.ec_data_deleted), snackbarDurationMillis) - .setAction( - R.string.view_conversation, - v -> startActivity(IntentProvider.getSendSmsIntentProvider(number).getIntent(this))) + .setAction(R.string.view_conversation, v -> { + IntentProvider provider = IntentProvider.getSendSmsIntentProvider(number); + startActivity(provider.getClickIntent(this)); + }) .setActionTextColor(getResources().getColor(R.color.dialer_snackbar_action_text_color)) .show(); } diff --git a/java/com/android/dialer/app/calllog/CallLogActivity.java b/java/com/android/dialer/app/calllog/CallLogActivity.java index fdfb3ab2a..f28aa0fc7 100644 --- a/java/com/android/dialer/app/calllog/CallLogActivity.java +++ b/java/com/android/dialer/app/calllog/CallLogActivity.java @@ -284,9 +284,10 @@ public class CallLogActivity extends TransactionSafeActivity && data.getBooleanExtra(OldCallDetailsActivity.EXTRA_HAS_ENRICHED_CALL_DATA, false)) { String number = data.getStringExtra(OldCallDetailsActivity.EXTRA_PHONE_NUMBER); Snackbar.make(findViewById(R.id.calllog_frame), getString(R.string.ec_data_deleted), 5_000) - .setAction( - R.string.view_conversation, - v -> startActivity(IntentProvider.getSendSmsIntentProvider(number).getIntent(this))) + .setAction(R.string.view_conversation, v -> { + IntentProvider provider = IntentProvider.getSendSmsIntentProvider(number); + startActivity(provider.getClickIntent(this)); + }) .setActionTextColor(getResources().getColor(R.color.dialer_snackbar_action_text_color)) .show(); } diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java index e044460c5..1d50a82ac 100644 --- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java +++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java @@ -106,6 +106,7 @@ import java.lang.ref.WeakReference; */ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, + View.OnLongClickListener, MenuItem.OnMenuItemClickListener, View.OnCreateContextMenuListener { @@ -306,6 +307,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder quickContactView.setOverlay(null); quickContactView.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE); primaryActionButtonView.setOnClickListener(this); + primaryActionButtonView.setOnLongClickListener(this); primaryActionView.setOnClickListener(this.expandCollapseListener); if (this.voicemailPlaybackPresenter != null && ConfigProviderComponent.get(this.context) @@ -519,6 +521,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder primaryActionButtonView.setContentDescription( TextUtils.expandTemplate( context.getString(R.string.description_voicemail_action), validNameOrNumber)); + primaryActionButtonView.setTag(null); primaryActionButtonView.setVisibility(View.VISIBLE); } else { primaryActionButtonView.setVisibility(View.GONE); @@ -1053,7 +1056,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder return; } intentProvider.logInteraction(context); - final Intent intent = intentProvider.getIntent(context); + + final Intent intent = intentProvider.getClickIntent(context); // See IntentProvider.getCallDetailIntentProvider() for why this may be null. if (intent == null) { return; @@ -1073,6 +1077,18 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder } } + @Override + public boolean onLongClick(View view) { + final IntentProvider intentProvider = (IntentProvider) view.getTag(); + final Intent intent = intentProvider != null + ? intentProvider.getLongClickIntent(context) : null; + if (intent != null) { + DialerUtils.startActivityWithErrorToast(context, intent); + return true; + } + return false; + } + private static boolean isNonContactEntry(ContactInfo info) { if (info == null || info.sourceType != Type.SOURCE_TYPE_DIRECTORY) { return true; diff --git a/java/com/android/dialer/app/calllog/IntentProvider.java b/java/com/android/dialer/app/calllog/IntentProvider.java index 21f341815..ed6d543d6 100644 --- a/java/com/android/dialer/app/calllog/IntentProvider.java +++ b/java/com/android/dialer/app/calllog/IntentProvider.java @@ -26,6 +26,7 @@ import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; import com.android.contacts.common.model.Contact; import com.android.contacts.common.model.ContactLoader; +import com.android.dialer.app.AccountSelectionActivity; import com.android.dialer.calldetails.CallDetailsEntries; import com.android.dialer.calldetails.OldCallDetailsActivity; import com.android.dialer.callintent.CallInitiationType; @@ -55,12 +56,18 @@ public abstract class IntentProvider { final String number, final PhoneAccountHandle accountHandle) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) .setPhoneAccountHandle(accountHandle)); } + + @Override + public Intent getLongClickIntent(Context context) { + return AccountSelectionActivity.createIntent(context, number, + CallInitiationType.Type.CALL_LOG); + } }; } @@ -68,12 +75,13 @@ public abstract class IntentProvider { final String number, final Context context, final TelephonyManager telephonyManager) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) .setAllowAssistedDial(true)); } + }; } @@ -85,7 +93,7 @@ public abstract class IntentProvider { final String number, final PhoneAccountHandle accountHandle) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) @@ -98,7 +106,7 @@ public abstract class IntentProvider { public static IntentProvider getDuoVideoIntentProvider(String number, boolean isNonContact) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, new CallIntentBuilder(number, CallInitiationType.Type.CALL_LOG) @@ -122,7 +130,7 @@ public abstract class IntentProvider { public static IntentProvider getInstallDuoIntentProvider() { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return DuoComponent.get(context).getDuo().getInstallDuoIntent().orNull(); } @@ -136,7 +144,7 @@ public abstract class IntentProvider { public static IntentProvider getSetUpDuoIntentProvider() { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return DuoComponent.get(context).getDuo().getActivateIntent().orNull(); } @@ -150,7 +158,7 @@ public abstract class IntentProvider { public static IntentProvider getDuoInviteIntentProvider(String number) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return DuoComponent.get(context).getDuo().getInviteIntent(number).orNull(); } @@ -165,7 +173,7 @@ public abstract class IntentProvider { @Nullable PhoneAccountHandle phoneAccountHandle) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return PreCall.getIntent( context, CallIntentBuilder.forVoicemail(phoneAccountHandle, CallInitiationType.Type.CALL_LOG)); @@ -176,7 +184,7 @@ public abstract class IntentProvider { public static IntentProvider getSendSmsIntentProvider(final String number) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return IntentUtil.getSendSmsIntent(number); } }; @@ -198,7 +206,7 @@ public abstract class IntentProvider { boolean canSupportAssistedDialing) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { return OldCallDetailsActivity.newInstance( context, callDetailsEntries, contact, canReportCallerId, canSupportAssistedDialing); } @@ -214,7 +222,7 @@ public abstract class IntentProvider { final boolean isNewContact) { return new IntentProvider() { @Override - public Intent getIntent(Context context) { + public Intent getClickIntent(Context context) { Contact contactToSave = null; if (lookupUri != null) { @@ -275,7 +283,9 @@ public abstract class IntentProvider { }; } - public abstract Intent getIntent(Context context); - + public abstract Intent getClickIntent(Context context); + public Intent getLongClickIntent(Context context) { + return null; + } public void logInteraction(Context context) {} } diff --git a/java/com/android/dialer/app/res/values/cm_strings.xml b/java/com/android/dialer/app/res/values/cm_strings.xml index b28dcaeb2..1e872c4a0 100644 --- a/java/com/android/dialer/app/res/values/cm_strings.xml +++ b/java/com/android/dialer/app/res/values/cm_strings.xml @@ -38,4 +38,7 @@ Audio format AMR-WB AAC + + Call via + Call via\u2026 diff --git a/java/com/android/dialer/app/res/values/styles.xml b/java/com/android/dialer/app/res/values/styles.xml index c2cad315c..0fa3503a4 100644 --- a/java/com/android/dialer/app/res/values/styles.xml +++ b/java/com/android/dialer/app/res/values/styles.xml @@ -23,6 +23,16 @@ ?android:attr/textColorPrimaryInverse + +