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