SetupWizard: Add option to apply default theme if one exists

* A bunch of code cleanup/refactoring to make this work

Change-Id: I059fb5fa5bcd7dd8821e993218a320554f10a314
This commit is contained in:
cretin45 2015-02-23 13:52:37 -08:00
parent 1d54e5207a
commit 01f21da16b
23 changed files with 375 additions and 168 deletions

View File

@ -77,6 +77,7 @@
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:uiOptions="none"
android:configChanges="themeChange|mcc|mnc"
android:immersive="true">
<intent-filter android:priority="9">

View File

@ -86,6 +86,42 @@
</LinearLayout>
<!-- Whether or not to enable default theme -->
<LinearLayout
android:id="@+id/theme"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/location_margin_left"
android:paddingRight="@dimen/content_margin_right"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<CheckBox
android:id="@+id/enable_theme_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:duplicateParentState="true"
android:clickable="false"/>
<TextView
android:id="@+id/enable_theme_summary"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="15sp"
android:lineSpacingExtra="@dimen/setup_line_spacing"
android:gravity="top"
android:layout_marginLeft="@dimen/location_text_margin_left"
android:layout_marginRight="@dimen/location_text_margin_right"
android:paddingBottom="@dimen/content_margin_bottom"
android:text="@string/services_metrics_label"/>
</LinearLayout>
<!-- Checkbox for using on-screen nav keys -->
<LinearLayout
android:id="@+id/nav_keys"

View File

@ -45,5 +45,13 @@
android:background="@drawable/reveal"
android:visibility="invisible"/>
<ProgressBar
android:id="@+id/finishing_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:visibility="gone"/>
</com.cyanogenmod.setupwizard.ui.widget.ScrimInsetsFrameLayout>

View File

@ -18,6 +18,7 @@
<string name="app_name">Setup Wizard</string>
<string name="product_name" translatable="false">cyanogenmod</string>
<string name="os_name" translatable="false">CyanogenMod</string>
<string name="default_theme_name" translatable="false">Material</string>
<string name="cm_account_type" translatable="false">com.cyanogenmod.account</string>
@ -67,12 +68,14 @@
<string name="emergency_call">Emergency call</string>
<string name="setup_services">Cyanogen services</string>
<string name="services_explanation" product="tablet">These services work for you to extend the capabilities of your tablet. You can turn them off at anytime. Data will be used in accordance with Cyanogen\'s <xliff:g id="name" example="Privacy Policy">%s</xliff:g>.</string>
<string name="services_explanation" product="default">These services work for you to extend the capabilities of your phone. You can turn them off at anytime. Data will be used in accordance with Cyanogen\'s <xliff:g id="name" example="Privacy Policy">%s</xliff:g>.</string>
<string name="setup_services">Cyanogen features</string>
<string name="services_explanation" product="tablet">These services work for you to extend the capabilities of your tablet. Data will be used in accordance with Cyanogen\'s <xliff:g id="name" example="Privacy Policy">%s</xliff:g>.</string>
<string name="services_explanation" product="default">These services work for you to extend the capabilities of your phone. Data will be used in accordance with Cyanogen\'s <xliff:g id="name" example="Privacy Policy">%s</xliff:g>.</string>
<string name="services_privacy_policy">Privacy Policy</string>
<string name="services_help_improve_cm">Help improve <xliff:g id="name" example="CyanogenMod">%s</xliff:g></string>
<string name="services_metrics_label"><xliff:g id="name" example="Help improve CyanogenMod">%s</xliff:g> by automatically sending diagnostic and usage data to Cyanogen. This information cant be used to identify you and lends a hand to teams working on things like battery life, app performance, and new <xliff:g id="name" example="CyanogenMod">%s</xliff:g> features.</string>
<string name="services_apply_theme">Apply the <xliff:g id="name" example="Material">%s</xliff:g> theme</string>
<string name="services_apply_theme_label"><xliff:g id="name" example="Apply the Material theme">%s</xliff:g> enabling unique icons, wallpapers, and fonts.</string>
<string name="services_os_nav_keys_label"><b>Use on screen navigation keys</b> instead of hardware keys.</string>
<string name="services_use_secure_sms">Use secure SMS</string>
<string name="services_secure_sms_label"><xliff:g id="name" example="Use secure SMS">%s</xliff:g> to encrypt SMS conversations with other users using secure SMS on a <xliff:g id="name" example="CyanogenMod">%s</xliff:g> device.</string>

View File

