SetupWizard: Wait for data connection
Issue-id: CRACKLING-786 Change-Id: I54ef75ffa8da87d829ce7ce45a7f42ca1ce54732
This commit is contained in:
parent
ac93a6765d
commit
763af1265c
@ -30,6 +30,7 @@ import android.text.TextUtils;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
@ -45,6 +46,8 @@ public class MobileDataPage extends SetupPage {
|
|||||||
|
|
||||||
public static final String TAG = "MobileDataPage";
|
public static final String TAG = "MobileDataPage";
|
||||||
|
|
||||||
|
private static final int DC_READY_TIMEOUT = 20 * 1000;
|
||||||
|
|
||||||
public MobileDataPage(Context context, SetupDataCallbacks callbacks) {
|
public MobileDataPage(Context context, SetupDataCallbacks callbacks) {
|
||||||
super(context, callbacks);
|
super(context, callbacks);
|
||||||
}
|
}
|
||||||
@ -80,6 +83,7 @@ public class MobileDataPage extends SetupPage {
|
|||||||
private Switch mEnableMobileData;
|
private Switch mEnableMobileData;
|
||||||
private ImageView mSignalView;
|
private ImageView mSignalView;
|
||||||
private TextView mNameView;
|
private TextView mNameView;
|
||||||
|
private Button mNextButton;
|
||||||
|
|
||||||
private TelephonyManager mPhone;
|
private TelephonyManager mPhone;
|
||||||
private SignalStrength mSignalStrength;
|
private SignalStrength mSignalStrength;
|
||||||
@ -98,6 +102,13 @@ public class MobileDataPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final Runnable mDataConnectionReadyRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
onDataStateReady();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private PhoneStateListener mPhoneStateListener =
|
private PhoneStateListener mPhoneStateListener =
|
||||||
new PhoneStateListener(SubscriptionManager.getDefaultDataSubId()) {
|
new PhoneStateListener(SubscriptionManager.getDefaultDataSubId()) {
|
||||||
|
|
||||||
@ -116,6 +127,13 @@ public class MobileDataPage extends SetupPage {
|
|||||||
updateSignalStrength();
|
updateSignalStrength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataConnectionStateChanged(int state) {
|
||||||
|
if (state == TelephonyManager.DATA_CONNECTED) {
|
||||||
|
onDataStateReady();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private View.OnClickListener mEnableDataClickListener = new View.OnClickListener() {
|
private View.OnClickListener mEnableDataClickListener = new View.OnClickListener() {
|
||||||
@ -124,6 +142,11 @@ public class MobileDataPage extends SetupPage {
|
|||||||
boolean checked = !mEnableMobileData.isChecked();
|
boolean checked = !mEnableMobileData.isChecked();
|
||||||
SetupWizardUtils.setMobileDataEnabled(getActivity(), checked);
|
SetupWizardUtils.setMobileDataEnabled(getActivity(), checked);
|
||||||
mEnableMobileData.setChecked(checked);
|
mEnableMobileData.setChecked(checked);
|
||||||
|
if (checked) {
|
||||||
|
waitForData();
|
||||||
|
} else {
|
||||||
|
onDataStateReady();
|
||||||
|
}
|
||||||
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
|
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
|
||||||
SetupStats.Action.ENABLE_MOBILE_DATA,
|
SetupStats.Action.ENABLE_MOBILE_DATA,
|
||||||
SetupStats.Label.CHECKED, String.valueOf(checked));
|
SetupStats.Label.CHECKED, String.valueOf(checked));
|
||||||
@ -139,6 +162,7 @@ public class MobileDataPage extends SetupPage {
|
|||||||
mEnableMobileData = (Switch) mRootView.findViewById(R.id.data_switch);
|
mEnableMobileData = (Switch) mRootView.findViewById(R.id.data_switch);
|
||||||
mSignalView = (ImageView) mRootView.findViewById(R.id.signal);
|
mSignalView = (ImageView) mRootView.findViewById(R.id.signal);
|
||||||
mNameView = (TextView) mRootView.findViewById(R.id.enable_data_title);
|
mNameView = (TextView) mRootView.findViewById(R.id.enable_data_title);
|
||||||
|
mNextButton = (Button) getActivity().findViewById(R.id.next_button);
|
||||||
updateDataConnectionStatus();
|
updateDataConnectionStatus();
|
||||||
updateSignalStrength();
|
updateSignalStrength();
|
||||||
}
|
}
|
||||||
@ -156,7 +180,8 @@ public class MobileDataPage extends SetupPage {
|
|||||||
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
mPhone.listen(mPhoneStateListener,
|
mPhone.listen(mPhoneStateListener,
|
||||||
PhoneStateListener.LISTEN_SERVICE_STATE
|
PhoneStateListener.LISTEN_SERVICE_STATE
|
||||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
|
||||||
|
| PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
|
||||||
updateDataConnectionStatus();
|
updateDataConnectionStatus();
|
||||||
updateSignalStrength();
|
updateSignalStrength();
|
||||||
if (SetupWizardUtils.isRadioReady(mContext, null)) {
|
if (SetupWizardUtils.isRadioReady(mContext, null)) {
|
||||||
@ -180,13 +205,35 @@ public class MobileDataPage extends SetupPage {
|
|||||||
if (mTitleView != null) {
|
if (mTitleView != null) {
|
||||||
mTitleView.setText(mPage.getTitleResId());
|
mTitleView.setText(mPage.getTitleResId());
|
||||||
}
|
}
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.INVISIBLE);
|
||||||
mPageView.setVisibility(View.VISIBLE);
|
mPageView.setVisibility(View.VISIBLE);
|
||||||
mPageView.startAnimation(
|
mPageView.startAnimation(
|
||||||
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_enter));
|
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_enter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void waitForData() {
|
||||||
|
if (getUserVisibleHint() && !mProgressBar.isShown()) {
|
||||||
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
mProgressBar.startAnimation(
|
||||||
|
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_enter));
|
||||||
|
mEnableDataRow.setEnabled(false);
|
||||||
|
mNextButton.setEnabled(false);
|
||||||
|
mHandler.postDelayed(mDataConnectionReadyRunnable, DC_READY_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDataStateReady() {
|
||||||
|
mHandler.removeCallbacks(mDataConnectionReadyRunnable);
|
||||||
|
if (getUserVisibleHint() && mProgressBar.isShown()) {
|
||||||
|
mProgressBar.startAnimation(
|
||||||
|
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_exit));
|
||||||
|
mProgressBar.setVisibility(View.INVISIBLE);
|
||||||
|
mEnableDataRow.setEnabled(true);
|
||||||
|
mNextButton.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateCarrierText() {
|
private void updateCarrierText() {
|
||||||
if (mIsAttached) {
|
if (mIsAttached) {
|
||||||
String name =
|
String name =
|
||||||
|
Loading…
Reference in New Issue
Block a user