cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The CyanogenMod Project |
Joey Rizzoli | d133188 | 2016-12-29 17:28:02 +0100 | [diff] [blame] | 3 | * Copyright (C) 2017 The LineageOS Project |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Maarten Derks | e901e0c | 2017-05-22 11:15:44 +0200 | [diff] [blame] | 18 | package com.fairphone.setupwizard.setup; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 19 | |
cretin45 | 6355048 | 2016-04-27 12:38:53 -0700 | [diff] [blame] | 20 | import android.app.Activity; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 21 | import android.app.Fragment; |
cretin45 | 61a331f | 2015-01-23 11:37:23 -0800 | [diff] [blame] | 22 | import android.app.FragmentManager; |
cretin45 | 01f21da | 2015-02-23 13:52:37 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
| 28 | import android.os.Messenger; |
| 29 | import android.os.RemoteException; |
| 30 | import android.util.Log; |
cretin45 | 6355048 | 2016-04-27 12:38:53 -0700 | [diff] [blame] | 31 | import android.view.View; |
cretin45 | 031e58e | 2015-01-27 15:23:16 -0800 | [diff] [blame] | 32 | |
Maarten Derks | e901e0c | 2017-05-22 11:15:44 +0200 | [diff] [blame] | 33 | import com.fairphone.setupwizard.R; |
| 34 | import com.fairphone.setupwizard.ui.SetupPageFragment; |
| 35 | import com.fairphone.setupwizard.ui.SetupWizardActivity; |
| 36 | import com.fairphone.setupwizard.util.SetupWizardUtils; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 37 | |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 38 | import java.lang.ref.WeakReference; |
| 39 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 40 | public class FinishPage extends SetupPage { |
| 41 | |
| 42 | public static final String TAG = "FinishPage"; |
| 43 | |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 44 | private static final String KEY_MESSENGER = "key_messenger"; |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 45 | |
cretin45 | 716ffa8 | 2015-01-21 15:55:03 -0800 | [diff] [blame] | 46 | private FinishFragment mFinishFragment; |
| 47 | |
cretin45 | 01f21da | 2015-02-23 13:52:37 -0800 | [diff] [blame] | 48 | public FinishPage(Context context, SetupDataCallbacks callbacks) { |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 49 | super(context, callbacks); |
| 50 | } |
| 51 | |
| 52 | @Override |
cretin45 | 61a331f | 2015-01-23 11:37:23 -0800 | [diff] [blame] | 53 | public Fragment getFragment(FragmentManager fragmentManager, int action) { |
| 54 | mFinishFragment = (FinishFragment)fragmentManager.findFragmentByTag(getKey()); |
| 55 | if (mFinishFragment == null) { |
| 56 | Bundle args = new Bundle(); |
| 57 | args.putString(Page.KEY_PAGE_ARGUMENT, getKey()); |
| 58 | args.putInt(Page.KEY_PAGE_ACTION, action); |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 59 | args.putParcelable(KEY_MESSENGER, new Messenger(mHandler)); |
cretin45 | 61a331f | 2015-01-23 11:37:23 -0800 | [diff] [blame] | 60 | mFinishFragment = new FinishFragment(); |
| 61 | mFinishFragment.setArguments(args); |
| 62 | } |
cretin45 | 716ffa8 | 2015-01-21 15:55:03 -0800 | [diff] [blame] | 63 | return mFinishFragment; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 66 | private final PageHandler mHandler = new PageHandler(this); |
| 67 | |
| 68 | private static class PageHandler extends Handler { |
| 69 | |
| 70 | private final WeakReference<FinishPage> mPage; |
| 71 | |
| 72 | private PageHandler(final FinishPage page) { |
| 73 | mPage = new WeakReference<>(page); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void handleMessage(final Message msg) { |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 81 | @Override |
| 82 | public String getKey() { |
| 83 | return TAG; |
| 84 | } |
| 85 | |
| 86 | @Override |
Joey Rizzoli | d133188 | 2016-12-29 17:28:02 +0100 | [diff] [blame] | 87 | public int getTitleResId() { |
| 88 | return R.string.setup_complete; |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
Joey Rizzoli | d133188 | 2016-12-29 17:28:02 +0100 | [diff] [blame] | 92 | public int getIconResId() { |
| 93 | return -1; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public boolean doNextAction() { |
cretin45 | 031e58e | 2015-01-27 15:23:16 -0800 | [diff] [blame] | 98 | getCallbacks().onFinish(); |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public int getNextButtonTitleResId() { |
Joey Rizzoli | d133188 | 2016-12-29 17:28:02 +0100 | [diff] [blame] | 104 | return R.string.start; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 105 | } |
| 106 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 107 | public static class FinishFragment extends SetupPageFragment { |
| 108 | |
| 109 | @Override |
cretin45 | 6355048 | 2016-04-27 12:38:53 -0700 | [diff] [blame] | 110 | protected void initializePage() { |
| 111 | final Activity activity = getActivity(); |
Joey Rizzoli | d133188 | 2016-12-29 17:28:02 +0100 | [diff] [blame] | 112 | if (activity == null) { |
Luis Mejia | b31e14b | 2016-07-14 11:51:58 -0700 | [diff] [blame] | 113 | return; |
cretin45 | 6355048 | 2016-04-27 12:38:53 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 116 | |
| 117 | @Override |
| 118 | protected int getLayoutResource() { |
Joey Rizzoli | d133188 | 2016-12-29 17:28:02 +0100 | [diff] [blame] | 119 | return R.layout.setup_finished_page; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 120 | } |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } |