mirror of
https://github.com/TrianguloY/LightningLauncher.git
synced 2024-12-28 09:58:34 +01:00
Handle pin item request in shortcut creation
This commit is contained in:
parent
eb71ae68bf
commit
49f08d35e8
4 changed files with 75 additions and 42 deletions
|
@ -3325,37 +3325,21 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.O)
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
private void addPinnedShortcut(Intent intent) {
|
private void addPinnedShortcut(Intent intent) {
|
||||||
Parcelable extra = intent.getParcelableExtra(LauncherApps.EXTRA_PIN_ITEM_REQUEST);
|
Utils.ShortcutDescription sd = Utils.createPinItemRequestFromIntent(this, intent);
|
||||||
if(extra instanceof LauncherApps.PinItemRequest) {
|
if(sd != null) {
|
||||||
LauncherApps.PinItemRequest request = (LauncherApps.PinItemRequest) extra;
|
final ItemLayout il = mScreen.getTargetOrTopmostItemLayout();
|
||||||
if (request.getRequestType() == LauncherApps.PinItemRequest.REQUEST_TYPE_SHORTCUT) {
|
Page page = il.getPage();
|
||||||
final LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
|
float scale = il.getCurrentScale();
|
||||||
ShortcutInfo shortcutInfo = request.getShortcutInfo();
|
final Item newItem = Utils.addShortcut(sd.name, sd.icon, sd.intent, page, Utils.POSITION_AUTO, Utils.POSITION_AUTO, scale, true);
|
||||||
|
|
||||||
final Drawable iconDrawable = launcherApps.getShortcutIconDrawable(shortcutInfo, Utils.getLauncherIconDensity());
|
mUndoStack.storePageAddItem(newItem);
|
||||||
Bitmap icon = Utils.createBitmapFromDrawable(iconDrawable);
|
editItem(il, newItem);
|
||||||
|
mHandler.postDelayed(new Runnable() {
|
||||||
Intent si = new Intent(Shortcut.INTENT_ACTION_APP_SHORTCUT);
|
@Override
|
||||||
si.putExtra(Shortcut.INTENT_EXTRA_APP_SHORTCUT_ID, shortcutInfo.getId());
|
public void run() {
|
||||||
si.putExtra(Shortcut.INTENT_EXTRA_APP_SHORTCUT_PKG, shortcutInfo.getPackage());
|
mScreen.ensureItemViewVisible(il.getItemView(newItem), false);
|
||||||
si.putExtra(Shortcut.INTENT_EXTRA_APP_SHORTCUT_DISABLED_MSG, shortcutInfo.getDisabledMessage());
|
}
|
||||||
|
}, 1000);
|
||||||
final ItemLayout il = mScreen.getTargetOrTopmostItemLayout();
|
|
||||||
Page page = il.getPage();
|
|
||||||
float scale = il.getCurrentScale();
|
|
||||||
final Item newItem = Utils.addShortcut(shortcutInfo.getShortLabel().toString(), icon, si, page, Utils.POSITION_AUTO, Utils.POSITION_AUTO, scale, true);
|
|
||||||
|
|
||||||
mUndoStack.storePageAddItem(newItem);
|
|
||||||
editItem(il, newItem);
|
|
||||||
mHandler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mScreen.ensureItemViewVisible(il.getItemView(newItem), false);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
request.accept();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,20 +61,21 @@ public class ShortcutReceiver extends BroadcastReceiver {
|
||||||
if(duplicate || found==null) {
|
if(duplicate || found==null) {
|
||||||
int icon_size=(int)(home_page.config.defaultShortcutConfig.iconScale* Utils.getStandardIconSize());
|
int icon_size=(int)(home_page.config.defaultShortcutConfig.iconScale* Utils.getStandardIconSize());
|
||||||
Utils.ShortcutDescription sd=Utils.createShortcutFromIntent(context, data, icon_size);
|
Utils.ShortcutDescription sd=Utils.createShortcutFromIntent(context, data, icon_size);
|
||||||
|
if(sd != null) {
|
||||||
|
int id = home_page.findFreeItemId();
|
||||||
|
int[] cell = Utils.findFreeCell(home_page);
|
||||||
|
Shortcut shortcut = new Shortcut(home_page);
|
||||||
|
File icon_dir = home_page.getAndCreateIconDir();
|
||||||
|
shortcut.init(id, new Rect(cell[0], cell[1], cell[0] + 1, cell[1] + 1), null, sd.name, sd.intent);
|
||||||
|
|
||||||
int id=home_page.findFreeItemId();
|
if (sd.icon != null) {
|
||||||
int[] cell=Utils.findFreeCell(home_page);
|
File icon_file = shortcut.getDefaultIconFile();
|
||||||
Shortcut shortcut=new Shortcut(home_page);
|
Utils.saveIconToFile(icon_file, sd.icon);
|
||||||
File icon_dir=home_page.getAndCreateIconDir();
|
sd.icon.recycle();
|
||||||
shortcut.init(id, new Rect(cell[0], cell[1], cell[0]+1, cell[1]+1), null, sd.name, sd.intent);
|
}
|
||||||
|
|
||||||
if(sd.icon != null) {
|
home_page.addItem(shortcut);
|
||||||
File icon_file=shortcut.getDefaultIconFile();
|
|
||||||
Utils.saveIconToFile(icon_file, sd.icon);
|
|
||||||
sd.icon.recycle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
home_page.addItem(shortcut);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.pierrox.lightning_launcher.data;
|
package net.pierrox.lightning_launcher.data;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
@ -11,9 +12,11 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.Intent.ShortcutIconResource;
|
import android.content.Intent.ShortcutIconResource;
|
||||||
|
import android.content.pm.LauncherApps;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -1032,6 +1035,10 @@ public class Utils {
|
||||||
public static ShortcutDescription createShortcutFromIntent(Context context, Intent data, int max_icon_size) {
|
public static ShortcutDescription createShortcutFromIntent(Context context, Intent data, int max_icon_size) {
|
||||||
// this comes from Launcher2
|
// this comes from Launcher2
|
||||||
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
|
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
|
||||||
|
if(intent == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
|
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
|
||||||
Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
|
Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
|
||||||
|
|
||||||
|
@ -1062,6 +1069,37 @@ public class Utils {
|
||||||
return sd;
|
return sd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
|
public static ShortcutDescription createPinItemRequestFromIntent(Context context, Intent intent) {
|
||||||
|
Parcelable extra = intent.getParcelableExtra(LauncherApps.EXTRA_PIN_ITEM_REQUEST);
|
||||||
|
if(extra instanceof LauncherApps.PinItemRequest) {
|
||||||
|
LauncherApps.PinItemRequest request = (LauncherApps.PinItemRequest) extra;
|
||||||
|
if (request.getRequestType() == LauncherApps.PinItemRequest.REQUEST_TYPE_SHORTCUT) {
|
||||||
|
final LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
|
||||||
|
ShortcutInfo shortcutInfo = request.getShortcutInfo();
|
||||||
|
|
||||||
|
final Drawable iconDrawable = launcherApps.getShortcutIconDrawable(shortcutInfo, Utils.getLauncherIconDensity());
|
||||||
|
Bitmap icon = Utils.createBitmapFromDrawable(iconDrawable);
|
||||||
|
|
||||||
|
Intent si = new Intent(Shortcut.INTENT_ACTION_APP_SHORTCUT);
|
||||||
|
si.putExtra(Shortcut.INTENT_EXTRA_APP_SHORTCUT_ID, shortcutInfo.getId());
|
||||||
|
si.putExtra(Shortcut.INTENT_EXTRA_APP_SHORTCUT_PKG, shortcutInfo.getPackage());
|
||||||
|
si.putExtra(Shortcut.INTENT_EXTRA_APP_SHORTCUT_DISABLED_MSG, shortcutInfo.getDisabledMessage());
|
||||||
|
|
||||||
|
ShortcutDescription sd=new ShortcutDescription();
|
||||||
|
sd.name = shortcutInfo.getShortLabel().toString();
|
||||||
|
sd.icon = icon;
|
||||||
|
sd.intent = si;
|
||||||
|
|
||||||
|
request.accept();
|
||||||
|
|
||||||
|
return sd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static void deleteDirectory(File dir, boolean delete_root) {
|
public static void deleteDirectory(File dir, boolean delete_root) {
|
||||||
File[] files=dir.listFiles();
|
File[] files=dir.listFiles();
|
||||||
if(files!=null) {
|
if(files!=null) {
|
||||||
|
@ -1479,7 +1517,17 @@ public class Utils {
|
||||||
|
|
||||||
public static Item addAndroidShortcutFromIntent(Context context, Intent data, Page page, int x, int y, float scale) {
|
public static Item addAndroidShortcutFromIntent(Context context, Intent data, Page page, int x, int y, float scale) {
|
||||||
int icon_size=(int)(page.config.defaultShortcutConfig.iconScale*getStandardIconSize());
|
int icon_size=(int)(page.config.defaultShortcutConfig.iconScale*getStandardIconSize());
|
||||||
|
|
||||||
ShortcutDescription sd=createShortcutFromIntent(context, data, icon_size);
|
ShortcutDescription sd=createShortcutFromIntent(context, data, icon_size);
|
||||||
|
if(sd == null) {
|
||||||
|
sd = createPinItemRequestFromIntent(context, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sd == null) {
|
||||||
|
sd = new ShortcutDescription();
|
||||||
|
sd.name = "no shortcut";
|
||||||
|
sd.intent = new Intent();
|
||||||
|
}
|
||||||
|
|
||||||
return addShortcut(sd.name, sd.icon, sd.intent, page, x, y, scale, true);
|
return addShortcut(sd.name, sd.icon, sd.intent, page, x, y, scale, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -652,7 +652,7 @@ public class LightningEngine implements Page.PageListener {
|
||||||
if (item.getClass() == Shortcut.class) {
|
if (item.getClass() == Shortcut.class) {
|
||||||
Shortcut shortcut = (Shortcut) item;
|
Shortcut shortcut = (Shortcut) item;
|
||||||
Intent intent = shortcut.getIntent();
|
Intent intent = shortcut.getIntent();
|
||||||
if (Shortcut.INTENT_ACTION_APP_SHORTCUT.equals(intent.getAction())) {
|
if (intent != null && Shortcut.INTENT_ACTION_APP_SHORTCUT.equals(intent.getAction())) {
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue