Fix class cast issue in AddItemActivity am: 671ffb88ca am: 414e50b0f3
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15299573 Change-Id: I799285ff538d8b9fd232edfb88faa8af09327cd0
This commit is contained in:
@@ -46,6 +46,7 @@ import androidx.annotation.Nullable;
|
|||||||
import com.android.launcher3.BaseActivity;
|
import com.android.launcher3.BaseActivity;
|
||||||
import com.android.launcher3.CheckLongPressHelper;
|
import com.android.launcher3.CheckLongPressHelper;
|
||||||
import com.android.launcher3.DeviceProfile;
|
import com.android.launcher3.DeviceProfile;
|
||||||
|
import com.android.launcher3.Launcher;
|
||||||
import com.android.launcher3.R;
|
import com.android.launcher3.R;
|
||||||
import com.android.launcher3.icons.FastBitmapDrawable;
|
import com.android.launcher3.icons.FastBitmapDrawable;
|
||||||
import com.android.launcher3.icons.RoundDrawableWrapper;
|
import com.android.launcher3.icons.RoundDrawableWrapper;
|
||||||
@@ -242,12 +243,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||||||
|
|
||||||
private void applyPreviewOnAppWidgetHostView(WidgetItem item) {
|
private void applyPreviewOnAppWidgetHostView(WidgetItem item) {
|
||||||
if (mRemoteViewsPreview != null) {
|
if (mRemoteViewsPreview != null) {
|
||||||
mAppWidgetHostViewPreview = new NavigableAppWidgetHostView(getContext()) {
|
mAppWidgetHostViewPreview = createAppWidgetHostView(getContext());
|
||||||
@Override
|
|
||||||
protected boolean shouldAllowDirectClick() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
setAppWidgetHostViewPreview(mAppWidgetHostViewPreview, item.widgetInfo,
|
setAppWidgetHostViewPreview(mAppWidgetHostViewPreview, item.widgetInfo,
|
||||||
mRemoteViewsPreview);
|
mRemoteViewsPreview);
|
||||||
return;
|
return;
|
||||||
@@ -255,10 +251,15 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||||||
|
|
||||||
if (!item.hasPreviewLayout()) return;
|
if (!item.hasPreviewLayout()) return;
|
||||||
|
|
||||||
mAppWidgetHostViewPreview = new LauncherAppWidgetHostView(getContext());
|
Context context = getContext();
|
||||||
|
// If the context is a Launcher activity, DragView will show mAppWidgetHostViewPreview as
|
||||||
|
// a preview during drag & drop. And thus, we should use LauncherAppWidgetHostView, which
|
||||||
|
// supports applying local color extraction during drag & drop.
|
||||||
|
mAppWidgetHostViewPreview = isLauncherContext(context)
|
||||||
|
? new LauncherAppWidgetHostView(context)
|
||||||
|
: createAppWidgetHostView(context);
|
||||||
LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo =
|
LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo =
|
||||||
LauncherAppWidgetProviderInfo.fromProviderInfo(getContext(),
|
LauncherAppWidgetProviderInfo.fromProviderInfo(context, item.widgetInfo.clone());
|
||||||
item.widgetInfo.clone());
|
|
||||||
// A hack to force the initial layout to be the preview layout since there is no API for
|
// A hack to force the initial layout to be the preview layout since there is no API for
|
||||||
// rendering a preview layout for work profile apps yet. For non-work profile layout, a
|
// rendering a preview layout for work profile apps yet. For non-work profile layout, a
|
||||||
// proper solution is to use RemoteViews(PackageName, LayoutId).
|
// proper solution is to use RemoteViews(PackageName, LayoutId).
|
||||||
@@ -431,6 +432,24 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static NavigableAppWidgetHostView createAppWidgetHostView(Context context) {
|
||||||
|
return new NavigableAppWidgetHostView(context) {
|
||||||
|
@Override
|
||||||
|
protected boolean shouldAllowDirectClick() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isLauncherContext(Context context) {
|
||||||
|
try {
|
||||||
|
Launcher.getLauncher(context);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getAccessibilityClassName() {
|
public CharSequence getAccessibilityClassName() {
|
||||||
return WidgetCell.class.getName();
|
return WidgetCell.class.getName();
|
||||||
|
|||||||
Reference in New Issue
Block a user