SetupWizard: Refactor context type

Context is assumed to be SetupWizardActivity and blindly cast. Just make the Context reference a SetupWizardActivity.

Change-Id: I3d7ffd08980fbff0fbea51b45b28002b49813038
This commit is contained in:
cretin45 2015-02-23 14:33:07 -08:00
parent c4584a78e3
commit d7e70040b7
16 changed files with 47 additions and 41 deletions

View File

@ -17,22 +17,23 @@
package com.cyanogenmod.setupwizard.setup; package com.cyanogenmod.setupwizard.setup;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import java.util.ArrayList; import java.util.ArrayList;
public abstract class AbstractSetupData extends BroadcastReceiver implements SetupDataCallbacks { public abstract class AbstractSetupData extends BroadcastReceiver implements SetupDataCallbacks {
private static final String TAG = AbstractSetupData.class.getSimpleName(); private static final String TAG = AbstractSetupData.class.getSimpleName();
protected Context mContext; protected SetupWizardActivity mContext;
private ArrayList<SetupDataCallbacks> mListeners = new ArrayList<SetupDataCallbacks>(); private ArrayList<SetupDataCallbacks> mListeners = new ArrayList<SetupDataCallbacks>();
private PageList mPageList; private PageList mPageList;
private int mCurrentPageIndex = 0; private int mCurrentPageIndex = 0;
public AbstractSetupData(Context context) { public AbstractSetupData(SetupWizardActivity context) {
mContext = context; mContext = context;
mPageList = onNewPageList(); mPageList = onNewPageList();
} }

View File

@ -23,6 +23,7 @@ import android.net.ConnectivityManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyIntents;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,7 +35,7 @@ public class CMSetupWizardData extends AbstractSetupData {
private boolean mTimeSet = false; private boolean mTimeSet = false;
private boolean mTimeZoneSet = false; private boolean mTimeZoneSet = false;
public CMSetupWizardData(Context context) { public CMSetupWizardData(SetupWizardActivity context) {
super(context); super(context);
} }

View File

@ -27,7 +27,6 @@ import android.telephony.SubInfoRecord;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -38,6 +37,7 @@ import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import java.util.List; import java.util.List;
@ -45,7 +45,7 @@ public class ChooseDataSimPage extends SetupPage {
public static final String TAG = "ChooseDataSimPage"; public static final String TAG = "ChooseDataSimPage";
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) { public ChooseDataSimPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -25,13 +25,13 @@ import android.app.Activity;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.ui.LoadingFragment; import com.cyanogenmod.setupwizard.ui.LoadingFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.io.IOException; import java.io.IOException;
@ -40,7 +40,7 @@ public class CyanogenServicesPage extends SetupPage {
public static final String TAG = "CyanogenServicesPage"; public static final String TAG = "CyanogenServicesPage";
public CyanogenServicesPage(Context context, SetupDataCallbacks callbacks) { public CyanogenServicesPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }
@ -73,7 +73,7 @@ public class CyanogenServicesPage extends SetupPage {
} }
@Override @Override
public void doLoadAction(Activity context, int action) { public void doLoadAction(SetupWizardActivity context, int action) {
if (action == Page.ACTION_PREVIOUS) { if (action == Page.ACTION_PREVIOUS) {
getCallbacks().onPreviousPage(); getCallbacks().onPreviousPage();
} else { } else {

View File

@ -39,6 +39,7 @@ import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment; import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import com.cyanogenmod.setupwizard.util.WhisperPushUtils; import com.cyanogenmod.setupwizard.util.WhisperPushUtils;
@ -59,7 +60,7 @@ public class CyanogenSettingsPage extends SetupPage {
public static final String SETTING_METRICS = "settings.cyanogen.allow_metrics"; public static final String SETTING_METRICS = "settings.cyanogen.allow_metrics";
public static final String PRIVACY_POLICY_URI = "https://cyngn.com/legal/privacy-policy"; public static final String PRIVACY_POLICY_URI = "https://cyngn.com/legal/privacy-policy";
public CyanogenSettingsPage(Context context, SetupDataCallbacks callbacks) { public CyanogenSettingsPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -16,11 +16,6 @@
package com.cyanogenmod.setupwizard.setup; package com.cyanogenmod.setupwizard.setup;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity; import android.app.Activity;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
@ -46,6 +41,12 @@ import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import org.xmlpull.v1.XmlPullParserException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
@ -68,7 +69,7 @@ public class DateTimePage extends SetupPage {
private static final int HOURS_1 = 60 * 60000; private static final int HOURS_1 = 60 * 60000;
public DateTimePage(Context context, SetupDataCallbacks callbacks) { public DateTimePage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -18,11 +18,11 @@ package com.cyanogenmod.setupwizard.setup;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
public class FinishPage extends SetupPage { public class FinishPage extends SetupPage {
@ -30,7 +30,7 @@ public class FinishPage extends SetupPage {
private FinishFragment mFinishFragment; private FinishFragment mFinishFragment;
public FinishPage(Context context, SetupDataCallbacks callbacks) { public FinishPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -27,7 +27,6 @@ import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.ContentQueryMap; import android.content.ContentQueryMap;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
@ -56,7 +55,7 @@ public class GmsAccountPage extends SetupPage {
private boolean mBackupEnabled = false; private boolean mBackupEnabled = false;
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) { public GmsAccountPage(final SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
final ContentResolver res = context.getContentResolver(); final ContentResolver res = context.getContentResolver();
mBackupEnabled = Settings.Secure.getInt(res, mBackupEnabled = Settings.Secure.getInt(res,
@ -106,7 +105,7 @@ public class GmsAccountPage extends SetupPage {
} }
@Override @Override
public void doLoadAction(Activity context, int action) { public void doLoadAction(SetupWizardActivity context, int action) {
if (action == Page.ACTION_PREVIOUS) { if (action == Page.ACTION_PREVIOUS) {
getCallbacks().onPreviousPage(); getCallbacks().onPreviousPage();
} else { } else {
@ -119,7 +118,7 @@ public class GmsAccountPage extends SetupPage {
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) { if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) {
if (!mBackupEnabled && SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) { if (!mBackupEnabled && SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) {
launchGmsRestorePage((Activity) mContext); launchGmsRestorePage(mContext);
} else { } else {
handleResult(resultCode); handleResult(resultCode);
} }
@ -149,7 +148,7 @@ public class GmsAccountPage extends SetupPage {
} }
} }
private static void launchGmsRestorePage(final Activity activity) { private static void launchGmsRestorePage(final SetupWizardActivity activity) {
try { try {
// GMS can disable this after logging in sometimes // GMS can disable this after logging in sometimes
SetupWizardUtils.enableGMSSetupWizard(activity); SetupWizardUtils.enableGMSSetupWizard(activity);
@ -172,11 +171,11 @@ public class GmsAccountPage extends SetupPage {
e.printStackTrace(); e.printStackTrace();
// XXX: In open source, we don't know what gms version a user has. // XXX: In open source, we don't know what gms version a user has.
// Bail if the restore activity is not found. // Bail if the restore activity is not found.
((SetupWizardActivity) activity).onNextPage(); activity.onNextPage();
} }
} }
private void launchGmsAccountSetup(final Activity activity) { private void launchGmsAccountSetup(final SetupWizardActivity activity) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true); bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true); bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);

View File

@ -34,13 +34,14 @@ import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
public class MobileDataPage extends SetupPage { public class MobileDataPage extends SetupPage {
public static final String TAG = "MobileDataPage"; public static final String TAG = "MobileDataPage";
public MobileDataPage(Context context, SetupDataCallbacks callbacks) { public MobileDataPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -39,6 +39,7 @@ import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment; import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -52,7 +53,7 @@ public class OtherSettingsPage extends SetupPage {
private static final String PRIVACY_POLICY_URI = private static final String PRIVACY_POLICY_URI =
"https://www.google.com/intl/en/policies/privacy/?fg=1"; "https://www.google.com/intl/en/policies/privacy/?fg=1";
public OtherSettingsPage(Context context, SetupDataCallbacks callbacks) { public OtherSettingsPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -16,12 +16,13 @@
package com.cyanogenmod.setupwizard.setup; package com.cyanogenmod.setupwizard.setup;
import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
public interface Page { public interface Page {
public static final String KEY_PAGE_ARGUMENT = "key_arg"; public static final String KEY_PAGE_ARGUMENT = "key_arg";
@ -43,7 +44,7 @@ public interface Page {
public Page setHidden(boolean hidden); public Page setHidden(boolean hidden);
public boolean doPreviousAction(); public boolean doPreviousAction();
public boolean doNextAction(); public boolean doNextAction();
public void doLoadAction(Activity context, int action); public void doLoadAction(SetupWizardActivity context, int action);
public void onFinishSetup(); public void onFinishSetup();
public boolean onActivityResult(int requestCode, int resultCode, Intent data); public boolean onActivityResult(int requestCode, int resultCode, Intent data);
public SetupDataCallbacks getCallbacks(); public SetupDataCallbacks getCallbacks();

View File

@ -17,6 +17,7 @@
package com.cyanogenmod.setupwizard.setup; package com.cyanogenmod.setupwizard.setup;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
@ -37,9 +38,9 @@ public abstract class SetupPage implements Page {
private boolean mRequired = false; private boolean mRequired = false;
private boolean mHidden = false; private boolean mHidden = false;
protected final Context mContext; protected final SetupWizardActivity mContext;
protected SetupPage(Context context, SetupDataCallbacks callbacks) { protected SetupPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
mContext = context; mContext = context;
mCallbacks = callbacks; mCallbacks = callbacks;
} }
@ -73,7 +74,7 @@ public abstract class SetupPage implements Page {
public void onFinishSetup() {} public void onFinishSetup() {}
@Override @Override
public void doLoadAction(Activity context, int action) { public void doLoadAction(SetupWizardActivity context, int action) {
if (context == null || context.isFinishing()) { return; } if (context == null || context.isFinishing()) { return; }
final FragmentManager fragmentManager = context.getFragmentManager(); final FragmentManager fragmentManager = context.getFragmentManager();
Fragment fragment = getFragment(fragmentManager, action); Fragment fragment = getFragment(fragmentManager, action);

View File

@ -18,12 +18,12 @@ package com.cyanogenmod.setupwizard.setup;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.widget.ImageView; import android.widget.ImageView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
public class SimCardMissingPage extends SetupPage { public class SimCardMissingPage extends SetupPage {
@ -33,7 +33,7 @@ public class SimCardMissingPage extends SetupPage {
private static final int SIM_SIDE = 1; private static final int SIM_SIDE = 1;
private static final int SIM_BACK = 2; private static final int SIM_BACK = 2;
public SimCardMissingPage(Context context, SetupDataCallbacks callbacks) { public SimCardMissingPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -19,7 +19,6 @@ package com.cyanogenmod.setupwizard.setup;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
@ -32,6 +31,7 @@ import android.widget.NumberPicker;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.LocalePicker; import com.cyanogenmod.setupwizard.ui.LocalePicker;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import java.util.Locale; import java.util.Locale;
@ -41,7 +41,7 @@ public class WelcomePage extends SetupPage {
private static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL"; private static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
public WelcomePage(Context context, SetupDataCallbacks callbacks) { public WelcomePage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
} }

View File

@ -20,7 +20,6 @@ import android.app.Activity;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.os.Bundle; import android.os.Bundle;
@ -31,6 +30,7 @@ import android.util.Log;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.ui.LoadingFragment; import com.cyanogenmod.setupwizard.ui.LoadingFragment;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.io.IOException; import java.io.IOException;
@ -59,7 +59,7 @@ public class WifiSetupPage extends SetupPage {
private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() { private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
final Activity activity = (Activity)mContext; final Activity activity = mContext;
if (mIsCaptivePortal) { if (mIsCaptivePortal) {
try { try {
int netId = ConnectivityManager.from(activity) int netId = ConnectivityManager.from(activity)
@ -90,7 +90,7 @@ public class WifiSetupPage extends SetupPage {
} }
}; };
public WifiSetupPage(Context context, SetupDataCallbacks callbacks) { public WifiSetupPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
super(context, callbacks); super(context, callbacks);
String server = Settings.Global.getString(context.getContentResolver(), "captive_portal_server"); String server = Settings.Global.getString(context.getContentResolver(), "captive_portal_server");
if (server == null) server = DEFAULT_SERVER; if (server == null) server = DEFAULT_SERVER;
@ -130,7 +130,7 @@ public class WifiSetupPage extends SetupPage {
} }
@Override @Override
public void doLoadAction(Activity context, int action) { public void doLoadAction(SetupWizardActivity context, int action) {
super.doLoadAction(context, action); super.doLoadAction(context, action);
SetupWizardUtils.launchWifiSetup(context); SetupWizardUtils.launchWifiSetup(context);
} }

View File

@ -17,7 +17,6 @@
package com.cyanogenmod.setupwizard.ui; package com.cyanogenmod.setupwizard.ui;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
public class LoadingFragment extends SetupPageFragment { public class LoadingFragment extends SetupPageFragment {
@Override @Override