fix flash when launch a shortcut
This commit is contained in:
@@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".external.shortcut.ShortcutActivity"
|
android:name=".external.shortcut.ShortcutActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:taskAffinity="com.stardust.scriptdroid.external.shortcut.ShortcutActivity"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.example.Project.Action"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
@@ -151,7 +152,9 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".external.open.RunIntentActivity"
|
android:name=".external.open.RunIntentActivity"
|
||||||
android:icon="@drawable/ic_ali_run"
|
android:icon="@drawable/ic_ali_run"
|
||||||
android:label="运行脚本">
|
android:label="运行脚本"
|
||||||
|
android:taskAffinity="com.stardust.scriptdroid.external.open.RunIntentActivity"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public class CommonUtils {
|
|||||||
String directoryPath = null;
|
String directoryPath = null;
|
||||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||||
ScriptSource source = null;
|
ScriptSource source = null;
|
||||||
Toast.makeText(context, path, Toast.LENGTH_SHORT).show();
|
|
||||||
if (path == null && script != null) {
|
if (path == null && script != null) {
|
||||||
source = new StringScriptSource(script);
|
source = new StringScriptSource(script);
|
||||||
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
|
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
|
||||||
|
|||||||
@@ -2,6 +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.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ public class ShortcutActivity extends Activity {
|
|||||||
if (new PathChecker(this).checkAndToastError(path)) {
|
if (new PathChecker(this).checkAndToastError(path)) {
|
||||||
runScriptFile(path);
|
runScriptFile(path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ScriptFile extends File {
|
|||||||
if (isDirectory())
|
if (isDirectory())
|
||||||
return renameTo(new File(getParent(), newName));
|
return renameTo(new File(getParent(), newName));
|
||||||
else
|
else
|
||||||
return renameTo(new File(getParent(), newName + getExtension()));
|
return renameTo(new File(getParent(), newName + "." + getExtension()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getExtension() {
|
private String getExtension() {
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
import com.stardust.autojs.runtime.ScriptInterface;
|
import com.stardust.autojs.runtime.ScriptInterface;
|
||||||
import com.stardust.util.IntentUtil;
|
import com.stardust.util.IntentUtil;
|
||||||
@@ -15,6 +17,8 @@ import com.stardust.util.IntentUtil;
|
|||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.stardust.pio.PFile.getExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/4/2.
|
* Created by Stardust on 2017/4/2.
|
||||||
*/
|
*/
|
||||||
@@ -55,7 +59,7 @@ public class AppUtils {
|
|||||||
return applicationInfo.processName;
|
return applicationInfo.processName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ScriptInterface
|
@ScriptInterface
|
||||||
@@ -75,6 +79,40 @@ public class AppUtils {
|
|||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public void viewFile(String path) {
|
||||||
|
if (path == null)
|
||||||
|
throw new NullPointerException("path == null");
|
||||||
|
path = "file://" + path;
|
||||||
|
String ext = getExtension(path);
|
||||||
|
String mimeType = TextUtils.isEmpty(ext) ? "*/*" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||||
|
mContext.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||||
|
.setDataAndType(Uri.parse(path), mimeType)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public void editFile(String path) {
|
||||||
|
if (path == null)
|
||||||
|
throw new NullPointerException("path == null");
|
||||||
|
path = "file://" + path;
|
||||||
|
String ext = getExtension(path);
|
||||||
|
String mimeType = TextUtils.isEmpty(ext) ? "*/*" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||||
|
mContext.startActivity(new Intent(Intent.ACTION_EDIT)
|
||||||
|
.setDataAndType(Uri.parse(path), mimeType)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public void openUrl(String url) {
|
||||||
|
if (!url.startsWith("http://") || !url.startsWith("https://")) {
|
||||||
|
url = "http://" + url;
|
||||||
|
}
|
||||||
|
mContext.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||||
|
.setData(Uri.parse(url))
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
|
}
|
||||||
|
|
||||||
public void setCurrentActivity(Activity currentActivity) {
|
public void setCurrentActivity(Activity currentActivity) {
|
||||||
mCurrentActivity = new WeakReference<>(currentActivity);
|
mCurrentActivity = new WeakReference<>(currentActivity);
|
||||||
Log.d("App", "setCurrentActivity: " + currentActivity);
|
Log.d("App", "setCurrentActivity: " + currentActivity);
|
||||||
|
|||||||
@@ -171,16 +171,16 @@ public class PFile {
|
|||||||
|
|
||||||
public static String renameWithoutExtension(String path, String newName) {
|
public static String renameWithoutExtension(String path, String newName) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
File newFile = new File(file.getParent(), newName + getExtension(file.getName()));
|
File newFile = new File(file.getParent(), newName + "." + getExtension(file.getName()));
|
||||||
file.renameTo(newFile);
|
file.renameTo(newFile);
|
||||||
return newFile.getAbsolutePath();
|
return newFile.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getExtension(String fileName) {
|
public static String getExtension(String fileName) {
|
||||||
int i = fileName.lastIndexOf('.');
|
int i = fileName.lastIndexOf('.');
|
||||||
if (i < 0 || i == fileName.length() - 1)
|
if (i < 0 || i + 1 >= fileName.length() - 1)
|
||||||
return "";
|
return "";
|
||||||
return fileName.substring(i);
|
return fileName.substring(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean write(String path, String text) {
|
public static boolean write(String path, String text) {
|
||||||
@@ -233,7 +233,7 @@ public class PFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static File copyAssetToTmpFile(Context context, String path) {
|
public static File copyAssetToTmpFile(Context context, String path) {
|
||||||
String extension = getExtension(path);
|
String extension = "." + getExtension(path);
|
||||||
String name = getNameWithoutExtension(path);
|
String name = getNameWithoutExtension(path);
|
||||||
if (name.length() < 5) {
|
if (name.length() < 5) {
|
||||||
name += name.hashCode();
|
name += name.hashCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user