From ba99befea1f4402a854351f80d8627909a532331 Mon Sep 17 00:00:00 2001 From: twyen Date: Mon, 20 Nov 2017 15:13:07 -0800 Subject: Implement SIM selection dialog Bug: 64216442,64214592,64213352 Test: N/A PiperOrigin-RevId: 176424724 Change-Id: I1709156098a14ac3bd35d98b913e7b881fcd9b2b --- .../common/res/layout/default_account_checkbox.xml | 42 ++++++++----- .../common/res/layout/select_account_list_item.xml | 70 +++++++++++++--------- .../widget/SelectPhoneAccountDialogFragment.java | 57 +++++++++++++++--- .../precall/impl/CallingAccountSelector.java | 45 ++++++++++++-- .../dialer/precall/impl/res/values/strings.xml | 12 ++++ .../com/android/incallui/InCallActivityCommon.java | 4 +- 6 files changed, 172 insertions(+), 58 deletions(-) diff --git a/java/com/android/contacts/common/res/layout/default_account_checkbox.xml b/java/com/android/contacts/common/res/layout/default_account_checkbox.xml index b7c0cf644..1e76b74f5 100644 --- a/java/com/android/contacts/common/res/layout/default_account_checkbox.xml +++ b/java/com/android/contacts/common/res/layout/default_account_checkbox.xml @@ -15,22 +15,36 @@ --> - + + /> + + + diff --git a/java/com/android/contacts/common/res/layout/select_account_list_item.xml b/java/com/android/contacts/common/res/layout/select_account_list_item.xml index fbd31e573..8f7cc7017 100644 --- a/java/com/android/contacts/common/res/layout/select_account_list_item.xml +++ b/java/com/android/contacts/common/res/layout/select_account_list_item.xml @@ -16,41 +16,53 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="64dp" + android:padding="8dp" + android:paddingStart="24dp" + android:paddingEnd="24dp" + android:orientation="horizontal" + android:gravity="center"> + android:id="@+id/icon" + android:layout_width="24dp" + android:layout_height="24dp" + android:scaleType="center"/> - + android:layout_weight="1" + android:paddingStart="24dp" + android:gravity="start|center_vertical" + android:orientation="vertical"> + android:id="@+id/label" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:includeFontPadding="false" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textColor="@color/dialer_primary_text_color"/> + + diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java index e21fded97..3c9d9268f 100644 --- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java +++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java @@ -55,12 +55,15 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { private static final String ARG_TITLE_RES_ID = "title_res_id"; private static final String ARG_CAN_SET_DEFAULT = "can_set_default"; + private static final String ARG_SET_DEFAULT_RES_ID = "set_default_res_id"; private static final String ARG_ACCOUNT_HANDLES = "account_handles"; private static final String ARG_IS_DEFAULT_CHECKED = "is_default_checked"; private static final String ARG_LISTENER = "listener"; private static final String ARG_CALL_ID = "call_id"; + private static final String ARG_HINTS = "hints"; private List mAccountHandles; + private List mHints; private boolean mIsSelected; private boolean mIsDefaultChecked; private SelectPhoneAccountListener mListener; @@ -78,7 +81,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { SelectPhoneAccountListener listener, @Nullable String callId) { return newInstance( - R.string.select_account_dialog_title, false, accountHandles, listener, callId); + R.string.select_account_dialog_title, false, 0, accountHandles, listener, callId, null); } /** @@ -88,15 +91,22 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { * @param titleResId The resource ID for the string to use in the title of the dialog. * @param canSetDefault {@code true} if the dialog should include an option to set the selection * as the default. False otherwise. + * @param setDefaultResId The resource ID for the string to use in the "set as default" checkbox * @param accountHandles The {@code PhoneAccountHandle}s available to select from. * @param listener The listener for the results of the account selection. + * @param callId The callId to be passed back to the listener in {@link + * SelectPhoneAccountListener#EXTRA_CALL_ID} + * @param hints Additional information to be shown underneath the phone account to help user + * choose. Index must match {@code accountHandles} */ public static SelectPhoneAccountDialogFragment newInstance( int titleResId, boolean canSetDefault, + int setDefaultResId, List accountHandles, SelectPhoneAccountListener listener, - @Nullable String callId) { + @Nullable String callId, + @Nullable List hints) { ArrayList accountHandlesCopy = new ArrayList<>(); if (accountHandles != null) { accountHandlesCopy.addAll(accountHandles); @@ -105,9 +115,13 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { final Bundle args = new Bundle(); args.putInt(ARG_TITLE_RES_ID, titleResId); args.putBoolean(ARG_CAN_SET_DEFAULT, canSetDefault); + args.putInt(ARG_SET_DEFAULT_RES_ID, setDefaultResId); args.putParcelableArrayList(ARG_ACCOUNT_HANDLES, accountHandlesCopy); args.putParcelable(ARG_LISTENER, listener); args.putString(ARG_CALL_ID, callId); + if (hints != null) { + args.putStringArrayList(ARG_HINTS, new ArrayList<>(hints)); + } fragment.setArguments(args); fragment.setListener(listener); return fragment; @@ -140,6 +154,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { boolean canSetDefault = getArguments().getBoolean(ARG_CAN_SET_DEFAULT); mAccountHandles = getArguments().getParcelableArrayList(ARG_ACCOUNT_HANDLES); mListener = getArguments().getParcelable(ARG_LISTENER); + mHints = getArguments().getStringArrayList(ARG_HINTS); if (savedInstanceState != null) { mIsDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED); } @@ -173,7 +188,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); ListAdapter selectAccountListAdapter = new SelectAccountListAdapter( - builder.getContext(), R.layout.select_account_list_item, mAccountHandles); + builder.getContext(), R.layout.select_account_list_item, mAccountHandles, mHints); AlertDialog dialog = builder @@ -189,10 +204,17 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { LayoutInflater.from(builder.getContext()) .inflate(R.layout.default_account_checkbox, null); - CheckBox cb = (CheckBox) checkboxLayout.findViewById(R.id.default_account_checkbox_view); - cb.setOnCheckedChangeListener(checkListener); - cb.setChecked(mIsDefaultChecked); - + CheckBox checkBox = checkboxLayout.findViewById(R.id.default_account_checkbox_view); + checkBox.setOnCheckedChangeListener(checkListener); + checkBox.setChecked(mIsDefaultChecked); + + TextView textView = checkboxLayout.findViewById(R.id.default_account_checkbox_text); + int setDefaultResId = + getArguments().getInt(ARG_SET_DEFAULT_RES_ID, R.string.set_default_account); + textView.setText(setDefaultResId); + textView.setOnClickListener((view) -> checkBox.performClick()); + checkboxLayout.setOnClickListener((view) -> checkBox.performClick()); + checkboxLayout.setContentDescription(getString(setDefaultResId)); dialog.getListView().addFooterView(checkboxLayout); } @@ -248,10 +270,15 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { private static class SelectAccountListAdapter extends ArrayAdapter { private int mResId; + private final List mHints; SelectAccountListAdapter( - Context context, int resource, List accountHandles) { + Context context, + int resource, + List accountHandles, + @Nullable List hints) { super(context, resource, accountHandles); + mHints = hints; mResId = resource; } @@ -269,6 +296,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { holder = new ViewHolder(); holder.labelTextView = (TextView) rowView.findViewById(R.id.label); holder.numberTextView = (TextView) rowView.findViewById(R.id.number); + holder.hintTextView = rowView.findViewById(R.id.hint); holder.imageView = (ImageView) rowView.findViewById(R.id.icon); rowView.setTag(holder); } else { @@ -294,6 +322,18 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { } holder.imageView.setImageDrawable( PhoneAccountCompat.createIconDrawable(account, getContext())); + if (mHints != null && position < mHints.size()) { + String hint = mHints.get(position); + if (TextUtils.isEmpty(hint)) { + holder.hintTextView.setVisibility(View.GONE); + } else { + holder.hintTextView.setVisibility(View.VISIBLE); + holder.hintTextView.setText(hint); + } + } else { + holder.hintTextView.setVisibility(View.GONE); + } + return rowView; } @@ -301,6 +341,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { TextView labelTextView; TextView numberTextView; + TextView hintTextView; ImageView imageView; } } diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java index d46e31711..fe3a5b631 100644 --- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java +++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java @@ -48,6 +48,7 @@ import com.android.dialer.preferredsim.PreferredSimFallbackContract.PreferredSim import com.android.dialer.preferredsim.suggestion.SimSuggestionComponent; import com.android.dialer.preferredsim.suggestion.SuggestionProvider.Suggestion; import com.google.common.base.Optional; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -158,22 +159,54 @@ public class CallingAccountSelector implements PreCallAction { PendingAction pendingAction, @Nullable String dataId, @Nullable String number, - @Nullable Suggestion unusedSuggestion) { // TODO(twyen): incoporate suggestion in dialog + @Nullable Suggestion suggestion) { Assert.isMainThread(); + List phoneAccountHandles = + coordinator + .getActivity() + .getSystemService(TelecomManager.class) + .getCallCapablePhoneAccounts(); selectPhoneAccountDialogFragment = SelectPhoneAccountDialogFragment.newInstance( R.string.pre_call_select_phone_account, dataId != null /* canSetDefault */, - coordinator - .getActivity() - .getSystemService(TelecomManager.class) - .getCallCapablePhoneAccounts(), + R.string.pre_call_select_phone_account_remember, + phoneAccountHandles, new SelectedListener(coordinator, pendingAction, dataId, number), - null /* call ID */); + null /* call ID */, + buildHint(coordinator.getActivity(), phoneAccountHandles, suggestion)); selectPhoneAccountDialogFragment.show( coordinator.getActivity().getFragmentManager(), TAG_CALLING_ACCOUNT_SELECTOR); } + @Nullable + private static List buildHint( + Context context, + List phoneAccountHandles, + @Nullable Suggestion suggestion) { + if (suggestion == null) { + return null; + } + List hints = new ArrayList<>(); + for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) { + if (!phoneAccountHandle.equals(suggestion.phoneAccountHandle)) { + hints.add(null); + continue; + } + switch (suggestion.reason) { + case INTRA_CARRIER: + hints.add(context.getString(R.string.pre_call_select_phone_account_hint_intra_carrier)); + break; + case FREQUENT: + hints.add(context.getString(R.string.pre_call_select_phone_account_hint_frequent)); + break; + default: + throw Assert.createAssertionFailException("unexpected reason " + suggestion.reason); + } + } + return hints; + } + @MainThread @Override public void onDiscard() { diff --git a/java/com/android/dialer/precall/impl/res/values/strings.xml b/java/com/android/dialer/precall/impl/res/values/strings.xml index 894394662..0d30ac9e5 100644 --- a/java/com/android/dialer/precall/impl/res/values/strings.xml +++ b/java/com/android/dialer/precall/impl/res/values/strings.xml @@ -19,4 +19,16 @@ multiple SIMs [CHAR LIMIT=40]--> Call with + + Remember this choice + + + Same carrier + + + You use often + \ No newline at end of file diff --git a/java/com/android/incallui/InCallActivityCommon.java b/java/com/android/incallui/InCallActivityCommon.java index e8588a67a..d2aae485d 100644 --- a/java/com/android/incallui/InCallActivityCommon.java +++ b/java/com/android/incallui/InCallActivityCommon.java @@ -524,9 +524,11 @@ public class InCallActivityCommon { SelectPhoneAccountDialogFragment.newInstance( R.string.select_phone_account_for_calls, true, + 0, phoneAccountHandles, selectAccountListener, - waitingForAccountCall.getId()); + waitingForAccountCall.getId(), + null); selectPhoneAccountDialogFragment.show( inCallActivity.getFragmentManager(), TAG_SELECT_ACCOUNT_FRAGMENT); return true; -- cgit v1.2.3