summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/setupwizard/setup
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2015-08-18 14:02:22 -0700
committercretin45 <cretin45@gmail.com>2015-08-18 16:43:34 -0700
commit62db4521887b19c9adcbfcf5ecf2df27a9447923 (patch)
tree9ca1da474cb36e3d2bfef16887cd1ed406d7e0e8 /src/com/cyanogenmod/setupwizard/setup
parentca721f949c5acb705b9728e68b3eaf789cdc960d (diff)
downloadpackages_apps_SetupWizard-62db4521887b19c9adcbfcf5ecf2df27a9447923.zip
packages_apps_SetupWizard-62db4521887b19c9adcbfcf5ecf2df27a9447923.tar.gz
packages_apps_SetupWizard-62db4521887b19c9adcbfcf5ecf2df27a9447923.tar.bz2
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
Diffstat (limited to 'src/com/cyanogenmod/setupwizard/setup')
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java134
1 files changed, 115 insertions, 19 deletions
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<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,19 +192,25 @@ 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();
mIsAttached = false;
@@ -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());