diff options
author | Anay Wadhera <awadhera@berkeley.edu> | 2020-10-10 22:46:40 -0700 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2022-05-06 14:30:30 +0800 |
commit | 7d5a1134e0476425fc0ec377a9441559ef0b0dbc (patch) | |
tree | 5e4129e7dabd52a2484f9be6e3f355f1b8f60851 | |
parent | 6dd012ebd21d7049f44bec4d7bef489a398e2ce3 (diff) |
CustomLauncher: Google Feed integration
Change-Id: I4dd635369513e7e8db8f8e4363acb017e0ce8eb1
[kdrag0n: Debranded to com.android.launcher3]
[kdrag0n: Ported to Android 12 and converted libGoogleFeed to Soong]
Signed-off-by: Danny Lin <danny@kdrag0n.dev>
-rw-r--r-- | Android.bp | 8 | ||||
-rw-r--r-- | libs/libGoogleFeed.jar | bin | 0 -> 50896 bytes | |||
-rw-r--r-- | quickstep/src/com/android/launcher3/CustomLauncher.java | 6 | ||||
-rw-r--r-- | res/values/ice_strings.xml | 27 | ||||
-rw-r--r-- | res/xml/launcher_preferences.xml | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/OverlayCallbackImpl.java | 185 | ||||
-rw-r--r-- | src/com/android/launcher3/settings/SettingsActivity.java | 28 |
7 files changed, 260 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp index bab994add5..817d2120da 100644 --- a/Android.bp +++ b/Android.bp @@ -100,6 +100,13 @@ java_library { min_sdk_version: min_launcher3_sdk_version, } +java_import { + name: "libGoogleFeed", + jars: [ + "libs/libGoogleFeed.jar", + ], +} + // Library with all the dependencies for building Launcher3 android_library { name: "Launcher3ResLib", @@ -117,6 +124,7 @@ android_library { "androidx.cardview_cardview", "com.google.android.material_material", "iconloader_base", + "libGoogleFeed", ], manifest: "AndroidManifest-common.xml", sdk_version: "current", diff --git a/libs/libGoogleFeed.jar b/libs/libGoogleFeed.jar Binary files differnew file mode 100644 index 0000000000..158b76de40 --- /dev/null +++ b/libs/libGoogleFeed.jar diff --git a/quickstep/src/com/android/launcher3/CustomLauncher.java b/quickstep/src/com/android/launcher3/CustomLauncher.java index 30060ead8e..1e41f42436 100644 --- a/quickstep/src/com/android/launcher3/CustomLauncher.java +++ b/quickstep/src/com/android/launcher3/CustomLauncher.java @@ -17,7 +17,13 @@ package com.android.launcher3; import com.android.launcher3.uioverrides.QuickstepLauncher; +import com.android.systemui.plugins.shared.LauncherOverlayManager; public class CustomLauncher extends QuickstepLauncher { + @Override + protected LauncherOverlayManager getDefaultOverlay() { + return new OverlayCallbackImpl(this); + } + } diff --git a/res/values/ice_strings.xml b/res/values/ice_strings.xml new file mode 100644 index 0000000000..fc75f8f81f --- /dev/null +++ b/res/values/ice_strings.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +* 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. +*/ +--> +<resources> + <!-- Settings title to show Google Now at -1 screen on launcher. [CHAR LIMIT=50] --> + <string name="title_show_google_app">Swipe to access 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">From Home screen, swipe left to open Google app</string> + <!-- Settings message explaining when the -1 screen is available on an RTL device. [CHAR LIMIT=100] --> + <string name="msg_minus_one_on_right">From Home screen, swipe right to open Google app</string> + <string name="pref_show_google_now_summary" translatable="false">@string/msg_minus_one_on_left</string> +</resources> diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index 90de4987f5..3ae0f0c481 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -50,6 +50,12 @@ launcher:logIdOn="615" launcher:logIdOff="616" /> + <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"/> + <androidx.preference.PreferenceScreen android:key="pref_developer_options" android:persistent="false" diff --git a/src/com/android/launcher3/OverlayCallbackImpl.java b/src/com/android/launcher3/OverlayCallbackImpl.java new file mode 100644 index 0000000000..8d8609bce4 --- /dev/null +++ b/src/com/android/launcher3/OverlayCallbackImpl.java @@ -0,0 +1,185 @@ +/* + * 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; + +import android.app.Activity; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.os.Bundle; + +import com.android.launcher3.Launcher; +import com.android.launcher3.Utilities; +import com.android.systemui.plugins.shared.LauncherOverlayManager; +import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay; + +import com.google.android.libraries.gsa.launcherclient.LauncherClient; +import com.google.android.libraries.gsa.launcherclient.LauncherClientCallbacks; + +import java.io.PrintWriter; + +/** + * 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, LauncherOverlayManager, + OnSharedPreferenceChangeListener { + + public static final String KEY_ENABLE_MINUS_ONE = "pref_enable_minus_one"; + + private final Launcher mLauncher; + private final LauncherClient mClient; + + private LauncherOverlayCallbacks mLauncherOverlayCallbacks; + private boolean mWasOverlayAttached = false; + + public OverlayCallbackImpl(Launcher launcher) { + SharedPreferences prefs = Utilities.getPrefs(launcher); + + mLauncher = launcher; + mClient = new LauncherClient(mLauncher, this, getClientOptions(prefs)); + prefs.registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onDeviceProvideChanged() { + mClient.reattachOverlay(); + } + + @Override + public void onAttachedToWindow() { + mClient.onAttachedToWindow(); + } + + @Override + public void onDetachedFromWindow() { + mClient.onDetachedFromWindow(); + } + + @Override + public void dump(String prefix, PrintWriter w) { + mClient.dump(prefix, w); + } + + @Override + public void openOverlay() { + mClient.showOverlay(true); + } + + @Override + public void hideOverlay(boolean animate) { + mClient.hideOverlay(animate); + } + + @Override + public void hideOverlay(int duration) { + mClient.hideOverlay(duration); + } + + @Override + public boolean startSearch(byte[] config, Bundle extras) { + return false; + } + + @Override + public void onActivityCreated(Activity activity, Bundle bundle) { + // Not called + } + + @Override + public void onActivityStarted(Activity activity) { + mClient.onStart(); + } + + @Override + public void onActivityResumed(Activity activity) { + mClient.onResume(); + } + + @Override + public void onActivityPaused(Activity activity) { + mClient.onPause(); + } + + @Override + public void onActivityStopped(Activity activity) { + mClient.onStop(); + } + + @Override + public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { } + + @Override + public void onActivityDestroyed(Activity activity) { + mClient.onDestroy(); + mLauncher.getSharedPrefs().unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + if (KEY_ENABLE_MINUS_ONE.equals(key)) { + mClient.setClientOptions(getClientOptions(prefs)); + } + } + + @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(LauncherOverlayCallbacks callbacks) { + mLauncherOverlayCallbacks = callbacks; + } + + + private LauncherClient.ClientOptions getClientOptions(SharedPreferences prefs) { + return new LauncherClient.ClientOptions( + prefs.getBoolean(KEY_ENABLE_MINUS_ONE, true), + true, /* enableHotword */ + true /* enablePrewarming */ + ); + } +} diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 0c39632708..0885df9be2 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -20,8 +20,12 @@ import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTIO import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY; +import static com.android.launcher3.OverlayCallbackImpl.KEY_ENABLE_MINUS_ONE; + +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.os.Bundle; import android.text.TextUtils; import android.view.MenuItem; @@ -189,6 +193,10 @@ public class SettingsActivity extends FragmentActivity private boolean mPreferenceHighlighted = false; private Preference mDeveloperOptionPref; + protected static final String GSA_PACKAGE = "com.google.android.googlequicksearchbox"; + + private Preference mShowGoogleAppPref; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { final Bundle args = getArguments(); @@ -270,6 +278,11 @@ public class SettingsActivity extends FragmentActivity case DEVELOPER_OPTIONS_KEY: mDeveloperOptionPref = preference; return updateDeveloperOption(); + + case KEY_ENABLE_MINUS_ONE: + mShowGoogleAppPref = preference; + updateIsGoogleAppEnabled(); + return true; } return true; @@ -293,6 +306,20 @@ public class SettingsActivity extends FragmentActivity return showPreference; } + public static boolean isGSAEnabled(Context context) { + try { + return context.getPackageManager().getApplicationInfo(GSA_PACKAGE, 0).enabled; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + private void updateIsGoogleAppEnabled() { + if (mShowGoogleAppPref != null) { + mShowGoogleAppPref.setEnabled(isGSAEnabled(getContext())); + } + } + @Override public void onResume() { super.onResume(); @@ -308,6 +335,7 @@ public class SettingsActivity extends FragmentActivity requestAccessibilityFocus(getListView()); } } + updateIsGoogleAppEnabled(); } private PreferenceHighlighter createHighlighter() { |