summaryrefslogtreecommitdiffstats
path: root/java/com/android/contacts
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-04-24 13:51:08 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-25 11:44:51 -0700
commit66adad0ab9921afcf3aefab270c030ceee9888df (patch)
tree67dcecd86b8a100243a6daaabd11c28d3f347c4f /java/com/android/contacts
parent05d17bda619dfdb7a729959dad098c10d67f84c8 (diff)
downloadandroid_packages_apps_Dialer-66adad0ab9921afcf3aefab270c030ceee9888df.tar.gz
android_packages_apps_Dialer-66adad0ab9921afcf3aefab270c030ceee9888df.tar.bz2
android_packages_apps_Dialer-66adad0ab9921afcf3aefab270c030ceee9888df.zip
Add "enabled" to SelectPhoneAccountDialogFragment.
This is used to inform the user an account cannot be used right now. On most dual SIM devices, only a single SIM can make calls at the same time. The UI will be implemented in a followup CL. This CL also packs the parameters of SelectPhoneAccountDialogFragment into a proto. There are too many arguments and it needs structured representation. TEST=TAP Bug: 69675796,72618783 Test: TAP PiperOrigin-RevId: 194139636 Change-Id: I7d9f92c73b650654fff28ba625a2c8e3dfa0b96c
Diffstat (limited to 'java/com/android/contacts')
-rw-r--r--java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java167
-rw-r--r--java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java55
-rw-r--r--java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto54
3 files changed, 163 insertions, 113 deletions
diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
index 295aa963a..e1fdd913b 100644
--- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
+++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
@@ -47,10 +47,9 @@ import com.android.contacts.common.R;
import com.android.contacts.common.compat.PhoneAccountCompat;
import com.android.dialer.location.GeoUtil;
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
+import com.android.dialer.protos.ProtoParsers;
import com.android.dialer.telecom.TelecomUtil;
import com.google.common.base.Optional;
-import java.util.ArrayList;
-import java.util.List;
/**
* Dialog that allows the user to select a phone accounts for a given action. Optionally provides
@@ -58,128 +57,73 @@ import java.util.List;
*/
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_OPTIONS = "options";
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<PhoneAccountHandle> mAccountHandles;
- private List<String> mHints;
- private boolean mIsSelected;
- private boolean mIsDefaultChecked;
- private SelectPhoneAccountListener mListener;
-
- public SelectPhoneAccountDialogFragment() {}
-
- /**
- * Create new fragment instance with default title and no option to set as default.
- *
- * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
- * @param listener The listener for the results of the account selection.
- */
- public static SelectPhoneAccountDialogFragment newInstance(
- List<PhoneAccountHandle> accountHandles,
- SelectPhoneAccountListener listener,
- @Nullable String callId) {
- return newInstance(
- R.string.select_account_dialog_title, false, 0, accountHandles, listener, callId, null);
- }
- /**
- * Create new fragment instance. This method also allows specifying a custom title and "set
- * default" checkbox.
- *
- * @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}
- */
+ private SelectPhoneAccountDialogOptions options =
+ SelectPhoneAccountDialogOptions.getDefaultInstance();
+ private SelectPhoneAccountListener listener;
+
+ private boolean isDefaultChecked;
+ private boolean isSelected;
+
+ /** Create new fragment instance. */
public static SelectPhoneAccountDialogFragment newInstance(
- int titleResId,
- boolean canSetDefault,
- int setDefaultResId,
- List<PhoneAccountHandle> accountHandles,
- SelectPhoneAccountListener listener,
- @Nullable String callId,
- @Nullable List<String> hints) {
- ArrayList<PhoneAccountHandle> accountHandlesCopy = new ArrayList<>();
- if (accountHandles != null) {
- accountHandlesCopy.addAll(accountHandles);
- }
+ SelectPhoneAccountDialogOptions options, SelectPhoneAccountListener listener) {
SelectPhoneAccountDialogFragment fragment = new SelectPhoneAccountDialogFragment();
- final Bundle args = new Bundle();
- args.putInt(ARG_TITLE_RES_ID, titleResId);
- args.putBoolean(ARG_CAN_SET_DEFAULT, canSetDefault);
- if (setDefaultResId != 0) {
- 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);
+ Bundle arguments = new Bundle();
+ ProtoParsers.put(arguments, ARG_OPTIONS, options);
+ fragment.setArguments(arguments);
return fragment;
}
public void setListener(SelectPhoneAccountListener listener) {
- mListener = listener;
+ this.listener = listener;
}
@Nullable
@VisibleForTesting
public SelectPhoneAccountListener getListener() {
- return mListener;
+ return listener;
}
@VisibleForTesting
public boolean canSetDefault() {
- return getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
+ return options.getCanSetDefault();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putBoolean(ARG_IS_DEFAULT_CHECKED, mIsDefaultChecked);
+ outState.putBoolean(ARG_IS_DEFAULT_CHECKED, isDefaultChecked);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
- int titleResId = getArguments().getInt(ARG_TITLE_RES_ID);
- boolean canSetDefault = getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
- mAccountHandles = getArguments().getParcelableArrayList(ARG_ACCOUNT_HANDLES);
- mListener = getArguments().getParcelable(ARG_LISTENER);
- mHints = getArguments().getStringArrayList(ARG_HINTS);
+ options =
+ ProtoParsers.getTrusted(
+ getArguments(), ARG_OPTIONS, SelectPhoneAccountDialogOptions.getDefaultInstance());
if (savedInstanceState != null) {
- mIsDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED);
+ isDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED);
}
- mIsSelected = false;
+ isSelected = false;
final DialogInterface.OnClickListener selectionListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- mIsSelected = true;
- PhoneAccountHandle selectedAccountHandle = mAccountHandles.get(which);
+ isSelected = true;
+ PhoneAccountHandle selectedAccountHandle =
+ SelectPhoneAccountDialogOptionsUtil.getPhoneAccountHandle(
+ options.getEntriesList().get(which));
Bundle result = new Bundle();
result.putParcelable(
SelectPhoneAccountListener.EXTRA_SELECTED_ACCOUNT_HANDLE, selectedAccountHandle);
- result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, mIsDefaultChecked);
+ result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, isDefaultChecked);
result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
- if (mListener != null) {
- mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result);
+ if (listener != null) {
+ listener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result);
}
}
};
@@ -188,22 +132,23 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton check, boolean isChecked) {
- mIsDefaultChecked = isChecked;
+ isDefaultChecked = isChecked;
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
ListAdapter selectAccountListAdapter =
new SelectAccountListAdapter(
- builder.getContext(), R.layout.select_account_list_item, mAccountHandles, mHints);
+ builder.getContext(), R.layout.select_account_list_item, options);
AlertDialog dialog =
builder
- .setTitle(titleResId)
+ .setTitle(
+ options.hasTitle() ? options.getTitle() : R.string.select_account_dialog_title)
.setAdapter(selectAccountListAdapter, selectionListener)
.create();
- if (canSetDefault) {
+ if (options.getCanSetDefault()) {
// Generate custom checkbox view, lint suppressed since no appropriate parent (is dialog)
@SuppressLint("InflateParams")
LinearLayout checkboxLayout =
@@ -213,11 +158,13 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
CheckBox checkBox = checkboxLayout.findViewById(R.id.default_account_checkbox_view);
checkBox.setOnCheckedChangeListener(checkListener);
- checkBox.setChecked(mIsDefaultChecked);
+ checkBox.setChecked(isDefaultChecked);
TextView textView = checkboxLayout.findViewById(R.id.default_account_checkbox_text);
int setDefaultResId =
- getArguments().getInt(ARG_SET_DEFAULT_RES_ID, R.string.set_default_account);
+ options.hasSetDefaultLabel()
+ ? options.getSetDefaultLabel()
+ : R.string.set_default_account;
textView.setText(setDefaultResId);
textView.setOnClickListener((view) -> checkBox.performClick());
checkboxLayout.setOnClickListener((view) -> checkBox.performClick());
@@ -230,17 +177,17 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
@Override
public void onCancel(DialogInterface dialog) {
- if (!mIsSelected && mListener != null) {
+ if (!isSelected && listener != null) {
Bundle result = new Bundle();
result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
- mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
+ listener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
}
super.onCancel(dialog);
}
@Nullable
private String getCallId() {
- return getArguments().getString(ARG_CALL_ID);
+ return options.getCallId();
}
public static class SelectPhoneAccountListener extends ResultReceiver {
@@ -274,18 +221,14 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
public void onDialogDismissed(@Nullable String callId) {}
}
- private static class SelectAccountListAdapter extends ArrayAdapter<PhoneAccountHandle> {
+ private static class SelectAccountListAdapter
+ extends ArrayAdapter<SelectPhoneAccountDialogOptions.Entry> {
private int mResId;
- private final List<String> mHints;
SelectAccountListAdapter(
- Context context,
- int resource,
- List<PhoneAccountHandle> accountHandles,
- @Nullable List<String> hints) {
- super(context, resource, accountHandles);
- mHints = hints;
+ Context context, int resource, SelectPhoneAccountDialogOptions options) {
+ super(context, resource, options.getEntriesList());
mResId = resource;
}
@@ -311,7 +254,9 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
holder = (ViewHolder) rowView.getTag();
}
- PhoneAccountHandle accountHandle = getItem(position);
+ SelectPhoneAccountDialogOptions.Entry entry = getItem(position);
+ PhoneAccountHandle accountHandle =
+ SelectPhoneAccountDialogOptionsUtil.getPhoneAccountHandle(entry);
PhoneAccount account =
getContext().getSystemService(TelecomManager.class).getPhoneAccount(accountHandle);
if (account == null) {
@@ -331,16 +276,12 @@ 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 {
+
+ if (TextUtils.isEmpty(entry.getHint())) {
holder.hintTextView.setVisibility(View.GONE);
+ } else {
+ holder.hintTextView.setVisibility(View.VISIBLE);
+ holder.hintTextView.setText(entry.getHint());
}
return rowView;
diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java
new file mode 100644
index 000000000..5a44ae7f8
--- /dev/null
+++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 The Android Open Source 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.contacts.common.widget;
+
+import android.telecom.PhoneAccountHandle;
+import com.android.dialer.common.Assert;
+import com.android.dialer.telecom.TelecomUtil;
+import java.util.Collection;
+
+/** Provides common operation on a {@link SelectPhoneAccountDialogOptions} */
+public final class SelectPhoneAccountDialogOptionsUtil {
+ private SelectPhoneAccountDialogOptionsUtil() {}
+
+ public static PhoneAccountHandle getPhoneAccountHandle(
+ SelectPhoneAccountDialogOptions.Entry entry) {
+ return Assert.isNotNull(
+ TelecomUtil.composePhoneAccountHandle(
+ entry.getPhoneAccountHandleComponentName(), entry.getPhoneAccountHandleId()));
+ }
+
+ public static SelectPhoneAccountDialogOptions.Entry.Builder setPhoneAccountHandle(
+ SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder,
+ PhoneAccountHandle phoneAccountHandle) {
+ entryBuilder.setPhoneAccountHandleComponentName(
+ phoneAccountHandle.getComponentName().flattenToString());
+ entryBuilder.setPhoneAccountHandleId(phoneAccountHandle.getId());
+ return entryBuilder;
+ }
+
+ public static SelectPhoneAccountDialogOptions.Builder builderWithAccounts(
+ Collection<PhoneAccountHandle> phoneAccountHandles) {
+ SelectPhoneAccountDialogOptions.Builder optionsBuilder =
+ SelectPhoneAccountDialogOptions.newBuilder();
+ for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
+ optionsBuilder.addEntries(
+ SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(
+ SelectPhoneAccountDialogOptions.Entry.newBuilder(), phoneAccountHandle));
+ }
+ return optionsBuilder;
+ }
+}
diff --git a/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto b/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto
new file mode 100644
index 000000000..9938f57ae
--- /dev/null
+++ b/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto
@@ -0,0 +1,54 @@
+// Copyright (C) 2018 The Android Open Source 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
+
+syntax = "proto2";
+
+option java_package = "com.android.contacts.common.widget";
+option java_multiple_files = true;
+option optimize_for = LITE_RUNTIME;
+
+
+package com.android.contacts.common.widget;
+
+// Parameters for SelectPhoneAccountDialogFragment
+message SelectPhoneAccountDialogOptions {
+ // The resource ID for the title. Defaults to
+ // R.string.select_account_dialog_title
+ optional int32 title = 1;
+ // Whether the dialog should include a "set as default" checkbox. Defaults to
+ // false
+ optional bool can_set_default = 2;
+ // The label on the "set as default" checkbox. Defaults
+ // R.string.set_default_account
+ optional int32 set_default_label = 3;
+ // The call ID to pass back to the callback
+ optional string call_id = 4;
+ // Phone accounts to show in the dialog
+ repeated Entry entries = 5;
+
+ message Entry {
+ // PhoneAccountHandle.getComponentName().flattenToString()
+ optional string phone_account_handle_component_name = 1;
+ // PhoneAccountHandle.getId()
+ optional string phone_account_handle_id = 2;
+ // The hint to show under the phone account, for example showing the user
+ // the account was selected frequently before.
+ optional string hint = 3;
+ // Whether the account is actually selectable. Defaults to true Sometimes an
+ // account will be temporarily unusable, for example the user is already in
+ // a call so the other SIM cannot be used. Hint should also be set to inform
+ // the user why the account is unavailable.
+ optional bool enabled = 4;
+ }
+} \ No newline at end of file