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_GMS= 1;
|
||||
public static final int REQUEST_CODE_SETUP_CYANOGEN= 2;
|
||||
|
||||
private StatusBarManager mStatusBarManager;
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.PhoneStateListener;
|
||||
@ -49,12 +50,15 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
ChooseDataSimFragment fragment = new ChooseDataSimFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new ChooseDataSimFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,15 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
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.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -47,6 +53,8 @@ import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||
|
||||
import org.cyanogenmod.hardware.KeyDisabler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CyanogenServicesPage extends SetupPage {
|
||||
|
||||
public static final String TAG = "CyanogenServicesPage";
|
||||
@ -62,12 +70,15 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
CyanogenServicesFragment fragment = new CyanogenServicesFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new CyanogenServicesFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@ -81,6 +92,16 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
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) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final int defaultBrightness = context.getResources().getInteger(
|
||||
@ -184,8 +205,9 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
final Activity activity = getActivity();
|
||||
activity.getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
|
||||
if (!SetupWizardUtils.accountExists(activity,
|
||||
activity.getString(R.string.cm_account_type))) {
|
||||
int action = getArguments().getInt(Page.KEY_PAGE_ACTION);
|
||||
if (savedInstanceState == null && !SetupWizardUtils.accountExists(activity,
|
||||
activity.getString(R.string.cm_account_type)) && action == Page.ACTION_NEXT) {
|
||||
launchCyanogenAccountSetup(activity);
|
||||
}
|
||||
}
|
||||
@ -270,7 +292,21 @@ public class CyanogenServicesPage extends SetupPage {
|
||||
bundle.putBoolean(SetupWizardApp.EXTRA_SHOW_BUTTON_BAR, true);
|
||||
AccountManager.get(activity)
|
||||
.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.DialogFragment;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -72,12 +73,15 @@ public class DateTimePage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
DateTimeFragment fragment = new DateTimeFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new DateTimeFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -38,12 +39,15 @@ public class FinishPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
mFinishFragment = new FinishFragment();
|
||||
mFinishFragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
mFinishFragment = (FinishFragment)fragmentManager.findFragmentByTag(getKey());
|
||||
if (mFinishFragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
mFinishFragment = new FinishFragment();
|
||||
mFinishFragment.setArguments(args);
|
||||
}
|
||||
return mFinishFragment;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ContentQueryMap;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@ -42,12 +43,15 @@ public class LocationSettingsPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
LocationSettingsFragment fragment = new LocationSettingsFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new LocationSettingsFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.telephony.PhoneStateListener;
|
||||
@ -44,12 +45,15 @@ public class MobileDataPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
MobileDataFragment fragment = new MobileDataFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new MobileDataFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,14 @@ 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;
|
||||
|
||||
public interface Page {
|
||||
|
||||
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_PREVIOUS = 2;
|
||||
@ -32,7 +34,7 @@ public interface Page {
|
||||
public int getTitleResId();
|
||||
public int getPrevButtonTitleResId();
|
||||
public int getNextButtonTitleResId();
|
||||
public Fragment getFragment();
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action);
|
||||
public Bundle getData();
|
||||
public void resetData(Bundle data);
|
||||
public boolean isRequired();
|
||||
|
@ -45,7 +45,7 @@ public abstract class SetupPage implements Page {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public abstract class SetupPage implements Page {
|
||||
public void doLoadAction(Activity context, int action) {
|
||||
if (context == null || context.isFinishing()) { return; }
|
||||
final FragmentManager fragmentManager = context.getFragmentManager();
|
||||
Fragment fragment = getFragment();
|
||||
Fragment fragment = getFragment(fragmentManager, action);
|
||||
if (action == Page.ACTION_NEXT) {
|
||||
Transition t = new Slide(Gravity.RIGHT);
|
||||
fragment.setEnterTransition(t);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
@ -32,12 +33,15 @@ public class SimCardMissingPage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
FinishFragment fragment = new FinishFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new SimCardMissingFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@ -57,7 +61,7 @@ public class SimCardMissingPage extends SetupPage {
|
||||
}
|
||||
|
||||
|
||||
public static class FinishFragment extends SetupPageFragment {
|
||||
public static class SimCardMissingFragment extends SetupPageFragment {
|
||||
|
||||
@Override
|
||||
protected void initializePage() {}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
@ -44,12 +45,15 @@ public class WelcomePage extends SetupPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getFragment() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(SetupPage.KEY_PAGE_ARGUMENT, getKey());
|
||||
|
||||
WelcomeFragment fragment = new WelcomeFragment();
|
||||
fragment.setArguments(args);
|
||||
public Fragment getFragment(FragmentManager fragmentManager, int action) {
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(getKey());
|
||||
if (fragment == null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new WelcomeFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user