diff options
author | Nancy Chen <nancychen@google.com> | 2014-10-21 18:53:11 -0700 |
---|---|---|
committer | Nancy Chen <nancychen@google.com> | 2014-10-22 17:38:13 -0700 |
commit | 90917145825ca7e8e34d407c72c80a15300fafdc (patch) | |
tree | d057175fc73c345fd621200ad35086f25fdd2403 | |
parent | 14558de5e203f981433d51b46a795a3a980c3e33 (diff) | |
download | android_packages_apps_ContactsCommon-90917145825ca7e8e34d407c72c80a15300fafdc.tar.gz android_packages_apps_ContactsCommon-90917145825ca7e8e34d407c72c80a15300fafdc.tar.bz2 android_packages_apps_ContactsCommon-90917145825ca7e8e34d407c72c80a15300fafdc.zip |
Add an option to set the selected phone account as the default. (3/3)
Modify the phoneAccountSelected method to support the option to set the
selected phone account as the default for outgoing phone calls.
Add checkbox to the select account dialog for user interaction.
Bug: 18078232
Change-Id: I7e6af5238fe2ff95d7f1e0622f7fa24111147f4e
-rw-r--r-- | res/layout/default_account_checkbox.xml | 38 | ||||
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java | 49 |
3 files changed, 81 insertions, 10 deletions
diff --git a/res/layout/default_account_checkbox.xml b/res/layout/default_account_checkbox.xml new file mode 100644 index 00000000..15180761 --- /dev/null +++ b/res/layout/default_account_checkbox.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/default_account_checkbox_layout" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="8dip" + android:orientation="vertical"> + <!-- Dummy to enable right-justification of checkbox --> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + <CheckBox + android:id="@+id/default_account_checkbox_view" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="20dip" + android:layout_marginLeft="20dip" + android:layout_marginBottom="20dip" + android:gravity="center" + android:textSize="14sp" + android:textAlignment="viewStart" + android:text="@string/set_default_account"/> +</LinearLayout>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 34449577..0f6cea03 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -768,4 +768,8 @@ a ren't members of any other group. [CHAR LIMIT=25] --> <!-- Title for Select Account Dialog [CHAR LIMIT=30] --> <string name="select_account_dialog_title">Select Account</string> + + <!-- Label for the check box to toggle default sim card setting [CHAR LIMIT=35]--> + <string name="set_default_account">Always use this for calls</string> + </resources> diff --git a/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java index f88d7191..0dbe70a8 100644 --- a/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java +++ b/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java @@ -18,7 +18,6 @@ package com.android.contacts.common.widget; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; - import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; @@ -31,7 +30,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.TextView; @@ -40,11 +42,14 @@ import com.android.contacts.common.R; import java.util.List; /** - * Dialog that allows the user to switch between default SIM cards + * Dialog that allows the user to select a phone accounts for a given action. Optionally provides + * the choice to set the phone account as default. */ public class SelectPhoneAccountDialogFragment extends DialogFragment { + private boolean mCanSetDefault; private List<PhoneAccountHandle> mAccountHandles; private boolean mIsSelected; + private boolean mIsDefaultChecked; private TelecomManager mTelecomManager; private SelectPhoneAccountListener mListener; @@ -55,28 +60,30 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { * @param fragmentManager The fragment manager. * @param accountHandles The {@code PhoneAccountHandle}s available to select from. */ - public static void showAccountDialog(FragmentManager fragmentManager, + public static void showAccountDialog(FragmentManager fragmentManager, boolean canSetDefault, List<PhoneAccountHandle> accountHandles, SelectPhoneAccountListener listener) { SelectPhoneAccountDialogFragment fragment = - new SelectPhoneAccountDialogFragment(accountHandles, listener); + new SelectPhoneAccountDialogFragment(canSetDefault, accountHandles, listener); fragment.show(fragmentManager, "selectAccount"); } - public SelectPhoneAccountDialogFragment(List<PhoneAccountHandle> accountHandles, - SelectPhoneAccountListener listener) { + public SelectPhoneAccountDialogFragment(boolean canSetDefault, + List<PhoneAccountHandle> accountHandles, SelectPhoneAccountListener listener) { super(); + mCanSetDefault = canSetDefault; mAccountHandles = accountHandles; mListener = listener; } public interface SelectPhoneAccountListener { - void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle); + void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, boolean setDefault); void onDialogDismissed(); } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { mIsSelected = false; + mIsDefaultChecked = false; mTelecomManager = (TelecomManager) getActivity().getSystemService(Context.TELECOM_SERVICE); @@ -86,20 +93,42 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { public void onClick(DialogInterface dialog, int which) { mIsSelected = true; PhoneAccountHandle selectedAccountHandle = mAccountHandles.get(which); - mListener.onPhoneAccountSelected(selectedAccountHandle); + mListener.onPhoneAccountSelected(selectedAccountHandle, mIsDefaultChecked); } }; - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + final CompoundButton.OnCheckedChangeListener checkListener = + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton check, boolean isChecked) { + mIsDefaultChecked = isChecked; + } + }; + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); ListAdapter selectAccountListAdapter = new SelectAccountListAdapter( builder.getContext(), R.layout.select_account_list_item, mAccountHandles); - return builder.setTitle(R.string.select_account_dialog_title) + AlertDialog dialog = builder.setTitle(R.string.select_account_dialog_title) .setAdapter(selectAccountListAdapter, selectionListener) .create(); + + if (mCanSetDefault) { + // Generate custom checkbox view + LinearLayout checkboxLayout = (LinearLayout) getActivity() + .getLayoutInflater() + .inflate(R.layout.default_account_checkbox, null); + + CheckBox cb = + (CheckBox) checkboxLayout.findViewById(R.id.default_account_checkbox_view); + cb.setOnCheckedChangeListener(checkListener); + + dialog.getListView().addFooterView(checkboxLayout); + } + + return dialog; } private class SelectAccountListAdapter extends ArrayAdapter<PhoneAccountHandle> { |