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:
parent
c4584a78e3
commit
d7e70040b7
@ -17,22 +17,23 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class AbstractSetupData extends BroadcastReceiver implements SetupDataCallbacks {
|
||||
|
||||
private static final String TAG = AbstractSetupData.class.getSimpleName();
|
||||
|
||||
protected Context mContext;
|
||||
protected SetupWizardActivity mContext;
|
||||
private ArrayList<SetupDataCallbacks> mListeners = new ArrayList<SetupDataCallbacks>();
|
||||
private PageList mPageList;
|
||||
|
||||
private int mCurrentPageIndex = 0;
|
||||
|
||||
public AbstractSetupData(Context context) {
|
||||
public AbstractSetupData(SetupWizardActivity context) {
|
||||
mContext = context;
|
||||
mPageList = onNewPageList();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import android.net.ConnectivityManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -34,7 +35,7 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||
private boolean mTimeSet = false;
|
||||
private boolean mTimeZoneSet = false;
|
||||
|
||||
public CMSetupWizardData(Context context) {
|
||||
public CMSetupWizardData(SetupWizardActivity context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ import android.telephony.SubInfoRecord;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -38,6 +37,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -45,7 +45,7 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
|
||||
public static final String TAG = "ChooseDataSimPage";
|
||||
|
||||
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public ChooseDataSimPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -25,13 +25,13 @@ import android.app.Activity;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
||||
import com.cyanogenmod.setupwizard.ui.LoadingFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -40,7 +40,7 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
|
||||
public static final String TAG = "CyanogenServicesPage";
|
||||
|
||||
public CyanogenServicesPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public CyanogenServicesPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLoadAction(Activity context, int action) {
|
||||
public void doLoadAction(SetupWizardActivity context, int action) {
|
||||
if (action == Page.ACTION_PREVIOUS) {
|
||||
getCallbacks().onPreviousPage();
|
||||
} else {
|
||||
|
@ -39,6 +39,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
|
||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||
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 PRIVACY_POLICY_URI = "https://cyngn.com/legal/privacy-policy";
|
||||
|
||||
public CyanogenSettingsPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public CyanogenSettingsPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,6 @@
|
||||
|
||||
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.AlarmManager;
|
||||
import android.app.DatePickerDialog;
|
||||
@ -46,6 +41,12 @@ import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
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.Calendar;
|
||||
import java.util.Collections;
|
||||
@ -68,7 +69,7 @@ public class DateTimePage extends SetupPage {
|
||||
private static final int HOURS_1 = 60 * 60000;
|
||||
|
||||
|
||||
public DateTimePage(Context context, SetupDataCallbacks callbacks) {
|
||||
public DateTimePage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,11 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
public class FinishPage extends SetupPage {
|
||||
|
||||
@ -30,7 +30,7 @@ public class FinishPage extends SetupPage {
|
||||
|
||||
private FinishFragment mFinishFragment;
|
||||
|
||||
public FinishPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public FinishPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ContentQueryMap;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
@ -56,7 +55,7 @@ public class GmsAccountPage extends SetupPage {
|
||||
|
||||
private boolean mBackupEnabled = false;
|
||||
|
||||
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) {
|
||||
public GmsAccountPage(final SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
final ContentResolver res = context.getContentResolver();
|
||||
mBackupEnabled = Settings.Secure.getInt(res,
|
||||
@ -106,7 +105,7 @@ public class GmsAccountPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLoadAction(Activity context, int action) {
|
||||
public void doLoadAction(SetupWizardActivity context, int action) {
|
||||
if (action == Page.ACTION_PREVIOUS) {
|
||||
getCallbacks().onPreviousPage();
|
||||
} else {
|
||||
@ -119,7 +118,7 @@ public class GmsAccountPage extends SetupPage {
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) {
|
||||
if (!mBackupEnabled && SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) {
|
||||
launchGmsRestorePage((Activity) mContext);
|
||||
launchGmsRestorePage(mContext);
|
||||
} else {
|
||||
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 {
|
||||
// GMS can disable this after logging in sometimes
|
||||
SetupWizardUtils.enableGMSSetupWizard(activity);
|
||||
@ -172,11 +171,11 @@ public class GmsAccountPage extends SetupPage {
|
||||
e.printStackTrace();
|
||||
// XXX: In open source, we don't know what gms version a user has.
|
||||
// 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.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
||||
|
@ -34,13 +34,14 @@ import android.widget.TextView;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||
|
||||
public class MobileDataPage extends SetupPage {
|
||||
|
||||
public static final String TAG = "MobileDataPage";
|
||||
|
||||
public MobileDataPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public MobileDataPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ import android.widget.TextView;
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
|
||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||
|
||||
@ -52,7 +53,7 @@ public class OtherSettingsPage extends SetupPage {
|
||||
private static final String PRIVACY_POLICY_URI =
|
||||
"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);
|
||||
}
|
||||
|
||||
|
@ -16,12 +16,13 @@
|
||||
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
public interface Page {
|
||||
|
||||
public static final String KEY_PAGE_ARGUMENT = "key_arg";
|
||||
@ -43,7 +44,7 @@ public interface Page {
|
||||
public Page setHidden(boolean hidden);
|
||||
public boolean doPreviousAction();
|
||||
public boolean doNextAction();
|
||||
public void doLoadAction(Activity context, int action);
|
||||
public void doLoadAction(SetupWizardActivity context, int action);
|
||||
public void onFinishSetup();
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data);
|
||||
public SetupDataCallbacks getCallbacks();
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
@ -37,9 +38,9 @@ public abstract class SetupPage implements Page {
|
||||
private boolean mRequired = 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;
|
||||
mCallbacks = callbacks;
|
||||
}
|
||||
@ -73,7 +74,7 @@ public abstract class SetupPage implements Page {
|
||||
public void onFinishSetup() {}
|
||||
|
||||
@Override
|
||||
public void doLoadAction(Activity context, int action) {
|
||||
public void doLoadAction(SetupWizardActivity context, int action) {
|
||||
if (context == null || context.isFinishing()) { return; }
|
||||
final FragmentManager fragmentManager = context.getFragmentManager();
|
||||
Fragment fragment = getFragment(fragmentManager, action);
|
||||
|
@ -18,12 +18,12 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
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_BACK = 2;
|
||||
|
||||
public SimCardMissingPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public SimCardMissingPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
@ -32,6 +31,7 @@ import android.widget.NumberPicker;
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.LocalePicker;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
|
||||
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";
|
||||
|
||||
public WelcomePage(Context context, SetupDataCallbacks callbacks) {
|
||||
public WelcomePage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ import android.app.Activity;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
@ -31,6 +30,7 @@ import android.util.Log;
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
||||
import com.cyanogenmod.setupwizard.ui.LoadingFragment;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
|
||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -59,7 +59,7 @@ public class WifiSetupPage extends SetupPage {
|
||||
private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Activity activity = (Activity)mContext;
|
||||
final Activity activity = mContext;
|
||||
if (mIsCaptivePortal) {
|
||||
try {
|
||||
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);
|
||||
String server = Settings.Global.getString(context.getContentResolver(), "captive_portal_server");
|
||||
if (server == null) server = DEFAULT_SERVER;
|
||||
@ -130,7 +130,7 @@ public class WifiSetupPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLoadAction(Activity context, int action) {
|
||||
public void doLoadAction(SetupWizardActivity context, int action) {
|
||||
super.doLoadAction(context, action);
|
||||
SetupWizardUtils.launchWifiSetup(context);
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.cyanogenmod.setupwizard.ui;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
|
||||
public class LoadingFragment extends SetupPageFragment {
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user