From 57080c360c7dc36fd6094f143b31f3cad36f4998 Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Thu, 17 Mar 2016 13:58:26 -0700 Subject: SetupWizard: Restore last page on setup wizard death. Since the restore process (or any external setup wizard process) can take a long time to finish execution, save the current page and restore it on recreation when necessary. Change-Id: I575cf58047eb307c95408a0955dd7e5b50a62107 TICKET: CYNGNOS-2233 --- .../cyanogenmod/setupwizard/setup/AbstractSetupData.java | 15 +++++++++++++++ src/com/cyanogenmod/setupwizard/setup/PageList.java | 13 +++++++++++++ .../cyanogenmod/setupwizard/setup/SetupDataCallbacks.java | 1 + 3 files changed, 29 insertions(+) (limited to 'src/com/cyanogenmod/setupwizard/setup') diff --git a/src/com/cyanogenmod/setupwizard/setup/AbstractSetupData.java b/src/com/cyanogenmod/setupwizard/setup/AbstractSetupData.java index 105facf..edae5c6 100644 --- a/src/com/cyanogenmod/setupwizard/setup/AbstractSetupData.java +++ b/src/com/cyanogenmod/setupwizard/setup/AbstractSetupData.java @@ -135,6 +135,21 @@ public abstract class AbstractSetupData extends BroadcastReceiver implements Set doPreviousNext(runnable); } + @Override + public void setCurrentPage(String key) { + if (mPageList.getPage(key) != null) { + mCurrentPageIndex = mPageList.getPageIndex(key); + } + } + + public Page getNextPage(String key) { + if (mPageList.getPage(key) != null) { + int currentPageIndex = mPageList.getPageIndex(key); + return mPageList.getPage(currentPageIndex + 1); + } + return null; + } + private boolean advanceToNextUnhidden() { while (mCurrentPageIndex < mPageList.size()) { mCurrentPageIndex++; diff --git a/src/com/cyanogenmod/setupwizard/setup/PageList.java b/src/com/cyanogenmod/setupwizard/setup/PageList.java index 6709d47..dcb5bc1 100644 --- a/src/com/cyanogenmod/setupwizard/setup/PageList.java +++ b/src/com/cyanogenmod/setupwizard/setup/PageList.java @@ -16,6 +16,8 @@ package com.cyanogenmod.setupwizard.setup; +import android.text.TextUtils; + import java.util.LinkedHashMap; public class PageList extends LinkedHashMap { @@ -30,6 +32,17 @@ public class PageList extends LinkedHashMap { return get(key); } + public int getPageIndex(String key) { + int i=0; + for (Page page : values()) { + if (TextUtils.equals(page.getKey(), key)) { + return i; + } + i++; + } + return i; + } + public Page getPage(int index) { int i=0; for (Page page : values()) { diff --git a/src/com/cyanogenmod/setupwizard/setup/SetupDataCallbacks.java b/src/com/cyanogenmod/setupwizard/setup/SetupDataCallbacks.java index 6b4982b..338c838 100644 --- a/src/com/cyanogenmod/setupwizard/setup/SetupDataCallbacks.java +++ b/src/com/cyanogenmod/setupwizard/setup/SetupDataCallbacks.java @@ -26,5 +26,6 @@ public interface SetupDataCallbacks { boolean isCurrentPage(Page page); Page getPage(String key); Page getPage(int key); + void setCurrentPage(String key); void addFinishRunnable(Runnable runnable); } -- cgit v1.1