SetupWizard: Wait for data sim change

When changing the default data sim for msim, disable the next action until the operation completes.
This PS also refactors how the wait for radio logic a bit.

CRACKLING-503

Change-Id: I38ba3ea00f63d3e42c260e5b0e8558c3bc9d347f
This commit is contained in:
cretin45 2015-08-18 14:02:22 -07:00
parent ca721f949c
commit 62db452188
5 changed files with 149 additions and 29 deletions

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The CyanogenMod 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/button_bar_text_disabled" />
<item android:color="@color/button_bar_text_enabled" />
</selector>

View File

@ -21,13 +21,6 @@
<include layout="@layout/header" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="8dp" />
<FrameLayout android:id="@+id/page"
android:layout_width="match_parent"
android:layout_height="0dp"
@ -59,6 +52,15 @@
</LinearLayout>
</ScrollView>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="top"
android:visibility="gone"/>
</FrameLayout>
</LinearLayout>

View File

@ -24,7 +24,8 @@
<color name="accent">#009789</color>
<color name="primary_text">#8a000000</color>
<color name="secondary_text">#727272</color>
<color name="button_bar_text">#1e1e1e</color>
<color name="button_bar_text_enabled">#ff1e1e1e</color>
<color name="button_bar_text_disabled">#321e1e1e</color>
<color name="divider">#40000000</color>
<color name="header_bg">@color/primary</color>
<color name="header_condensed_bg">@color/primary_dark</color>

View File

