fix some bugs

This commit is contained in:
hyb1996
2018-10-11 12:00:50 +08:00
parent f757083657
commit e56682162e
25 changed files with 168 additions and 52 deletions

View File

@@ -45,7 +45,7 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
}
@Override
protected Console createGlobalConsole() {
protected GlobalStardustConsole createGlobalConsole() {
return new GlobalStardustConsole(getUiHandler()) {
@Override
public String println(int level, CharSequence charSequence) {

View File

@@ -41,6 +41,7 @@ public class ScriptIntents {
long interval = intent.getLongExtra(EXTRA_KEY_LOOP_INTERVAL, 0);
ScriptSource source = null;
ExecutionConfig config = new ExecutionConfig().loop(delay, loopTimes, interval);
config.setArgument("intent", intent);
if (path == null && script != null) {
source = new StringScriptSource(script);
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {

View File

@@ -1,5 +1,6 @@
package org.autojs.autojs.model.script;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.Nullable;
@@ -147,9 +148,10 @@ public class Scripts {
}
public static void send(ScriptFile file) {
GlobalAppContext.get().startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
Context context = GlobalAppContext.get();
context.startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)),
.putExtra(Intent.EXTRA_STREAM, IntentUtil.getUriOfFile(context, file.getPath(), AppFileProvider.AUTHORITY)),
GlobalAppContext.getString(R.string.text_send)
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

View File

@@ -24,7 +24,7 @@ public abstract class FullScreenFloatyWindow implements FloatyWindow {
mLayoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
FloatyWindowManger.getWindowType(),
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT);
mWindowManager.addView(mView, mLayoutParams);

View File

@@ -13,6 +13,7 @@ import com.stardust.app.DialogUtils;
import com.stardust.enhancedfloaty.FloatyService;
import org.autojs.autojs.R;
import org.autojs.autojs.ui.codegeneration.CodeGenerateDialog;
import org.autojs.autojs.ui.floating.FloatyWindowManger;
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
import com.stardust.view.accessibility.NodeInfo;
import org.autojs.autojs.ui.widget.BubblePopupMenu;
@@ -115,7 +116,7 @@ public class LayoutBoundsFloatyWindow extends FullScreenFloatyWindow {
.customView(mNodeInfoView, false)
.theme(Theme.LIGHT)
.build();
mNodeInfoDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
mNodeInfoDialog.getWindow().setType(FloatyWindowManger.getWindowType());
}
}

View File

@@ -14,6 +14,7 @@ import com.stardust.app.DialogUtils;
import com.stardust.enhancedfloaty.FloatyService;
import org.autojs.autojs.R;
import org.autojs.autojs.ui.codegeneration.CodeGenerateDialog;
import org.autojs.autojs.ui.floating.FloatyWindowManger;
import org.autojs.autojs.ui.floating.FullScreenFloatyWindow;
import com.stardust.view.accessibility.NodeInfo;
import org.autojs.autojs.ui.widget.BubblePopupMenu;
@@ -124,7 +125,7 @@ public class LayoutHierarchyFloatyWindow extends FullScreenFloatyWindow {
.theme(Theme.LIGHT)
.build();
if (mNodeInfoDialog.getWindow() != null)
mNodeInfoDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
mNodeInfoDialog.getWindow().setType(FloatyWindowManger.getWindowType());
}
}

View File

@@ -2,15 +2,14 @@ package org.autojs.autojs.ui.project;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.CardView;
import android.text.Editable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -25,7 +24,6 @@ import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.autojs.autojs.App;
import org.autojs.autojs.Pref;
import org.autojs.autojs.R;
import org.autojs.autojs.autojs.build.AutoJsApkBuilder;
@@ -41,9 +39,9 @@ import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity_;
import java.io.File;
import java.io.InputStream;
import java.security.KeyStore;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.regex.Pattern;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -60,6 +58,7 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog
public static final String EXTRA_SOURCE = BuildActivity.class.getName() + ".extra_source_file";
private static final String LOG_TAG = "BuildActivity";
private static final Pattern REGEX_PACKAGE_NAME = Pattern.compile("^([A-Za-z][A-Za-z\\d_]*\\.)+([A-Za-z][A-Za-z\\d_]*)$");
@ViewById(R.id.source_path)
TextInputEditText mSourcePath;
@@ -221,10 +220,25 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog
inputValid &= checkNotEmpty(mSourcePath);
inputValid &= checkNotEmpty(mVersionCode);
inputValid &= checkNotEmpty(mVersionName);
inputValid &= checkNotEmpty(mPackageName);
inputValid &= checkPackageNameValid(mPackageName);
return inputValid;
}
private boolean checkPackageNameValid(TextInputEditText editText) {
Editable text = editText.getText();
String hint = ((TextInputLayout) editText.getParent().getParent()).getHint().toString();
if(TextUtils.isEmpty(text)){
editText.setError(hint + getString(R.string.text_should_not_be_empty));
return false;
}
if(!REGEX_PACKAGE_NAME.matcher(text).matches()){
editText.setError(getString(R.string.text_invalid_package_name));
return false;
}
return true;
}
private boolean checkNotEmpty(TextInputEditText editText) {
if (!TextUtils.isEmpty(editText.getText()) || !editText.isShown())
return true;

View File

@@ -7,6 +7,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
@@ -35,6 +36,7 @@ import org.autojs.autojs.ui.widget.SimpleTextWatcher;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.regex.Pattern;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -50,6 +52,7 @@ public class ProjectConfigActivity extends BaseActivity {
public static final String EXTRA_DIRECTORY = "directory";
private static final int REQUEST_CODE = 12477;
private static final Pattern REGEX_PACKAGE_NAME = Pattern.compile("^([A-Za-z][A-Za-z\\d_]*\\.)+([A-Za-z][A-Za-z\\d_]*)$");
@ViewById(R.id.project_location)
@@ -138,10 +141,10 @@ public class ProjectConfigActivity extends BaseActivity {
@SuppressLint("CheckResult")
@Click(R.id.fab)
void commit() {
syncProjectConfig();
if (!checkInputs()) {
return;
}
syncProjectConfig();
if (mIconBitmap != null) {
saveIcon(mIconBitmap)
.subscribe(ignored -> saveProjectConfig(), e -> {
@@ -209,10 +212,25 @@ public class ProjectConfigActivity extends BaseActivity {
inputValid &= checkNotEmpty(mAppName);
inputValid &= checkNotEmpty(mVersionCode);
inputValid &= checkNotEmpty(mVersionName);
inputValid &= checkNotEmpty(mPackageName);
inputValid &= checkPackageNameValid(mPackageName);
return inputValid;
}
private boolean checkPackageNameValid(TextInputEditText editText) {
Editable text = editText.getText();
String hint = ((TextInputLayout) editText.getParent().getParent()).getHint().toString();
if(TextUtils.isEmpty(text)){
editText.setError(hint + getString(R.string.text_should_not_be_empty));
return false;
}
if(!REGEX_PACKAGE_NAME.matcher(text).matches()){
editText.setError(getString(R.string.text_invalid_package_name));
return false;
}
return true;
}
private boolean checkNotEmpty(TextInputEditText editText) {
if (!TextUtils.isEmpty(editText.getText()))
return true;

View File

@@ -2,6 +2,7 @@ package org.autojs.autojs.ui.timing;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.ColorFilter;
import android.net.ConnectivityManager;
@@ -346,8 +347,13 @@ public class TimedTaskSettingActivity extends BaseActivity {
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_done) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !((PowerManager) getSystemService(POWER_SERVICE)).isIgnoringBatteryOptimizations(getPackageName())) {
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
try{
startActivityForResult(new Intent().setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:" + getPackageName())), REQUEST_CODE_IGNORE_BATTERY);
}catch(ActivityNotFoundException e){
e.printStackTrace();
createOrUpdateTask();
}
} else {
createOrUpdateTask();
}

View File

@@ -422,4 +422,5 @@
<string name="text_run_on_time_tick">每分钟一次</string>
<string name="text_run_on_config_change">某些设置(屏幕方向,地区等)更改时</string>
<string name="error_pattern_syntax">正则表达式错误</string>
<string name="text_invalid_package_name">非法包名</string>
</resources>