Skip to content

Commit c105d5a

Browse files
ekcrossneobuddy89
authored andcommittedJun 28, 2024
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. [neobuddy89: Improvise checks. Move to SwitchPreferenceCompat] Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
1 parent 13a5a58 commit c105d5a

File tree

10 files changed

+247
-0
lines changed

10 files changed

+247
-0
lines changed
 

‎Android.bp

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ android_library {
179179
"androidx.window_window",
180180
"com.google.android.material_material",
181181
"iconloader_base",
182+
"libGoogleFeed",
182183
"SettingsLib",
183184
"view_capture",
184185
"animationlib",
@@ -263,6 +264,13 @@ android_app {
263264
},
264265
}
265266

267+
java_import {
268+
name: "libGoogleFeed",
269+
jars: [
270+
"libs/libGoogleFeed.jar",
271+
],
272+
}
273+
266274
// Library with all the dependencies for building quickstep
267275
android_library {
268276
name: "QuickstepResLib",

‎build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ allprojects {
143143
}
144144

145145
dependencies {
146+
implementation fileTree(dir: 'libs', include: ['libGoogleFeed.jar'])
147+
146148
implementation "androidx.dynamicanimation:dynamicanimation:${ANDROID_X_VERSION}"
147149
implementation "androidx.recyclerview:recyclerview:${ANDROID_X_VERSION}"
148150
implementation "androidx.preference:preference:${ANDROID_X_VERSION}"

‎libs/libGoogleFeed.jar

49.7 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.launcher3.uioverrides;
18+
19+
import android.app.Activity;
20+
import android.content.SharedPreferences;
21+
import android.os.Bundle;
22+
23+
import com.android.launcher3.Launcher;
24+
import com.android.launcher3.LauncherPrefs;
25+
import com.android.systemui.plugins.shared.LauncherOverlayManager;
26+
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
27+
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks;
28+
29+
import com.google.android.libraries.gsa.launcherclient.LauncherClient;
30+
import com.google.android.libraries.gsa.launcherclient.LauncherClientCallbacks;
31+
32+
import java.io.PrintWriter;
33+
34+
/**
35+
* Implements {@link LauncherOverlay} and passes all the corresponding events to {@link
36+
* LauncherClient}. {@see setClient}
37+
*
38+
* <p>Implements {@link LauncherClientCallbacks} and sends all the corresponding callbacks to {@link
39+
* Launcher}.
40+
*/
41+
public class OverlayCallbackImpl
42+
implements LauncherOverlay, LauncherClientCallbacks, LauncherOverlayManager,
43+
SharedPreferences.OnSharedPreferenceChangeListener {
44+
45+
private static final String KEY_ENABLE_MINUS_ONE = "pref_enable_minus_one";
46+
47+
private final Launcher mLauncher;
48+
private final LauncherClient mClient;
49+
50+
private LauncherOverlayCallbacks mLauncherOverlayCallbacks;
51+
private boolean mWasOverlayAttached = false;
52+
53+
public OverlayCallbackImpl(Launcher launcher) {
54+
SharedPreferences prefs = LauncherPrefs.getPrefs(launcher);
55+
56+
mLauncher = launcher;
57+
mClient = new LauncherClient(mLauncher, this, getClientOptions(prefs));
58+
prefs.registerOnSharedPreferenceChangeListener(this);
59+
}
60+
61+
@Override
62+
public void onDeviceProvideChanged() {
63+
mClient.reattachOverlay();
64+
}
65+
66+
@Override
67+
public void onAttachedToWindow() {
68+
mClient.onAttachedToWindow();
69+
}
70+
71+
@Override
72+
public void onDetachedFromWindow() {
73+
mClient.onDetachedFromWindow();
74+
}
75+
76+
@Override
77+
public void dump(String prefix, PrintWriter w) {
78+
mClient.dump(prefix, w);
79+
}
80+
81+
@Override
82+
public void openOverlay() {
83+
mClient.showOverlay(true);
84+
}
85+
86+
@Override
87+
public void hideOverlay(boolean animate) {
88+
mClient.hideOverlay(animate);
89+
}
90+
91+
@Override
92+
public void hideOverlay(int duration) {
93+
mClient.hideOverlay(duration);
94+
}
95+
96+
@Override
97+
public void onActivityStarted() {
98+
mClient.onStart();
99+
}
100+
101+
@Override
102+
public void onActivityResumed() {
103+
mClient.onResume();
104+
}
105+
106+
@Override
107+
public void onActivityPaused() {
108+
mClient.onPause();
109+
}
110+
111+
@Override
112+
public void onActivityStopped() {
113+
mClient.onStop();
114+
}
115+
116+
@Override
117+
public void onActivityDestroyed() {
118+
mClient.onDestroy();
119+
mLauncher.getSharedPrefs().unregisterOnSharedPreferenceChangeListener(this);
120+
}
121+
122+
@Override
123+
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
124+
if (KEY_ENABLE_MINUS_ONE.equals(key)) {
125+
mClient.setClientOptions(getClientOptions(prefs));
126+
}
127+
}
128+
129+
@Override
130+
public void onServiceStateChanged(boolean overlayAttached, boolean hotwordActive) {
131+
if (overlayAttached != mWasOverlayAttached) {
132+
mWasOverlayAttached = overlayAttached;
133+
mLauncher.setLauncherOverlay(overlayAttached ? this : null);
134+
}
135+
}
136+
137+
@Override
138+
public void onOverlayScrollChanged(float progress) {
139+
if (mLauncherOverlayCallbacks != null) {
140+
mLauncherOverlayCallbacks.onOverlayScrollChanged(progress);
141+
}
142+
}
143+
144+
@Override
145+
public void onScrollInteractionBegin() {
146+
mClient.startMove();
147+
}
148+
149+
@Override
150+
public void onScrollInteractionEnd() {
151+
mClient.endMove();
152+
}
153+
154+
@Override
155+
public void onScrollChange(float progress, boolean rtl) {
156+
mClient.updateMove(progress);
157+
}
158+
159+
@Override
160+
public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) {
161+
mLauncherOverlayCallbacks = callbacks;
162+
}
163+
164+
private LauncherClient.ClientOptions getClientOptions(SharedPreferences prefs) {
165+
return new LauncherClient.ClientOptions(
166+
prefs.getBoolean(KEY_ENABLE_MINUS_ONE, true),
167+
true, /* enableHotword */
168+
true /* enablePrewarming */
169+
);
170+
}
171+
}

