SetupWizard: Add receivers for sim state and time

Change-Id: I8d44623e898eaa175d69d682c8089caa1a58f287
This commit is contained in:
cretin45 2015-01-29 17:36:30 -08:00
parent b0167c853f
commit 106a127508
7 changed files with 118 additions and 34 deletions

View File

@ -16,12 +16,13 @@
package com.cyanogenmod.setupwizard.setup;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.Bundle;
import java.util.ArrayList;
public abstract class AbstractSetupData implements SetupDataCallbacks {
public abstract class AbstractSetupData extends BroadcastReceiver implements SetupDataCallbacks {
private static final String TAG = AbstractSetupData.class.getSimpleName();

View File

@ -16,29 +16,47 @@
package com.cyanogenmod.setupwizard.setup;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import android.content.Context;
import android.telephony.SubscriptionManager;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.TelephonyManager;
import com.android.internal.telephony.TelephonyIntents;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.util.ArrayList;
public class CMSetupWizardData extends AbstractSetupData {
private static final String TAG = CMSetupWizardData.class.getSimpleName();
private final TelephonyManager mTelephonyManager;
private boolean mTimeSet = false;
private boolean mTimeZoneSet = false;
private final int mSimSlotCount;
private final int[] mSimStates;
public CMSetupWizardData(Context 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
protected PageList onNewPageList() {
ArrayList<SetupPage> pages = new ArrayList<SetupPage>();
ArrayList<Page> pages = new ArrayList<Page>();
pages.add(new WelcomePage(mContext, this));
pages.add(new WifiSetupPage(mContext, this));
if (SetupWizardUtils.isSimMissing(mContext)) {
pages.add(new SimCardMissingPage(mContext, this));
if (TelephonyManager.from(mContext).getSimCount() > 0) {
pages.add(new SimCardMissingPage(mContext, this).setHidden(true));
}
if (SetupWizardUtils.isMultiSimDevice(mContext)
&& SubscriptionManager.getActiveSubInfoCount() > 1) {
if (SetupWizardUtils.isMultiSimDevice(mContext)) {
pages.add(new ChooseDataSimPage(mContext, this));
}
if (SetupWizardUtils.hasTelephony(mContext) &&
@ -57,4 +75,61 @@ public class CMSetupWizardData extends AbstractSetupData {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
int slot = intent.getIntExtra("slot", -1);
if (slot != -1 && mSimStates.length > 0) {
mSimStates[slot] = mTelephonyManager.getSimState(slot);
}
} else if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
mTimeZoneSet = true;
} else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) {
mTimeSet = true;
}
DateTimePage dateTimePage = (DateTimePage) getPage(DateTimePage.TAG);
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() {
IntentFilter filter = new IntentFilter();
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(Intent.ACTION_TIME_CHANGED);
return filter;
}
// We only care that one sim is inserted
private boolean isSimInserted() {
for (int state : mSimStates) {
if (state != TelephonyManager.SIM_STATE_ABSENT
&& state != TelephonyManager.SIM_STATE_UNKNOWN) {
return true;
}
}
return false;
}
// We only care the each slot has a sim
private boolean allSimsInserted() {
for (int state : mSimStates) {
if (state == TelephonyManager.SIM_STATE_ABSENT) {
return false;
}
}
return true;
}
}

View File

@ -107,6 +107,7 @@ public class CyanogenServicesPage extends SetupPage {
Bundle bundle = new Bundle();
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
bundle.putBoolean(SetupWizardApp.EXTRA_SHOW_BUTTON_BAR, true);
bundle.putBoolean(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
AccountManager.get(activity)
.addAccount(activity.getString(R.string.cm_account_type), null, null, bundle,
null, new AccountManagerCallback<Bundle>() {

View File

@ -68,11 +68,6 @@ public class FinishPage extends SetupPage {
return R.string.start;
}
@Override
public int getPrevButtonTitleResId() {
return -1;
}
public static class FinishFragment extends SetupPageFragment {
@Override

View File

@ -40,7 +40,7 @@ public interface Page {
public boolean isRequired();
public Page setRequired(boolean required);
public boolean isHidden();
public void setHidden(boolean hidden);
public Page setHidden(boolean hidden);
public boolean doPreviousAction();
public boolean doNextAction();
public void doLoadAction(Activity context, int action);

View File

@ -111,8 +111,9 @@ public abstract class SetupPage implements Page {
}
@Override
public void setHidden(boolean hidden) {
public Page setHidden(boolean hidden) {
mHidden = hidden;
return this;
}
@Override

View File

@ -33,7 +33,6 @@ import android.widget.Button;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.setup.AbstractSetupData;
import com.cyanogenmod.setupwizard.setup.CMSetupWizardData;
import com.cyanogenmod.setupwizard.setup.CyanogenServicesPage;
import com.cyanogenmod.setupwizard.setup.CyanogenSettingsPage;
@ -53,7 +52,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
private Button mPrevButton;
private View mReveal;
private AbstractSetupData mSetupData;
private EnableAccessibilityController mEnableAccessibilityController;
private CMSetupWizardData mSetupData;
private final Handler mHandler = new Handler();
@ -63,7 +64,7 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
getWindow().setWindowAnimations(android.R.anim.fade_in);
mRootView = findViewById(R.id.root);
((SetupWizardApp)getApplicationContext()).disableStatusBar();
mSetupData = (AbstractSetupData)getLastNonConfigurationInstance();
mSetupData = (CMSetupWizardData)getLastNonConfigurationInstance();
if (mSetupData == null) {
mSetupData = new CMSetupWizardData(this);
}
@ -90,13 +91,15 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
if (savedInstanceState != null && savedInstanceState.containsKey("data")) {
mSetupData.load(savedInstanceState.getBundle("data"));
}
final EnableAccessibilityController acc = new EnableAccessibilityController(this);
mRootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return acc.onInterceptTouchEvent(event);
}
});
if (EnableAccessibilityController.canEnableAccessibilityViaGesture(this)) {
mEnableAccessibilityController = new EnableAccessibilityController(this);
mRootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mEnableAccessibilityController.onInterceptTouchEvent(event);
}
});
}
// Since this is a new component, we need to disable here if the user
// has already been through setup on a previous version.
try {
@ -107,6 +110,7 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
} catch (Settings.SettingNotFoundException e) {
// Continue with setup
}
registerReceiver(mSetupData, mSetupData.getIntentFilter());
}
@Override
@ -118,7 +122,11 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
@Override
protected void onDestroy() {
super.onDestroy();
if (mEnableAccessibilityController != null) {
mEnableAccessibilityController.onDestroy();
}
mSetupData.unregisterListener(this);
unregisterReceiver(mSetupData);
}
@Override
@ -139,9 +147,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
@Override
public void onBackPressed() {
if (!mSetupData.isFirstPage()) {
mSetupData.onPreviousPage();
}
if (!mSetupData.isFirstPage()) {
mSetupData.onPreviousPage();
}
}
@Override
@ -161,10 +169,11 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
if (getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE &&
mSetupData.isFirstPage()) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
} else {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
updateButtonBar();
}
@ -191,13 +200,15 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
}
final Resources resources = getResources();
if (mSetupData.isLastPage()) {
mPrevButton.setVisibility(View.INVISIBLE);
mRootView.setBackgroundColor(resources.getColor(R.color.primary));
mNextButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
getDrawable(R.drawable.ic_chevron_right_wht), null);
mNextButton.setTextColor(resources.getColor(R.color.white));
mPrevButton.setCompoundDrawablesWithIntrinsicBounds(
getDrawable(R.drawable.ic_chevron_left_wht), null,
null, null);
mPrevButton.setTextColor(resources.getColor(R.color.white));
} else {
mPrevButton.setVisibility(View.VISIBLE);
mRootView.setBackgroundColor(resources.getColor(R.color.window_background));
mNextButton.setCompoundDrawablesWithIntrinsicBounds(null, null,
getDrawable(R.drawable.ic_chevron_right_dark), null);