Merge "Migrate AA+ Search related files" into sc-dev am: 1d8a2a6e0d
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/13521180 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Id4337e6167723d5008705f29ce94c2bb1e7ceaea
This commit is contained in:
commit
f59c60753f
28 files changed
-2767
No files matched your search
@@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2020 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.
|
||||
-->
|
||||
<com.android.launcher3.search.FallbackSearchInputView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="48dp"
|
||||
android:layout_marginRight="48dp"
|
||||
android:background="@android:color/transparent"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="start|center_vertical"
|
||||
android:inputType="textNoSuggestions"
|
||||
android:imeOptions="actionSearch|flagNoExtractUi"
|
||||
android:maxLines="1"
|
||||
android:privateImeOptions="bc_search"
|
||||
android:scrollHorizontally="true"
|
||||
android:singleLine="true"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textColorHint="?android:attr/textColorTertiary"
|
||||
android:textSize="16sp" />
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2008 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.
|
||||
-->
|
||||
<com.android.launcher3.search.DeviceSearchEdu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/search_box_wrapper"
|
||||
android:layout_width="match_parent">
|
||||
|
||||
<include
|
||||
layout="@layout/fallback_search_input"
|
||||
android:id="@+id/mock_search_box" />
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/edu_wrapper"
|
||||
android:padding="24dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent">
|
||||
|
||||
<TextView
|
||||
style="@style/TextHeadline"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="24sp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/search_edu_primary" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextHeadline"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="18sp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/search_edu_secondary" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/dismiss_edu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_marginTop="@dimen/dynamic_grid_edge_margin"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/search_edu_dismiss" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.android.launcher3.search.DeviceSearchEdu>
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2008 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.
|
||||
-->
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon xmlns:launcher="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/BaseIcon.AllApps"
|
||||
launcher:iconDisplay="all_apps"
|
||||
launcher:centerVertically="true" />
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2020 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.
|
||||
-->
|
||||
<com.android.launcher3.search.SearchResultIconRow xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/dynamic_grid_edge_margin">
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
launcher:iconDisplay="hero_app" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/dynamic_grid_edge_margin"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_vertical"
|
||||
android:maxLines="1"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/search_hero_title_size" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/subtitle"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="@dimen/search_hero_subtitle_size"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon
|
||||
android:id="@+id/shortcut_0"
|
||||
style="@style/BaseIcon"
|
||||
android:layout_width="@dimen/deep_shortcut_icon_size"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="4dp"
|
||||
android:gravity="center"
|
||||
launcher:iconDisplay="shortcut_popup"
|
||||
android:textSize="@dimen/search_hero_inline_button_size"
|
||||
launcher:iconSizeOverride="@dimen/deep_shortcut_icon_size"
|
||||
launcher:layoutHorizontal="false" />
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon
|
||||
android:id="@+id/shortcut_1"
|
||||
style="@style/BaseIcon"
|
||||
android:layout_width="@dimen/deep_shortcut_icon_size"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="4dp"
|
||||
android:gravity="center"
|
||||
launcher:iconDisplay="shortcut_popup"
|
||||
android:textSize="@dimen/search_hero_inline_button_size"
|
||||
launcher:iconSizeOverride="@dimen/deep_shortcut_icon_size"
|
||||
launcher:layoutHorizontal="false" />
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon
|
||||
android:id="@+id/shortcut_2"
|
||||
style="@style/BaseIcon"
|
||||
android:layout_width="@dimen/deep_shortcut_icon_size"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="4dp"
|
||||
android:gravity="center"
|
||||
launcher:iconDisplay="shortcut_popup"
|
||||
android:textSize="@dimen/search_hero_inline_button_size"
|
||||
launcher:iconSizeOverride="@dimen/deep_shortcut_icon_size"
|
||||
launcher:layoutHorizontal="false" />
|
||||
</com.android.launcher3.search.SearchResultIconRow>
|
||||
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2020 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.
|
||||
-->
|
||||
<com.android.launcher3.search.SearchResultIconSlice xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto"
|
||||
android:padding="@dimen/dynamic_grid_edge_margin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/icon"
|
||||
launcher:iconDisplay="hero_app" />
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.slice.widget.SliceView
|
||||
android:id="@+id/slice"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="@dimen/dynamic_grid_cell_padding_x"
|
||||
android:layout_width="0dp" />
|
||||
|
||||
</com.android.launcher3.search.SearchResultIconSlice>
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 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.
|
||||
-->
|
||||
<com.android.launcher3.search.SearchResultSmallIconRow
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/dynamic_grid_edge_margin">
|
||||
|
||||
<com.android.launcher3.search.SearchResultIcon
|
||||
android:id="@+id/icon"
|
||||
style="@style/BaseIcon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawablePadding="@dimen/dynamic_grid_icon_drawable_padding"
|
||||
android:drawableTint="?android:attr/textColorPrimary"
|
||||
android:padding="@dimen/dynamic_grid_edge_margin"
|
||||
launcher:iconDisplay="hero_app"
|
||||
launcher:iconSizeOverride="48dp"
|
||||
launcher:matchTextInsetWithQuery="true"
|
||||
launcher:layoutHorizontal="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/dynamic_grid_edge_margin" >
|
||||
|
||||
<TextView
|
||||
android:id="@id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingEnd="4dp"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/search_hero_title_size" />
|
||||
<TextView
|
||||
android:id="@+id/delimeter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="\u2022"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/search_hero_subtitle_size" />
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="4dp"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="@dimen/search_hero_subtitle_size" />
|
||||
</LinearLayout>
|
||||
</com.android.launcher3.search.SearchResultSmallIconRow>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2020 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.
|
||||
-->
|
||||
<com.android.launcher3.search.SearchResultThumbnailView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="125dp"
|
||||
android:layout_height="125dp"/>
|
||||
@@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.android.launcher3.search.SearchResultWidget
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingVertical="@dimen/widget_section_vertical_padding"
|
||||
android:layout_marginBottom="@dimen/widget_section_vertical_padding"
|
||||
android:gravity="center"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.android.launcher3.BubbleTextView
|
||||
android:id="@+id/widget_provider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/widget_section_height"
|
||||
android:drawablePadding="@dimen/widget_section_horizontal_padding"
|
||||
android:focusable="true"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingHorizontal="@dimen/widget_section_horizontal_padding"
|
||||
android:paddingVertical="@dimen/widget_section_horizontal_padding"
|
||||
android:singleLine="true"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp"
|
||||
android:textAlignment="viewStart"
|
||||
launcher:iconDisplay="widget_section"
|
||||
launcher:layoutHorizontal="true"
|
||||
launcher:iconSizeOverride="@dimen/widget_section_icon_size" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/widget_section_height"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.android.launcher3.search.SearchResultWidget>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.android.launcher3.search.SearchResultWidgetPreview xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="@dimen/dynamic_grid_cell_padding_x"
|
||||
android:layout_height="wrap_content">
|
||||
<include layout="@layout/widget_cell" android:id="@+id/widget_cell"/>
|
||||
<!-- <include layout="@layout/widget_cell_content" />-->
|
||||
</com.android.launcher3.search.SearchResultWidgetPreview>
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2020 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.
|
||||
-->
|
||||
<com.android.launcher3.search.SearchSectionHeaderView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/section_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/TextHeadline"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:paddingTop="12dp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="18sp" />
|
||||
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.search;
|
||||
|
||||
import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_ICON;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.app.search.LayoutType;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.AllAppsContainerView;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter;
|
||||
import com.android.launcher3.allapps.search.SearchAdapterProvider;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
|
||||
/**
|
||||
* Provides views for on-device search results
|
||||
*/
|
||||
public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
|
||||
|
||||
public static final int VIEW_TYPE_SEARCH_CORPUS_TITLE = 1 << 5;
|
||||
public static final int VIEW_TYPE_SEARCH_SLICE = 1 << 7;
|
||||
public static final int VIEW_TYPE_SEARCH_ICON = (1 << 8) | VIEW_TYPE_ICON;
|
||||
public static final int VIEW_TYPE_SEARCH_ICON_ROW = (1 << 9);
|
||||
public static final int VIEW_TYPE_SEARCH_SMALL_ICON_ROW = (1 << 10);
|
||||
public static final int VIEW_TYPE_SEARCH_THUMBNAIL = 1 << 12;
|
||||
public static final int VIEW_TYPE_SEARCH_WIDGET_LIVE = 1 << 15;
|
||||
public static final int VIEW_TYPE_SEARCH_WIDGET_PREVIEW = 1 << 16;
|
||||
|
||||
private static final String TAG = "SearchServiceAdapter";
|
||||
|
||||
private final AllAppsContainerView mAppsView;
|
||||
private final SparseIntArray mViewTypeToLayoutMap = new SparseIntArray();
|
||||
|
||||
public DeviceSearchAdapterProvider(Launcher launcher, AllAppsContainerView appsView) {
|
||||
super(launcher);
|
||||
mAppsView = appsView;
|
||||
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_CORPUS_TITLE, R.layout.search_section_title);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_ICON, R.layout.search_result_icon);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_ICON_ROW, R.layout.search_result_icon_row);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_SMALL_ICON_ROW, R.layout.search_result_small_icon_row);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_SLICE, R.layout.search_result_slice);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_THUMBNAIL, R.layout.search_result_thumbnail);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_WIDGET_LIVE, R.layout.search_result_widget_live);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_WIDGET_PREVIEW,
|
||||
R.layout.search_result_widget_preview);
|
||||
mViewTypeToLayoutMap.put(VIEW_TYPE_ALL_APPS_DIVIDER, R.layout.all_apps_divider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) {
|
||||
SearchAdapterItem item = (SearchAdapterItem) mAppsView.getApps().getAdapterItems().get(
|
||||
position);
|
||||
SearchTargetHandler
|
||||
payloadResultView =
|
||||
(SearchTargetHandler) holder.itemView;
|
||||
payloadResultView.apply(item.getSearchTarget(), item.getInlineItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSearchView(int viewType) {
|
||||
return mViewTypeToLayoutMap.get(viewType, -1) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater inflater,
|
||||
ViewGroup parent, int viewType) {
|
||||
return new AllAppsGridAdapter.ViewHolder(inflater.inflate(
|
||||
mViewTypeToLayoutMap.get(viewType), parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGridSpanSize(int viewType, int appsPerRow) {
|
||||
if (viewType == VIEW_TYPE_SEARCH_THUMBNAIL
|
||||
|| viewType == VIEW_TYPE_SEARCH_WIDGET_PREVIEW) {
|
||||
return appsPerRow;
|
||||
}
|
||||
return super.getGridSpanSize(viewType, appsPerRow);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onAdapterItemSelected(AllAppsGridAdapter.AdapterItem adapterItem, View view) {
|
||||
if (view instanceof SearchTargetHandler) {
|
||||
return ((SearchTargetHandler) view).quickSelect();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines what view type should be used to present search target.
|
||||
* Returns -1 if viewType is not found or if required field is not present
|
||||
* to render the viewType.
|
||||
*/
|
||||
public int getViewTypeForSearchTarget(SearchTarget t) {
|
||||
switch (t.getLayoutType()) {
|
||||
case LayoutType.TEXT_HEADER:
|
||||
return VIEW_TYPE_SEARCH_CORPUS_TITLE;
|
||||
case LayoutType.ICON_SINGLE_VERTICAL_TEXT:
|
||||
return VIEW_TYPE_SEARCH_ICON;
|
||||
case LayoutType.ICON_SLICE:
|
||||
if (t.getSliceUri() != null) {
|
||||
return VIEW_TYPE_SEARCH_SLICE;
|
||||
}
|
||||
Log.w(TAG, "LayoutType.ICON_SLICE target doesn't contain sliceUri.");
|
||||
break;
|
||||
case LayoutType.ICON_DOUBLE_HORIZONTAL_TEXT:
|
||||
case LayoutType.ICON_SINGLE_HORIZONTAL_TEXT:
|
||||
case LayoutType.ICON_DOUBLE_HORIZONTAL_TEXT_BUTTON:
|
||||
case LayoutType.ICON_HORIZONTAL_TEXT:
|
||||
return VIEW_TYPE_SEARCH_ICON_ROW;
|
||||
case LayoutType.SMALL_ICON_HORIZONTAL_TEXT:
|
||||
return VIEW_TYPE_SEARCH_SMALL_ICON_ROW;
|
||||
case LayoutType.THUMBNAIL:
|
||||
if (t.getSearchAction() != null) {
|
||||
return VIEW_TYPE_SEARCH_THUMBNAIL;
|
||||
}
|
||||
Log.w(TAG, "LayoutType.THUMBNAIL target doesn't contain searchAction.");
|
||||
break;
|
||||
case LayoutType.WIDGET_PREVIEW:
|
||||
return VIEW_TYPE_SEARCH_WIDGET_PREVIEW;
|
||||
case LayoutType.WIDGET_LIVE:
|
||||
return VIEW_TYPE_SEARCH_WIDGET_LIVE;
|
||||
case LayoutType.DIVIDER:
|
||||
return VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.search;
|
||||
|
||||
import static com.android.launcher3.util.OnboardingPrefs.SEARCH_EDU_SEEN;
|
||||
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.statemanager.StateManager;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.launcher3.views.AbstractSlideInView;
|
||||
|
||||
/**
|
||||
* Feature education for on-device Search. Shown the first time user opens AllApps Search
|
||||
*/
|
||||
public class DeviceSearchEdu extends AbstractSlideInView implements
|
||||
StateManager.StateListener<LauncherState>, TextWatcher, Insettable,
|
||||
TextView.OnEditorActionListener {
|
||||
|
||||
private static final long ANIMATION_DURATION = 350;
|
||||
private static final int ANIMATION_CONTENT_TRANSLATION = 200;
|
||||
|
||||
private EditText mEduInput;
|
||||
|
||||
private View mInputWrapper;
|
||||
private EditText mSearchInput;
|
||||
|
||||
private boolean mSwitchFocusOnDismiss;
|
||||
|
||||
|
||||
public DeviceSearchEdu(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public DeviceSearchEdu(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public DeviceSearchEdu(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
|
||||
private void dismiss() {
|
||||
handleClose(true);
|
||||
mLauncher.getOnboardingPrefs().markChecked(SEARCH_EDU_SEEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleClose(boolean animate) {
|
||||
handleClose(animate, ANIMATION_DURATION);
|
||||
mLauncher.getAllAppsController().getInsetController().show();
|
||||
mLauncher.getStateManager().removeStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isOfType(int type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mSearchInput = mLauncher.getAppsView().getSearchUiManager().getEditText();
|
||||
mInputWrapper = findViewById(R.id.search_box_wrapper);
|
||||
mContent = findViewById(R.id.edu_wrapper);
|
||||
|
||||
mEduInput = findViewById(R.id.mock_search_box);
|
||||
mEduInput.setHint(R.string.all_apps_on_device_search_bar_hint);
|
||||
mEduInput.addTextChangedListener(this);
|
||||
if (mSearchInput != null) {
|
||||
mEduInput.getLayoutParams().height = mSearchInput.getHeight();
|
||||
mEduInput.setOnEditorActionListener(this);
|
||||
} else {
|
||||
mEduInput.setVisibility(INVISIBLE);
|
||||
}
|
||||
|
||||
findViewById(R.id.dismiss_edu).setOnClickListener((view) -> {
|
||||
mSwitchFocusOnDismiss = true;
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
private void showInternal() {
|
||||
mLauncher.getStateManager().addStateListener(this);
|
||||
AbstractFloatingView.closeAllOpenViews(mLauncher);
|
||||
attachToContainer();
|
||||
if (mSearchInput != null) {
|
||||
Rect r = mLauncher.getViewBounds(mSearchInput);
|
||||
mEduInput.requestFocus();
|
||||
InputMethodManager imm = mLauncher.getSystemService(InputMethodManager.class);
|
||||
imm.showSoftInput(mEduInput, InputMethodManager.SHOW_IMPLICIT);
|
||||
((LayoutParams) mInputWrapper.getLayoutParams()).setMargins(0, r.top, 0, 0);
|
||||
}
|
||||
animateOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrimColor(Context context) {
|
||||
return ColorUtils.setAlphaComponent(Themes.getAttrColor(context, R.attr.allAppsScrimColor),
|
||||
230);
|
||||
}
|
||||
|
||||
protected void setTranslationShift(float translationShift) {
|
||||
mTranslationShift = translationShift;
|
||||
mContent.setAlpha(getBoxedProgress(1 - mTranslationShift, .25f, 1));
|
||||
mContent.setTranslationY(ANIMATION_CONTENT_TRANSLATION * translationShift);
|
||||
if (mColorScrim != null) {
|
||||
mColorScrim.setAlpha(getBoxedProgress(1 - mTranslationShift, 0, .75f));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given input [0-1], returns progress within bounds [min,max] allowing for staged animations
|
||||
*/
|
||||
private float getBoxedProgress(float input, float min, float max) {
|
||||
if (input < min) return 0;
|
||||
if (input > max) return 1;
|
||||
return (input - min) / (max - min);
|
||||
}
|
||||
|
||||
private void animateOpen() {
|
||||
if (mIsOpen || mOpenCloseAnimator.isRunning()) {
|
||||
return;
|
||||
}
|
||||
mIsOpen = true;
|
||||
mOpenCloseAnimator.setValues(
|
||||
PropertyValuesHolder.ofFloat(TRANSLATION_SHIFT, TRANSLATION_SHIFT_OPENED));
|
||||
mOpenCloseAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
|
||||
mOpenCloseAnimator.setDuration(ANIMATION_DURATION);
|
||||
mOpenCloseAnimator.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show On-device search education view.
|
||||
*/
|
||||
public static void show(Launcher launcher) {
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(launcher);
|
||||
((DeviceSearchEdu) layoutInflater.inflate(
|
||||
R.layout.search_edu_view, launcher.getDragLayer(),
|
||||
false)).showInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateTransitionStart(LauncherState toState) {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCloseComplete() {
|
||||
super.onCloseComplete();
|
||||
if (mSearchInput != null && mSwitchFocusOnDismiss) {
|
||||
mSearchInput.requestFocus();
|
||||
mSearchInput.setSelection(mSearchInput.getText().length());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
//Does nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
//Does nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
if (mSearchInput != null) {
|
||||
mSearchInput.setText(charSequence.toString());
|
||||
mSwitchFocusOnDismiss = true;
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInsets(Rect insets) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
||||
mSearchInput.onEditorAction(i);
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.search;
|
||||
|
||||
import static com.android.launcher3.LauncherState.ALL_APPS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.launcher3.ExtendedEditText;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.allapps.AllAppsContainerView;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem;
|
||||
import com.android.launcher3.allapps.AllAppsStore;
|
||||
import com.android.launcher3.allapps.AlphabeticalAppsList;
|
||||
import com.android.launcher3.allapps.FloatingHeaderView;
|
||||
import com.android.launcher3.allapps.search.AllAppsSearchBarController;
|
||||
import com.android.launcher3.allapps.search.SearchAlgorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A search view shown in all apps for on device search
|
||||
*/
|
||||
public class FallbackSearchInputView extends ExtendedEditText
|
||||
implements AllAppsSearchBarController.Callbacks, AllAppsStore.OnUpdateListener {
|
||||
|
||||
private final AllAppsSearchBarController mSearchBarController;
|
||||
|
||||
private AlphabeticalAppsList mApps;
|
||||
private Runnable mOnResultsChanged;
|
||||
private AllAppsContainerView mAppsView;
|
||||
|
||||
public FallbackSearchInputView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public FallbackSearchInputView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public FallbackSearchInputView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mSearchBarController = new AllAppsSearchBarController();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
Launcher.getLauncher(getContext()).getAppsView().getAppsStore().addUpdateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
Launcher.getLauncher(getContext()).getAppsView().getAppsStore().removeUpdateListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes SearchInput
|
||||
*/
|
||||
public void initialize(AllAppsContainerView appsView, SearchAlgorithm algo, Runnable changed) {
|
||||
mOnResultsChanged = changed;
|
||||
mApps = appsView.getApps();
|
||||
mAppsView = appsView;
|
||||
mSearchBarController.initialize(algo, this, Launcher.getLauncher(getContext()), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchResult(String query, ArrayList<AdapterItem> items) {
|
||||
if (mApps != null && getParent() != null) {
|
||||
mApps.setSearchResults(items);
|
||||
notifyResultChanged();
|
||||
collapseAppsViewHeader(true);
|
||||
mAppsView.setLastSearchQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppendSearchResult(String query, ArrayList<AdapterItem> items) {
|
||||
if (mApps != null && getParent() != null) {
|
||||
mApps.appendSearchResults(items);
|
||||
notifyResultChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSearchResult() {
|
||||
if (getParent() != null && mApps != null) {
|
||||
mApps.setSearchResults(null);
|
||||
notifyResultChanged();
|
||||
collapseAppsViewHeader(false);
|
||||
mAppsView.onClearSearchResult();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppsUpdated() {
|
||||
mSearchBarController.refreshSearchResult();
|
||||
}
|
||||
|
||||
private void collapseAppsViewHeader(boolean collapse) {
|
||||
FloatingHeaderView header = mAppsView.getFloatingHeaderView();
|
||||
if (header != null) {
|
||||
header.setCollapsed(collapse);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyResultChanged() {
|
||||
if (mOnResultsChanged != null) {
|
||||
mOnResultsChanged.run();
|
||||
}
|
||||
mAppsView.onSearchResultsChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
|
||||
// TODO: Consider animating the state transition here
|
||||
if (focused) {
|
||||
// Getting focus will open the keyboard. Go to the all-apps state, so that the input
|
||||
// box is at the top and there is enough space below to show search results.
|
||||
Launcher.getLauncher(getContext()).getStateManager().goToState(ALL_APPS, false);
|
||||
}
|
||||
super.onFocusChanged(focused, direction, previouslyFocusedRect);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.search;
|
||||
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_ICON;
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_ICON_ROW;
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_SMALL_ICON_ROW;
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_SLICE;
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_THUMBNAIL;
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_LIVE;
|
||||
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_PREVIEW;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extension of AdapterItem that contains an extra payload specific to item
|
||||
*/
|
||||
public class SearchAdapterItem extends AllAppsGridAdapter.AdapterItem {
|
||||
private SearchTarget mSearchTarget;
|
||||
private List<SearchTarget> mInlineItems = new ArrayList<>();
|
||||
|
||||
|
||||
private static final int AVAILABLE_FOR_ACCESSIBILITY = VIEW_TYPE_SEARCH_SLICE
|
||||
| VIEW_TYPE_SEARCH_THUMBNAIL
|
||||
| VIEW_TYPE_SEARCH_ICON_ROW
|
||||
| VIEW_TYPE_SEARCH_ICON
|
||||
| VIEW_TYPE_SEARCH_SMALL_ICON_ROW
|
||||
| VIEW_TYPE_SEARCH_WIDGET_PREVIEW
|
||||
| VIEW_TYPE_SEARCH_WIDGET_LIVE;
|
||||
|
||||
public SearchAdapterItem(SearchTarget searchTarget, int type) {
|
||||
mSearchTarget = searchTarget;
|
||||
viewType = type;
|
||||
}
|
||||
|
||||
public SearchTarget getSearchTarget() {
|
||||
return mSearchTarget;
|
||||
}
|
||||
|
||||
public List<SearchTarget> getInlineItems() {
|
||||
return mInlineItems;
|
||||
}
|
||||
@Override
|
||||
protected boolean isCountedForAccessibility() {
|
||||
return (AVAILABLE_FOR_ACCESSIBILITY & viewType) == viewType;
|
||||
}
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.EXTENDED_CONTAINERS;
|
||||
import static com.android.launcher3.model.data.SearchActionItemInfo.FLAG_BADGE_WITH_PACKAGE;
|
||||
import static com.android.launcher3.model.data.SearchActionItemInfo.FLAG_PRIMARY_ICON_FROM_TITLE;
|
||||
import static com.android.launcher3.search.SearchTargetUtil.BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE;
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import android.app.search.SearchAction;
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.app.search.ResultType;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.allapps.AllAppsStore;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.BitmapRenderer;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
import com.android.launcher3.logger.LauncherAtomExtensions.DeviceSearchResultContainer;
|
||||
import com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
import com.android.launcher3.model.data.PackageItemInfo;
|
||||
import com.android.launcher3.model.data.SearchActionItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A {@link BubbleTextView} representing a single cell result in AllApps
|
||||
*/
|
||||
public class SearchResultIcon extends BubbleTextView implements
|
||||
SearchTargetHandler, View.OnClickListener,
|
||||
View.OnLongClickListener {
|
||||
|
||||
//Play store thumbnail process workaround
|
||||
private final Rect mTempRect = new Rect();
|
||||
private final Paint mIconPaint = new Paint();
|
||||
private static final int BITMAP_CROP_MASK_COLOR = 0xff424242;
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final SearchSessionTracker mSearchSessionTracker;
|
||||
private String mTargetId;
|
||||
private Consumer<ItemInfoWithIcon> mOnItemInfoChanged;
|
||||
|
||||
|
||||
public SearchResultIcon(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public SearchResultIcon(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SearchResultIcon(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mLauncher = Launcher.getLauncher(getContext());
|
||||
mSearchSessionTracker = SearchSessionTracker.getInstance(getContext());
|
||||
}
|
||||
|
||||
private boolean mLongPressSupported;
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
setLongPressTimeoutFactor(1f);
|
||||
setOnFocusChangeListener(mLauncher.getFocusHandler());
|
||||
setOnClickListener(this);
|
||||
setOnLongClickListener(this);
|
||||
setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
mLauncher.getDeviceProfile().allAppsCellHeightPx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies {@link SearchTarget} to view. registers a consumer after a corresponding {@link
|
||||
* ItemInfoWithIcon} is created
|
||||
*/
|
||||
public void apply(SearchTarget searchTarget, List<SearchTarget> inlineItems,
|
||||
Consumer<ItemInfoWithIcon> cb) {
|
||||
mOnItemInfoChanged = cb;
|
||||
apply(searchTarget, inlineItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mTargetId = parentTarget.getId();
|
||||
if (parentTarget.getShortcutInfo() != null) {
|
||||
prepareUsingShortcutInfo(parentTarget.getShortcutInfo());
|
||||
mLongPressSupported = true;
|
||||
} else if (parentTarget.getSearchAction() != null) {
|
||||
prepareUsingSearchAction(parentTarget);
|
||||
mLongPressSupported = false;
|
||||
} else {
|
||||
String className = parentTarget.getExtras().getString(SearchTargetUtil.EXTRA_CLASS);
|
||||
prepareUsingApp(new ComponentName(parentTarget.getPackageName(), className),
|
||||
parentTarget.getUserHandle());
|
||||
mLongPressSupported = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareUsingSearchAction(SearchTarget searchTarget) {
|
||||
SearchAction searchAction = searchTarget.getSearchAction();
|
||||
Bundle extras = searchAction.getExtras();
|
||||
|
||||
SearchActionItemInfo itemInfo = new SearchActionItemInfo(searchAction.getIcon(),
|
||||
searchTarget.getPackageName(), searchTarget.getUserHandle(),
|
||||
searchAction.getTitle()) {
|
||||
@Override
|
||||
protected ExtendedContainers getExtendedContainer() {
|
||||
return ExtendedContainers.newBuilder()
|
||||
.setDeviceSearchResultContainer(buildDeviceSearchResultContainer()).build();
|
||||
}
|
||||
};
|
||||
itemInfo.setIntent(searchAction.getIntent());
|
||||
itemInfo.setPendingIntent(searchAction.getPendingIntent());
|
||||
|
||||
//TODO: remove this after flags are introduced in SearchAction. Settings results require
|
||||
// startActivityForResult
|
||||
boolean isSettingsResult = searchTarget.getResultType() == ResultType.SETTING;
|
||||
if ((extras != null && extras.getBoolean(
|
||||
SearchTargetUtil.BUNDLE_EXTRA_SHOULD_START_FOR_RESULT))
|
||||
|| isSettingsResult) {
|
||||
itemInfo.setFlags(SearchActionItemInfo.FLAG_SHOULD_START_FOR_RESULT);
|
||||
} else if (extras != null && extras.getBoolean(
|
||||
SearchTargetUtil.BUNDLE_EXTRA_SHOULD_START)) {
|
||||
itemInfo.setFlags(SearchActionItemInfo.FLAG_SHOULD_START);
|
||||
}
|
||||
if (extras != null && extras.getBoolean(
|
||||
SearchTargetUtil.BUNDLE_EXTRA_BADGE_WITH_PACKAGE)) {
|
||||
itemInfo.setFlags(FLAG_BADGE_WITH_PACKAGE);
|
||||
}
|
||||
if (extras != null && extras.getBoolean(BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE)) {
|
||||
itemInfo.setFlags(FLAG_PRIMARY_ICON_FROM_TITLE);
|
||||
}
|
||||
|
||||
notifyItemInfoChanged(itemInfo);
|
||||
LauncherAppState appState = LauncherAppState.getInstance(mLauncher);
|
||||
MODEL_EXECUTOR.post(() -> {
|
||||
try (LauncherIcons li = LauncherIcons.obtain(getContext())) {
|
||||
Icon icon = searchTarget.getSearchAction().getIcon();
|
||||
BitmapInfo pkgBitmap = getPackageBitmap(appState, searchTarget);
|
||||
if (itemInfo.hasFlags(FLAG_PRIMARY_ICON_FROM_TITLE)) {
|
||||
// create a bitmap with first char if FLAG_PRIMARY_ICON_FROM_TITLE is set
|
||||
itemInfo.bitmap = li.createIconBitmap(String.valueOf(itemInfo.title.charAt(0)),
|
||||
pkgBitmap.color);
|
||||
} else if (icon == null) {
|
||||
// Use default icon from package name
|
||||
itemInfo.bitmap = pkgBitmap;
|
||||
} else {
|
||||
boolean isPlayResult = searchTarget.getResultType() == ResultType.PLAY;
|
||||
if (isPlayResult) {
|
||||
Bitmap b = getPlayResultBitmap(searchAction.getIcon());
|
||||
itemInfo.bitmap = b == null
|
||||
? BitmapInfo.LOW_RES_INFO : BitmapInfo.fromBitmap(b);
|
||||
} else {
|
||||
itemInfo.bitmap = li.createBadgedIconBitmap(icon.loadDrawable(getContext()),
|
||||
itemInfo.user, false);
|
||||
}
|
||||
}
|
||||
|
||||
// badge with package name
|
||||
if (itemInfo.hasFlags(FLAG_BADGE_WITH_PACKAGE) && itemInfo.bitmap != pkgBitmap) {
|
||||
itemInfo.bitmap = li.badgeBitmap(itemInfo.bitmap.icon, pkgBitmap);
|
||||
}
|
||||
}
|
||||
MAIN_EXECUTOR.post(() -> applyFromSearchActionItemInfo(itemInfo));
|
||||
});
|
||||
}
|
||||
|
||||
private static BitmapInfo getPackageBitmap(LauncherAppState appState, SearchTarget target) {
|
||||
PackageItemInfo pkgInfo = new PackageItemInfo(target.getPackageName());
|
||||
pkgInfo.user = target.getUserHandle();
|
||||
appState.getIconCache().getTitleAndIconForApp(pkgInfo, false);
|
||||
return pkgInfo.bitmap;
|
||||
}
|
||||
|
||||
private Bitmap getPlayResultBitmap(Icon icon) {
|
||||
try {
|
||||
int iconSize = getIconSize();
|
||||
URL url = new URL(icon.getUri().toString());
|
||||
URLConnection con = url.openConnection();
|
||||
con.addRequestProperty("Cache-Control", "max-age: 0");
|
||||
con.setUseCaches(true);
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(con.getInputStream());
|
||||
return getRoundedBitmap(Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Bitmap getRoundedBitmap(Bitmap bitmap) {
|
||||
final int iconSize = bitmap.getWidth();
|
||||
final float radius = Themes.getDialogCornerRadius(getContext());
|
||||
|
||||
return BitmapRenderer.createHardwareBitmap(iconSize, iconSize, (canvas) -> {
|
||||
mTempRect.set(0, 0, iconSize, iconSize);
|
||||
final RectF rectF = new RectF(mTempRect);
|
||||
|
||||
mIconPaint.setAntiAlias(true);
|
||||
mIconPaint.reset();
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
mIconPaint.setColor(BITMAP_CROP_MASK_COLOR);
|
||||
canvas.drawRoundRect(rectF, radius, radius, mIconPaint);
|
||||
|
||||
mIconPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap, mTempRect, mTempRect, mIconPaint);
|
||||
});
|
||||
}
|
||||
|
||||
private void prepareUsingApp(ComponentName componentName, UserHandle userHandle) {
|
||||
AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore();
|
||||
AppInfo appInfo = new AppInfo(
|
||||
appsStore.getApp(new ComponentKey(componentName, userHandle))) {
|
||||
@Override
|
||||
protected ExtendedContainers getExtendedContainer() {
|
||||
return ExtendedContainers.newBuilder()
|
||||
.setDeviceSearchResultContainer(buildDeviceSearchResultContainer()).build();
|
||||
}
|
||||
};
|
||||
appInfo.container = EXTENDED_CONTAINERS;
|
||||
if (appInfo == null) {
|
||||
setVisibility(GONE);
|
||||
return;
|
||||
}
|
||||
applyFromApplicationInfo(appInfo);
|
||||
notifyItemInfoChanged(appInfo);
|
||||
}
|
||||
|
||||
private void prepareUsingShortcutInfo(ShortcutInfo shortcutInfo) {
|
||||
WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo(shortcutInfo, getContext()) {
|
||||
@Override
|
||||
protected ExtendedContainers getExtendedContainer() {
|
||||
return ExtendedContainers.newBuilder()
|
||||
.setDeviceSearchResultContainer(buildDeviceSearchResultContainer()).build();
|
||||
}
|
||||
};
|
||||
workspaceItemInfo.container = EXTENDED_CONTAINERS;
|
||||
notifyItemInfoChanged(workspaceItemInfo);
|
||||
LauncherAppState launcherAppState = LauncherAppState.getInstance(getContext());
|
||||
MODEL_EXECUTOR.execute(() -> {
|
||||
launcherAppState.getIconCache().getShortcutIcon(workspaceItemInfo, shortcutInfo);
|
||||
MAIN_EXECUTOR.post(() -> applyFromWorkspaceItem(workspaceItemInfo));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quickSelect() {
|
||||
this.performClick();
|
||||
notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_LAUNCH_KEYBOARD_FOCUS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ItemClickHandler.INSTANCE.onClick(view);
|
||||
notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_LAUNCH_TOUCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
if (!mLongPressSupported) {
|
||||
return false;
|
||||
}
|
||||
notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_LONGPRESS);
|
||||
return ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(this);
|
||||
}
|
||||
|
||||
|
||||
private void notifyItemInfoChanged(ItemInfoWithIcon itemInfoWithIcon) {
|
||||
if (mOnItemInfoChanged != null) {
|
||||
mOnItemInfoChanged.accept(itemInfoWithIcon);
|
||||
mOnItemInfoChanged = null;
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceSearchResultContainer buildDeviceSearchResultContainer() {
|
||||
return mSearchSessionTracker.getQueryLength()
|
||||
.map(queryLength -> DeviceSearchResultContainer.newBuilder()
|
||||
.setQueryLength(queryLength))
|
||||
.orElse(DeviceSearchResultContainer.newBuilder()).build();
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
import com.android.launcher3.model.data.PackageItemInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A full width representation of {@link SearchResultIcon} with a secondary label and inline
|
||||
* SearchTargets
|
||||
*/
|
||||
public class SearchResultIconRow extends LinearLayout implements SearchTargetHandler {
|
||||
|
||||
public static final int MAX_INLINE_ITEMS = 3;
|
||||
|
||||
protected final Launcher mLauncher;
|
||||
protected final SearchResultIcon[] mInlineIcons = new SearchResultIcon[MAX_INLINE_ITEMS];
|
||||
private SearchResultIcon mResultIcon;
|
||||
|
||||
private final LauncherAppState mLauncherAppState;
|
||||
private TextView mTitleView;
|
||||
private TextView mSubTitleView;
|
||||
|
||||
private PackageItemInfo mProviderInfo;
|
||||
|
||||
public SearchResultIconRow(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public SearchResultIconRow(Context context,
|
||||
@Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SearchResultIconRow(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(getContext());
|
||||
mLauncherAppState = LauncherAppState.getInstance(getContext());
|
||||
}
|
||||
|
||||
protected int getIconSize() {
|
||||
return mLauncher.getDeviceProfile().allAppsIconSizePx;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
int iconSize = getIconSize();
|
||||
|
||||
mResultIcon = findViewById(R.id.icon);
|
||||
|
||||
mTitleView = findViewById(R.id.title);
|
||||
mSubTitleView = findViewById(R.id.subtitle);
|
||||
mSubTitleView.setVisibility(GONE);
|
||||
|
||||
mResultIcon.getLayoutParams().height = iconSize;
|
||||
mResultIcon.getLayoutParams().width = iconSize;
|
||||
mResultIcon.setTextVisibility(false);
|
||||
|
||||
mInlineIcons[0] = findViewById(R.id.shortcut_0);
|
||||
mInlineIcons[1] = findViewById(R.id.shortcut_1);
|
||||
mInlineIcons[2] = findViewById(R.id.shortcut_2);
|
||||
for (SearchResultIcon inlineIcon : mInlineIcons) {
|
||||
inlineIcon.getLayoutParams().width = getIconSize();
|
||||
}
|
||||
setOnClickListener(mResultIcon);
|
||||
setOnLongClickListener(mResultIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mResultIcon.apply(parentTarget, children, this::onItemInfoCreated);
|
||||
|
||||
showSubtitleIfNeeded(null);
|
||||
|
||||
if (parentTarget.getShortcutInfo() != null) {
|
||||
updateWithShortcutInfo(parentTarget.getShortcutInfo());
|
||||
} else if (parentTarget.getSearchAction() != null) {
|
||||
showSubtitleIfNeeded(parentTarget.getSearchAction().getSubtitle());
|
||||
}
|
||||
showInlineItems(children);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quickSelect() {
|
||||
this.performClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateWithShortcutInfo(ShortcutInfo shortcutInfo) {
|
||||
PackageItemInfo packageItemInfo = new PackageItemInfo(shortcutInfo.getPackage());
|
||||
if (packageItemInfo.equals(mProviderInfo)) return;
|
||||
MODEL_EXECUTOR.post(() -> {
|
||||
mLauncherAppState.getIconCache().getTitleAndIconForApp(packageItemInfo, true);
|
||||
MAIN_EXECUTOR.post(() -> {
|
||||
showSubtitleIfNeeded(packageItemInfo.title);
|
||||
mProviderInfo = packageItemInfo;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected void showSubtitleIfNeeded(CharSequence subTitle) {
|
||||
if (!TextUtils.isEmpty(subTitle)) {
|
||||
mSubTitleView.setText(subTitle);
|
||||
mSubTitleView.setVisibility(VISIBLE);
|
||||
} else {
|
||||
mSubTitleView.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void showInlineItems(List<SearchTarget> children) {
|
||||
for (int i = 0; i < MAX_INLINE_ITEMS; i++) {
|
||||
if (i < children.size()) {
|
||||
mInlineIcons[i].apply(children.get(i), new ArrayList<>());
|
||||
mInlineIcons[i].setVisibility(VISIBLE);
|
||||
} else {
|
||||
mInlineIcons[i].setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onItemInfoCreated(ItemInfoWithIcon info) {
|
||||
setTag(info);
|
||||
mTitleView.setText(info.title);
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.slice.SliceItem;
|
||||
import androidx.slice.widget.EventInfo;
|
||||
import androidx.slice.widget.SliceView;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.model.data.PackageItemInfo;
|
||||
import com.android.launcher3.util.SafeCloseable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A slice view wrapper with settings app icon at start
|
||||
*/
|
||||
public class SearchResultIconSlice extends LinearLayout implements SearchTargetHandler,
|
||||
SliceView.OnSliceActionListener {
|
||||
|
||||
private final Launcher mLauncher;
|
||||
|
||||
private SliceView mSliceView;
|
||||
private SearchResultIcon mIcon;
|
||||
private SafeCloseable mSliceSession;
|
||||
private String mTargetId;
|
||||
|
||||
public SearchResultIconSlice(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public SearchResultIconSlice(Context context,
|
||||
@Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SearchResultIconSlice(Context context, @Nullable AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mSliceView = findViewById(R.id.slice);
|
||||
mIcon = findViewById(R.id.icon);
|
||||
mIcon.setTextVisibility(false);
|
||||
int iconSize = mLauncher.getDeviceProfile().iconSizePx;
|
||||
mIcon.getLayoutParams().height = iconSize;
|
||||
mIcon.getLayoutParams().width = iconSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mTargetId = parentTarget.getId();
|
||||
reset();
|
||||
updateIcon(parentTarget, children);
|
||||
mSliceSession = mLauncher.getLiveSearchManager()
|
||||
.addObserver(parentTarget.getSliceUri(), mSliceView);
|
||||
}
|
||||
|
||||
private void updateIcon(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
if (children.size() == 1) {
|
||||
mIcon.apply(children.get(0), new ArrayList<>());
|
||||
} else {
|
||||
PackageItemInfo pkgItem = new PackageItemInfo(parentTarget.getPackageName());
|
||||
pkgItem.user = parentTarget.getUserHandle();
|
||||
if (!pkgItem.equals(mIcon.getTag())) {
|
||||
// The icon will load and apply high res icon automatically
|
||||
mIcon.applyFromItemInfoWithIcon(pkgItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mSliceView.setOnSliceActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
reset();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
mSliceView.setOnSliceActionListener(null);
|
||||
if (mSliceSession != null) {
|
||||
mSliceSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSliceAction(@NonNull EventInfo eventInfo, @NonNull SliceItem sliceItem) {
|
||||
notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_TAP);
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
import com.android.launcher3.model.data.PackageItemInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A full width representation of {@link SearchResultIcon} with a secondary label and inline
|
||||
* SearchTargets
|
||||
*/
|
||||
public class SearchResultSmallIconRow extends LinearLayout implements SearchTargetHandler {
|
||||
|
||||
protected final Launcher mLauncher;
|
||||
private final LauncherAppState mLauncherAppState;
|
||||
protected SearchResultIcon mResultIcon;
|
||||
|
||||
private TextView mTitleView;
|
||||
private TextView mDelimeterView;
|
||||
private TextView mSubTitleView;
|
||||
|
||||
private PackageItemInfo mProviderInfo;
|
||||
|
||||
public SearchResultSmallIconRow(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public SearchResultSmallIconRow(Context context,
|
||||
@Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SearchResultSmallIconRow(Context context,
|
||||
@Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(getContext());
|
||||
mLauncherAppState = LauncherAppState.getInstance(getContext());
|
||||
}
|
||||
|
||||
protected int getIconSize() {
|
||||
return mLauncher.getDeviceProfile().allAppsIconSizePx;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
int iconSize = getIconSize();
|
||||
|
||||
mResultIcon = findViewById(R.id.icon);
|
||||
|
||||
mTitleView = findViewById(R.id.title);
|
||||
mDelimeterView = findViewById(R.id.delimeter);
|
||||
mDelimeterView.setVisibility(GONE);
|
||||
mSubTitleView = findViewById(R.id.subtitle);
|
||||
mSubTitleView.setVisibility(GONE);
|
||||
|
||||
mResultIcon.getLayoutParams().height = iconSize;
|
||||
mResultIcon.getLayoutParams().width = iconSize;
|
||||
mResultIcon.setTextVisibility(false);
|
||||
|
||||
setOnClickListener(mResultIcon);
|
||||
setOnLongClickListener(mResultIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mResultIcon.apply(parentTarget, children, this::onItemInfoCreated);
|
||||
|
||||
showSubtitleIfNeeded(null);
|
||||
|
||||
if (parentTarget.getShortcutInfo() != null) {
|
||||
updateWithShortcutInfo(parentTarget.getShortcutInfo());
|
||||
} else if (parentTarget.getSearchAction() != null) {
|
||||
showSubtitleIfNeeded(parentTarget.getSearchAction().getSubtitle());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quickSelect() {
|
||||
this.performClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateWithShortcutInfo(ShortcutInfo shortcutInfo) {
|
||||
PackageItemInfo packageItemInfo = new PackageItemInfo(shortcutInfo.getPackage());
|
||||
if (packageItemInfo.equals(mProviderInfo)) return;
|
||||
MODEL_EXECUTOR.post(() -> {
|
||||
mLauncherAppState.getIconCache().getTitleAndIconForApp(packageItemInfo, true);
|
||||
MAIN_EXECUTOR.post(() -> {
|
||||
showSubtitleIfNeeded(packageItemInfo.title);
|
||||
mProviderInfo = packageItemInfo;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected void showSubtitleIfNeeded(CharSequence subTitle) {
|
||||
if (!TextUtils.isEmpty(subTitle)) {
|
||||
mSubTitleView.setText(subTitle);
|
||||
mSubTitleView.setVisibility(VISIBLE);
|
||||
mDelimeterView.setVisibility(VISIBLE);
|
||||
|
||||
} else {
|
||||
mSubTitleView.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onItemInfoCreated(ItemInfoWithIcon info) {
|
||||
setTag(info);
|
||||
mTitleView.setText(info.title);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.model.data.SearchActionItemInfo;
|
||||
import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A view representing a high confidence app search result that includes shortcuts
|
||||
*/
|
||||
public class SearchResultThumbnailView extends androidx.appcompat.widget.AppCompatImageView
|
||||
implements SearchTargetHandler, View.OnClickListener {
|
||||
|
||||
private SearchTarget mSearchTarget;
|
||||
|
||||
public SearchResultThumbnailView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SearchResultThumbnailView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SearchResultThumbnailView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
setOnFocusChangeListener(Launcher.getLauncher(getContext()).getFocusHandler());
|
||||
setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mSearchTarget = parentTarget;
|
||||
Bitmap bitmap;
|
||||
|
||||
SearchActionItemInfo itemInfo = new SearchActionItemInfo(
|
||||
parentTarget.getSearchAction().getIcon(),
|
||||
parentTarget.getPackageName(),
|
||||
parentTarget.getUserHandle(),
|
||||
parentTarget.getSearchAction().getTitle());
|
||||
itemInfo.setIntent(parentTarget.getSearchAction().getIntent());
|
||||
itemInfo.setPendingIntent(parentTarget.getSearchAction().getPendingIntent());
|
||||
|
||||
bitmap = ((BitmapDrawable) itemInfo.getIcon()
|
||||
.loadDrawable(getContext())).getBitmap();
|
||||
// crop
|
||||
if (bitmap.getWidth() < bitmap.getHeight()) {
|
||||
bitmap = Bitmap.createBitmap(bitmap, 0,
|
||||
bitmap.getHeight() / 2 - bitmap.getWidth() / 2,
|
||||
bitmap.getWidth(), bitmap.getWidth());
|
||||
} else {
|
||||
bitmap = Bitmap.createBitmap(bitmap, bitmap.getWidth() / 2 - bitmap.getHeight() / 2,
|
||||
0,
|
||||
bitmap.getHeight(), bitmap.getHeight());
|
||||
}
|
||||
setTag(itemInfo);
|
||||
|
||||
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(null, bitmap);
|
||||
drawable.setCornerRadius(Themes.getDialogCornerRadius(getContext()));
|
||||
setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ItemClickHandler.onClickSearchAction(Launcher.getLauncher(getContext()),
|
||||
(SearchActionItemInfo) view.getTag());
|
||||
notifyEvent(getContext(), mSearchTarget.getId(), SearchTargetEvent.ACTION_LAUNCH_TOUCH);
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.AppWidgetResizeFrame;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.CheckLongPressHelper;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.allapps.search.SearchWidgetInfoContainer;
|
||||
import com.android.launcher3.dragndrop.DraggableView;
|
||||
import com.android.launcher3.icons.cache.HandlerRunnable;
|
||||
import com.android.launcher3.model.data.PackageItemInfo;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.widget.PendingAddWidgetInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* displays live version of a widget upon receiving {@link AppWidgetProviderInfo} from Search
|
||||
* provider
|
||||
*/
|
||||
public class SearchResultWidget extends LinearLayout implements SearchTargetHandler, DraggableView,
|
||||
View.OnLongClickListener {
|
||||
|
||||
|
||||
private final Rect mWidgetOffset = new Rect();
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final CheckLongPressHelper mLongPressHelper;
|
||||
private final GestureDetector mClickDetector;
|
||||
private final AppWidgetHostView mHostView;
|
||||
private final float mScaleToFit;
|
||||
|
||||
private SearchWidgetInfoContainer mInfoContainer;
|
||||
private HandlerRunnable mLabelRequest;
|
||||
private BubbleTextView mWidgetProvider;
|
||||
private TextView mWidgetLabel;
|
||||
|
||||
public SearchResultWidget(@NonNull Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public SearchResultWidget(@NonNull Context context,
|
||||
@Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SearchResultWidget(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
mHostView = new AppWidgetHostView(context);
|
||||
DeviceProfile grid = mLauncher.getDeviceProfile();
|
||||
mScaleToFit = Math.min(grid.appWidgetScale.x, grid.appWidgetScale.y);
|
||||
|
||||
// detect tap event on widget container for search target event reporting
|
||||
mClickDetector = new GestureDetector(context,
|
||||
new ClickListener(
|
||||
() -> reportEvent(SearchTargetEvent.ACTION_LAUNCH_TOUCH)));
|
||||
mLongPressHelper = new CheckLongPressHelper(this);
|
||||
mLongPressHelper.setLongPressTimeoutFactor(1);
|
||||
setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mWidgetProvider = findViewById(R.id.widget_provider);
|
||||
mWidgetLabel = findViewById(R.id.widget_label);
|
||||
addView(mHostView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
AppWidgetProviderInfo providerInfo = parentTarget.getAppWidgetProviderInfo();
|
||||
removeListener();
|
||||
|
||||
showWidgetInfo(providerInfo);
|
||||
mInfoContainer = mLauncher.getLiveSearchManager().getPlaceHolderWidget(providerInfo);
|
||||
if (mInfoContainer == null) {
|
||||
setVisibility(GONE);
|
||||
return;
|
||||
}
|
||||
setVisibility(VISIBLE);
|
||||
mInfoContainer.attachWidget(mHostView);
|
||||
PendingAddWidgetInfo info = (PendingAddWidgetInfo) mHostView.getTag();
|
||||
int[] size = mLauncher.getWorkspace().estimateItemSize(info);
|
||||
mHostView.getLayoutParams().width = size[0];
|
||||
mHostView.getLayoutParams().height = size[1];
|
||||
AppWidgetResizeFrame.updateWidgetSizeRanges(mHostView, mLauncher, info.spanX,
|
||||
info.spanY);
|
||||
mHostView.requestLayout();
|
||||
setTag(info);
|
||||
}
|
||||
|
||||
private void showWidgetInfo(AppWidgetProviderInfo providerInfo) {
|
||||
PackageItemInfo pinfo = new PackageItemInfo(providerInfo.provider.getPackageName());
|
||||
pinfo.user = providerInfo.getProfile();
|
||||
mWidgetProvider.applyFromItemInfoWithIcon(pinfo);
|
||||
|
||||
mLabelRequest = new HandlerRunnable<>(
|
||||
MODEL_EXECUTOR.getHandler(),
|
||||
() -> LauncherAppState.getInstance(mLauncher).getIconCache()
|
||||
.getTitleNoCache(LauncherAppWidgetProviderInfo
|
||||
.fromProviderInfo(mLauncher, providerInfo)),
|
||||
MAIN_EXECUTOR,
|
||||
mWidgetLabel::setText);
|
||||
Utilities.postAsyncCallback(MODEL_EXECUTOR.getHandler(), mLabelRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops hostView from getting updates on a widget provider
|
||||
*/
|
||||
public void removeListener() {
|
||||
if (mInfoContainer != null) {
|
||||
mInfoContainer.detachWidget(mHostView);
|
||||
mInfoContainer = null;
|
||||
}
|
||||
if (mLabelRequest != null) {
|
||||
mLabelRequest.cancel();
|
||||
mLabelRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
removeListener();
|
||||
}
|
||||
|
||||
private void reportEvent(int eventType) {
|
||||
SearchSessionTracker.INSTANCE.get(getContext()).notifyEvent(
|
||||
new SearchTargetEvent.Builder("search target id", eventType).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
mLongPressHelper.onTouchEvent(ev);
|
||||
mClickDetector.onTouchEvent(ev);
|
||||
return mLongPressHelper.hasPerformedLongPress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
mLongPressHelper.onTouchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLongPress() {
|
||||
super.cancelLongPress();
|
||||
mLongPressHelper.cancelLongPress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewType() {
|
||||
return DraggableView.DRAGGABLE_WIDGET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSourceVisualDragBounds(Rect bounds) {
|
||||
mHostView.getHitRect(mWidgetOffset);
|
||||
int width = (int) (mHostView.getMeasuredWidth() * mScaleToFit);
|
||||
int height = (int) (mHostView.getMeasuredHeight() * mScaleToFit);
|
||||
bounds.set(mWidgetOffset.left,
|
||||
mWidgetOffset.top,
|
||||
width + mWidgetOffset.left,
|
||||
height + mWidgetOffset.top);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(view);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static class ClickListener extends GestureDetector.SimpleOnGestureListener {
|
||||
private final Runnable mCb;
|
||||
|
||||
ClickListener(Runnable cb) {
|
||||
mCb = cb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
mCb.run();
|
||||
return super.onSingleTapConfirmed(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.widget.BaseWidgetSheet;
|
||||
import com.android.launcher3.widget.PendingItemDragHelper;
|
||||
import com.android.launcher3.widget.WidgetCell;
|
||||
import com.android.launcher3.widget.WidgetImageView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* displays preview of a widget upon receiving {@link AppWidgetProviderInfo} from Search provider
|
||||
*/
|
||||
public class SearchResultWidgetPreview extends LinearLayout implements SearchTargetHandler,
|
||||
View.OnClickListener, View.OnLongClickListener {
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final LauncherAppState mAppState;
|
||||
private WidgetCell mWidgetCell;
|
||||
private Toast mWidgetToast;
|
||||
|
||||
private String mTargetId;
|
||||
public SearchResultWidgetPreview(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public SearchResultWidgetPreview(Context context,
|
||||
@Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SearchResultWidgetPreview(Context context, @Nullable AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
mAppState = LauncherAppState.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
mWidgetCell = findViewById(R.id.widget_cell);
|
||||
mWidgetCell.setOnLongClickListener(this);
|
||||
mWidgetCell.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mTargetId = parentTarget.getId();
|
||||
AppWidgetProviderInfo providerInfo = parentTarget.getAppWidgetProviderInfo();
|
||||
LauncherAppWidgetProviderInfo pInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
|
||||
getContext(), providerInfo);
|
||||
MODEL_EXECUTOR.post(() -> {
|
||||
WidgetItem widgetItem = new WidgetItem(pInfo, mLauncher.getDeviceProfile().inv,
|
||||
mAppState.getIconCache());
|
||||
MAIN_EXECUTOR.post(() -> {
|
||||
mWidgetCell.applyFromCellItem(widgetItem, mAppState.getWidgetCache());
|
||||
mWidgetCell.ensurePreview();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
view.cancelLongPress();
|
||||
if (!ItemLongClickListener.canStartDrag(mLauncher)) return false;
|
||||
if (mWidgetCell.getTag() == null) return false;
|
||||
|
||||
WidgetImageView imageView = mWidgetCell.getWidgetView();
|
||||
if (imageView.getBitmap() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int[] loc = new int[2];
|
||||
mLauncher.getDragLayer().getLocationInDragLayer(imageView, loc);
|
||||
|
||||
new PendingItemDragHelper(mWidgetCell).startDrag(
|
||||
imageView.getBitmapBounds(), imageView.getBitmap().getWidth(), imageView.getWidth(),
|
||||
new Point(loc[0], loc[1]), mLauncher.getAppsView(), new DragOptions());
|
||||
reportEvent(SearchTargetEvent.ACTION_LONGPRESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mWidgetToast = BaseWidgetSheet.showWidgetToast(getContext(), mWidgetToast);
|
||||
reportEvent(SearchTargetEvent.ACTION_LAUNCH_TOUCH);
|
||||
}
|
||||
|
||||
private void reportEvent(int eventType) {
|
||||
SearchSessionTracker.INSTANCE.get(getContext()).notifyEvent(
|
||||
new SearchTargetEvent.Builder(mTargetId, eventType).build());
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Header text view that shows a title for a given section in All apps search
|
||||
*/
|
||||
public class SearchSectionHeaderView extends TextView implements SearchTargetHandler {
|
||||
|
||||
public SearchSectionHeaderView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SearchSectionHeaderView(Context context,
|
||||
@Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SearchSectionHeaderView(Context context, @Nullable AttributeSet attrs, int styleAttr) {
|
||||
super(context, attrs, styleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
setText(parentTarget.getSearchAction().getTitle());
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.search;
|
||||
|
||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
|
||||
import android.app.search.Query;
|
||||
import android.app.search.SearchContext;
|
||||
import android.app.search.SearchSession;
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchUiManager;
|
||||
import android.content.Context;
|
||||
import android.os.CancellationSignal;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.app.search.ResultType;
|
||||
import com.android.launcher3.allapps.AllAppsGridAdapter;
|
||||
import com.android.launcher3.allapps.AllAppsSectionDecorator;
|
||||
import com.android.launcher3.allapps.search.SearchPipeline;
|
||||
import com.android.launcher3.allapps.search.SearchSectionInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Search pipeline utilizing {@link android.app.search.SearchUiManager}
|
||||
*/
|
||||
public class SearchServicePipeline implements SearchPipeline {
|
||||
private static final int SUPPORTED_RESULT_TYPES =
|
||||
ResultType.APPLICATION | ResultType.SHORTCUT | ResultType.PLAY | ResultType.PEOPLE
|
||||
| ResultType.SETTING;
|
||||
|
||||
private static final boolean DEBUG = true;
|
||||
private static final int REQUEST_TIMEOUT = 200;
|
||||
private static final String TAG = "SearchServicePipeline";
|
||||
|
||||
private final Context mContext;
|
||||
private final SearchSession mSession;
|
||||
private final DeviceSearchAdapterProvider mAdapterProvider;
|
||||
|
||||
private boolean mCanceled = false;
|
||||
|
||||
|
||||
public SearchServicePipeline(Context context, DeviceSearchAdapterProvider adapterProvider) {
|
||||
mContext = context;
|
||||
mAdapterProvider = adapterProvider;
|
||||
SearchUiManager manager = context.getSystemService(SearchUiManager.class);
|
||||
mSession = manager.createSearchSession(
|
||||
new SearchContext(SUPPORTED_RESULT_TYPES, REQUEST_TIMEOUT, null));
|
||||
SearchSessionTracker.getInstance(context).setSearchSession(mSession);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@Override
|
||||
public void query(String input, Consumer<ArrayList<AllAppsGridAdapter.AdapterItem>> callback,
|
||||
CancellationSignal cancellationSignal) {
|
||||
mCanceled = false;
|
||||
Query query = new Query(input, System.currentTimeMillis(), null);
|
||||
mSession.query(query, UI_HELPER_EXECUTOR, targets -> {
|
||||
if (!mCanceled) {
|
||||
if (DEBUG) {
|
||||
printSearchTargets(input, targets);
|
||||
}
|
||||
SearchSessionTracker.getInstance(mContext).setQuery(query);
|
||||
callback.accept(this.onResult(targets));
|
||||
}
|
||||
Log.w(TAG, "Ignoring results due to cancel signal");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given A list of search Targets, pairs a group of search targets to a AdapterItem that can
|
||||
* be inflated in AllAppsRecyclerView
|
||||
*/
|
||||
private ArrayList<AllAppsGridAdapter.AdapterItem> onResult(List<SearchTarget> searchTargets) {
|
||||
HashMap<String, SearchAdapterItem> adapterMap = new LinkedHashMap<>();
|
||||
List<SearchTarget> unmappedChildren = new ArrayList<>();
|
||||
SearchSectionInfo section = new SearchSectionInfo();
|
||||
section.setDecorationHandler(
|
||||
new AllAppsSectionDecorator.SectionDecorationHandler(mContext, true));
|
||||
for (SearchTarget target : searchTargets) {
|
||||
if (!TextUtils.isEmpty(target.getParentId())) {
|
||||
if (!addChildToParent(target, adapterMap)) {
|
||||
unmappedChildren.add(target);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int viewType = mAdapterProvider.getViewTypeForSearchTarget(target);
|
||||
if (viewType != -1) {
|
||||
SearchAdapterItem adapterItem = new SearchAdapterItem(target, viewType);
|
||||
adapterItem.searchSectionInfo = section;
|
||||
adapterMap.put(target.getId(), adapterItem);
|
||||
}
|
||||
}
|
||||
for (SearchTarget s : unmappedChildren) {
|
||||
if (!addChildToParent(s, adapterMap)) {
|
||||
Log.w(TAG,
|
||||
"Unable to pair child " + s.getId() + " to parent " + s.getParentId());
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(adapterMap.values());
|
||||
}
|
||||
|
||||
private void printSearchTargets(String query, List<SearchTarget> results) {
|
||||
Log.d(TAG, " query=" + query + " size=" + results.size());
|
||||
for (SearchTarget s : results) {
|
||||
Log.d(TAG, "layoutType=" + s.getLayoutType() + " resultType=" + s.getResultType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child SearchTarget to a collection of searchTarget children with a shared parentId.
|
||||
* Returns false if no parent searchTarget with id=$parentId does not exists.
|
||||
*/
|
||||
private boolean addChildToParent(SearchTarget target, HashMap<String, SearchAdapterItem> map) {
|
||||
if (!map.containsKey(target.getParentId())) return false;
|
||||
map.get(target.getParentId()).getInlineItems().add(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister callbacks and destroy search session
|
||||
*/
|
||||
public void destroy() {
|
||||
mSession.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels current ongoing search request.
|
||||
*/
|
||||
public void cancel() {
|
||||
mCanceled = true;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.search;
|
||||
|
||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
|
||||
import android.app.search.Query;
|
||||
import android.app.search.SearchSession;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.util.MainThreadInitializedObject;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A singleton class to track and report search events back to SearchSession
|
||||
*/
|
||||
public class SearchSessionTracker {
|
||||
|
||||
private static final String TAG = "SearchSessionTracker";
|
||||
|
||||
@Nullable
|
||||
private SearchSession mSession;
|
||||
private Query mQuery;
|
||||
|
||||
public static final MainThreadInitializedObject<SearchSessionTracker> INSTANCE =
|
||||
new MainThreadInitializedObject<>(SearchSessionTracker::new);
|
||||
|
||||
private SearchSessionTracker(Context context) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance of SearchSessionTracker
|
||||
*/
|
||||
public static SearchSessionTracker getInstance(Context context) {
|
||||
return SearchSessionTracker.INSTANCE.get(context);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public void setSearchSession(SearchSession session) {
|
||||
mSession = session;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public void setQuery(Query query) {
|
||||
mQuery = query;
|
||||
}
|
||||
|
||||
public Optional<Integer> getQueryLength() {
|
||||
return Optional.ofNullable(mQuery).map(Query::getInput).map(String::length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the user event handling back to the {@link SearchSession} object.
|
||||
*/
|
||||
public void notifyEvent(SearchTargetEvent event) {
|
||||
if (mSession == null) {
|
||||
Log.d(TAG, "Dropping event " + event.getTargetId());
|
||||
}
|
||||
Log.d(TAG, "notifyEvent:" + mQuery.getInput() + ":" + event.getTargetId());
|
||||
UI_HELPER_EXECUTOR.post(() -> mSession.notifyEvent(mQuery, event));
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.search;
|
||||
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An interface for supporting dynamic search results
|
||||
*/
|
||||
public interface SearchTargetHandler {
|
||||
|
||||
/**
|
||||
* Update view using values from {@link SearchTarget}
|
||||
*/
|
||||
default void apply(SearchTarget parentTarget, List<SearchTarget> children) { }
|
||||
|
||||
/**
|
||||
* Handle IME quick select event. returns whether event was handled.
|
||||
*/
|
||||
default boolean quickSelect() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void notifyEvent(Context context, String id, int eventType) {
|
||||
SearchTargetEvent.Builder builder = new SearchTargetEvent.Builder(id, eventType);
|
||||
SearchSessionTracker.getInstance(context).notifyEvent(builder.build());
|
||||
}
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.search;
|
||||
|
||||
import static com.android.app.search.LayoutType.DIVIDER;
|
||||
import static com.android.app.search.LayoutType.ICON_HORIZONTAL_TEXT;
|
||||
import static com.android.app.search.LayoutType.SMALL_ICON_HORIZONTAL_TEXT;
|
||||
import static com.android.app.search.LayoutType.THUMBNAIL;
|
||||
import static com.android.app.search.ResultType.ACTION;
|
||||
import static com.android.app.search.ResultType.SCREENSHOT;
|
||||
import static com.android.app.search.ResultType.SUGGEST;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.search.SearchAction;
|
||||
import android.app.search.SearchTarget;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.app.search.ResultType;
|
||||
|
||||
public class SearchTargetUtil {
|
||||
|
||||
public static final String BUNDLE_EXTRA_SHOULD_START = "should_start";
|
||||
public static final String BUNDLE_EXTRA_SHOULD_START_FOR_RESULT = "should_start_for_result";
|
||||
public static final String BUNDLE_EXTRA_BADGE_WITH_PACKAGE = "badge_with_package";
|
||||
public static final String BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE = "primary_icon_from_title";
|
||||
|
||||
public static final String EXTRA_CLASS = "class";
|
||||
|
||||
private static final String TITLE = " title: weather ";
|
||||
private static final String SUBTITLE = " subtitle: 68 degrees ";
|
||||
private static final String PACKAGE2 = "com.google.android.gm";
|
||||
private static final UserHandle USERHANDLE = Process.myUserHandle();
|
||||
|
||||
|
||||
/**
|
||||
* Generate SearchTargetUtil for ICON_HORIZONTAL_TEXT layout type.
|
||||
*
|
||||
* targets.add(SearchTargetUtil.generateIconDoubleHorizontalText_SearchAction(
|
||||
* mContext, "red", Color.RED));
|
||||
* targets.add(SearchTargetUtil.generateIconDoubleHorizontalText_SearchAction(
|
||||
* mContext, "yellow", Color.YELLOW));
|
||||
*/
|
||||
public static SearchTarget generateIcoHorizontalText_usingSearchAction(
|
||||
Context context, String id, int color) {
|
||||
SearchTarget.Builder builder =
|
||||
new SearchTarget.Builder(ACTION, ICON_HORIZONTAL_TEXT, id)
|
||||
.setPackageName(PACKAGE2) /* required */
|
||||
.setUserHandle(USERHANDLE); /* required */
|
||||
|
||||
Intent intent = new Intent("com.google.android.googlequicksearchbox.GENERIC_QUERY");
|
||||
intent.putExtra("query", "weather");
|
||||
intent.putExtra("full_screen", false);
|
||||
PendingIntent pendingIntent =
|
||||
PendingIntent.getActivity(
|
||||
context, 1, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawColor(color);
|
||||
Icon icon = Icon.createWithAdaptiveBitmap(bitmap);
|
||||
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean(BUNDLE_EXTRA_SHOULD_START_FOR_RESULT, true);
|
||||
b.putBoolean(BUNDLE_EXTRA_BADGE_WITH_PACKAGE, true);
|
||||
b.putBoolean(BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE, true);
|
||||
|
||||
builder.setSearchAction(new SearchAction.Builder(id, id + TITLE)
|
||||
.setSubtitle(id + SUBTITLE)
|
||||
.setPendingIntent(pendingIntent)
|
||||
.setIcon(icon)
|
||||
.setExtras(b)
|
||||
.build());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inside SearchServicePipeline, add following samples to test the search target.
|
||||
*
|
||||
* targets.add(SearchTargetUtil.generateThumbnail_SearchAction("blue", Color.BLUE));
|
||||
* targets.add(SearchTargetUtil.generateThumbnail_SearchAction("red", Color.RED));
|
||||
* targets.add(SearchTargetUtil.generateThumbnail_SearchAction("green", Color.GREEN));
|
||||
*/
|
||||
public static SearchTarget generateThumbnail_usingSearchAction(String id, int color) {
|
||||
SearchTarget.Builder builder =
|
||||
new SearchTarget.Builder(SCREENSHOT, THUMBNAIL, id)
|
||||
.setPackageName(PACKAGE2) /* required */
|
||||
.setUserHandle(USERHANDLE); /* required */
|
||||
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW)
|
||||
.setData(Uri.parse("uri blah blah"))
|
||||
.setType("image/*")
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(1000, 500, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawColor(color);
|
||||
Icon icon = Icon.createWithBitmap(bitmap);
|
||||
|
||||
builder.setSearchAction(new SearchAction.Builder(id, TITLE)
|
||||
.setSubtitle(SUBTITLE)
|
||||
.setIcon(icon)
|
||||
.setIntent(intent)
|
||||
.build());
|
||||
return builder.build();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate SearchTargetUtil for SMALL_ICON_HORIZONTAL_TEXT layout type.
|
||||
*
|
||||
* targets.add(SearchTargetUtil.generateIconHorizontalText_SearchAction(
|
||||
* mContext, "red", Color.RED));
|
||||
* targets.add(SearchTargetUtil.generateIconHorizontalText_SearchAction(
|
||||
* mContext, "yellow", Color.YELLOW));
|
||||
*/
|
||||
public static SearchTarget generateSmallIconHorizontalText_usingSearchAction(
|
||||
Context context, String id, int color) {
|
||||
String title = "Ask the assistant";
|
||||
String fallbackQuery = "sourdough bread";
|
||||
SearchTarget.Builder builder =
|
||||
new SearchTarget.Builder(SUGGEST, SMALL_ICON_HORIZONTAL_TEXT, id)
|
||||
.setPackageName(PACKAGE2) /* required */
|
||||
.setUserHandle(USERHANDLE); /* required */
|
||||
|
||||
Intent intent3 = new Intent("com.google.android.googlequicksearchbox.GENERIC_QUERY");
|
||||
intent3.putExtra("query", fallbackQuery);
|
||||
intent3.putExtra("full_screen", false);
|
||||
PendingIntent pendingIntent3 =
|
||||
PendingIntent.getActivity(
|
||||
context, 1, intent3,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawColor(color);
|
||||
Icon icon = Icon.createWithAdaptiveBitmap(bitmap);
|
||||
|
||||
Bundle extra = new Bundle();
|
||||
extra.putBoolean(BUNDLE_EXTRA_SHOULD_START_FOR_RESULT, true);
|
||||
|
||||
SearchAction searchAction = new SearchAction.Builder(id, title)
|
||||
.setSubtitle(fallbackQuery)
|
||||
.setPendingIntent(pendingIntent3)
|
||||
.setIcon(icon)
|
||||
.setExtras(extra)
|
||||
.build();
|
||||
return builder.setSearchAction(searchAction).build();
|
||||
}
|
||||
|
||||
public static SearchTarget generateDivider() {
|
||||
SearchTarget.Builder builder =
|
||||
new SearchTarget.Builder(SUGGEST, DIVIDER, "divider")
|
||||
.setPackageName("") /* required but not used*/
|
||||
.setUserHandle(USERHANDLE); /* required */
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate SearchTargetUtil for ICON_DOUBLE_HORIZONTAL_TEXT layout type.
|
||||
*/
|
||||
public static SearchTarget generateIconDoubleHorizontalText_ShortcutInfo(Context context) {
|
||||
String id = "23456";
|
||||
SearchTarget.Builder builder =
|
||||
new SearchTarget.Builder(ResultType.SHORTCUT, SMALL_ICON_HORIZONTAL_TEXT, id)
|
||||
.setPackageName("com.google.android.gm") /* required */
|
||||
.setUserHandle(UserHandle.CURRENT); /* required */
|
||||
|
||||
builder.setShortcutInfo(new ShortcutInfo.Builder(context, id).build());
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -45,8 +45,6 @@ import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.LauncherState;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.allapps.AllAppsContainerView;
|
||||
import com.android.launcher3.allapps.search.SearchAdapterProvider;
|
||||
import com.android.launcher3.anim.AnimatorPlaybackController;
|
||||
import com.android.launcher3.appprediction.PredictionRowView;
|
||||
import com.android.launcher3.hybridhotseat.HotseatPredictionController;
|
||||
@@ -56,7 +54,6 @@ import com.android.launcher3.model.BgDataModel.FixedContainerItems;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.popup.SystemShortcut;
|
||||
import com.android.launcher3.search.DeviceSearchAdapterProvider;
|
||||
import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory;
|
||||
import com.android.launcher3.uioverrides.states.QuickstepAtomicAnimationFactory;
|
||||
import com.android.launcher3.uioverrides.touchcontrollers.NavBarToHomeTouchController;
|
||||
@@ -277,11 +274,6 @@ public class QuickstepLauncher extends BaseQuickstepLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView appsView) {
|
||||
return new DeviceSearchAdapterProvider(this, appsView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TouchController[] createTouchControllers() {
|
||||
Mode mode = SysUINavigationMode.getMode(this);
|
||||
|
||||
@@ -27,10 +27,8 @@ import android.content.SharedPreferences;
|
||||
|
||||
import com.android.launcher3.LauncherState;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.allapps.AllAppsInsetTransitionController;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.hybridhotseat.HotseatPredictionController;
|
||||
import com.android.launcher3.search.DeviceSearchEdu;
|
||||
import com.android.launcher3.statemanager.StateManager;
|
||||
import com.android.launcher3.statemanager.StateManager.StateListener;
|
||||
import com.android.launcher3.uioverrides.QuickstepLauncher;
|
||||
@@ -43,7 +41,6 @@ import com.android.quickstep.views.AllAppsEduView;
|
||||
*/
|
||||
public class QuickstepOnboardingPrefs extends OnboardingPrefs<QuickstepLauncher> {
|
||||
|
||||
|
||||
public QuickstepOnboardingPrefs(QuickstepLauncher launcher, SharedPreferences sharedPrefs) {
|
||||
super(launcher, sharedPrefs);
|
||||
|
||||
@@ -133,22 +130,5 @@ public class QuickstepOnboardingPrefs extends OnboardingPrefs<QuickstepLauncher>
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get() && !getBoolean(SEARCH_EDU_SEEN)) {
|
||||
stateManager.addStateListener(new StateListener<LauncherState>() {
|
||||
@Override
|
||||
public void onStateTransitionStart(LauncherState toState) {
|
||||
if (toState == ALL_APPS) {
|
||||
AllAppsInsetTransitionController insetTransitionController =
|
||||
mLauncher.getAllAppsController().getInsetController();
|
||||
insetTransitionController.setSearchEduRunnable(() -> {
|
||||
DeviceSearchEdu.show(launcher);
|
||||
insetTransitionController.setSearchEduRunnable(null);
|
||||
});
|
||||
stateManager.removeStateListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user