SetupWizard: Better handle next and previous actions
Change-Id: I239269d9313594b1d37ce3468e0c095c851946c6
This commit is contained in:
parent
30af327616
commit
61a331f403
@ -41,6 +41,7 @@ public class SetupWizardApp extends Application {
|
|||||||
|
|
||||||
public static final int REQUEST_CODE_SETUP_WIFI = 0;
|
public static final int REQUEST_CODE_SETUP_WIFI = 0;
|
||||||
public static final int REQUEST_CODE_SETUP_GMS= 1;
|
public static final int REQUEST_CODE_SETUP_GMS= 1;
|
||||||
|
public static final int REQUEST_CODE_SETUP_CYANOGEN= 2;
|
||||||
|
|
||||||
private StatusBarManager mStatusBarManager;
|
private StatusBarManager mStatusBarManager;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.cyanogenmod.setupwizard.setup;
|
package com.cyanogenmod.setupwizard.setup;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
@ -49,12 +50,15 @@ public class ChooseDataSimPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
ChooseDataSimFragment fragment = new ChooseDataSimFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new ChooseDataSimFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,15 @@
|
|||||||
package com.cyanogenmod.setupwizard.setup;
|
package com.cyanogenmod.setupwizard.setup;
|
||||||
|
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
|
import android.accounts.AccountManagerCallback;
|
||||||
|
import android.accounts.AccountManagerFuture;
|
||||||
|
import android.accounts.AuthenticatorException;
|
||||||
|
import android.accounts.OperationCanceledException;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -47,6 +53,8 @@ import com.google.android.gms.common.GooglePlayServicesUtil;
|
|||||||
|
|
||||||
import org.cyanogenmod.hardware.KeyDisabler;
|
import org.cyanogenmod.hardware.KeyDisabler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class CyanogenServicesPage extends SetupPage {
|
public class CyanogenServicesPage extends SetupPage {
|
||||||
|
|
||||||
public static final String TAG = "CyanogenServicesPage";
|
public static final String TAG = "CyanogenServicesPage";
|
||||||
@ -62,12 +70,15 @@ public class CyanogenServicesPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
CyanogenServicesFragment fragment = new CyanogenServicesFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new CyanogenServicesFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +92,16 @@ public class CyanogenServicesPage extends SetupPage {
|
|||||||
return R.string.setup_services;
|
return R.string.setup_services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN) {
|
||||||
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
getCallbacks().onPreviousPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static void writeDisableNavkeysOption(Context context, boolean enabled) {
|
private static void writeDisableNavkeysOption(Context context, boolean enabled) {
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final int defaultBrightness = context.getResources().getInteger(
|
final int defaultBrightness = context.getResources().getInteger(
|
||||||
@ -184,8 +205,9 @@ public class CyanogenServicesPage extends SetupPage {
|
|||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
activity.getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
|
activity.getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
|
||||||
if (!SetupWizardUtils.accountExists(activity,
|
int action = getArguments().getInt(Page.KEY_PAGE_ACTION);
|
||||||
activity.getString(R.string.cm_account_type))) {
|
if (savedInstanceState == null && !SetupWizardUtils.accountExists(activity,
|
||||||
|
activity.getString(R.string.cm_account_type)) && action == Page.ACTION_NEXT) {
|
||||||
launchCyanogenAccountSetup(activity);
|
launchCyanogenAccountSetup(activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +292,21 @@ public class CyanogenServicesPage extends SetupPage {
|
|||||||
bundle.putBoolean(SetupWizardApp.EXTRA_SHOW_BUTTON_BAR, true);
|
bundle.putBoolean(SetupWizardApp.EXTRA_SHOW_BUTTON_BAR, true);
|
||||||
AccountManager.get(activity)
|
AccountManager.get(activity)
|
||||||
.addAccount(activity.getString(R.string.cm_account_type), null, null, bundle,
|
.addAccount(activity.getString(R.string.cm_account_type), null, null, bundle,
|
||||||
activity, null, null);
|
null, new AccountManagerCallback<Bundle>() {
|
||||||
|
@Override
|
||||||
|
public void run(AccountManagerFuture<Bundle> future) {
|
||||||
|
try {
|
||||||
|
Bundle result = future.getResult();
|
||||||
|
Intent intent = result
|
||||||
|
.getParcelable(AccountManager.KEY_INTENT);
|
||||||
|
activity.startActivityForResult(intent,
|
||||||
|
SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN);
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
} catch (AuthenticatorException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import android.app.DatePickerDialog;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.app.TimePickerDialog;
|
import android.app.TimePickerDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -72,12 +73,15 @@ public class DateTimePage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
DateTimeFragment fragment = new DateTimeFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new DateTimeFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
|||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -38,12 +39,15 @@ public class FinishPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
mFinishFragment = (FinishFragment)fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
if (mFinishFragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
mFinishFragment = new FinishFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
mFinishFragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
mFinishFragment = new FinishFragment();
|
||||||
|
mFinishFragment.setArguments(args);
|
||||||
|
}
|
||||||
return mFinishFragment;
|
return mFinishFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.cyanogenmod.setupwizard.setup;
|
package com.cyanogenmod.setupwizard.setup;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
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.Context;
|
||||||
@ -42,12 +43,15 @@ public class LocationSettingsPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
LocationSettingsFragment fragment = new LocationSettingsFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new LocationSettingsFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package com.cyanogenmod.setupwizard.setup;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
@ -44,12 +45,15 @@ public class MobileDataPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
MobileDataFragment fragment = new MobileDataFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new MobileDataFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,14 @@ package com.cyanogenmod.setupwizard.setup;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public interface Page {
|
public interface Page {
|
||||||
|
|
||||||
public static final String KEY_PAGE_ARGUMENT = "key_arg";
|
public static final String KEY_PAGE_ARGUMENT = "key_arg";
|
||||||
|
public static final String KEY_PAGE_ACTION= "action";
|
||||||
|
|
||||||
public static final int ACTION_NEXT = 1;
|
public static final int ACTION_NEXT = 1;
|
||||||
public static final int ACTION_PREVIOUS = 2;
|
public static final int ACTION_PREVIOUS = 2;
|
||||||
@ -32,7 +34,7 @@ public interface Page {
|
|||||||
public int getTitleResId();
|
public int getTitleResId();
|
||||||
public int getPrevButtonTitleResId();
|
public int getPrevButtonTitleResId();
|
||||||
public int getNextButtonTitleResId();
|
public int getNextButtonTitleResId();
|
||||||
public Fragment getFragment();
|
public Fragment getFragment(FragmentManager fragmentManager, int action);
|
||||||
public Bundle getData();
|
public Bundle getData();
|
||||||
public void resetData(Bundle data);
|
public void resetData(Bundle data);
|
||||||
public boolean isRequired();
|
public boolean isRequired();
|
||||||
|
@ -45,7 +45,7 @@ public abstract class SetupPage implements Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public abstract class SetupPage implements Page {
|
|||||||
public void doLoadAction(Activity context, int action) {
|
public void doLoadAction(Activity 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();
|
Fragment fragment = getFragment(fragmentManager, action);
|
||||||
if (action == Page.ACTION_NEXT) {
|
if (action == Page.ACTION_NEXT) {
|
||||||
Transition t = new Slide(Gravity.RIGHT);
|
Transition t = new Slide(Gravity.RIGHT);
|
||||||
fragment.setEnterTransition(t);
|
fragment.setEnterTransition(t);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.cyanogenmod.setupwizard.setup;
|
package com.cyanogenmod.setupwizard.setup;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
@ -32,12 +33,15 @@ public class SimCardMissingPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
FinishFragment fragment = new FinishFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new SimCardMissingFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +61,7 @@ public class SimCardMissingPage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class FinishFragment extends SetupPageFragment {
|
public static class SimCardMissingFragment extends SetupPageFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initializePage() {}
|
protected void initializePage() {}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.cyanogenmod.setupwizard.setup;
|
package com.cyanogenmod.setupwizard.setup;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -44,12 +45,15 @@ public class WelcomePage extends SetupPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getFragment() {
|
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||||
Bundle args = new Bundle();
|
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
if (fragment == null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
WelcomeFragment fragment = new WelcomeFragment();
|
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||||
fragment.setArguments(args);
|
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||||
|
fragment = new WelcomeFragment();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user