From 1fcde3985e9d62eb22eff0b8eacf1d4832234867 Mon Sep 17 00:00:00 2001 From: cretin45 Date: Fri, 23 Jan 2015 14:04:04 -0800 Subject: SetupWizard: Add loading fragment if launching into another activity Also always show the Wi-Fi page Change-Id: I3be39f793403131ea07d071c3d107b1800771e65 --- .../setupwizard/setup/GmsAccountPage.java | 18 ++++++++++++- .../setupwizard/setup/LoadingFragment.java | 30 +++++++++++++++++++++ .../setupwizard/setup/WifiSetupPage.java | 31 +++++++++++++++++----- 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/com/cyanogenmod/setupwizard/setup/LoadingFragment.java (limited to 'src/com/cyanogenmod/setupwizard/setup') diff --git a/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java b/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java index 3e45ed4..8b808dc 100644 --- a/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java +++ b/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java @@ -22,6 +22,8 @@ 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.os.Bundle; @@ -41,13 +43,26 @@ public class GmsAccountPage extends SetupPage { } @Override + 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 LoadingFragment(); + fragment.setArguments(args); + } + return fragment; + } + + @Override public String getKey() { return TAG; } @Override public int getTitleResId() { - return R.string.setup_gms_account; + return R.string.loading; } @Override @@ -60,6 +75,7 @@ public class GmsAccountPage extends SetupPage { if (action == Page.ACTION_PREVIOUS) { getCallbacks().onPreviousPage(); } else { + super.doLoadAction(context, action); launchGmsAccountSetup(context); } } diff --git a/src/com/cyanogenmod/setupwizard/setup/LoadingFragment.java b/src/com/cyanogenmod/setupwizard/setup/LoadingFragment.java new file mode 100644 index 0000000..1983806 --- /dev/null +++ b/src/com/cyanogenmod/setupwizard/setup/LoadingFragment.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.setupwizard.setup; + +import com.cyanogenmod.setupwizard.R; +import com.cyanogenmod.setupwizard.ui.SetupPageFragment; + +public class LoadingFragment extends SetupPageFragment { + @Override + protected void initializePage() {} + + @Override + protected int getLayoutResource() { + return R.layout.setup_loading_page; + } +} diff --git a/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java b/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java index 705b932..2d764d6 100644 --- a/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java +++ b/src/com/cyanogenmod/setupwizard/setup/WifiSetupPage.java @@ -17,8 +17,11 @@ package com.cyanogenmod.setupwizard.setup; import android.app.Activity; +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; @@ -33,6 +36,19 @@ public class WifiSetupPage extends SetupPage { } @Override + 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 LoadingFragment(); + fragment.setArguments(args); + } + return fragment; + } + + @Override public int getNextButtonTitleResId() { return R.string.skip; } @@ -44,22 +60,23 @@ public class WifiSetupPage extends SetupPage { @Override public int getTitleResId() { - return R.string.existing; + return R.string.setup_wifi; } @Override public void doLoadAction(Activity context, int action) { - if (action == Page.ACTION_PREVIOUS) { - getCallbacks().onPreviousPage(); - } else { - SetupWizardUtils.launchWifiSetup(context); - } + super.doLoadAction(context, action); + SetupWizardUtils.launchWifiSetup(context); } @Override public boolean onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != SetupWizardApp.REQUEST_CODE_SETUP_WIFI) return false; - getCallbacks().onNextPage(); + if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_FIRST_USER) { + getCallbacks().onNextPage(); + } else if (resultCode == Activity.RESULT_CANCELED) { + getCallbacks().onPreviousPage(); + } return true; } } -- cgit v1.1