diff options
-rw-r--r-- | Android.mk | 24 | ||||
-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/SettingsActivity.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher3/lineage/LineageLauncherCallbacks.java | 55 | ||||
-rw-r--r-- | src/com/android/launcher3/lineage/LineageUtils.java | 17 | ||||
-rw-r--r-- | src/com/android/launcher3/lineage/OverlayCallbackImpl.java | 80 |
11 files changed, 249 insertions, 10 deletions
diff --git a/Android.mk b/Android.mk index 2ec8b0a19..5a9489451 100644 --- a/Android.mk +++ b/Android.mk @@ -29,6 +29,18 @@ LOCAL_SDK_VERSION := current include $(BUILD_PREBUILT) # +# 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) @@ -68,7 +80,9 @@ include $(CLEAR_VARS) LOCAL_USE_AAPT2 := true LOCAL_MODULE_TAGS := optional +LOCAL_STATIC_JAVA_LIBRARIES := libGoogleFeed LOCAL_STATIC_ANDROID_LIBRARIES := Launcher3CommonDepsLib + LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ $(call all-java-files-under, src_ui_overrides) \ @@ -94,6 +108,8 @@ include $(BUILD_PACKAGE) include $(CLEAR_VARS) LOCAL_USE_AAPT2 := true LOCAL_MODULE_TAGS := optional + +LOCAL_STATIC_JAVA_LIBRARIES := libGoogleFeed LOCAL_STATIC_ANDROID_LIBRARIES := Launcher3CommonDepsLib LOCAL_SRC_FILES := \ @@ -127,7 +143,9 @@ LOCAL_USE_AAPT2 := true LOCAL_AAPT2_ONLY := true LOCAL_MODULE_TAGS := optional -LOCAL_STATIC_JAVA_LIBRARIES := libSharedSystemUI +LOCAL_STATIC_JAVA_LIBRARIES := \ + libSharedSystemUI \ + libGoogleFeed LOCAL_STATIC_ANDROID_LIBRARIES := Launcher3CommonDepsLib LOCAL_SRC_FILES := \ @@ -181,7 +199,9 @@ include $(CLEAR_VARS) LOCAL_USE_AAPT2 := true LOCAL_MODULE_TAGS := optional -LOCAL_STATIC_JAVA_LIBRARIES := libSharedSystemUI +LOCAL_STATIC_JAVA_LIBRARIES := \ + libSharedSystemUI \ + libGoogleFeed LOCAL_STATIC_ANDROID_LIBRARIES := Launcher3CommonDepsLib LOCAL_SRC_FILES := \ diff --git a/build.gradle b/build.gradle index 8fcd4b466..d974c551d 100644 --- a/build.gradle +++ b/build.gradle @@ -118,6 +118,8 @@ repositories { } dependencies { + implementation fileTree(dir: 'libs', include: ['libGoogleFeed.jar']) + implementation "com.android.support:support-v4:${SUPPORT_LIBS_VERSION}" implementation "com.android.support:support-dynamic-animation:${SUPPORT_LIBS_VERSION}" implementation "com.android.support:recyclerview-v7:${SUPPORT_LIBS_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..a7bf32345 --- /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>
\ No newline at end of file diff --git a/res/values/lineage_config.xml b/res/values/lineage_config.xml new file mode 100644 index 000000000..a7bf32345 --- /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>
\ No newline at end of file diff --git a/res/values/lineage_strings.xml b/res/values/lineage_strings.xml new file mode 100644 index 000000000..96b7004ed --- /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>
\ No newline at end of file diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index 3bba73a6c..63923053f 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -43,6 +43,12 @@ android:defaultValue="@bool/allow_rotation" 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" /> + <ListPreference android:key="pref_override_icon_shape" android:title="@string/icon_shape_override_label" diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java index 32c198ab0..c2dcfe4c2 100644 --- a/src/com/android/launcher3/SettingsActivity.java +++ b/src/com/android/launcher3/SettingsActivity.java @@ -36,6 +36,7 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; import android.provider.Settings; import android.text.TextUtils; import android.view.View; @@ -43,6 +44,8 @@ import android.widget.Adapter; import android.widget.ListView; import com.android.launcher3.graphics.IconShapeOverride; +import com.android.launcher3.lineage.LineageLauncherCallbacks; +import com.android.launcher3.lineage.LineageUtils; import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.util.ListViewHighlighter; import com.android.launcher3.util.SettingsObserver; @@ -66,6 +69,8 @@ public class SettingsActivity extends Activity { private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600; private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted"; + public static final String KEY_MINUS_ONE = "pref_enable_minus_one"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -136,6 +141,12 @@ public class SettingsActivity extends Activity { } else { // Initialize the UI once rotationPref.setDefaultValue(getAllowRotationDefaultValue()); + + SwitchPreference minusOne = (SwitchPreference) findPreference(KEY_MINUS_ONE); + if (!LineageUtils.hasPackageInstalled(getActivity(), + LineageLauncherCallbacks.SEARCH_PACKAGE)) { + getPreferenceScreen().removePreference(minusOne); + } } } diff --git a/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java b/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java index d61aa3fe6..138991289 100644 --- a/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java +++ b/src/com/android/launcher3/lineage/LineageLauncherCallbacks.java @@ -21,6 +21,9 @@ import android.os.Bundle; import com.android.launcher3.AppInfo; import com.android.launcher3.LauncherCallbacks; +import com.android.launcher3.SettingsActivity; +import com.android.launcher3.Utilities; +import com.google.android.libraries.gsa.launcherclient.LauncherClient; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -28,9 +31,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 +48,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 +111,12 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @Override public void onAttachedToWindow() { - + mLauncherClient.onAttachedToWindow(); } @Override public void onDetachedFromWindow() { - + mLauncherClient.onDetachedFromWindow(); } @Override @@ -98,7 +126,7 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @Override public void onHomeIntent(boolean internalStateHandled) { - + mLauncherClient.hideOverlay(mAlreadyOnHome); } @Override @@ -128,11 +156,22 @@ public class LineageLauncherCallbacks implements LauncherCallbacks, @Override public boolean hasSettings() { - return false; + return true; } @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; + } +} |