Migrate Widgets to new Search API
Test: Manual Bug: 168321831 Bug: 177223401 Change-Id: Ide276002a47f2345fbe535adbcb3acdc2fbc1233
This commit is contained in:
1 parent
f1bcf7a4dd
commit
7c1e37cce1
5 files changed
+103
-24
No files matched your search
@@ -1,5 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.android.launcher3.search.SearchResultWidget android:layout_height="wrap_content"
|
||||
<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"
|
||||
android:layout_width="match_parent" />
|
||||
>
|
||||
|
||||
<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>
|
||||
@@ -18,10 +18,7 @@ package com.android.launcher3.search;
|
||||
|
||||
import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_ICON;
|
||||
|
||||
import android.app.search.Query;
|
||||
import android.app.search.SearchSession;
|
||||
import android.app.search.SearchTarget;
|
||||
import android.app.search.SearchTargetEvent;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -125,6 +122,7 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
|
||||
return VIEW_TYPE_SEARCH_SLICE;
|
||||
}
|
||||
Log.w(TAG, "Dropping as LayoutType.ICON_SLICE target doesn't contain sliceUri.");
|
||||
break;
|
||||
case LayoutType.ICON_DOUBLE_HORIZONTAL_TEXT:
|
||||
case LayoutType.ICON_SINGLE_HORIZONTAL_TEXT:
|
||||
return VIEW_TYPE_SEARCH_ICON_ROW;
|
||||
@@ -133,6 +131,11 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
|
||||
return VIEW_TYPE_SEARCH_THUMBNAIL;
|
||||
}
|
||||
Log.w(TAG, "Dropping as 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;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -102,6 +102,7 @@ public class SearchResultIconRow extends LinearLayout implements SearchTargetHan
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
showSubtitleIfNeeded(null);
|
||||
mResultIcon.applySearchTarget(parentTarget, children, this::onItemInfoCreated);
|
||||
if (parentTarget.getShortcutInfo() != null) {
|
||||
updateWithShortcutInfo(parentTarget.getShortcutInfo());
|
||||
|
||||
@@ -25,28 +25,34 @@ import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
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.R;
|
||||
import com.android.launcher3.allapps.search.SearchWidgetInfoContainer;
|
||||
import com.android.launcher3.dragndrop.DraggableView;
|
||||
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 RelativeLayout implements
|
||||
SearchTargetHandler, DraggableView {
|
||||
public class SearchResultWidget extends LinearLayout implements SearchTargetHandler, DraggableView,
|
||||
View.OnLongClickListener {
|
||||
|
||||
private static final String TAG = "SearchResultWidget";
|
||||
|
||||
public static final String TARGET_TYPE_WIDGET_LIVE = "widget";
|
||||
|
||||
private final Rect mWidgetOffset = new Rect();
|
||||
|
||||
@@ -56,10 +62,9 @@ public class SearchResultWidget extends RelativeLayout implements
|
||||
private final AppWidgetHostView mHostView;
|
||||
private final float mScaleToFit;
|
||||
|
||||
private SearchTarget mSearchTarget;
|
||||
private AppWidgetProviderInfo mProviderInfo;
|
||||
|
||||
private SearchWidgetInfoContainer mInfoContainer;
|
||||
private BubbleTextView mWidgetProvider;
|
||||
private TextView mWidgetLabel;
|
||||
|
||||
public SearchResultWidget(@NonNull Context context) {
|
||||
this(context, null, 0);
|
||||
@@ -80,7 +85,8 @@ public class SearchResultWidget extends RelativeLayout implements
|
||||
|
||||
// detect tap event on widget container for search target event reporting
|
||||
mClickDetector = new GestureDetector(context,
|
||||
new ClickListener(() -> handleSelection(SearchTargetEvent.ACTION_LAUNCH_TOUCH)));
|
||||
new ClickListener(
|
||||
() -> reportEvent(SearchTargetEvent.ACTION_LAUNCH_TOUCH)));
|
||||
mLongPressHelper = new CheckLongPressHelper(this);
|
||||
mLongPressHelper.setLongPressTimeoutFactor(1);
|
||||
setOnLongClickListener(this);
|
||||
@@ -89,9 +95,42 @@ public class SearchResultWidget extends RelativeLayout implements
|
||||
@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) {
|
||||
String title = providerInfo.loadLabel(mLauncher.getPackageManager());
|
||||
PackageItemInfo pinfo = new PackageItemInfo(providerInfo.provider.getPackageName());
|
||||
pinfo.user = providerInfo.getProfile();
|
||||
mWidgetProvider.applyFromItemInfoWithIcon(pinfo);
|
||||
mWidgetLabel.setText(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops hostView from getting updates on a widget provider
|
||||
*/
|
||||
@@ -101,7 +140,7 @@ public class SearchResultWidget extends RelativeLayout implements
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSelection(int eventType) {
|
||||
private void reportEvent(int eventType) {
|
||||
SearchSessionTracker.INSTANCE.get(getContext()).notifyEvent(
|
||||
new SearchTargetEvent.Builder("search target id", eventType).build());
|
||||
}
|
||||
|
||||
@@ -54,9 +54,7 @@ public class SearchResultWidgetPreview extends LinearLayout implements SearchTar
|
||||
private WidgetCell mWidgetCell;
|
||||
private Toast mWidgetToast;
|
||||
|
||||
private SearchTarget mSearchTarget;
|
||||
|
||||
|
||||
private String mTargetId;
|
||||
public SearchResultWidgetPreview(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
@@ -83,7 +81,7 @@ public class SearchResultWidgetPreview extends LinearLayout implements SearchTar
|
||||
|
||||
@Override
|
||||
public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
|
||||
mSearchTarget = parentTarget;
|
||||
mTargetId = parentTarget.getId();
|
||||
AppWidgetProviderInfo providerInfo = parentTarget.getAppWidgetProviderInfo();
|
||||
LauncherAppWidgetProviderInfo pInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(
|
||||
getContext(), providerInfo);
|
||||
@@ -114,18 +112,18 @@ public class SearchResultWidgetPreview extends LinearLayout implements SearchTar
|
||||
new PendingItemDragHelper(mWidgetCell).startDrag(
|
||||
imageView.getBitmapBounds(), imageView.getBitmap().getWidth(), imageView.getWidth(),
|
||||
new Point(loc[0], loc[1]), mLauncher.getAppsView(), new DragOptions());
|
||||
handleSelection(SearchTargetEvent.ACTION_LONGPRESS);
|
||||
reportEvent(SearchTargetEvent.ACTION_LONGPRESS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mWidgetToast = BaseWidgetSheet.showWidgetToast(getContext(), mWidgetToast);
|
||||
handleSelection(SearchTargetEvent.ACTION_LAUNCH_TOUCH);
|
||||
reportEvent(SearchTargetEvent.ACTION_LAUNCH_TOUCH);
|
||||
}
|
||||
|
||||
public void handleSelection(int eventType) {
|
||||
private void reportEvent(int eventType) {
|
||||
SearchSessionTracker.INSTANCE.get(getContext()).notifyEvent(
|
||||
new SearchTargetEvent.Builder(mSearchTarget.getId(), eventType).build());
|
||||
new SearchTargetEvent.Builder(mTargetId, eventType).build());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user