Settings: Add Circle To Search [2/2]
Requires framework overlays: <string name="config_defaultContextualSearchPackageName" translatable="false">com.google.android.googlequicksearchbox</string> Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -306,4 +306,8 @@
|
|||||||
<!-- Long press navbar to search -->
|
<!-- Long press navbar to search -->
|
||||||
<string name="navbar_long_press_gesture_title">Long press to search</string>
|
<string name="navbar_long_press_gesture_title">Long press to search</string>
|
||||||
<string name="navbar_long_press_gesture_summary">Touch and hold the Home button or the navigation handle to search using the content on your screen</string>
|
<string name="navbar_long_press_gesture_summary">Touch and hold the Home button or the navigation handle to search using the content on your screen</string>
|
||||||
|
|
||||||
|
<!-- Circle to search -->
|
||||||
|
<string name="search_all_entrypoints_enabled_title">Circle to Search</string>
|
||||||
|
<string name="search_all_entrypoints_enabled_summary">Use CTS instead of Google Lens for navbar long press</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -73,6 +73,12 @@
|
|||||||
android:summary="@string/navbar_long_press_gesture_summary"
|
android:summary="@string/navbar_long_press_gesture_summary"
|
||||||
settings:controller="com.android.settings.gestures.GestureNavigationLongPressController" />
|
settings:controller="com.android.settings.gestures.GestureNavigationLongPressController" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:key="search_all_entrypoints_enabled"
|
||||||
|
android:title="@string/search_all_entrypoints_enabled_title"
|
||||||
|
android:summary="@string/search_all_entrypoints_enabled_summary"
|
||||||
|
settings:controller="com.android.settings.gestures.GestureNavigationCtsController" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Yet Another AOSP 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.settings.gestures;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
|
public class GestureNavigationCtsController extends TogglePreferenceController {
|
||||||
|
|
||||||
|
private final boolean mDefaultEnabled;
|
||||||
|
private final String mCtsPackage;
|
||||||
|
|
||||||
|
public GestureNavigationCtsController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
|
||||||
|
mDefaultEnabled = context.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_searchAllEntrypointsEnabledDefault);
|
||||||
|
mCtsPackage = mContext.getResources().getString(
|
||||||
|
com.android.internal.R.string.config_defaultContextualSearchPackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, mDefaultEnabled ? 1 : 0) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.SEARCH_ALL_ENTRYPOINTS_ENABLED, isChecked ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
PackageManager pm = mContext.getPackageManager();
|
||||||
|
if (pm == null) {
|
||||||
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ApplicationInfo ai = pm.getApplicationInfo(mCtsPackage, 0);
|
||||||
|
if (ai.enabled && ai.isProduct()) {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_system;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,17 +21,31 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
public class GestureNavigationLongPressController extends TogglePreferenceController {
|
public class GestureNavigationLongPressController extends TogglePreferenceController {
|
||||||
|
|
||||||
private static final String GSA_PACKAGE = "com.google.android.googlequicksearchbox";
|
private static final String GSA_PACKAGE = "com.google.android.googlequicksearchbox";
|
||||||
|
private static final String LONGPRESS_KEY = "search_all_entrypoints_enabled";
|
||||||
|
|
||||||
|
private Preference mLongPressPref;
|
||||||
|
|
||||||
public GestureNavigationLongPressController(Context context, String key) {
|
public GestureNavigationLongPressController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
|
||||||
|
mLongPressPref = (Preference) screen.findPreference(LONGPRESS_KEY);
|
||||||
|
mLongPressPref.setEnabled(isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return Settings.System.getInt(mContext.getContentResolver(),
|
return Settings.System.getInt(mContext.getContentResolver(),
|
||||||
@@ -40,6 +54,8 @@ public class GestureNavigationLongPressController extends TogglePreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
if (mLongPressPref != null)
|
||||||
|
mLongPressPref.setEnabled(isChecked);
|
||||||
return Settings.System.putInt(mContext.getContentResolver(),
|
return Settings.System.putInt(mContext.getContentResolver(),
|
||||||
Settings.System.NAVBAR_LONG_PRESS_GESTURE, isChecked ? 1 : 0);
|
Settings.System.NAVBAR_LONG_PRESS_GESTURE, isChecked ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user