diff options
author | Adam Cohen <adamcohen@google.com> | 2014-01-08 15:21:04 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2014-01-09 14:08:49 -0800 |
commit | b54a5989a21bef4e6bac304591ca4030bfbe709d (patch) | |
tree | 5e85ea2abfc34b7cdefa9daff0d0c1d575a487cc | |
parent | 0259c629cb5b280d0d9c821f8b1685707d7ba589 (diff) | |
download | android_packages_apps_Trebuchet-b54a5989a21bef4e6bac304591ca4030bfbe709d.tar.gz android_packages_apps_Trebuchet-b54a5989a21bef4e6bac304591ca4030bfbe709d.tar.bz2 android_packages_apps_Trebuchet-b54a5989a21bef4e6bac304591ca4030bfbe709d.zip |
Adding optional first run activity to Launcher
Change-Id: I146927d8a065f1cf5ef5cec41c8fb4f9ad09d25c
-rw-r--r-- | src/com/android/launcher3/Alarm.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 54 | ||||
-rw-r--r-- | src/com/android/launcher3/OnAlarmListener.java | 5 |
3 files changed, 50 insertions, 13 deletions
diff --git a/src/com/android/launcher3/Alarm.java b/src/com/android/launcher3/Alarm.java index 91f9bd091..e9f1fd963 100644 --- a/src/com/android/launcher3/Alarm.java +++ b/src/com/android/launcher3/Alarm.java @@ -78,7 +78,3 @@ public class Alarm implements Runnable{ return mAlarmPending; } } - -interface OnAlarmListener { - public void onAlarm(Alarm alarm); -} diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index c05769cfa..269f53baa 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -187,6 +187,9 @@ public class Launcher extends Activity // Type: int[] private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids"; + + static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed"; + private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = "com.android.launcher.toolbar_search_icon"; @@ -476,6 +479,7 @@ public class Launcher extends Activity // On large interfaces, we want the screen to auto-rotate based on the current orientation unlockScreenOrientation(true); + showFirstRunActivity(); showFirstRunCling(); } @@ -498,6 +502,21 @@ public class Launcher extends Activity } /** + * To be overridden by subclasses to indicate that there is an activity to launch + * before showing the standard launcher experience. + */ + protected boolean hasFirstRunActivity() { + return false; + } + + /** + * To be overridden by subclasses to launch any first run activity + */ + protected Intent getFirstRunActivity() { + return null; + } + + /** * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to * ensure the custom content page is added or removed if necessary. */ @@ -4206,6 +4225,10 @@ public class Launcher extends Activity } } + private boolean shouldRunFirstRunActivity() { + return !ActivityManager.isRunningInTestHarness(); + } + /* Cling related */ private boolean isClingsEnabled() { if (DISABLE_CLINGS) { @@ -4274,15 +4297,9 @@ public class Launcher extends Activity final Runnable cleanUpClingCb = new Runnable() { public void run() { cling.cleanup(); - // We should update the shared preferences on a background thread - new AsyncTask<Void, Void, Void>() { - public Void doInBackground(Void ... args) { - SharedPreferences.Editor editor = mSharedPrefs.edit(); - editor.putBoolean(flag, true); - editor.commit(); - return null; - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); + SharedPreferences.Editor editor = mSharedPrefs.edit(); + editor.putBoolean(flag, true); + editor.apply(); if (postAnimationCb != null) { postAnimationCb.run(); } @@ -4379,10 +4396,29 @@ public class Launcher extends Activity } } + public void showFirstRunActivity() { + if (shouldRunFirstRunActivity() && hasFirstRunActivity() + && !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false)) { + Intent firstRunIntent = getFirstRunActivity(); + if (firstRunIntent != null) { + startActivity(firstRunIntent); + markFirstRunActivityShown(); + } + } + } + + private void markFirstRunActivityShown() { + SharedPreferences.Editor editor = mSharedPrefs.edit(); + editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true); + editor.apply(); + } + public void showFirstRunCling() { if (isClingsEnabled() && !mSharedPrefs.getBoolean(Cling.FIRST_RUN_CLING_DISMISSED_KEY, false) && !skipCustomClingIfNoAccounts() ) { + + // If we're not using the default workspace layout, replace workspace cling // with a custom workspace cling (usually specified in an overlay) // For now, only do this on tablets diff --git a/src/com/android/launcher3/OnAlarmListener.java b/src/com/android/launcher3/OnAlarmListener.java new file mode 100644 index 000000000..b5ef83e83 --- /dev/null +++ b/src/com/android/launcher3/OnAlarmListener.java @@ -0,0 +1,5 @@ +package com.android.launcher3; + +public interface OnAlarmListener { + public void onAlarm(Alarm alarm); +} |