[MEP] renew the default data selection UI
- renew the default Data/Call/SMS selection Bug: 199902896 Test: build pass and local UI test Change-Id: I5c6ad4b35d38112d5e88330a3fc9638be533bc94 Merged-In: I5c6ad4b35d38112d5e88330a3fc9638be533bc94
This commit is contained in:
committed by
SongFerng Wang
parent
59a6ecbde2
commit
db2ddb6a92
@@ -3370,7 +3370,7 @@
|
||||
|
||||
<activity
|
||||
android:name=".sim.SimDialogActivity"
|
||||
android:theme="@style/Theme.AlertDialog"
|
||||
android:theme="@style/Theme.AlertDialog.SimConfirmDialog"
|
||||
android:label="@string/sim_settings_title"
|
||||
android:launchMode="singleTop"
|
||||
android:exported="true"
|
||||
|
@@ -16,42 +16,26 @@
|
||||
|
||||
<!-- Layout of a single item for displaying sim cards. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground" >
|
||||
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:scaleType="center" />
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginStart="15dip"
|
||||
android:layout_marginEnd="6dip"
|
||||
android:layout_marginTop="6dip"
|
||||
android:layout_marginBottom="6dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1" >
|
||||
<TextView android:id="@+id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:gravity="start|center_vertical"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/listPreferredItemHeightSmall"
|
||||
android:background="@drawable/sim_confirm_dialog_rounded_bg"
|
||||
android:gravity="center">
|
||||
<TextView android:id="@+id/title"
|
||||
android:textAppearance="@style/TextAppearance.SimConfirmDialogList"
|
||||
android:gravity="start|center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
<TextView android:id="@+id/summary"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textAppearance="@style/TextAppearance.SimConfirmDialogList.Summary"
|
||||
android:gravity="start|center_vertical"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/title"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_alignStart="@id/title" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.settings.sim;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Presents a dialog asking the user if they want to switch the data to another sim
|
||||
*/
|
||||
public class SelectSpecificDataSimDialogFragment extends SimDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String TAG = "PreferredSimDialogFrag";
|
||||
|
||||
private SubscriptionInfo mSubscriptionInfo;
|
||||
|
||||
/**
|
||||
* @return the dialog fragment.
|
||||
*/
|
||||
public static SelectSpecificDataSimDialogFragment newInstance() {
|
||||
final SelectSpecificDataSimDialogFragment
|
||||
fragment = new SelectSpecificDataSimDialogFragment();
|
||||
final Bundle args = initArguments(SimDialogActivity.DATA_PICK,
|
||||
R.string.select_specific_sim_for_data_title);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
final AlertDialog dialog = new AlertDialog.Builder(getContext())
|
||||
.setNegativeButton(R.string.sim_action_no_thanks, null)
|
||||
.create();
|
||||
updateDialog(dialog);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int buttonClicked) {
|
||||
if (buttonClicked != DialogInterface.BUTTON_POSITIVE) {
|
||||
return;
|
||||
}
|
||||
final SimDialogActivity activity = (SimDialogActivity) getActivity();
|
||||
final SubscriptionInfo info = getTargetSubscriptionInfo();
|
||||
if (info != null) {
|
||||
activity.onSubscriptionSelected(getDialogType(), info.getSubscriptionId());
|
||||
}
|
||||
}
|
||||
|
||||
private SubscriptionInfo getNonDefaultDataSubscriptionInfo(SubscriptionInfo dds) {
|
||||
List<SubscriptionInfo> subInfos = getSubscriptionManager().getActiveSubscriptionInfoList();
|
||||
if (subInfos == null || dds == null) {
|
||||
return null;
|
||||
}
|
||||
return subInfos.stream().filter(subinfo -> subinfo != dds).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private SubscriptionInfo getDefaultDataSubId() {
|
||||
return getSubscriptionManager().getDefaultDataSubscriptionInfo();
|
||||
}
|
||||
|
||||
private void updateDialog(AlertDialog dialog) {
|
||||
Log.d(TAG, "Dialog updated, dismiss status: " + mWasDismissed);
|
||||
if (mWasDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
SubscriptionInfo activeSubInfo = getDefaultDataSubId();
|
||||
SubscriptionInfo newSubInfo = getNonDefaultDataSubscriptionInfo(activeSubInfo);
|
||||
|
||||
if (newSubInfo == null || activeSubInfo == null) {
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
setTargetSubscriptionInfo(newSubInfo);
|
||||
|
||||
CharSequence newDataCarrierName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
||||
newSubInfo, getContext());
|
||||
CharSequence currentDataCarrierName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
||||
activeSubInfo, getContext());
|
||||
|
||||
String positive = getContext().getString(
|
||||
R.string.select_specific_sim_for_data_button, newDataCarrierName);
|
||||
String message = getContext().getString(R.string.select_specific_sim_for_data_msg,
|
||||
newDataCarrierName, currentDataCarrierName);
|
||||
|
||||
View content = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.sim_confirm_dialog_multiple_enabled_profiles_supported, null);
|
||||
TextView dialogMessage = content.findViewById(R.id.msg);
|
||||
if (!TextUtils.isEmpty(message) && dialogMessage != null) {
|
||||
dialogMessage.setText(message);
|
||||
}
|
||||
|
||||
final ListView lvItems = content.findViewById(R.id.carrier_list);
|
||||
if (lvItems != null) {
|
||||
lvItems.setVisibility(View.GONE);
|
||||
}
|
||||
final LinearLayout infoOutline = content.findViewById(R.id.info_outline_layout);
|
||||
if (infoOutline != null) {
|
||||
infoOutline.setVisibility(View.GONE);
|
||||
}
|
||||
dialog.setView(content);
|
||||
|
||||
View titleView = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.sim_confirm_dialog_title_multiple_enabled_profiles_supported, null);
|
||||
TextView titleTextView = titleView.findViewById(R.id.title);
|
||||
titleTextView.setText(getContext().getString(getTitleResId(), newDataCarrierName));
|
||||
|
||||
dialog.setCustomTitle(titleTextView);
|
||||
dialog.setButton(AlertDialog.BUTTON_POSITIVE, positive, this);
|
||||
}
|
||||
|
||||
private void setTargetSubscriptionInfo(SubscriptionInfo subInfo) {
|
||||
mSubscriptionInfo = subInfo;
|
||||
}
|
||||
|
||||
private SubscriptionInfo getTargetSubscriptionInfo() {
|
||||
return mSubscriptionInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDialog() {
|
||||
updateDialog((AlertDialog) getDialog());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected SubscriptionManager getSubscriptionManager() {
|
||||
return getContext().getSystemService(SubscriptionManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DIALOG_PREFERRED_SIM_PICKER;
|
||||
}
|
||||
}
|
@@ -95,15 +95,16 @@ public class SimDialogActivity extends FragmentActivity {
|
||||
private SimDialogFragment createFragment(int dialogType) {
|
||||
switch (dialogType) {
|
||||
case DATA_PICK:
|
||||
return SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_data,
|
||||
false /* includeAskEveryTime */);
|
||||
return getDataPickDialogFramgent();
|
||||
case CALLS_PICK:
|
||||
return CallsSimListDialogFragment.newInstance(dialogType,
|
||||
R.string.select_sim_for_calls,
|
||||
true /* includeAskEveryTime */);
|
||||
true /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */);
|
||||
case SMS_PICK:
|
||||
return SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_sms,
|
||||
true /* includeAskEveryTime */);
|
||||
true /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */);
|
||||
case PREFERRED_PICK:
|
||||
if (!getIntent().hasExtra(PREFERRED_SIM)) {
|
||||
throw new IllegalArgumentException("Missing required extra " + PREFERRED_SIM);
|
||||
@@ -111,12 +112,23 @@ public class SimDialogActivity extends FragmentActivity {
|
||||
return PreferredSimDialogFragment.newInstance();
|
||||
case SMS_PICK_FOR_MESSAGE:
|
||||
return SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_sms,
|
||||
false /* includeAskEveryTime */);
|
||||
false /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid dialog type " + dialogType + " sent.");
|
||||
}
|
||||
}
|
||||
|
||||
private SimDialogFragment getDataPickDialogFramgent() {
|
||||
if (SubscriptionManager.getDefaultDataSubscriptionId()
|
||||
== SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
return SimListDialogFragment.newInstance(DATA_PICK, R.string.select_sim_for_data,
|
||||
false /* includeAskEveryTime */,
|
||||
true /* isCancelItemShowed */);
|
||||
}
|
||||
return SelectSpecificDataSimDialogFragment.newInstance();
|
||||
}
|
||||
|
||||
public void onSubscriptionSelected(int dialogType, int subId) {
|
||||
if (getSupportFragmentManager().findFragmentByTag(Integer.toString(dialogType)) == null) {
|
||||
Log.w(TAG, "onSubscriptionSelected ignored because stored fragment was null");
|
||||
|
@@ -29,7 +29,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -38,7 +38,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -52,16 +51,19 @@ public class SimListDialogFragment extends SimDialogFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
private static final String TAG = "SimListDialogFragment";
|
||||
protected static final String KEY_INCLUDE_ASK_EVERY_TIME = "include_ask_every_time";
|
||||
protected static final String KEY_SHOW_CANCEL_ITEM = "show_cancel_item";
|
||||
private static final int LIST_VIEW_DIVIDER_LINE_WEIGHT = 2;
|
||||
|
||||
protected SelectSubscriptionAdapter mAdapter;
|
||||
@VisibleForTesting
|
||||
List<SubscriptionInfo> mSubscriptions;
|
||||
|
||||
public static SimListDialogFragment newInstance(int dialogType, int titleResId,
|
||||
boolean includeAskEveryTime) {
|
||||
boolean includeAskEveryTime, boolean isCancelItemShowed) {
|
||||
final SimListDialogFragment fragment = new SimListDialogFragment();
|
||||
final Bundle args = initArguments(dialogType, titleResId);
|
||||
args.putBoolean(KEY_INCLUDE_ASK_EVERY_TIME, includeAskEveryTime);
|
||||
args.putBoolean(KEY_SHOW_CANCEL_ITEM, isCancelItemShowed);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
@@ -72,12 +74,20 @@ public class SimListDialogFragment extends SimDialogFragment implements
|
||||
mSubscriptions = new ArrayList<>();
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(getTitleResId());
|
||||
View titleView = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.sim_confirm_dialog_title_multiple_enabled_profiles_supported, null);
|
||||
TextView titleTextView = titleView.findViewById(R.id.title);
|
||||
titleTextView.setText(getContext().getString(getTitleResId()));
|
||||
builder.setCustomTitle(titleTextView);
|
||||
|
||||
mAdapter = new SelectSubscriptionAdapter(builder.getContext(), mSubscriptions);
|
||||
|
||||
setAdapter(builder);
|
||||
final Dialog dialog = builder.create();
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
ListView listView = dialog.getListView();
|
||||
if (listView != null) {
|
||||
listView.setDividerHeight(LIST_VIEW_DIVIDER_LINE_WEIGHT);
|
||||
}
|
||||
updateDialog();
|
||||
return dialog;
|
||||
}
|
||||
@@ -112,10 +122,22 @@ public class SimListDialogFragment extends SimDialogFragment implements
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (getArguments().getBoolean(KEY_INCLUDE_ASK_EVERY_TIME)) {
|
||||
final List<SubscriptionInfo> tmp = new ArrayList<>(currentSubscriptions.size() + 1);
|
||||
boolean includeAskEveryTime = getArguments().getBoolean(KEY_INCLUDE_ASK_EVERY_TIME);
|
||||
boolean isCancelItemShowed = getArguments().getBoolean(KEY_SHOW_CANCEL_ITEM);
|
||||
if (includeAskEveryTime || isCancelItemShowed) {
|
||||
int arraySize = currentSubscriptions.size()
|
||||
+ (includeAskEveryTime ? 1 : 0)
|
||||
+ (isCancelItemShowed ? 1 : 0);
|
||||
final List<SubscriptionInfo> tmp = new ArrayList<>(arraySize);
|
||||
if (includeAskEveryTime) {
|
||||
// add the value of 'AskEveryTime' item
|
||||
tmp.add(null);
|
||||
}
|
||||
tmp.addAll(currentSubscriptions);
|
||||
if (isCancelItemShowed) {
|
||||
// add the value of 'Cancel' item
|
||||
tmp.add(null);
|
||||
}
|
||||
currentSubscriptions = tmp;
|
||||
}
|
||||
if (currentSubscriptions.equals(mSubscriptions)) {
|
||||
@@ -177,19 +199,23 @@ public class SimListDialogFragment extends SimDialogFragment implements
|
||||
|
||||
final TextView title = convertView.findViewById(R.id.title);
|
||||
final TextView summary = convertView.findViewById(R.id.summary);
|
||||
final ImageView icon = convertView.findViewById(R.id.icon);
|
||||
|
||||
if (sub == null) {
|
||||
if (position == 0) {
|
||||
title.setText(R.string.sim_calls_ask_first_prefs_title);
|
||||
summary.setText("");
|
||||
icon.setImageDrawable(mContext.getDrawable(R.drawable.ic_feedback_24dp));
|
||||
icon.setImageTintList(
|
||||
Utils.getColorAttr(mContext, android.R.attr.textColorSecondary));
|
||||
} else {
|
||||
title.setText(R.string.sim_action_cancel);
|
||||
}
|
||||
summary.setVisibility(View.GONE);
|
||||
} else {
|
||||
title.setText(SubscriptionUtil.getUniqueSubscriptionDisplayName(sub, mContext));
|
||||
summary.setText(isMdnProvisioned(sub.getNumber()) ? sub.getNumber() : "");
|
||||
icon.setImageBitmap(sub.createIconBitmap(mContext));
|
||||
|
||||
String phoneNumber = isMdnProvisioned(sub.getNumber()) ? sub.getNumber() : "";
|
||||
if (!TextUtils.isEmpty(phoneNumber)) {
|
||||
summary.setVisibility(View.VISIBLE);
|
||||
summary.setText(phoneNumber);
|
||||
} else {
|
||||
summary.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
@@ -53,7 +53,8 @@ public class SimListDialogFragmentTest extends SimDialogFragmentTestBase<SimList
|
||||
final int dialogType = DATA_PICK;
|
||||
setDialogType(dialogType);
|
||||
mFragment = spy(SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_data,
|
||||
false /* includeAskEveryTime */));
|
||||
false /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */));
|
||||
doReturn(null).when(mFragment).getCurrentSubscriptions();
|
||||
startDialog();
|
||||
verify(mFragment).dismiss();
|
||||
@@ -64,7 +65,8 @@ public class SimListDialogFragmentTest extends SimDialogFragmentTestBase<SimList
|
||||
final int dialogType = DATA_PICK;
|
||||
setDialogType(dialogType);
|
||||
mFragment = spy(SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_data,
|
||||
false /* includeAskEveryTime */));
|
||||
false /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */));
|
||||
doReturn(Arrays.asList(mSim1, mSim2)).when(mFragment).getCurrentSubscriptions();
|
||||
// Avoid problems robolectric has with our real adapter.
|
||||
doNothing().when(mFragment).setAdapter(any());
|
||||
@@ -84,7 +86,8 @@ public class SimListDialogFragmentTest extends SimDialogFragmentTestBase<SimList
|
||||
final int dialogType = DATA_PICK;
|
||||
setDialogType(dialogType);
|
||||
mFragment = spy(SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_data,
|
||||
false /* includeAskEveryTime */));
|
||||
false /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */));
|
||||
doReturn(Arrays.asList(mSim1, mSim2)).when(mFragment).getCurrentSubscriptions();
|
||||
// Avoid problems robolectric has with our real adapter.
|
||||
doNothing().when(mFragment).setAdapter(any());
|
||||
@@ -101,7 +104,8 @@ public class SimListDialogFragmentTest extends SimDialogFragmentTestBase<SimList
|
||||
final int dialogType = SMS_PICK;
|
||||
setDialogType(dialogType);
|
||||
mFragment = spy(SimListDialogFragment.newInstance(dialogType, R.string.select_sim_for_sms,
|
||||
true /* includeAskEveryTime */));
|
||||
true /* includeAskEveryTime */,
|
||||
false /* isCancelItemShowed */));
|
||||
doReturn(Arrays.asList(mSim1, mSim2)).when(mFragment).getCurrentSubscriptions();
|
||||
// Avoid problems robolectric has with our real adapter.
|
||||
doNothing().when(mFragment).setAdapter(any());
|
||||
|
Reference in New Issue
Block a user