summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Cross <edward.k.cross@gmail.com>2019-11-01 10:37:52 (GMT)
committerBruno Martins <bgcngm@gmail.com>2019-11-03 08:57:38 (GMT)
commitb6b08cb11b306077a2cdd88f642300078b561270 (patch)
treef018c319e4ebe7e671fb58722a6f4b2f04e94598
parent4cc9599aa5b04df9a6bc4bef4545f545a810a8f0 (diff)
downloadandroid_packages_apps_Trebuchet-b6b08cb11b306077a2cdd88f642300078b561270.zip
android_packages_apps_Trebuchet-b6b08cb11b306077a2cdd88f642300078b561270.tar.gz
android_packages_apps_Trebuchet-b6b08cb11b306077a2cdd88f642300078b561270.tar.bz2
Trebuchet: update feed lib
Change-Id: I75dffd93536c3827404d8a3feda741b79c08e337
-rw-r--r--libs/libGoogleFeed.jarbin24271 -> 50896 bytes
-rw-r--r--src/com/android/launcher3/lineage/LineageLauncher.java9
-rw-r--r--src/com/android/launcher3/lineage/LineageLauncherCallbacks.java152
3 files changed, 102 insertions, 59 deletions
diff --git a/libs/libGoogleFeed.jar b/libs/libGoogleFeed.jar
index 5cda956..158b76d 100644
--- a/libs/libGoogleFeed.jar
+++ b/libs/libGoogleFeed.jar
Binary files differ
diff --git a/src/com/android/launcher3/lineage/LineageLauncher.java b/src/com/android/launcher3/lineage/LineageLauncher.java
index 37150d8..f8aedcc 100644
--- a/src/com/android/launcher3/lineage/LineageLauncher.java
+++ b/src/com/android/launcher3/lineage/LineageLauncher.java
@@ -19,7 +19,14 @@ import com.android.launcher3.Launcher;
public class LineageLauncher extends Launcher {
+ private final LineageLauncherCallbacks mCallbacks;
+
public LineageLauncher() {
- setLauncherCallbacks(new LineageLauncherCallbacks(this));
+ mCallbacks = new LineageLauncherCallbacks(this);
+ setLauncherCallbacks(mCallbacks);
+ }
+
+ public LineageLauncherCallbacks getCallbacks() {
+ return mCallbacks;
}
}
diff --git a/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java b/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java
index 2e6e667..b7e662b 100644
--- a/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java
+++ b/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java
@@ -17,11 +17,15 @@ package com.android.launcher3.lineage;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
+import android.os.Handler;
import com.android.launcher3.AppInfo;
+import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherCallbacks;
-import com.android.launcher3.settings.SettingsActivity;
import com.android.launcher3.Utilities;
import com.google.android.libraries.gsa.launcherclient.LauncherClient;
@@ -31,22 +35,28 @@ import java.io.PrintWriter;
import java.util.ArrayList;
public class LineageLauncherCallbacks implements LauncherCallbacks,
- SharedPreferences.OnSharedPreferenceChangeListener {
- public static final String SEARCH_PACKAGE = "com.google.android.googlequicksearchbox";
+ OnSharedPreferenceChangeListener, OnDeviceProfileChangeListener {
+ public static final String KEY_ENABLE_MINUS_ONE = "pref_enable_minus_one";
+ public static final String SEARCH_PACKAGE = "com.google.android.googlequicksearchbox";
private final LineageLauncher mLauncher;
private OverlayCallbackImpl mOverlayCallbacks;
private LauncherClient mLauncherClient;
-
- private boolean mStarted;
- private boolean mResumed;
- private boolean mAlreadyOnHome;
+ private boolean mDeferCallbacks;
public LineageLauncherCallbacks(LineageLauncher launcher) {
mLauncher = launcher;
}
+ public void deferCallbacksUntilNextResumeOrStop() {
+ mDeferCallbacks = true;
+ }
+
+ public LauncherClient getLauncherClient() {
+ return mLauncherClient;
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
SharedPreferences prefs = Utilities.getPrefs(mLauncher);
@@ -54,80 +64,118 @@ public class LineageLauncherCallbacks implements LauncherCallbacks,
mLauncherClient = new LauncherClient(mLauncher, mOverlayCallbacks, getClientOptions(prefs));
mOverlayCallbacks.setClient(mLauncherClient);
prefs.registerOnSharedPreferenceChangeListener(this);
+
+ mLauncher.addOnDeviceProfileChangeListener(this);
}
@Override
- public void onResume() {
- mResumed = true;
- if (mStarted) {
- mAlreadyOnHome = true;
- }
+ public void onDetachedFromWindow() {
+ mLauncherClient.onDetachedFromWindow();
+ }
- mLauncherClient.onResume();
+ @Override
+ public void onAttachedToWindow() {
+ mLauncherClient.onAttachedToWindow();
}
@Override
- public void onStart() {
- mStarted = true;
- mLauncherClient.onStart();
+ public void onHomeIntent(boolean internalStateHandled) {
+ mLauncherClient.hideOverlay(mLauncher.isStarted() && !mLauncher.isForceInvisible());
}
@Override
- public void onStop() {
- mStarted = false;
- if (!mResumed) {
- mAlreadyOnHome = false;
+ public void onResume() {
+ Handler handler = mLauncher.getDragLayer().getHandler();
+ if (mDeferCallbacks) {
+ if (handler == null) {
+ // Finish defer if we are not attached to window.
+ checkIfStillDeferred();
+ } else {
+ // Wait one frame before checking as we can get multiple resume-pause events
+ // in the same frame.
+ handler.post(this::checkIfStillDeferred);
+ }
+ } else {
+ mLauncherClient.onResume();
}
- mLauncherClient.onStop();
}
@Override
public void onPause() {
- mResumed = false;
- mLauncherClient.onPause();
+ if (!mDeferCallbacks) {
+ mLauncherClient.onPause();
+ }
}
@Override
- public void onDestroy() {
- mLauncherClient.onDestroy();
-
- Utilities.getPrefs(mLauncher).unregisterOnSharedPreferenceChangeListener(this);
+ public void onStart() {
+ if (!mDeferCallbacks) {
+ mLauncherClient.onStart();
+ }
}
@Override
- public void onSaveInstanceState(Bundle outState) {
-
+ public void onStop() {
+ if (mDeferCallbacks) {
+ checkIfStillDeferred();
+ } else {
+ mLauncherClient.onStop();
+ }
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
-
+ public void onDeviceProfileChanged(DeviceProfile dp) {
+ mLauncherClient.reattachOverlay();
}
- @Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ private void checkIfStillDeferred() {
+ if (!mDeferCallbacks) {
+ return;
+ }
+ if (!mLauncher.hasBeenResumed() && mLauncher.isStarted()) {
+ return;
+ }
+ mDeferCallbacks = false;
+ // Move the client to the correct state. Calling the same method twice is no-op.
+ if (mLauncher.isStarted()) {
+ mLauncherClient.onStart();
+ }
+ if (mLauncher.hasBeenResumed()) {
+ mLauncherClient.onResume();
+ } else {
+ mLauncherClient.onPause();
+ }
+ if (!mLauncher.isStarted()) {
+ mLauncherClient.onStop();
+ }
}
-
@Override
- public void onAttachedToWindow() {
- mLauncherClient.onAttachedToWindow();
+ public void onDestroy() {
+ mLauncherClient.onDestroy();
+ Utilities.getPrefs(mLauncher).unregisterOnSharedPreferenceChangeListener(this);
}
@Override
- public void onDetachedFromWindow() {
- mLauncherClient.onDetachedFromWindow();
+ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+ if (KEY_ENABLE_MINUS_ONE.equals(key)) {
+ mLauncherClient.setClientOptions(getClientOptions(prefs));
+ }
}
@Override
- public void dump(String prefix, FileDescriptor fd, PrintWriter w, String[] args) {
+ public void onSaveInstanceState(Bundle outState) { }
- }
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) { }
@Override
- public void onHomeIntent(boolean internalStateHandled) {
- mLauncherClient.hideOverlay(mAlreadyOnHome);
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { }
+
+ @Override
+ public void dump(String prefix, FileDescriptor fd, PrintWriter w, String[] args) {
+ mLauncherClient.dump(prefix, w);
}
@Override
@@ -136,31 +184,19 @@ public class LineageLauncherCallbacks implements LauncherCallbacks,
}
@Override
- public void onTrimMemory(int level) {
-
- }
+ public void onTrimMemory(int level) { }
@Override
- public void onLauncherProviderChange() {
-
- }
+ public void onLauncherProviderChange() { }
@Override
public boolean startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData) {
return false;
}
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (SettingsActivity.KEY_MINUS_ONE.equals(key)) {
- mLauncherClient.setClientOptions(getClientOptions(sharedPreferences));
- }
- }
-
private LauncherClient.ClientOptions getClientOptions(SharedPreferences prefs) {
- boolean hasPackage = LineageUtils.hasPackageInstalled(mLauncher, SEARCH_PACKAGE);
- boolean isEnabled = prefs.getBoolean(SettingsActivity.KEY_MINUS_ONE, true);
- return new LauncherClient.ClientOptions(hasPackage && isEnabled,
+ return new LauncherClient.ClientOptions(
+ prefs.getBoolean(KEY_ENABLE_MINUS_ONE, true),
true, /* enableHotword */
true /* enablePrewarming */
);