Skip to content

Commit

Permalink
Merge branch 'kkevsekk1:dev-test' into dev-test
Browse files Browse the repository at this point in the history
  • Loading branch information
aiselp authored Aug 26, 2023
2 parents 3bd9a04 + 5d8800f commit d28ae61
Show file tree
Hide file tree
Showing 31 changed files with 289 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 15
java-version: 17
- name: set up kotlin
uses: fwilhe2/setup-kotlin@main
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: checkout
id: check
uses: actions/checkout@v1
- name: set up JDK 15
- name: set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 15
java-version: 17
- name: Build inrt template
run: |
chmod 777 ./gradlew
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
* autojs 能不能商用,取决于你对于附带的 “ **非商业性使用** ” 的理解和其法律效益。
* 反正本产品不会拿autojs 进行商用。

#### 编译相关:
### 编译相关:
环境要求:`jdk`版本17以上

命令说明:在项目根目录下运行命令,如果使用 Windows powerShell < 7.0,请使用包含 ";" 的命令

##### 本地安装调试版本到设备:
Expand Down
1 change: 1 addition & 0 deletions apkbuilder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
)
}
}
namespace = "com.stardust.autojs.apkbuilder"


}
Expand Down
3 changes: 1 addition & 2 deletions apkbuilder/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stardust.autojs.apkbuilder">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import java.util.*
import java.io.File
import java.util.Properties

plugins {
id("com.android.application")
Expand Down Expand Up @@ -166,6 +165,7 @@ android {
)
)
}
namespace = "org.autojs.autoxjs"

}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.autojs.autoxjs">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/org/autojs/autojs/ui/edit/EditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -29,12 +30,12 @@
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.autojs.autoxjs.R;
import org.autojs.autojs.storage.file.TmpScriptFiles;
import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder;
import org.autojs.autojs.tool.Observers;
import org.autojs.autojs.ui.BaseActivity;
import org.autojs.autojs.ui.main.MainActivity;
import org.autojs.autoxjs.R;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -129,7 +130,9 @@ private void onLoadFileError(String message) {
}

private void setUpToolbar() {
BaseActivity.setToolbarAsBack(this, R.id.toolbar, mEditorView.getName());
BaseActivity.setToolbarAsBack(this, R.id.toolbar, "" );
TextView filePath= findViewById(R.id.file_path);
filePath.setText(mEditorView.getUri().getPath());
}

