Skip to content

Commit

Permalink
优化 编辑文件的多任务体验
Browse files Browse the repository at this point in the history
  • Loading branch information
hyb1996 committed Jan 23, 2019
1 parent ce54478 commit 3fecfa9
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 37 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_SedTORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
Expand Down Expand Up @@ -84,6 +84,7 @@
<activity
android:name=".ui.edit.EditActivity_"
android:configChanges="orientation|screenSize"
android:launchMode="standard"
android:multiprocess="true"
android:taskAffinity="org.autojs.autojs.edit"
android:theme="@style/EditorTheme">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;

import androidx.annotation.Nullable;

import android.text.TextUtils;
import android.widget.Toast;

Expand Down Expand Up @@ -56,9 +58,9 @@ private void handleIntent() {
}
}
if (!TextUtils.isEmpty(path)) {
EditActivity.editFile(this, path);
EditActivity.editFile(this, path, false);
} else {
EditActivity.editFile(this, uri);
EditActivity.editFile(this, uri, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ object Scripts {


fun edit(context: Context, file: ScriptFile) {
EditActivity.editFile(context, file.simplifiedName, file.path)
EditActivity.editFile(context, file.simplifiedName, file.path, true)
}

fun edit(context: Context, path: String) {
Expand Down
48 changes: 28 additions & 20 deletions app/src/main/java/org/autojs/autojs/ui/edit/EditActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.autojs.autojs.ui.edit;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -31,6 +32,7 @@
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.autojs.autojs.ui.main.MainActivity_;

import java.io.File;
import java.io.IOException;
Expand All @@ -56,35 +58,46 @@ public class EditActivity extends BaseActivity implements OnActivityResultDelega
@ViewById(R.id.editor_view)
EditorView mEditorView;


private EditorMenu mEditorMenu;
private RequestPermissionCallbacks mRequestPermissionCallbacks = new RequestPermissionCallbacks();
private boolean mNewTask;

public static void editFile(Context context, String path) {
editFile(context, null, path);
public static void editFile(Context context, String path, boolean newTask) {
editFile(context, null, path, newTask);
}

public static void editFile(Context context, Uri uri) {
context.startActivity(new Intent(context, EditActivity_.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
public static void editFile(Context context, Uri uri, boolean newTask) {
context.startActivity(newIntent(context, newTask)
.setData(uri));
}

public static void editFile(Context context, String name, String path) {
context.startActivity(new Intent(context, EditActivity_.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
public static void editFile(Context context, String name, String path, boolean newTask) {
context.startActivity(newIntent(context, newTask)
.putExtra(EXTRA_PATH, path)
.putExtra(EXTRA_NAME, name));
}

public static void viewContent(Context context, String name, String content) {
context.startActivity(new Intent(context, EditActivity_.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
public static void viewContent(Context context, String name, String content, boolean newTask) {
context.startActivity(newIntent(context, newTask)
.putExtra(EXTRA_CONTENT, content)
.putExtra(EXTRA_NAME, name)
.putExtra(EXTRA_READ_ONLY, true));
}

private static Intent newIntent(Context context, boolean newTask) {
Intent intent = new Intent(context, EditActivity_.class);
if (newTask || !(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
return intent;
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNewTask = (getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0;
}

@SuppressLint("CheckResult")
@AfterViews
void setUpViews() {
Expand Down Expand Up @@ -142,14 +155,6 @@ public boolean onPrepareOptionsMenu(Menu menu) {
return super.onPrepareOptionsMenu(menu);
}

public boolean onPrepareActionMode(Menu menu) {
Log.d(LOG_TAG, "onPrepareActionMode: " + menu);
boolean isScriptRunning = mEditorView.getScriptExecutionId() != ScriptExecution.NO_ID;
MenuItem forceStopItem = menu.findItem(R.id.action_force_stop);
forceStopItem.setEnabled(isScriptRunning);
return super.onPrepareOptionsMenu(menu);
}

@Override
public void onActionModeStarted(ActionMode mode) {
Log.d(LOG_TAG, "onActionModeStarted: " + mode);
Expand Down Expand Up @@ -207,6 +212,9 @@ private void finishAndRemoveFromRecents() {
} else {
finish();
}
if (mNewTask) {
startActivity(new Intent(this, MainActivity_.class));
}
}

private void showExitConfirmDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;

import android.util.SparseArray;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -15,13 +18,16 @@
import com.stardust.app.OnActivityResultDelegate;
import com.stardust.autojs.engine.JavaScriptEngine;
import com.stardust.autojs.execution.ScriptExecution;

import org.autojs.autojs.R;
import org.autojs.autojs.autojs.AutoJs;
import org.autojs.autojs.model.sample.SampleFile;
import org.autojs.autojs.ui.BaseActivity;
import org.autojs.autojs.ui.common.ScriptOperations;

import com.stardust.theme.ThemeColorManager;
import com.stardust.util.SparseArrayEntries;

import org.autojs.autojs.ui.widget.ToolbarMenuItem;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -99,12 +105,9 @@ void edit() {
new ScriptOperations(this, mView)
.importSample(mSample)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<String>() {
@Override
public void accept(@NonNull String path) throws Exception {
EditActivity.editFile(ViewSampleActivity.this, path);
finish();
}
.subscribe(path -> {
EditActivity.editFile(ViewSampleActivity.this, path, false);
finish();
});
}

Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/org/autojs/autojs/ui/main/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import androidx.core.view.GravityCompat;
Expand Down Expand Up @@ -65,7 +67,6 @@
@EActivity(R.layout.activity_main)
public class MainActivity extends BaseActivity implements OnActivityResultDelegate.DelegateHost, BackPressedHandler.HostActivity, PermissionRequestProxyActivity {


public static class DrawerOpenEvent {
static DrawerOpenEvent SINGLETON = new DrawerOpenEvent();
}
Expand Down Expand Up @@ -138,7 +139,7 @@ private void registerBackPressHandlers() {
}

private void checkPermissions() {
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

private void showAccessibilitySettingPromptIfDisabled() {
Expand Down Expand Up @@ -180,8 +181,6 @@ private void setUpTabViewPager() {
}

private void setUpViewPagerFragmentBehaviors() {


mPagerAdapter.setOnFragmentInstantiateListener((pos, fragment) -> {
((ViewPagerFragment) fragment).setFab(mFab);
if (pos == mViewPager.getCurrentItem()) {
Expand Down
1 change: 1 addition & 0 deletions autojs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>

<application
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ScriptCanvasView(context: Context, private val mScriptRuntime: ScriptRunti
while (mDrawing) {
canvas = lockCanvas()
scriptCanvas.setCanvas(canvas)
// scriptCanvas.drawColor(Color.WHITE);
emit("draw", scriptCanvas, this@ScriptCanvasView)
unlockCanvasAndPost(canvas)
canvas = null
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions project-versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"appVersionCode": 455,
"appVersionName": "4.1.0 Alpha5",
"appVersionCode": 460,
"appVersionName": "4.1.1 Alpha",
"target": 28,
"mini": 17,
"compile": 28,
Expand Down

0 comments on commit 3fecfa9

Please sign in to comment.