@ -17,33 +17,30 @@
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 SetupWizardActivity mContext;
protected final Context mContext;
private ArrayList<SetupDataCallbacks> mListeners = new ArrayList<SetupDataCallbacks>();
private PageList mPageList;
private int mCurrentPageIndex = 0;
private boolean mIsResumed = false;
private OnResumeRunnable mOnResumeRunnable;
public AbstractSetupData(SetupWizardActivity context) {
public AbstractSetupData(Context context) {
mContext = context;
mPageList = onNewPageList();
}
public void setContext(SetupWizardActivity context) {
mContext = context;
}
protected abstract PageList onNewPageList();
@Override
@ -67,6 +64,13 @@ public abstract class AbstractSetupData extends BroadcastReceiver implements Set
}
}
@Override
public void finishSetup() {
for (int i = 0; i < mListeners.size(); i++) {
mListeners.get(i).finishSetup();
}
}
@Override
public Page getPage(String key) {
return mPageList.getPage(key);
@ -159,7 +163,7 @@ public abstract class AbstractSetupData extends BroadcastReceiver implements Set
}
private void doPreviousNext(Runnable runnable) {
if (mContext.isResumed()) {
if (mIsResumed) {
runnable.run();
} else {
mOnResumeRunnable = new OnResumeRunnable(runnable, this);
@ -170,7 +174,12 @@ public abstract class AbstractSetupData extends BroadcastReceiver implements Set
mOnResumeRunnable = null;
}
public void onPause() {
mIsResumed = false;
}
public void onResume() {
mIsResumed = true;
if (mOnResumeRunnable != null) {
mOnResumeRunnable.run();
}

View File

@ -35,7 +35,7 @@ public class CMSetupWizardData extends AbstractSetupData {
private boolean mTimeSet = false;
private boolean mTimeZoneSet = false;
public CMSetupWizardData(SetupWizardActivity context) {
public CMSetupWizardData(Context context) {
super(context);
}

View File

@ -37,7 +37,6 @@ 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 +44,7 @@ public class ChooseDataSimPage extends SetupPage {
public static final String TAG = "ChooseDataSimPage";
public ChooseDataSimPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -25,13 +25,14 @@ 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.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.io.IOException;
@ -40,21 +41,23 @@ public class CyanogenServicesPage extends SetupPage {
public static final String TAG = "CyanogenServicesPage";
public CyanogenServicesPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
private Fragment mFragment;
public CyanogenServicesPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}
@Override
public Fragment getFragment(FragmentManager fragmentManager, int action) {
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
if (fragment == null) {
mFragment = fragmentManager.findFragmentByTag(getKey());
if (mFragment == null) {
Bundle args = new Bundle();
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
args.putInt(Page.KEY_PAGE_ACTION, action);
fragment = new LoadingFragment();
fragment.setArguments(args);
mFragment = new LoadingFragment();
mFragment.setArguments(args);
}
return fragment;
return mFragment;
}
@Override
@ -73,20 +76,24 @@ public class CyanogenServicesPage extends SetupPage {
}
@Override
public void doLoadAction(SetupWizardActivity context, int action) {
public void doLoadAction(FragmentManager fragmentManager, int action) {
if (action == Page.ACTION_PREVIOUS) {
getCallbacks().onPreviousPage();
} else {
if (!SetupWizardUtils.accountExists(mContext,
mContext.getString(R.string.cm_account_type))) {
super.doLoadAction(context, action);
launchCyanogenAccountSetup(context);
super.doLoadAction(fragmentManager, action);
} else {
getCallbacks().onNextPage();
}
}
}
@Override
public void onFragmentReady() {
launchCyanogenAccountSetup();
}
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN) {
@ -102,14 +109,13 @@ public class CyanogenServicesPage extends SetupPage {
return true;
}
private void launchCyanogenAccountSetup(final Activity activity) {
private void launchCyanogenAccountSetup() {
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,
AccountManager.get(mContext)
.addAccount(mContext.getString(R.string.cm_account_type), null, null, bundle,
null, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
@ -118,10 +124,10 @@ public class CyanogenServicesPage extends SetupPage {
Intent intent = result
.getParcelable(AccountManager.KEY_INTENT);
ActivityOptions options =
ActivityOptions.makeCustomAnimation(activity,
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
activity.startActivityForResult(intent,
mFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN,
options.toBundle());
} catch (OperationCanceledException e) {

View File

@ -20,6 +20,9 @@ import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ThemeUtils;
import android.content.res.ThemeConfig;
import android.content.res.ThemeManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.preference.PreferenceManager;
@ -39,7 +42,6 @@ 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;
@ -56,11 +58,12 @@ public class CyanogenSettingsPage extends SetupPage {
public static final String KEY_SEND_METRICS = "send_metrics";
public static final String KEY_REGISTER_WHISPERPUSH = "register";
public static final String KEY_ENABLE_NAV_KEYS = "enable_nav_keys";
public static final String KEY_APPLY_DEFAULT_THEME = "apply_default_theme";
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(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public CyanogenSettingsPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}
@ -125,6 +128,7 @@ public class CyanogenSettingsPage extends SetupPage {
}
handleWhisperPushRegistration();
handleEnableMetrics();
handleDefaultThemeSetup();
}
private void handleWhisperPushRegistration() {
@ -146,6 +150,18 @@ public class CyanogenSettingsPage extends SetupPage {
}
}
private void handleDefaultThemeSetup() {
Bundle privacyData = getData();
if (!ThemeUtils.getDefaultThemePackageName(mContext).equals(ThemeConfig.SYSTEM_DEFAULT) &&
privacyData != null && privacyData.getBoolean(KEY_APPLY_DEFAULT_THEME)) {
Log.i(TAG, "Applying default theme");
final ThemeManager tm = (ThemeManager) mContext.getSystemService(Context.THEME_SERVICE);
tm.applyDefaultTheme();
} else {
getCallbacks().finishSetup();
}
}
private static boolean hideKeyDisabler() {
try {
return !KeyDisabler.isSupported();
@ -172,12 +188,18 @@ public class CyanogenSettingsPage extends SetupPage {
SetupWizardUtils.isSimMissing(context));
}
protected static boolean hideThemeSwitch(Context context) {
return ThemeUtils.getDefaultThemePackageName(context).equals(ThemeConfig.SYSTEM_DEFAULT);
}
public static class CyanogenSettingsFragment extends SetupPageFragment {
private View mMetricsRow;
private View mDefaultThemeRow;
private View mNavKeysRow;
private View mSecureSmsRow;
private CheckBox mMetrics;
private CheckBox mDefaultTheme;
private CheckBox mNavKeys;
private CheckBox mSecureSms;
@ -191,6 +213,15 @@ public class CyanogenSettingsPage extends SetupPage {
}
};
private View.OnClickListener mDefaultThemeClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !mDefaultTheme.isChecked();
mDefaultTheme.setChecked(checked);
mPage.getData().putBoolean(KEY_APPLY_DEFAULT_THEME, checked);
}
};
private View.OnClickListener mNavKeysClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -211,6 +242,7 @@ public class CyanogenSettingsPage extends SetupPage {
@Override
protected void initializePage() {
final Bundle myPageBundle = mPage.getData();
String privacy_policy = getString(R.string.services_privacy_policy);
String policySummary = getString(R.string.services_explanation, privacy_policy);
SpannableString ss = new SpannableString(policySummary);
@ -242,10 +274,34 @@ public class CyanogenSettingsPage extends SetupPage {
metrics.setText(metricsSpan);
mMetrics = (CheckBox) mRootView.findViewById(R.id.enable_metrics_checkbox);
boolean metricsChecked =
!mPage.getData().containsKey(KEY_SEND_METRICS) || mPage.getData()
!myPageBundle.containsKey(KEY_SEND_METRICS) || myPageBundle
.getBoolean(KEY_SEND_METRICS);
mMetrics.setChecked(metricsChecked);
mPage.getData().putBoolean(KEY_SEND_METRICS, metricsChecked);
myPageBundle.putBoolean(KEY_SEND_METRICS, metricsChecked);
mDefaultThemeRow = mRootView.findViewById(R.id.theme);
if (hideThemeSwitch(getActivity())) {
mDefaultThemeRow.setVisibility(View.GONE);
} else {
mDefaultThemeRow.setOnClickListener(mDefaultThemeClickListener);
String defaultTheme =
getString(R.string.services_apply_theme,
getString(R.string.default_theme_name));
String defaultThemeSummary = getString(R.string.services_apply_theme_label,
defaultTheme);
final SpannableStringBuilder themeSpan =
new SpannableStringBuilder(defaultThemeSummary);
themeSpan.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD),
0, defaultTheme.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView theme = (TextView) mRootView.findViewById(R.id.enable_theme_summary);
theme.setText(themeSpan);
mDefaultTheme = (CheckBox) mRootView.findViewById(R.id.enable_theme_checkbox);
boolean themesChecked =
!myPageBundle.containsKey(KEY_APPLY_DEFAULT_THEME) || myPageBundle
.getBoolean(KEY_APPLY_DEFAULT_THEME);
mDefaultTheme.setChecked(themesChecked);
myPageBundle.putBoolean(KEY_APPLY_DEFAULT_THEME, themesChecked);
}
mNavKeysRow = mRootView.findViewById(R.id.nav_keys);
mNavKeysRow.setOnClickListener(mNavKeysClickListener);
@ -279,11 +335,11 @@ public class CyanogenSettingsPage extends SetupPage {
mSecureSmsRow.setVisibility(View.GONE);
}
mSecureSms = (CheckBox) mRootView.findViewById(R.id.secure_sms_checkbox);
boolean smsChecked = mPage.getData().containsKey(KEY_REGISTER_WHISPERPUSH) ?
mPage.getData().getBoolean(KEY_REGISTER_WHISPERPUSH) :
boolean smsChecked = myPageBundle.containsKey(KEY_REGISTER_WHISPERPUSH) ?
myPageBundle.getBoolean(KEY_REGISTER_WHISPERPUSH) :
false;
mSecureSms.setChecked(smsChecked);
mPage.getData().putBoolean(KEY_REGISTER_WHISPERPUSH, smsChecked);
myPageBundle.putBoolean(KEY_REGISTER_WHISPERPUSH, smsChecked);
}
@Override

View File

@ -43,7 +43,6 @@ 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;
@ -69,7 +68,7 @@ public class DateTimePage extends SetupPage {
private static final int HOURS_1 = 60 * 60000;
public DateTimePage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public DateTimePage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -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(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public FinishPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -27,15 +27,16 @@ 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;
import android.provider.Settings;
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;
@ -55,7 +56,9 @@ public class GmsAccountPage extends SetupPage {
private boolean mBackupEnabled = false;
public GmsAccountPage(final SetupWizardActivity context, SetupDataCallbacks callbacks) {
private Fragment mFragment;
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
final ContentResolver res = context.getContentResolver();
mBackupEnabled = Settings.Secure.getInt(res,
@ -78,15 +81,15 @@ public class GmsAccountPage extends SetupPage {
@Override
public Fragment getFragment(FragmentManager fragmentManager, int action) {
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
if (fragment == null) {
mFragment = fragmentManager.findFragmentByTag(getKey());
if (mFragment == null) {
Bundle args = new Bundle();
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
args.putInt(Page.KEY_PAGE_ACTION, action);
fragment = new LoadingFragment();
fragment.setArguments(args);
mFragment = new LoadingFragment();
mFragment.setArguments(args);
}
return fragment;
return mFragment;
}
@Override
@ -105,20 +108,24 @@ public class GmsAccountPage extends SetupPage {
}
@Override
public void doLoadAction(SetupWizardActivity context, int action) {
public void doLoadAction(FragmentManager fragmentManager, int action) {
if (action == Page.ACTION_PREVIOUS) {
getCallbacks().onPreviousPage();
} else {
launchGmsAccountSetup(context);
super.doLoadAction(context, action);
super.doLoadAction(fragmentManager, action);
}
}
@Override
public void onFragmentReady() {
launchGmsAccountSetup();
}
@Override
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(mContext);
launchGmsRestorePage();
} else {
handleResult(resultCode);
}
@ -131,10 +138,13 @@ public class GmsAccountPage extends SetupPage {
@Override
public void onFinishSetup() {
if (mContentQueryMap != null) {
mContentQueryMap.close();
try {
if (mContentQueryMap != null) {
mContentQueryMap.close();
}
} catch (Exception e) {
Log.wtf(TAG, e.toString());
}
}
private void handleResult(int resultCode) {
@ -148,10 +158,10 @@ public class GmsAccountPage extends SetupPage {
}
}
private static void launchGmsRestorePage(final SetupWizardActivity activity) {
private void launchGmsRestorePage() {
try {
// GMS can disable this after logging in sometimes
SetupWizardUtils.enableGMSSetupWizard(activity);
SetupWizardUtils.enableGMSSetupWizard(mContext);
Intent intent = new Intent(ACTION_RESTORE);
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
@ -161,27 +171,27 @@ public class GmsAccountPage extends SetupPage {
// This is necessary to get the material theme on the restore page.
intent.putExtra("scriptUri", RESTORE_WIZARD_SCRIPT);
ActivityOptions options =
ActivityOptions.makeCustomAnimation(activity,
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
activity.startActivityForResult(
mFragment.startActivityForResult(
intent,
SetupWizardApp.REQUEST_CODE_RESTORE_GMS, options.toBundle());
} catch (Exception e) {
e.printStackTrace();
// XXX: In open source, we don't know what gms version a user has.
// Bail if the restore activity is not found.
activity.onNextPage();
getCallbacks().onNextPage();
}
}
private void launchGmsAccountSetup(final SetupWizardActivity activity) {
private void launchGmsAccountSetup() {
Bundle bundle = new Bundle();
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
bundle.putBoolean(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
AccountManager
.get(activity).addAccount(SetupWizardApp.ACCOUNT_TYPE_GMS, null, null,
.get(mContext).addAccount(SetupWizardApp.ACCOUNT_TYPE_GMS, null, null,
bundle, null, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
@ -190,10 +200,10 @@ public class GmsAccountPage extends SetupPage {
Intent intent = result
.getParcelable(AccountManager.KEY_INTENT);
ActivityOptions options =
ActivityOptions.makeCustomAnimation(activity,
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
activity.startActivityForResult(intent,
mFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_GMS, options.toBundle());
} catch (OperationCanceledException e) {
} catch (IOException e) {

View File

@ -34,14 +34,13 @@ 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(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public MobileDataPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -39,7 +39,6 @@ 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;
@ -53,7 +52,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(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public OtherSettingsPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -21,8 +21,6 @@ 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";
@ -44,7 +42,8 @@ public interface Page {
public Page setHidden(boolean hidden);
public boolean doPreviousAction();
public boolean doNextAction();
public void doLoadAction(SetupWizardActivity context, int action);
public void doLoadAction(FragmentManager fragmentManager, int action);
public void onFragmentReady();
public void onFinishSetup();
public boolean onActivityResult(int requestCode, int resultCode, Intent data);
public SetupDataCallbacks getCallbacks();

View File

@ -22,6 +22,7 @@ public interface SetupDataCallbacks {
void onPageLoaded(Page page);
void onPageTreeChanged();
void onFinish();
void finishSetup();
boolean isCurrentPage(Page page);
Page getPage(String key);
Page getPage(int key);

View File

@ -16,10 +16,6 @@
package com.cyanogenmod.setupwizard.setup;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.ui.SetupWizardActivity;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
@ -29,6 +25,8 @@ import android.transition.Slide;
import android.transition.Transition;
import android.view.Gravity;
import com.cyanogenmod.setupwizard.R;
public abstract class SetupPage implements Page {
@ -38,9 +36,9 @@ public abstract class SetupPage implements Page {
private boolean mRequired = false;
private boolean mHidden = false;
protected final SetupWizardActivity mContext;
protected final Context mContext;
protected SetupPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
protected SetupPage(Context context, SetupDataCallbacks callbacks) {
mContext = context;
mCallbacks = callbacks;
}
@ -74,9 +72,7 @@ public abstract class SetupPage implements Page {
public void onFinishSetup() {}
@Override
public void doLoadAction(SetupWizardActivity context, int action) {
if (context == null || context.isFinishing()) { return; }
final FragmentManager fragmentManager = context.getFragmentManager();
public void doLoadAction(FragmentManager fragmentManager, int action) {
Fragment fragment = getFragment(fragmentManager, action);
if (action == Page.ACTION_NEXT) {
Transition t = new Slide(Gravity.RIGHT);
@ -93,6 +89,9 @@ public abstract class SetupPage implements Page {
}
}
@Override
public void onFragmentReady(){}
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
return false;

View File

@ -18,6 +18,7 @@ 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;
@ -33,7 +34,7 @@ public class SimCardMissingPage extends SetupPage {
private static final int SIM_SIDE = 1;
private static final int SIM_BACK = 2;
public SimCardMissingPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public SimCardMissingPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -19,6 +19,7 @@ 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;
@ -31,7 +32,6 @@ 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(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public WelcomePage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}

View File

@ -18,8 +18,8 @@ package com.cyanogenmod.setupwizard.setup;
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;
@ -30,7 +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.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.io.IOException;
@ -59,10 +59,9 @@ public class WifiSetupPage extends SetupPage {
private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() {
@Override
public void run() {
final SetupWizardActivity activity = mContext;
if (mIsCaptivePortal) {
try {
int netId = ConnectivityManager.from(activity)
int netId = ConnectivityManager.from(mContext)
.getNetworkForType(ConnectivityManager.TYPE_WIFI).netId;
Intent intent = new Intent(CAPTIVE_PORTAL_LOGIN_ACTION);
intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(netId));
@ -76,25 +75,25 @@ public class WifiSetupPage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
activity.startActivityForResult(intent,
mLoadingFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL,
options.toBundle());
} catch (Exception e) {
//Oh well
Log.e(TAG, "No captive portal activity found" + e);
if (activity.isCurrentPage(WifiSetupPage.this)) {
if (getCallbacks().isCurrentPage(WifiSetupPage.this)) {
getCallbacks().onNextPage();
}
}
} else {
if (activity.isCurrentPage(WifiSetupPage.this)) {
if (getCallbacks().isCurrentPage(WifiSetupPage.this)) {
getCallbacks().onNextPage();
}
}
}
};
public WifiSetupPage(SetupWizardActivity context, SetupDataCallbacks callbacks) {
public WifiSetupPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
String server = Settings.Global.getString(context.getContentResolver(), "captive_portal_server");
if (server == null) server = DEFAULT_SERVER;
@ -106,7 +105,7 @@ public class WifiSetupPage extends SetupPage {
}
@Override
public Fragment getFragment(FragmentManager fragmentManager, int action) {
public SetupPageFragment getFragment(FragmentManager fragmentManager, int action) {
mLoadingFragment = (LoadingFragment)fragmentManager.findFragmentByTag(getKey());
if (mLoadingFragment == null) {
Bundle args = new Bundle();
@ -134,9 +133,8 @@ public class WifiSetupPage extends SetupPage {
}
@Override
public void doLoadAction(SetupWizardActivity context, int action) {
super.doLoadAction(context, action);
SetupWizardUtils.launchWifiSetup(context);
public void onFragmentReady() {
launchWifiSetup();
}
@Override
@ -151,7 +149,7 @@ public class WifiSetupPage extends SetupPage {
}
} else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL) {
if (resultCode == Activity.RESULT_CANCELED) {
SetupWizardUtils.launchWifiSetup(mContext);
launchWifiSetup();
} else {
getCallbacks().onNextPage();
}
@ -183,6 +181,11 @@ public class WifiSetupPage extends SetupPage {
urlConnection.setUseCaches(false);
urlConnection.getInputStream();
// We got a valid response, but not from the real google
final int responseCode = urlConnection.getResponseCode();
if (responseCode == 408 || responseCode == 504) {
// If we timeout here, we'll try and go through captive portal login
return true;
}
return urlConnection.getResponseCode() != 204;
} catch (IOException e) {
Log.e(TAG, "Captive portal check - probably not a portal: exception "
@ -194,4 +197,20 @@ public class WifiSetupPage extends SetupPage {
}
}
}
private void launchWifiSetup() {
SetupWizardUtils.tryEnablingWifi(mContext);
Intent intent = new Intent(SetupWizardApp.ACTION_SETUP_WIFI);
intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
intent.putExtra(SetupWizardApp.EXTRA_THEME, SetupWizardApp.EXTRA_MATERIAL_LIGHT);
intent.putExtra(SetupWizardApp.EXTRA_AUTO_FINISH, false);
ActivityOptions options =
ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
mLoadingFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_WIFI, options.toBundle());
}
}

View File

@ -18,6 +18,7 @@ package com.cyanogenmod.setupwizard.ui;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -40,6 +41,7 @@ public abstract class SetupPageFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
Bundle args = getArguments();
mKey = args.getString(Page.KEY_PAGE_ARGUMENT);
if (mKey == null) {
@ -65,6 +67,7 @@ public abstract class SetupPageFragment extends Fragment {
mTitleView.setText(mPage.getTitleResId());
}
initializePage();
mPage.onFragmentReady();
mCallbacks.onPageLoaded(mPage);
}
@ -83,6 +86,11 @@ public abstract class SetupPageFragment extends Fragment {
mCallbacks = null;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mPage.onActivityResult(requestCode, resultCode, data);
}
protected abstract void initializePage();
protected abstract int getLayoutResource();

View File

@ -19,10 +19,13 @@ package com.cyanogenmod.setupwizard.ui;
import android.animation.Animator;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.content.res.ThemeManager;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
@ -30,7 +33,11 @@ import android.provider.Settings;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
@ -49,7 +56,8 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
private View mButtonBar;
private Button mNextButton;
private Button mPrevButton;
private View mReveal;
private ImageView mReveal;
private ProgressBar mFinishingProgressBar;
private EnableAccessibilityController mEnableAccessibilityController;
@ -59,23 +67,38 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
private boolean mIsGuestUser = false;
private volatile boolean mIsFinishing = false;
private ThemeManager.ThemeChangeListener mThemeChangeListener = new ThemeManager.ThemeChangeListener() {
@Override
public void onProgress(int progress) {
if (progress > 0) {
mFinishingProgressBar.setIndeterminate(false);
mFinishingProgressBar.setProgress(progress);
}
}
@Override
public void onFinish(boolean isSuccess) {
finishSetup();
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_main);
getWindow().setWindowAnimations(android.R.anim.fade_in);
setContentView(R.layout.setup_main);
mRootView = findViewById(R.id.root);
mReveal = (ImageView)mRootView.findViewById(R.id.reveal);
mButtonBar = findViewById(R.id.button_bar);
mFinishingProgressBar = (ProgressBar)findViewById(R.id.finishing_bar);
((SetupWizardApp)getApplicationContext()).disableStatusBar();
mSetupData = (CMSetupWizardData)getLastNonConfigurationInstance();
if (mSetupData == null) {
mSetupData = new CMSetupWizardData(this);
} else {
mSetupData.setContext(this);
mSetupData = new CMSetupWizardData(getApplicationContext());
}
mNextButton = (Button) findViewById(R.id.next_button);
mPrevButton = (Button) findViewById(R.id.prev_button);
mReveal = findViewById(R.id.reveal);
setupRevealImage();
mSetupData.registerListener(this);
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -93,7 +116,7 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
});
if (savedInstanceState == null) {
Page page = mSetupData.getCurrentPage();
page.doLoadAction(this, Page.ACTION_NEXT);
page.doLoadAction(getFragmentManager(), Page.ACTION_NEXT);
}
if (savedInstanceState != null && savedInstanceState.containsKey("data")) {
mSetupData.load(savedInstanceState.getBundle("data"));
@ -111,14 +134,14 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
try {
if (Settings.Secure.getInt(getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE) == 1) {
finishSetup(false);
finalizeSetup();
}
} catch (Settings.SettingNotFoundException e) {
// Continue with setup
}
mIsGuestUser = SetupWizardUtils.isGuestUser(this);
if (mIsGuestUser) {
finishSetup(false);
finalizeSetup();
}
registerReceiver(mSetupData, mSetupData.getIntentFilter());
}
@ -135,6 +158,12 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
enableButtonBar(true);
}
@Override
protected void onPause() {
super.onPause();
mSetupData.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -143,11 +172,6 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
unregisterReceiver(mSetupData);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mSetupData.getCurrentPage().onActivityResult(requestCode, resultCode, data);
}
@Override
public Object onRetainNonConfigurationInstance() {
return mSetupData;
@ -169,13 +193,17 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
@Override
public void onNextPage() {
Page page = mSetupData.getCurrentPage();
page.doLoadAction(this, Page.ACTION_NEXT);
if (!isFinishing()) {
page.doLoadAction(getFragmentManager(), Page.ACTION_NEXT);
}
}
@Override
public void onPreviousPage() {
Page page = mSetupData.getCurrentPage();
page.doLoadAction(this, Page.ACTION_PREVIOUS);
if (!isFinishing()) {
page.doLoadAction(getFragmentManager(), Page.ACTION_PREVIOUS);
}
}
@Override
@ -247,7 +275,39 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
@Override
public void onFinish() {
animateOut();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
Animation fadeOut = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
mNextButton.startAnimation(fadeOut);
mNextButton.setVisibility(View.INVISIBLE);
mPrevButton.startAnimation(fadeOut);
mPrevButton.setVisibility(View.INVISIBLE);
final SetupWizardApp setupWizardApp = (SetupWizardApp)getApplication();
setupWizardApp.enableStatusBar();
setupWizardApp.enableCaptivePortalDetection();
Animation fadeIn = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
mFinishingProgressBar.setVisibility(View.VISIBLE);
mFinishingProgressBar.setIndeterminate(true);
mFinishingProgressBar.startAnimation(fadeIn);
final ThemeManager tm = (ThemeManager) getSystemService(Context.THEME_SERVICE);
tm.addClient(mThemeChangeListener);
mSetupData.finishPages();
}
@Override
public void finishSetup() {
if (!mIsFinishing) {
mIsFinishing = true;
mHandler.post(new Runnable() {
@Override
public void run() {
final SetupWizardApp setupWizardApp = (SetupWizardApp)getApplication();
setupWizardApp.sendStickyBroadcastAsUser(
new Intent(SetupWizardApp.ACTION_FINISHED),
UserHandle.getCallingUserHandle());
setupRevealImage();
}
});
}
}
@Override
@ -257,22 +317,41 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
}
private void setupRevealImage() {
Thread t = new Thread() {
mFinishingProgressBar.setProgress(100);
Animation fadeOut = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
mFinishingProgressBar.startAnimation(fadeOut);
mFinishingProgressBar.setVisibility(View.INVISIBLE);
final Thread t = new Thread() {
@Override
public void run() {
Point p = new Point();
final Point p = new Point();
getWindowManager().getDefaultDisplay().getRealSize(p);
final Drawable drawable = WallpaperManager.getInstance(SetupWizardActivity.this)
.getBuiltInDrawable(
p.x, p.y, false, 0, 0);
if (drawable != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
mReveal.setBackground(drawable);
}
});
final WallpaperManager wallpaperManager =
WallpaperManager.getInstance(SetupWizardActivity.this);
wallpaperManager.forgetLoadedWallpaper();
final Bitmap wallpaper = wallpaperManager.getBitmap();
Bitmap cropped = null;
if (wallpaper != null) {
cropped = Bitmap.createBitmap(wallpaper, 0,
0, Math.min(p.x, wallpaper.getWidth()),
Math.min(p.y, wallpaper.getHeight()));
}
final Bitmap croppedWallpaper = cropped;
mHandler.post(new Runnable() {
@Override
public void run() {
if (croppedWallpaper != null) {
mReveal.setScaleType(ImageView.ScaleType.CENTER_CROP);
mReveal.setImageBitmap(croppedWallpaper);
} else {
mReveal.setBackground(wallpaperManager
.getBuiltInDrawable(p.x, p.y, false, 0, 0));
}
animateOut();
}
});
}
};
t.start();
@ -296,7 +375,7 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
mHandler.post(new Runnable() {
@Override
public void run() {
finishSetup(true);
finalizeSetup();
}
});
}
@ -310,25 +389,22 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
anim.start();
}
private void finishSetup(boolean broadcastFinish) {
SetupWizardApp setupWizardApp = (SetupWizardApp)getApplication();
if (broadcastFinish && !mIsGuestUser) {
setupWizardApp.sendBroadcastAsUser(new Intent(SetupWizardApp.ACTION_FINISHED),
UserHandle.getCallingUserHandle());
}
mSetupData.finishPages();
private void finalizeSetup() {
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
setupWizardApp.enableCaptivePortalDetection();
setupWizardApp.enableStatusBar();
finish();
if (mEnableAccessibilityController != null) {
mEnableAccessibilityController.onDestroy();
}
SetupWizardUtils.disableGMSSetupWizard(this);
SetupWizardUtils.disableSetupWizard(this);
final ThemeManager tm = (ThemeManager) this.getSystemService(THEME_SERVICE);
tm.removeClient(mThemeChangeListener);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
final WallpaperManager wallpaperManager =
WallpaperManager.getInstance(SetupWizardActivity.this);
wallpaperManager.forgetLoadedWallpaper();
}
}

View File

@ -17,11 +17,8 @@
package com.cyanogenmod.setupwizard.util;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@ -34,8 +31,6 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
@ -54,22 +49,6 @@ public class SetupWizardUtils {
}
}
public static void launchWifiSetup(Activity context) {
SetupWizardUtils.tryEnablingWifi(context);
Intent intent = new Intent(SetupWizardApp.ACTION_SETUP_WIFI);
intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
intent.putExtra(SetupWizardApp.EXTRA_THEME, SetupWizardApp.EXTRA_MATERIAL_LIGHT);
intent.putExtra(SetupWizardApp.EXTRA_AUTO_FINISH, false);
ActivityOptions options =
ActivityOptions.makeCustomAnimation(context,
android.R.anim.fade_in,
android.R.anim.fade_out);
context.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_WIFI, options.toBundle());
}
public static boolean isNetworkConnected(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
@ -160,12 +139,12 @@ public class SetupWizardUtils {
return AccountManager.get(context).getAccountsByType(accountType).length > 0;
}
public static void disableSetupWizard(Activity context) {
public static void disableSetupWizard(Context context) {
disableComponent(context, context.getPackageName(),
"com.cyanogenmod.setupwizard.ui.SetupWizardActivity");
}
public static void disableGMSSetupWizard(Activity context) {
public static void disableGMSSetupWizard(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(GOOGLE_SETUPWIZARD_PACKAGE,
@ -179,7 +158,7 @@ public class SetupWizardUtils {
}
}
public static void enableGMSSetupWizard(Activity context) {
public static void enableGMSSetupWizard(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(GOOGLE_SETUPWIZARD_PACKAGE,
@ -193,7 +172,7 @@ public class SetupWizardUtils {
}
}
private static void disableComponentArray(Activity context, ComponentInfo[] components) {
private static void disableComponentArray(Context context, ComponentInfo[] components) {
if(components != null) {
ComponentInfo[] componentInfos = components;
for(int i = 0; i < componentInfos.length; i++) {
@ -202,16 +181,16 @@ public class SetupWizardUtils {
}
}
private static void disableComponent(Activity context, String packageName, String name) {
private static void disableComponent(Context context, String packageName, String name) {
disableComponent(context, new ComponentName(packageName, name));
}
private static void disableComponent(Activity context, ComponentName component) {
private static void disableComponent(Context context, ComponentName component) {
context.getPackageManager().setComponentEnabledSetting(component,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
}
private static void enableComponentArray(Activity context, ComponentInfo[] components) {
private static void enableComponentArray(Context context, ComponentInfo[] components) {
if(components != null) {
ComponentInfo[] componentInfos = components;
for(int i = 0; i < componentInfos.length; i++) {
@ -220,11 +199,11 @@ public class SetupWizardUtils {
}
}
private static void enableComponent(Activity context, String packageName, String name) {
private static void enableComponent(Context context, String packageName, String name) {
enableComponent(context, new ComponentName(packageName, name));
}
private static void enableComponent(Activity context, ComponentName component) {
private static void enableComponent(Context context, ComponentName component) {
context.getPackageManager().setComponentEnabledSetting(component,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}