Moving slice loading on a background thread
> Also fixing slice icon loading, such that the request is cancelled if views are recycled quickly > Loading widget label on dg thread and cancelling request if views are recycled quickly. Bug: 179068415 Test: verified locally Change-Id: Id5a524e2bf596862330a8170394aef9ffd708544
This commit is contained in:
1 parent
f4d19f4614
commit
79e52fc23b
8 files changed
+235
-129
No files matched your search
@@ -15,28 +15,22 @@
|
||||
*/
|
||||
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.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceItem;
|
||||
import androidx.slice.widget.EventInfo;
|
||||
import androidx.slice.widget.SliceView;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
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;
|
||||
@@ -47,13 +41,11 @@ import java.util.List;
|
||||
public class SearchResultIconSlice extends LinearLayout implements SearchTargetHandler,
|
||||
SliceView.OnSliceActionListener {
|
||||
|
||||
private static final String TAG = "SearchSliceController";
|
||||
|
||||
private final Launcher mLauncher;
|
||||
|
||||
private SliceView mSliceView;
|
||||
private SearchResultIcon mIcon;
|
||||
private LiveData<Slice> mSliceLiveData;
|
||||
private SafeCloseable mSliceSession;
|
||||
private String mTargetId;
|
||||
|
||||
public SearchResultIconSlice(Context context) {
|
||||
@@ -87,26 +79,20 @@ public class SearchResultIconSlice extends LinearLayout implements SearchTargetH
|
||||
mTargetId = parentTarget.getId();
|
||||
reset();
|
||||
updateIcon(parentTarget, children);
|
||||
try {
|
||||
mSliceLiveData = mLauncher.getLiveSearchManager().getSliceForUri(
|
||||
parentTarget.getSliceUri());
|
||||
mSliceLiveData.observe(mLauncher, mSliceView);
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "unable to bind slice", ex);
|
||||
}
|
||||
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 {
|
||||
LauncherAppState appState = LauncherAppState.getInstance(getContext());
|
||||
MODEL_EXECUTOR.post(() -> {
|
||||
PackageItemInfo pkgItem = new PackageItemInfo(parentTarget.getPackageName());
|
||||
pkgItem.user = parentTarget.getUserHandle();
|
||||
appState.getIconCache().getTitleAndIconForApp(pkgItem, false);
|
||||
MAIN_EXECUTOR.post(() -> mIcon.applyFromItemInfoWithIcon(pkgItem));
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +110,8 @@ public class SearchResultIconSlice extends LinearLayout implements SearchTargetH
|
||||
|
||||
private void reset() {
|
||||
mSliceView.setOnSliceActionListener(null);
|
||||
if (mSliceLiveData != null) {
|
||||
mSliceLiveData.removeObservers(mLauncher);
|
||||
if (mSliceSession != null) {
|
||||
mSliceSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
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;
|
||||
@@ -36,16 +39,19 @@ 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
|
||||
@@ -63,6 +69,7 @@ public class SearchResultWidget extends LinearLayout implements SearchTargetHand
|
||||
private final float mScaleToFit;
|
||||
|
||||
private SearchWidgetInfoContainer mInfoContainer;
|
||||
private HandlerRunnable mLabelRequest;
|
||||
private BubbleTextView mWidgetProvider;
|
||||
private TextView mWidgetLabel;
|
||||
|
||||
@@ -124,11 +131,18 @@ public class SearchResultWidget extends LinearLayout implements SearchTargetHand
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +151,18 @@ public class SearchResultWidget extends LinearLayout implements SearchTargetHand
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user