From 62db4521887b19c9adcbfcf5ecf2df27a9447923 Mon Sep 17 00:00:00 2001 From: cretin45 Date: Tue, 18 Aug 2015 14:02:22 -0700 Subject: [PATCH] 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 --- res/color/button_bar_text.xml | 21 +++ res/layout/choose_data_sim_page.xml | 16 ++- res/values/colors.xml | 3 +- .../setupwizard/setup/ChooseDataSimPage.java | 134 +++++++++++++++--- .../setupwizard/ui/SetupWizardActivity.java | 4 +- 5 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 res/color/button_bar_text.xml diff --git a/res/color/button_bar_text.xml b/res/color/button_bar_text.xml new file mode 100644 index 0000000..c670d2d --- /dev/null +++ b/res/color/button_bar_text.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/res/layout/choose_data_sim_page.xml b/res/layout/choose_data_sim_page.xml index d470dbd..c93a89f 100644 --- a/res/layout/choose_data_sim_page.xml +++ b/res/layout/choose_data_sim_page.xml @@ -21,13 +21,6 @@ - - + + diff --git a/res/values/colors.xml b/res/values/colors.xml index 7943291..34110b7 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -24,7 +24,8 @@ #009789 #8a000000 #727272 - #1e1e1e + #ff1e1e1e + #321e1e1e #40000000 @color/primary @color/primary_dark diff --git a/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java b/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java index af123e0..e053399 100644 --- a/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java +++ b/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java @@ -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 mNameViews; private SparseArray mSignalViews; private SparseArray mCheckBoxes; + private SparseArray mRows; + private Button mNextButton; private TelephonyManager mPhone; private SparseArray mSubInfoRecords; @@ -93,16 +98,24 @@ public class ChooseDataSimPage extends SetupPage { private SparseArray 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 subInfoRecords = mSubscriptionManager.getActiveSubscriptionInfoList(); int simCount = subInfoRecords != null ? subInfoRecords.size() : 0; @@ -131,6 +145,7 @@ public class ChooseDataSimPage extends SetupPage { mNameViews = new SparseArray(simCount); mSignalViews = new SparseArray(simCount); mCheckBoxes = new SparseArray(simCount); + mRows = new SparseArray(simCount); mServiceStates = new SparseArray(simCount); mSignalStrengths = new SparseArray(simCount); mPhoneStateListeners = new SparseArray(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()); diff --git a/src/com/cyanogenmod/setupwizard/ui/SetupWizardActivity.java b/src/com/cyanogenmod/setupwizard/ui/SetupWizardActivity.java index afa861a..373e7e8 100644 --- a/src/com/cyanogenmod/setupwizard/ui/SetupWizardActivity.java +++ b/src/com/cyanogenmod/setupwizard/ui/SetupWizardActivity.java @@ -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)); } }