mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 18:06:48 +00:00
Updating the title of the Add to homescreen prompt to the requesting app
instead of the Launcher name Bug: 239055068 Test: Verified on device Change-Id: I1494d911565ddf3a598f9fbf372b8d784a4276e4
This commit is contained in:
@@ -31,6 +31,7 @@ import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipDescription;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.LauncherApps.PinItemRequest;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.res.Configuration;
|
||||
@@ -62,6 +63,8 @@ import com.android.launcher3.model.ItemInstallQueue;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.pm.PinRequestHelper;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
import com.android.launcher3.util.SystemUiController;
|
||||
import com.android.launcher3.views.AbstractSlideInView;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
@@ -136,13 +139,25 @@ public class AddItemActivity extends BaseActivity
|
||||
mAccessibilityManager =
|
||||
getApplicationContext().getSystemService(AccessibilityManager.class);
|
||||
|
||||
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
|
||||
setupShortcut();
|
||||
} else {
|
||||
if (!setupWidget()) {
|
||||
// TODO: show error toast?
|
||||
finish();
|
||||
}
|
||||
PackageUserKey targetApp = null;
|
||||
switch (mRequest.getRequestType()) {
|
||||
case PinItemRequest.REQUEST_TYPE_SHORTCUT:
|
||||
targetApp = setupShortcut();
|
||||
break;
|
||||
case PinItemRequest.REQUEST_TYPE_APPWIDGET:
|
||||
targetApp = setupWidget();
|
||||
break;
|
||||
}
|
||||
if (targetApp == null) {
|
||||
// TODO: show error toast?
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
ApplicationInfo info = new PackageManagerHelper(this)
|
||||
.getApplicationInfo(targetApp.mPackageName, targetApp.mUser, 0);
|
||||
if (info == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
WidgetCellPreview previewContainer = mWidgetCell.findViewById(
|
||||
@@ -156,8 +171,10 @@ public class AddItemActivity extends BaseActivity
|
||||
logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_START);
|
||||
}
|
||||
|
||||
// Set the label synchronously instead of via IconCache as this is the first thing
|
||||
// user sees
|
||||
TextView widgetAppName = findViewById(R.id.widget_appName);
|
||||
widgetAppName.setText(getApplicationInfo().labelRes);
|
||||
widgetAppName.setText(info.loadLabel(getPackageManager()));
|
||||
|
||||
mSlideInView = findViewById(R.id.add_item_bottom_sheet);
|
||||
mSlideInView.addOnCloseListener(this);
|
||||
@@ -246,20 +263,23 @@ public class AddItemActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void setupShortcut() {
|
||||
private PackageUserKey setupShortcut() {
|
||||
PinShortcutRequestActivityInfo shortcutInfo =
|
||||
new PinShortcutRequestActivityInfo(mRequest, this);
|
||||
mWidgetCell.getWidgetView().setTag(new PendingAddShortcutInfo(shortcutInfo));
|
||||
applyWidgetItemAsync(
|
||||
() -> new WidgetItem(shortcutInfo, mApp.getIconCache(), getPackageManager()));
|
||||
return new PackageUserKey(
|
||||
mRequest.getShortcutInfo().getPackage(),
|
||||
mRequest.getShortcutInfo().getUserHandle());
|
||||
}
|
||||
|
||||
private boolean setupWidget() {
|
||||
private PackageUserKey setupWidget() {
|
||||
LauncherAppWidgetProviderInfo widgetInfo = LauncherAppWidgetProviderInfo
|
||||
.fromProviderInfo(this, mRequest.getAppWidgetProviderInfo(this));
|
||||
if (widgetInfo.minSpanX > mIdp.numColumns || widgetInfo.minSpanY > mIdp.numRows) {
|
||||
// Cannot add widget
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
mWidgetCell.setRemoteViewsPreview(PinItemDragListener.getPreview(mRequest));
|
||||
|
||||
@@ -274,7 +294,7 @@ public class AddItemActivity extends BaseActivity
|
||||
mWidgetCell.getWidgetView().setTag(pendingInfo);
|
||||
|
||||
applyWidgetItemAsync(() -> new WidgetItem(widgetInfo, mIdp, mApp.getIconCache()));
|
||||
return true;
|
||||
return new PackageUserKey(widgetInfo.provider.getPackageName(), widgetInfo.getUser());
|
||||
}
|
||||
|
||||
private void applyWidgetItemAsync(final Supplier<WidgetItem> itemProvider) {
|
||||
|
||||
Reference in New Issue
Block a user