fix lag when click shortcut of script with dialog
This commit is contained in:
@@ -2,7 +2,7 @@ package com.stardust.scriptdroid.external.shortcut;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,9 +15,10 @@ public class Shortcut {
|
|||||||
private String mName;
|
private String mName;
|
||||||
private String mTargetClass;
|
private String mTargetClass;
|
||||||
private String mTargetPackage;
|
private String mTargetPackage;
|
||||||
private Intent.ShortcutIconResource mIcon;
|
private Intent.ShortcutIconResource mIconRes;
|
||||||
private boolean mDuplicate = false;
|
private boolean mDuplicate = false;
|
||||||
private Intent mLaunchIntent = new Intent();
|
private Intent mLaunchIntent = new Intent();
|
||||||
|
private Bitmap mIcon;
|
||||||
|
|
||||||
public Shortcut(Context context) {
|
public Shortcut(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -50,16 +51,32 @@ public class Shortcut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Shortcut icon(Intent.ShortcutIconResource icon) {
|
public Shortcut iconRes(Intent.ShortcutIconResource icon) {
|
||||||
|
if (mIcon != null) {
|
||||||
|
throw new IllegalStateException("Cannot set both iconRes and icon");
|
||||||
|
}
|
||||||
|
mIconRes = icon;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Shortcut iconRes(int resId) {
|
||||||
|
return iconRes(Intent.ShortcutIconResource.fromContext(mContext, resId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Shortcut icon(Bitmap icon) {
|
||||||
|
if (mIconRes != null) {
|
||||||
|
throw new IllegalStateException("Cannot set both iconRes and icon");
|
||||||
|
}
|
||||||
mIcon = icon;
|
mIcon = icon;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shortcut icon(int resId) {
|
public Intent.ShortcutIconResource getIconRes() {
|
||||||
mIcon = Intent.ShortcutIconResource.fromContext(mContext, resId);
|
return mIconRes;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Shortcut duplicate(boolean duplicate) {
|
public Shortcut duplicate(boolean duplicate) {
|
||||||
mDuplicate = duplicate;
|
mDuplicate = duplicate;
|
||||||
return this;
|
return this;
|
||||||
@@ -69,7 +86,7 @@ public class Shortcut {
|
|||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Intent.ShortcutIconResource getIcon() {
|
public Bitmap getIcon() {
|
||||||
return mIcon;
|
return mIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,12 +103,18 @@ public class Shortcut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Intent getCreateIntent() {
|
public Intent getCreateIntent() {
|
||||||
return new Intent(Intent.ACTION_CREATE_SHORTCUT)
|
Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT)
|
||||||
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getName())
|
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getName())
|
||||||
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, getIcon())
|
|
||||||
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getLaunchIntent())
|
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getLaunchIntent())
|
||||||
.putExtra("duplicate", isDuplicate())
|
.putExtra("duplicate", isDuplicate())
|
||||||
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
||||||
|
Bitmap icon = getIcon();
|
||||||
|
if (icon == null) {
|
||||||
|
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, getIconRes());
|
||||||
|
} else {
|
||||||
|
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
|
||||||
|
}
|
||||||
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Intent getLaunchIntent() {
|
public Intent getLaunchIntent() {
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ public class BlockedMaterialDialog extends MaterialDialog {
|
|||||||
private boolean isActivityContext(Context context) {
|
private boolean isActivityContext(Context context) {
|
||||||
if (context == null)
|
if (context == null)
|
||||||
return false;
|
return false;
|
||||||
if (context instanceof Activity)
|
if (context instanceof Activity) {
|
||||||
return true;
|
return !((Activity) context).isFinishing();
|
||||||
|
}
|
||||||
if (context instanceof ContextWrapper) {
|
if (context instanceof ContextWrapper) {
|
||||||
return isActivityContext(((ContextWrapper) context).getBaseContext());
|
return isActivityContext(((ContextWrapper) context).getBaseContext());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.stardust.autojs.runtime.api.ui;
|
package com.stardust.autojs.runtime.api.ui;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -73,7 +74,7 @@ public class Dialogs {
|
|||||||
private Context getContext() {
|
private Context getContext() {
|
||||||
if (mThemeWrapper != null)
|
if (mThemeWrapper != null)
|
||||||
return mThemeWrapper;
|
return mThemeWrapper;
|
||||||
mThemeWrapper = new ContextThemeWrapper(mUiHandler.getContext(), R.style.Theme_AppCompat_Light);
|
mThemeWrapper = new ContextThemeWrapper(mUiHandler.getContext().getApplicationContext(), R.style.Theme_AppCompat_Light);
|
||||||
return mThemeWrapper;
|
return mThemeWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ public class Dialogs {
|
|||||||
|
|
||||||
private BlockedMaterialDialog.Builder dialogBuilder() {
|
private BlockedMaterialDialog.Builder dialogBuilder() {
|
||||||
Context context = mAppUtils.getCurrentActivity();
|
Context context = mAppUtils.getCurrentActivity();
|
||||||
if (context == null) {
|
if (context == null || ((Activity) context).isFinishing()) {
|
||||||
context = getContext();
|
context = getContext();
|
||||||
}
|
}
|
||||||
return (BlockedMaterialDialog.Builder) new BlockedMaterialDialog.Builder(context, mUiHandler)
|
return (BlockedMaterialDialog.Builder) new BlockedMaterialDialog.Builder(context, mUiHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user