diff options
author | Edward Cross <edward.k.cross@gmail.com> | 2018-07-31 15:17:57 +0200 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-12-12 15:18:16 +0200 |
commit | 2ff76ca66a76f3efc96198967c3d1c94d2b8de77 (patch) | |
tree | c462dd9ad3c14a3bbcbf1840a989346068807e7f | |
parent | c2e244a55e8826fd5262df60e5c35aa324dbc1fa (diff) | |
download | android_packages_apps_Trebuchet-2ff76ca66a76f3efc96198967c3d1c94d2b8de77.tar.gz android_packages_apps_Trebuchet-2ff76ca66a76f3efc96198967c3d1c94d2b8de77.tar.bz2 android_packages_apps_Trebuchet-2ff76ca66a76f3efc96198967c3d1c94d2b8de77.zip |
Launcher3: Google Feed integration
If Google Search is installed, the Google Feed can be found at
the -1 screen (which is the very left).
This feature is enabled by default.
Change-Id: I495196818699fd378cd60e6dd61b07a0ab951762
-rw-r--r-- | Android.mk | 16 | ||||
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | libs/libGoogleFeed.jar | bin | 0 -> 24271 bytes | |||
-rw-r--r-- | res/values-ldrtl/lineage_config.xml | 19 | ||||
-rw-r--r-- | res/values/lineage_config.xml | 19 | ||||
-rw-r--r-- | res/values/lineage_strings.xml | 26 | ||||
-rw-r--r-- | res/xml/launcher_preferences.xml | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/lineage/LineageLauncherCallbacks.java | 54 | ||||
-rw-r--r-- | src/com/android/launcher3/lineage/LineageUtils.java | 17 | ||||
-rw-r--r-- | src/com/android/launcher3/lineage/OverlayCallbackImpl.java | 80 | ||||
-rw-r--r-- | src/com/android/launcher3/settings/SettingsActivity.java | 9 |
11 files changed, 240 insertions, 8 deletions
diff --git a/Android.mk b/Android.mk index a765b1399..811322f7a 100644 --- a/Android.mk +++ b/Android.mk @@ -40,6 +40,18 @@ LOCAL_MODULE := LauncherPluginLib include $(BUILD_STATIC_JAVA_LIBRARY) # +# Prebuilt Google Feed library +# +include $(CLEAR_VARS) +LOCAL_MODULE := libGoogleFeed +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := JAVA_LIBRARIES +LOCAL_SRC_FILES := libs/libGoogleFeed.jar +LOCAL_UNINSTALLABLE_MODULE := true +LOCAL_SDK_VERSION := 27 +include $(BUILD_PREBUILT) + +# # Build rule for Launcher3 dependencies lib. # include $(CLEAR_VARS) @@ -53,7 +65,9 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \ androidx.preference_preference \ iconloader_base -LOCAL_STATIC_JAVA_LIBRARIES := LauncherPluginLib +LOCAL_STATIC_JAVA_LIBRARIES := \ + LauncherPluginLib \ + libGoogleFeed LOCAL_SRC_FILES := \ $(call all-proto-files-under, protos) \ diff --git a/build.gradle b/build.gradle index e296455be..e419b0adc 100644 --- a/build.gradle +++ b/build.gradle @@ -147,6 +147,8 @@ repositories { } dependencies { + implementation fileTree(dir: 'libs', include: ['libGoogleFeed.jar']) + implementation "androidx.dynamicanimation:dynamicanimation:${ANDROID_X_VERSION}" implementation "androidx.recyclerview:recyclerview:${ANDROID_X_VERSION}" implementation "androidx.preference:preference:${ANDROID_X_VERSION}" diff --git a/libs/libGoogleFeed.jar b/libs/libGoogleFeed.jar Binary files differnew file mode 100644 index 000000000..5cda956ac --- /dev/null +++ b/libs/libGoogleFeed.jar diff --git a/res/values-ldrtl/lineage_config.xml b/res/values-ldrtl/lineage_config.xml new file mode 100644 index 000000000..7067ca880 --- /dev/null +++ b/res/values-ldrtl/lineage_config.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 The LineageOS 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. +--> +<resources> + + <string name="pref_show_google_now_summary" translatable="false">@string/msg_minus_one_on_left</string> +</resources> diff --git a/res/values/lineage_config.xml b/res/values/lineage_config.xml new file mode 100644 index 000000000..7067ca880 --- /dev/null +++ b/res/values/lineage_config.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 The LineageOS 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. +--> +<resources> + + <string name="pref_show_google_now_summary" translatable="false">@string/msg_minus_one_on_left</string> +</resources> diff --git a/res/values/lineage_strings.xml b/res/values/lineage_strings.xml new file mode 100644 index 000000000..e5a10302d --- /dev/null +++ b/res/values/lineage_strings.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 The LineageOS 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. +--> +<resources> + + <!-- Settings --> + + <!-- Settings title to show Google Now at -1 screen on launcher. [CHAR LIMIT=50] --> + <string name="title_show_google_app">Show Google app</string> + <!-- Settings message explaining when the -1 screen is available on an LTR device. [CHAR LIMIT=100] --> + <string name="msg_minus_one_on_left">When you swipe right from main home screen</string> + <!-- Settings message explaining when the -1 screen is available on an RTL device. [CHAR LIMIT=100] --> + <string name="msg_minus_one_on_right">When you swipe left from main home screen</string> +</resources> diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index 3455cb866..f4165c3b2 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -45,6 +45,12 @@ android:persistent="true" /> <SwitchPreference + android:defaultValue="true" + android:key="pref_enable_minus_one" + android:summary="@string/pref_show_google_now_summary" + android:title="@string/title_show_google_app" /> + + <SwitchPreference android:key="pref_grid_options" android:title="Enable grid options" android:defaultValue="false" diff --git a/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java b/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java index f71ad72e8..2e6e66728 100644 --- a/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java +++ b/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java @@ -21,6 +21,10 @@ import android.os.Bundle; import com.android.launcher3.AppInfo; import com.android.launcher3.LauncherCallbacks; +import com.android.launcher3.settings.SettingsActivity; +import com.android.launcher3.Utilities; + +import com.google.android.libraries.gsa.launcherclient.LauncherClient; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -28,9 +32,16 @@ import java.util.ArrayList; public class LineageLauncherCallbacks implements LauncherCallbacks, SharedPreferences.OnSharedPreferenceChangeListener { + 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; public LineageLauncherCallbacks(LineageLauncher launcher) { mLauncher = launcher; @@ -38,32 +49,50 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @Override public void onCreate(Bundle savedInstanceState) { - + SharedPreferences prefs = Utilities.getPrefs(mLauncher); + mOverlayCallbacks = new OverlayCallbackImpl(mLauncher); + mLauncherClient = new LauncherClient(mLauncher, mOverlayCallbacks, getClientOptions(prefs)); + mOverlayCallbacks.setClient(mLauncherClient); + prefs.registerOnSharedPreferenceChangeListener(this); } @Override public void onResume() { + mResumed = true; + if (mStarted) { + mAlreadyOnHome = true; + } + mLauncherClient.onResume(); } @Override public void onStart() { - + mStarted = true; + mLauncherClient.onStart(); } @Override public void onStop() { + mStarted = false; + if (!mResumed) { + mAlreadyOnHome = false; + } + mLauncherClient.onStop(); } @Override public void onPause() { - + mResumed = false; + mLauncherClient.onPause(); } @Override public void onDestroy() { + mLauncherClient.onDestroy(); + Utilities.getPrefs(mLauncher).unregisterOnSharedPreferenceChangeListener(this); } @Override @@ -83,12 +112,12 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @Override public void onAttachedToWindow() { - + mLauncherClient.onAttachedToWindow(); } @Override public void onDetachedFromWindow() { - + mLauncherClient.onDetachedFromWindow(); } @Override @@ -98,7 +127,7 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @Override public void onHomeIntent(boolean internalStateHandled) { - + mLauncherClient.hideOverlay(mAlreadyOnHome); } @Override @@ -123,6 +152,17 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @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, + true, /* enableHotword */ + true /* enablePrewarming */ + ); } } diff --git a/src/com/android/launcher3/lineage/LineageUtils.java b/src/com/android/launcher3/lineage/LineageUtils.java new file mode 100644 index 000000000..ae324dd10 --- /dev/null +++ b/src/com/android/launcher3/lineage/LineageUtils.java @@ -0,0 +1,17 @@ +package com.android.launcher3.lineage; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; + +public class LineageUtils { + + public static boolean hasPackageInstalled(Context context, String pkgName) { + try { + ApplicationInfo ai = context.getPackageManager().getApplicationInfo(pkgName, 0); + return ai.enabled; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } +} diff --git a/src/com/android/launcher3/lineage/OverlayCallbackImpl.java b/src/com/android/launcher3/lineage/OverlayCallbackImpl.java new file mode 100644 index 000000000..d0d6756a4 --- /dev/null +++ b/src/com/android/launcher3/lineage/OverlayCallbackImpl.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2016 The Android Open Source 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.android.launcher3.lineage; + +import com.android.launcher3.Launcher; +import com.android.launcher3.Launcher.LauncherOverlay; +import com.android.launcher3.Launcher.LauncherOverlayCallbacks; +import com.google.android.libraries.gsa.launcherclient.LauncherClient; +import com.google.android.libraries.gsa.launcherclient.LauncherClientCallbacks; + +/** + * Implements {@link LauncherOverlay} and passes all the corresponding events to {@link + * LauncherClient}. {@see setClient} + * + * <p>Implements {@link LauncherClientCallbacks} and sends all the corresponding callbacks to {@link + * Launcher}. + */ +public class OverlayCallbackImpl implements LauncherOverlay, LauncherClientCallbacks { + private final Launcher mLauncher; + + private LauncherClient mClient; + private LauncherOverlayCallbacks mLauncherOverlayCallbacks; + private boolean mWasOverlayAttached = false; + + public OverlayCallbackImpl(Launcher launcher) { + mLauncher = launcher; + } + + public void setClient(LauncherClient client) { + mClient = client; + } + + @Override + public void onServiceStateChanged(boolean overlayAttached, boolean hotwordActive) { + if (overlayAttached != mWasOverlayAttached) { + mWasOverlayAttached = overlayAttached; + mLauncher.setLauncherOverlay(overlayAttached ? this : null); + } + } + + @Override + public void onOverlayScrollChanged(float progress) { + if (mLauncherOverlayCallbacks != null) { + mLauncherOverlayCallbacks.onScrollChanged(progress); + } + } + + @Override + public void onScrollInteractionBegin() { + mClient.startMove(); + } + + @Override + public void onScrollInteractionEnd() { + mClient.endMove(); + } + + @Override + public void onScrollChange(float progress, boolean rtl) { + mClient.updateMove(progress); + } + + @Override + public void setOverlayCallbacks(Launcher.LauncherOverlayCallbacks callbacks) { + mLauncherOverlayCallbacks = callbacks; + } +} diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 18b6094fb..6209c5ef0 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -37,6 +37,8 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.GridOptionsProvider; +import com.android.launcher3.lineage.LineageLauncherCallbacks; +import com.android.launcher3.lineage.LineageUtils; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.util.SecureSettingsObserver; @@ -69,6 +71,8 @@ public class SettingsActivity extends Activity public static final String GRID_OPTIONS_PREFERENCE_KEY = "pref_grid_options"; + public static final String KEY_MINUS_ONE = "pref_enable_minus_one"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -230,6 +234,11 @@ public class SettingsActivity extends Activity // Show if plugins are enabled or flag UI is enabled. return FeatureFlags.showFlagTogglerUi(getContext()) || PluginManagerWrapper.hasPlugins(getContext()); + + case KEY_MINUS_ONE: + return LineageUtils.hasPackageInstalled(getActivity(), + LineageLauncherCallbacks.SEARCH_PACKAGE); + case GRID_OPTIONS_PREFERENCE_KEY: return Utilities.isDevelopersOptionsEnabled(getContext()) && Utilities.IS_DEBUG_DEVICE && |