@Override
Expand Down
38 changes: 30 additions & 8 deletions app/src/main/java/org/autojs/autojs/ui/edit/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseBooleanArray;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -154,6 +157,7 @@ public void onReceive(Context context, Intent intent) {
private String mRestoredText;
private NormalToolbarFragment mNormalToolbar = new NormalToolbarFragment_();
private boolean mDebugging = false;
private EditorMenu mEditorMenu;

public EditorView(Context context) {
super(context);
Expand Down Expand Up @@ -296,8 +300,8 @@ void init() {

private void initNormalToolbar() {
mNormalToolbar.setOnMenuItemClickListener(this);
mNormalToolbar.setOnMenuItemLongClickListener(id -> {
if (id == R.id.run) {
mNormalToolbar.setOnMenuItemLongClickListener(view -> {
if (view.getId() == R.id.run) {
debug();
return true;
}
Expand Down Expand Up @@ -336,6 +340,7 @@ private void setUpEditor() {
}));
mEditor.addCursorChangeCallback(this::autoComplete);
mEditor.getCodeEditText().setTextSize(Pref.getEditorTextSize((int) ViewUtils.pxToSp(getContext(), mEditor.getCodeEditText().getTextSize())));
mEditorMenu = new EditorMenu(this);
}

private void autoComplete(String line, int cursor) {
Expand Down Expand Up @@ -378,8 +383,8 @@ public boolean onBackPressed() {
}

@Override
public void onToolbarMenuItemClick(int id) {
switch (id) {
public void onToolbarMenuItemClick(View view) {
switch (view.getId()) {
case R.id.run:
runAndSaveFileIfNeeded();
break;
Expand All @@ -404,14 +409,31 @@ public void onToolbarMenuItemClick(int id) {
case R.id.cancel_search:
cancelSearch();
break;
case R.id.textSizePlus:
setTextSizePlus();
case R.id.action_log:
LogActivityKt.start(getContext());
break;
case R.id.textSizeMinus:
setTextSizeMinus();
case R.id.debug:
showOptionMenu(view,R.menu.menu_editor_debug);
break;
case R.id.jump:
showOptionMenu(view,R.menu.menu_editor_jump);
break;
case R.id.edit:
showOptionMenu(view,R.menu.menu_editor_edit);
break;
}
}
void showOptionMenu( View view,int menuId) {
PopupMenu popupMenu = new PopupMenu(getContext(), view);
popupMenu.inflate(menuId);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return mEditorMenu.onOptionsItemSelected(item);
}
});
popupMenu.show();
}

@SuppressLint("CheckResult")
public void runAndSaveFileIfNeeded() {
Expand Down
49 changes: 46 additions & 3 deletions app/src/main/java/org/autojs/autojs/ui/edit/editor/CodeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import android.graphics.Canvas;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.google.android.material.snackbar.Snackbar;
import com.stardust.autojs.script.JsBeautifier;
import com.stardust.util.ClipboardUtil;
import com.stardust.util.TextUtils;
import com.stardust.util.ViewUtils;

import org.autojs.autoxjs.R;
import org.autojs.autojs.Pref;
import org.autojs.autojs.ui.edit.theme.Theme;
import org.autojs.autoxjs.R;

import java.util.LinkedHashMap;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -60,7 +64,7 @@ public interface CursorChangeCallback {
private Theme mTheme;
private JsBeautifier mJsBeautifier;
private MaterialDialog mProcessDialog;

private ScaleGestureDetector detector;
private CharSequence mReplacement = "";
private String mKeywords;
private Matcher mMatcher;
Expand All @@ -76,7 +80,6 @@ public CodeEditor(Context context, AttributeSet attrs) {
init();
}


private void init() {
//setFillViewport(true);
inflate(getContext(), R.layout.code_editor, this);
Expand All @@ -85,6 +88,46 @@ private void init() {
mTextViewRedoUndo = new TextViewUndoRedo(mCodeEditText);
mJavaScriptHighlighter = new JavaScriptHighlighter(mTheme, mCodeEditText);
mJsBeautifier = new JsBeautifier(this, "js/js-beautify");
detector = new ScaleGestureDetector(getContext(),getScaleGestureListener());
}

public ScaleGestureDetector.OnScaleGestureListener getScaleGestureListener() {
return new ScaleGestureDetector.OnScaleGestureListener() {
private double mLastScaleFactor = 1.0;
private int mLastTextSize;
private final int mMinTextSize = Integer.parseInt(getContext().getString(R.string.text_size_min_value));
private final int mMaxTextSize = Integer.parseInt(getContext().getString(R.string.text_size_max_value));;
@Override
public boolean onScale(ScaleGestureDetector detector) {
double currentFactor = Math.floor(detector.getScaleFactor() * 10) / 10;
if (currentFactor > 0 && mLastScaleFactor != currentFactor) {
int currentTextSize = mLastTextSize + (currentFactor > mLastScaleFactor ? 1 : -1);
mLastTextSize = Math.max(mMinTextSize, Math.min(mMaxTextSize, currentTextSize));
mCodeEditText.setTextSize(mLastTextSize);
mLastScaleFactor = currentFactor;
}
mCodeEditText.invalidate();
return false;
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
mLastTextSize =Pref.getEditorTextSize((int) ViewUtils.pxToSp(getContext(), (int) mCodeEditText.getTextSize()));;
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
mLastScaleFactor = 1.0;
Pref.setEditorTextSize(mLastTextSize);
}
};
}

@Override
public boolean onTouchEvent(MotionEvent event) {
//缩放手势检测
detector.onTouchEvent(event);
//只拦截手势传递
return detector.isInProgress() || super.onTouchEvent(event);
}

public Observable<Integer> getLineCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class NormalToolbarFragment extends ToolbarFragment {

@Override
public List<Integer> getMenuItemIds() {
return Arrays.asList(R.id.run, R.id.undo, R.id.redo, R.id.save, R.id.textSizePlus, R.id.textSizeMinus);
return Arrays.asList(R.id.edit, R.id.jump, R.id.debug, R.id.action_log, R.id.run, R.id.undo, R.id.redo, R.id.save);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public abstract class ToolbarFragment extends Fragment implements View.OnClickLi


public interface OnMenuItemClickListener {
void onToolbarMenuItemClick(int id);
void onToolbarMenuItemClick(View view);
}

public interface OnMenuItemLongClickListener {
boolean onToolbarMenuItemLongClick(int id);
boolean onToolbarMenuItemLongClick(View view);
}

private OnMenuItemClickListener mOnMenuItemClickListener;
Expand Down Expand Up @@ -73,15 +73,15 @@ private void updateMenuItemStatus(View rootView) {
@Override
public void onClick(View view) {
if (mOnMenuItemClickListener != null) {
mOnMenuItemClickListener.onToolbarMenuItemClick(view.getId());
mOnMenuItemClickListener.onToolbarMenuItemClick(view);
}
}


@Override
public boolean onLongClick(View v) {
return mOnMenuItemLongClickListener != null &&
mOnMenuItemLongClickListener.onToolbarMenuItemLongClick(v.getId());
mOnMenuItemLongClickListener.onToolbarMenuItemLongClick(v);
}

public void setMenuItemStatus(int id, boolean enabled) {
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/res/layout/editor_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
android:theme="@style/ToolBarStyle"
android:background="?attr/colorPrimary"
android:title="@string/app_name"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay">

<FrameLayout
android:id="@+id/toolbar_menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"/>
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</com.stardust.theme.widget.ThemeColorToolbar>

Expand All @@ -41,7 +42,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/file_path"
android:background="?attr/colorPrimary"
android:gravity="start"
android:paddingStart="10dp"
android:textColor="@android:color/white"
android:textSize="14sp"/>

<org.autojs.autojs.ui.edit.editor.CodeEditor
android:id="@+id/editor"
android:layout_width="match_parent"
Expand Down
Loading

0 comments on commit d28ae61

Please sign in to comment.