@ -33,6 +33,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ProgressBar;
@ -50,6 +51,8 @@ public class ChooseDataSimPage extends SetupPage {
public static final String TAG = "ChooseDataSimPage";
private static final String CHANGE_DATA_SIM_ID_EXTRA = ".changingToId";
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}
@ -85,6 +88,8 @@ public class ChooseDataSimPage extends SetupPage {
private SparseArray<TextView> mNameViews;
private SparseArray<ImageView> mSignalViews;
private SparseArray<CheckBox> mCheckBoxes;
private SparseArray<View> mRows;
private Button mNextButton;
private TelephonyManager mPhone;
private SparseArray<SubscriptionInfo> mSubInfoRecords;
@ -93,16 +98,24 @@ public class ChooseDataSimPage extends SetupPage {
private SparseArray<PhoneStateListener> mPhoneStateListeners;
private boolean mIsAttached = false;
private boolean mRadioReady = false;
private Context mContext;
private SubscriptionManager mSubscriptionManager;
private int mCurrentDataPhoneId;
private int mChangingToDataPhoneId;
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = new Runnable() {
@Override
public void run() {
hideWaitForRadio();
// If we timeout out waiting for the radio, Oh well.
if (!mRadioReady) {
mRadioReady = true;
checkForRadioReady();
}
}
};
@ -110,9 +123,9 @@ public class ChooseDataSimPage extends SetupPage {
@Override
public void onClick(View view) {
SubscriptionInfo subInfoRecord = (SubscriptionInfo)view.getTag();
if (subInfoRecord != null) {
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId());
setDataSubChecked(subInfoRecord);
if (subInfoRecord != null &&
subInfoRecord.getSimSlotIndex() != mCurrentDataPhoneId) {
changeDataSub(subInfoRecord);
}
}
};
@ -121,6 +134,7 @@ public class ChooseDataSimPage extends SetupPage {
protected void initializePage() {
mPageView = (ViewGroup)mRootView.findViewById(R.id.page_view);
mProgressBar = (ProgressBar) mRootView.findViewById(R.id.progress);
mNextButton = (Button) getActivity().findViewById(R.id.next_button);
List<SubscriptionInfo> subInfoRecords = mSubscriptionManager.getActiveSubscriptionInfoList();
int simCount =
subInfoRecords != null ? subInfoRecords.size() : 0;
@ -131,6 +145,7 @@ public class ChooseDataSimPage extends SetupPage {
mNameViews = new SparseArray<TextView>(simCount);
mSignalViews = new SparseArray<ImageView>(simCount);
mCheckBoxes = new SparseArray<CheckBox>(simCount);
mRows = new SparseArray<View>(simCount);
mServiceStates = new SparseArray<ServiceState>(simCount);
mSignalStrengths = new SparseArray<SignalStrength>(simCount);
mPhoneStateListeners = new SparseArray<PhoneStateListener>(simCount);
@ -145,6 +160,7 @@ public class ChooseDataSimPage extends SetupPage {
mNameViews.put(slot, (TextView) simRow.findViewById(R.id.sim_title));
mSignalViews.put(slot, (ImageView) simRow.findViewById(R.id.signal));
mCheckBoxes.put(slot, (CheckBox) simRow.findViewById(R.id.enable_check));
mRows.put(slot, simRow);
mPhoneStateListeners.put(slot, createPhoneStateListener(subInfoRecord));
mPageView.addView(inflater.inflate(R.layout.divider, null));
}
@ -162,6 +178,10 @@ public class ChooseDataSimPage extends SetupPage {
super.onCreate(savedInstanceState);
mContext = getActivity().getApplicationContext();
mSubscriptionManager = SubscriptionManager.from(mContext);
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
mChangingToDataPhoneId = (savedInstanceState == null) ?
mCurrentDataPhoneId :
savedInstanceState.getInt(CHANGE_DATA_SIM_ID_EXTRA, mCurrentDataPhoneId);
}
@Override
@ -172,18 +192,24 @@ public class ChooseDataSimPage extends SetupPage {
for (int i = 0; i < mPhoneStateListeners.size(); i++) {
mPhone.listen(mPhoneStateListeners.valueAt(i),
PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
);
}
mRadioReady = SetupWizardUtils.isRadioReady(mContext, null);
updateSignalStrengths();
updateCurrentDataSub();
if (SetupWizardUtils.isRadioReady(mContext, null)) {
hideWaitForRadio();
} else if (mTitleView != null) {
mTitleView.setText(R.string.loading);
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
checkForRadioReady();
if (mRadioReady) {
checkSimChangingState();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(CHANGE_DATA_SIM_ID_EXTRA, mChangingToDataPhoneId);
}
@Override
public void onPause() {
super.onPause();
@ -204,25 +230,66 @@ public class ChooseDataSimPage extends SetupPage {
@Override
public void onServiceStateChanged(ServiceState state) {
if (SetupWizardUtils.isRadioReady(mContext, state)) {
hideWaitForRadio();
}
mRadioReady = SetupWizardUtils.isRadioReady(mContext, state);
checkForRadioReady();
mServiceStates.put(subInfoRecord.getSimSlotIndex(), state);
updateSignalStrength(subInfoRecord);
}
@Override
public void onDataConnectionStateChanged(int state) {
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
checkSimChangingState();
}
};
}
private void hideWaitForRadio() {
if (getUserVisibleHint() && mProgressBar.isShown()) {
private void checkForRadioReady() {
if (mRadioReady) {
mHandler.removeCallbacks(mRadioReadyRunnable);
hideProgress();
mNextButton.setEnabled(true);
showPage();
return;
} else {
if (mTitleView != null) {
mTitleView.setText(mPage.getTitleResId());
mTitleView.setText(R.string.loading);
}
mProgressBar.setVisibility(View.GONE);
mPageView.setVisibility(View.VISIBLE);
mNextButton.setEnabled(false);
showProgress();
if (!mHandler.hasCallbacks(mRadioReadyRunnable)) {
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
}
}
}
private void showPage() {
final Context context = getActivity();
if (mTitleView != null) {
mTitleView.setText(mPage.getTitleResId());
}
mPageView.setVisibility(View.VISIBLE);
if (context != null && getUserVisibleHint() && !mPageView.isShown()) {
mPageView.startAnimation(
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_enter));
AnimationUtils.loadAnimation(context, R.anim.translucent_enter));
}
}
private void showProgress() {
final Context context = getActivity();
if (context != null && getUserVisibleHint() && !mProgressBar.isShown()) {
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.startAnimation(
AnimationUtils.loadAnimation(context, R.anim.translucent_enter));
}
}
private void hideProgress() {
final Context context = getActivity();
if (context != null && getUserVisibleHint() && mProgressBar.isShown()) {
mProgressBar.startAnimation(
AnimationUtils.loadAnimation(context, R.anim.translucent_exit));
mProgressBar.setVisibility(View.INVISIBLE);
}
}
@ -234,6 +301,29 @@ public class ChooseDataSimPage extends SetupPage {
}
}
private void changeDataSub(SubscriptionInfo subInfoRecord) {
if (mChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) {
mChangingToDataPhoneId = subInfoRecord.getSimSlotIndex();
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId());
setDataSubChecked(subInfoRecord);
}
checkSimChangingState();
}
private void checkSimChangingState() {
if (mIsAttached && mRadioReady) {
if (mCurrentDataPhoneId != mChangingToDataPhoneId) {
showProgress();
mNextButton.setEnabled(false);
enableRows(false);
} else {
hideProgress();
mNextButton.setEnabled(true);
enableRows(true);
}
}
}
private void setDataSubChecked(SubscriptionInfo subInfoRecord) {
if (mIsAttached) {
for (int i = 0; i < mCheckBoxes.size(); i++) {
@ -260,6 +350,12 @@ public class ChooseDataSimPage extends SetupPage {
}
}
private void enableRows(boolean enabled) {
for (int i = 0; i < mRows.size(); i++) {
mRows.get(i).setEnabled(enabled);
}
}
private void updateCarrierText(SubscriptionInfo subInfoRecord) {
if (mIsAttached) {
String name = mPhone.getNetworkOperatorName(subInfoRecord.getSubscriptionId());

View File

@ -265,8 +265,8 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks,
mButtonBar.setBackgroundResource(R.color.button_bar_background);
mNextButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
getDrawable(R.drawable.ic_chevron_right_dark), null);
mNextButton.setTextColor(resources.getColor(R.color.button_bar_text));
mPrevButton.setTextColor(resources.getColor(R.color.button_bar_text));
mNextButton.setTextColor(resources.getColorStateList(R.color.button_bar_text));
mPrevButton.setTextColor(resources.getColorStateList(R.color.button_bar_text));
}
}