‎quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
import com.android.quickstep.views.OverviewActionsView;
183183
import com.android.quickstep.views.RecentsView;
184184
import com.android.quickstep.views.TaskView;
185+
import com.android.systemui.plugins.shared.LauncherOverlayManager;
185186
import com.android.systemui.shared.recents.model.Task;
186187
import com.android.systemui.shared.system.ActivityManagerWrapper;
187188
import com.android.systemui.unfold.RemoteUnfoldSharedComponent;
@@ -249,6 +250,11 @@ public class QuickstepLauncher extends Launcher {
249250

250251
private HomeTransitionController mHomeTransitionController;
251252

253+
@Override
254+
protected LauncherOverlayManager getDefaultOverlay() {
255+
return new OverlayCallbackImpl(this);
256+
}
257+
252258
@Override
253259
protected void setupViews() {
254260
super.setupViews();

‎res/values-ldrtl/cr_strings.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2016-2024 crDroid Android Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
18+
19+
<string name="pref_show_google_now_summary" translatable="false">@string/msg_minus_one_on_right</string>
20+
</resources>

‎res/values/cr_strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@
5252
<!-- Hide labels -->
5353
<string name="desktop_show_labels">Icon labels on desktop</string>
5454
<string name="drawer_show_labels">Icon labels in drawer</string>
55+
56+
<!-- Settings title to show Google Now at -1 screen on launcher. [CHAR LIMIT=50] -->
57+
<string name="title_show_google_app">Swipe to access Google app</string>
58+
<string name="pref_show_google_now_summary" translatable="false">@string/msg_minus_one_on_left</string>
59+
<!-- Settings message explaining when the -1 screen is available on an LTR device. [CHAR LIMIT=100] -->
60+
<string name="msg_minus_one_on_left">When you swipe right from main home screen</string>
61+
<!-- Settings message explaining when the -1 screen is available on an RTL device. [CHAR LIMIT=100] -->
62+
<string name="msg_minus_one_on_right">When you swipe left from main home screen</string>
5563
</resources>

‎res/xml/launcher_home_screen_preferences.xml

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
<PreferenceCategory
4747
android:title="@string/interface_category_title">
4848

49+
<SwitchPreferenceCompat
50+
android:key="pref_enable_minus_one"
51+
android:title="@string/title_show_google_app"
52+
android:summary="@string/pref_show_google_now_summary"
53+
android:defaultValue="true"
54+
launcher:iconSpaceReserved="false" />
55+
4956
<SwitchPreferenceCompat
5057
android:key="pref_desktop_show_labels"
5158
android:title="@string/desktop_show_labels"

‎src/com/android/launcher3/Utilities.java

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.content.SharedPreferences;
3333
import android.content.pm.LauncherActivityInfo;
3434
import android.content.pm.LauncherApps;
35+
import android.content.pm.PackageManager;
3536
import android.content.pm.ShortcutInfo;
3637
import android.content.res.Configuration;
3738
import android.content.res.Resources;
@@ -152,6 +153,8 @@ public final class Utilities {
152153
@IntDef({TRANSLATE_UP, TRANSLATE_DOWN, TRANSLATE_LEFT, TRANSLATE_RIGHT})
153154
public @interface AdjustmentDirection{}
154155

156+
public static final String GSA_PACKAGE = "com.google.android.googlequicksearchbox";
157+
155158
/**
156159
* Returns true if theme is dark.
157160
*/
@@ -842,4 +845,12 @@ public static boolean isWorkspaceEditAllowed(Context context) {
842845
SharedPreferences prefs = LauncherPrefs.getPrefs(context.getApplicationContext());
843846
return !prefs.getBoolean(InvariantDeviceProfile.KEY_WORKSPACE_LOCK, false);
844847
}
848+
849+
public static boolean isGSAEnabled(Context context) {
850+
try {
851+
return context.getPackageManager().getApplicationInfo(GSA_PACKAGE, 0).enabled;
852+
} catch (PackageManager.NameNotFoundException e) {
853+
return false;
854+
}
855+
}
845856
}

‎src/com/android/launcher3/settings/SettingsHomescreen.java

+14
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ public static class HomescreenSettingsFragment extends PreferenceFragmentCompat
151151
private String mHighLightKey;
152152
private boolean mPreferenceHighlighted = false;
153153

154+
private static final String KEY_MINUS_ONE = "pref_enable_minus_one";
155+
156+
private Preference mShowGoogleAppPref;
157+
154158
@Override
155159
public void onCreate(@Nullable Bundle savedInstanceState) {
156160
super.onCreate(savedInstanceState);
@@ -168,6 +172,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
168172
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
169173
setPreferencesFromResource(R.xml.launcher_home_screen_preferences, rootKey);
170174

175+
mShowGoogleAppPref = getPreferenceScreen().findPreference(KEY_MINUS_ONE);
176+
updateIsGoogleAppEnabled();
177+
171178
if (getActivity() != null && !TextUtils.isEmpty(getPreferenceScreen().getTitle())) {
172179
getActivity().setTitle(getPreferenceScreen().getTitle());
173180
}
@@ -197,6 +204,12 @@ public void onSaveInstanceState(Bundle outState) {
197204
outState.putBoolean(SAVE_HIGHLIGHTED_KEY, mPreferenceHighlighted);
198205
}
199206

207+
private void updateIsGoogleAppEnabled() {
208+
if (mShowGoogleAppPref != null) {
209+
mShowGoogleAppPref.setEnabled(Utilities.isGSAEnabled(getContext()));
210+
}
211+
}
212+
200213
@Override
201214
public void onResume() {
202215
super.onResume();
@@ -208,6 +221,7 @@ public void onResume() {
208221
mPreferenceHighlighted = true;
209222
}
210223
}
224+
updateIsGoogleAppEnabled();
211225

212226
if (mRestartOnResume) {
213227
recreateActivityNow();

0 commit comments

Comments
 (0)
Please sign in to comment.