SetupWizard: Improved show/hide page logic
Change-Id: I23212a97c0435ee69db46c8b478207c62e3b07cb
This commit is contained in:
parent
b0e3ace8ca
commit
cb291e170c
|
@ -30,22 +30,11 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||||
|
|
||||||
private static final String TAG = CMSetupWizardData.class.getSimpleName();
|
private static final String TAG = CMSetupWizardData.class.getSimpleName();
|
||||||
|
|
||||||
private final TelephonyManager mTelephonyManager;
|
|
||||||
|
|
||||||
private boolean mTimeSet = false;
|
private boolean mTimeSet = false;
|
||||||
private boolean mTimeZoneSet = false;
|
private boolean mTimeZoneSet = false;
|
||||||
|
|
||||||
private final int mSimSlotCount;
|
|
||||||
private final int[] mSimStates;
|
|
||||||
|
|
||||||
public CMSetupWizardData(Context context) {
|
public CMSetupWizardData(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mTelephonyManager = TelephonyManager.from(context);
|
|
||||||
mSimSlotCount = mTelephonyManager.getPhoneCount();
|
|
||||||
mSimStates = new int[mSimSlotCount];
|
|
||||||
for (int i = 0; i < mSimSlotCount; i++) {
|
|
||||||
mSimStates[i] = TelephonyManager.SIM_STATE_ABSENT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,14 +43,14 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||||
pages.add(new WelcomePage(mContext, this));
|
pages.add(new WelcomePage(mContext, this));
|
||||||
pages.add(new WifiSetupPage(mContext, this));
|
pages.add(new WifiSetupPage(mContext, this));
|
||||||
if (SetupWizardUtils.hasTelephony(mContext)) {
|
if (SetupWizardUtils.hasTelephony(mContext)) {
|
||||||
pages.add(new SimCardMissingPage(mContext, this).setHidden(true));
|
pages.add(new SimCardMissingPage(mContext, this).setHidden(isSimInserted()));
|
||||||
}
|
}
|
||||||
if (SetupWizardUtils.isMultiSimDevice(mContext)) {
|
if (SetupWizardUtils.isMultiSimDevice(mContext)) {
|
||||||
pages.add(new ChooseDataSimPage(mContext, this));
|
pages.add(new ChooseDataSimPage(mContext, this).setHidden(!allSimsInserted()));
|
||||||
}
|
}
|
||||||
if (SetupWizardUtils.hasTelephony(mContext) &&
|
if (SetupWizardUtils.hasTelephony(mContext)) {
|
||||||
!SetupWizardUtils.isMobileDataEnabled(mContext)) {
|
pages.add(new MobileDataPage(mContext, this)
|
||||||
pages.add(new MobileDataPage(mContext, this));
|
.setHidden(!isSimInserted() || SetupWizardUtils.isMobileDataEnabled(mContext)));
|
||||||
}
|
}
|
||||||
if (SetupWizardUtils.hasGMS(mContext)) {
|
if (SetupWizardUtils.hasGMS(mContext)) {
|
||||||
pages.add(new GmsAccountPage(mContext, this));
|
pages.add(new GmsAccountPage(mContext, this));
|
||||||
|
@ -78,36 +67,53 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
|
if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
|
||||||
int slot = intent.getIntExtra("slot", -1);
|
ChooseDataSimPage chooseDataSimPage =
|
||||||
if (slot != -1 && mSimStates.length > 0) {
|
(ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
|
||||||
mSimStates[slot] = mTelephonyManager.getSimState(slot);
|
if (chooseDataSimPage != null) {
|
||||||
}
|
chooseDataSimPage.setHidden(!allSimsInserted());
|
||||||
|
}
|
||||||
|
SimCardMissingPage simCardMissingPage =
|
||||||
|
(SimCardMissingPage) getPage(SimCardMissingPage.TAG);
|
||||||
|
if (simCardMissingPage != null) {
|
||||||
|
simCardMissingPage.setHidden(isSimInserted());
|
||||||
|
}
|
||||||
|
showHideMobileDataPage();
|
||||||
|
} else if (intent.getAction()
|
||||||
|
.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
|
||||||
|
showHideMobileDataPage();
|
||||||
} else if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED) ||
|
} else if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED) ||
|
||||||
intent.getAction().equals(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE)) {
|
intent.getAction().equals(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE)) {
|
||||||
mTimeZoneSet = true;
|
mTimeZoneSet = true;
|
||||||
|
showHideDateTimePage();
|
||||||
} else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED) ||
|
} else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED) ||
|
||||||
intent.getAction().equals(TelephonyIntents.ACTION_NETWORK_SET_TIME)) {
|
intent.getAction().equals(TelephonyIntents.ACTION_NETWORK_SET_TIME)) {
|
||||||
mTimeSet = true;
|
mTimeSet = true;
|
||||||
|
showHideDateTimePage();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHideMobileDataPage() {
|
||||||
|
MobileDataPage mobileDataPage =
|
||||||
|
(MobileDataPage) getPage(MobileDataPage.TAG);
|
||||||
|
if (mobileDataPage != null) {
|
||||||
|
mobileDataPage.setHidden(!isSimInserted() ||
|
||||||
|
SetupWizardUtils.isMobileDataEnabled(mContext));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHideDateTimePage() {
|
||||||
DateTimePage dateTimePage = (DateTimePage) getPage(DateTimePage.TAG);
|
DateTimePage dateTimePage = (DateTimePage) getPage(DateTimePage.TAG);
|
||||||
dateTimePage.setHidden(mTimeZoneSet & mTimeSet);
|
if (dateTimePage != null) {
|
||||||
|
dateTimePage.setHidden(mTimeZoneSet & mTimeSet);
|
||||||
SimCardMissingPage simCardMissingPage =
|
|
||||||
(SimCardMissingPage) getPage(SimCardMissingPage.TAG);
|
|
||||||
if (simCardMissingPage != null) {
|
|
||||||
simCardMissingPage.setHidden(isSimInserted());
|
|
||||||
}
|
|
||||||
|
|
||||||
ChooseDataSimPage chooseDataSimPage =
|
|
||||||
(ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
|
|
||||||
if (chooseDataSimPage != null) {
|
|
||||||
chooseDataSimPage.setHidden(!allSimsInserted());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntentFilter getIntentFilter() {
|
public IntentFilter getIntentFilter() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
|
if (SetupWizardUtils.hasTelephony(mContext)) {
|
||||||
|
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
|
||||||
|
filter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
|
||||||
|
}
|
||||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||||
filter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIME);
|
filter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIME);
|
||||||
|
@ -117,7 +123,10 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||||
|
|
||||||
// We only care that one sim is inserted
|
// We only care that one sim is inserted
|
||||||
private boolean isSimInserted() {
|
private boolean isSimInserted() {
|
||||||
for (int state : mSimStates) {
|
TelephonyManager tm = TelephonyManager.from(mContext);
|
||||||
|
int simSlotCount = tm.getSimCount();
|
||||||
|
for (int i = 0; i < simSlotCount; i++) {
|
||||||
|
int state = tm.getSimState(i);
|
||||||
if (state != TelephonyManager.SIM_STATE_ABSENT
|
if (state != TelephonyManager.SIM_STATE_ABSENT
|
||||||
&& state != TelephonyManager.SIM_STATE_UNKNOWN) {
|
&& state != TelephonyManager.SIM_STATE_UNKNOWN) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -126,9 +135,12 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only care the each slot has a sim
|
// We only care that each slot has a sim
|
||||||
private boolean allSimsInserted() {
|
private boolean allSimsInserted() {
|
||||||
for (int state : mSimStates) {
|
TelephonyManager tm = TelephonyManager.from(mContext);
|
||||||
|
int simSlotCount = tm.getSimCount();
|
||||||
|
for (int i = 0; i < simSlotCount; i++) {
|
||||||
|
int state = tm.getSimState(i);
|
||||||
if (state == TelephonyManager.SIM_STATE_ABSENT) {
|
if (state == TelephonyManager.SIM_STATE_ABSENT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue