fix lag when click shortcut of script with dialog

This commit is contained in:
hyb1996 2017-07-09 10:08:47 +08:00
parent fd2b5e5206
commit a660a98539
3 changed files with 38 additions and 13 deletions

View File

@ -2,7 +2,7 @@ package com.stardust.scriptdroid.external.shortcut;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
/**
@ -15,9 +15,10 @@ public class Shortcut {
private String mName;
private String mTargetClass;
private String mTargetPackage;
private Intent.ShortcutIconResource mIcon;
private Intent.ShortcutIconResource mIconRes;
private boolean mDuplicate = false;
private Intent mLaunchIntent = new Intent();
private Bitmap mIcon;
public Shortcut(Context 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;
return this;
}
public Shortcut icon(int resId) {
mIcon = Intent.ShortcutIconResource.fromContext(mContext, resId);
return this;
public Intent.ShortcutIconResource getIconRes() {
return mIconRes;
}
public Shortcut duplicate(boolean duplicate) {
mDuplicate = duplicate;
return this;
@ -69,7 +86,7 @@ public class Shortcut {
return mName;
}
public Intent.ShortcutIconResource getIcon() {
public Bitmap getIcon() {
return mIcon;
}
@ -86,12 +103,18 @@ public class Shortcut {
}
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_ICON_RESOURCE, getIcon())
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getLaunchIntent())
.putExtra("duplicate", isDuplicate())
.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() {

View File

@ -36,8 +36,9 @@ public class BlockedMaterialDialog extends MaterialDialog {
private boolean isActivityContext(Context context) {
if (context == null)
return false;
if (context instanceof Activity)
return true;
if (context instanceof Activity) {
return !((Activity) context).isFinishing();
}
if (context instanceof ContextWrapper) {
return isActivityContext(((ContextWrapper) context).getBaseContext());
}

View File

@ -1,5 +1,6 @@
package com.stardust.autojs.runtime.api.ui;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.text.TextUtils;
@ -73,7 +74,7 @@ public class Dialogs {
private Context getContext() {
if (mThemeWrapper != null)
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;
}
@ -115,7 +116,7 @@ public class Dialogs {
private BlockedMaterialDialog.Builder dialogBuilder() {
Context context = mAppUtils.getCurrentActivity();
if (context == null) {
if (context == null || ((Activity) context).isFinishing()) {
context = getContext();
}
return (BlockedMaterialDialog.Builder) new BlockedMaterialDialog.Builder(context, mUiHandler)