fix crash caused by recorded script too large
This commit is contained in:
@@ -83,10 +83,6 @@ public class App extends MultiDexApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getResString(int id) {
|
|
||||||
return getApp().getString(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VolumeChangeObserver getVolumeChangeObserver() {
|
public VolumeChangeObserver getVolumeChangeObserver() {
|
||||||
return mVolumeChangeObserver;
|
return mVolumeChangeObserver;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,15 +51,17 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
|||||||
@BindView(R.id.text_start_or_pause)
|
@BindView(R.id.text_start_or_pause)
|
||||||
TextView mStartOrPauseRecordText;
|
TextView mStartOrPauseRecordText;
|
||||||
|
|
||||||
|
|
||||||
@BindView(R.id.stop_record)
|
@BindView(R.id.stop_record)
|
||||||
View mStopRecord;
|
View mStopRecord;
|
||||||
|
|
||||||
|
@BindView(R.id.discard_record)
|
||||||
|
View mDiscardRecord;
|
||||||
|
|
||||||
|
|
||||||
private Recorder mRecorder;
|
private Recorder mRecorder;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private boolean mDiscard = false;
|
||||||
private KeyObserver mKeyObserver;
|
private KeyObserver mKeyObserver;
|
||||||
|
|
||||||
private VolumeChangeObserver.OnVolumeChangeListener mOnVolumeChangeListener = new VolumeChangeObserver.OnVolumeChangeListener() {
|
private VolumeChangeObserver.OnVolumeChangeListener mOnVolumeChangeListener = new VolumeChangeObserver.OnVolumeChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVolumeChange() {
|
public void onVolumeChange() {
|
||||||
@@ -123,6 +125,12 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.discard_record)
|
||||||
|
void discardRecord() {
|
||||||
|
mDiscard = true;
|
||||||
|
stopRecord();
|
||||||
|
}
|
||||||
|
|
||||||
private void resumeRecord() {
|
private void resumeRecord() {
|
||||||
mRecorder.resume();
|
mRecorder.resume();
|
||||||
setState(Recorder.STATE_RECORDING);
|
setState(Recorder.STATE_RECORDING);
|
||||||
@@ -135,6 +143,7 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startRecord() {
|
private void startRecord() {
|
||||||
|
mDiscard = false;
|
||||||
mRecorder = mRecordedByRootSwitch.isChecked() ? new TouchRecorder(mContext) : AutoJs.getInstance().getAccessibilityActionRecorder();
|
mRecorder = mRecordedByRootSwitch.isChecked() ? new TouchRecorder(mContext) : AutoJs.getInstance().getAccessibilityActionRecorder();
|
||||||
mRecorder.setOnStateChangedListener(this);
|
mRecorder.setOnStateChangedListener(this);
|
||||||
mRecorder.start();
|
mRecorder.start();
|
||||||
@@ -191,7 +200,9 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
MainActivity.onRecordStop(mContext, mRecorder.getCode());
|
if (!mDiscard) {
|
||||||
|
MainActivity.onRecordStop(mContext, mRecorder.getCode());
|
||||||
|
}
|
||||||
mRecorder = null;
|
mRecorder = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import com.stardust.scriptdroid.script.ScriptFile;
|
|||||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||||
import com.stardust.scriptdroid.script.sample.Sample;
|
import com.stardust.scriptdroid.script.sample.Sample;
|
||||||
import com.stardust.scriptdroid.ui.main.task.TaskManagerFragment_;
|
import com.stardust.scriptdroid.ui.main.task.TaskManagerFragment_;
|
||||||
|
import com.stardust.util.IntentExtras;
|
||||||
import com.stardust.view.accessibility.AccessibilityService;
|
import com.stardust.view.accessibility.AccessibilityService;
|
||||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||||
import com.stardust.scriptdroid.tool.DrawableSaver;
|
import com.stardust.scriptdroid.tool.DrawableSaver;
|
||||||
@@ -306,7 +307,10 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
return;
|
return;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_ON_ACTION_RECORD_STOPPED:
|
case ACTION_ON_ACTION_RECORD_STOPPED:
|
||||||
handleRecordedScript(intent.getStringExtra(ARGUMENT_SCRIPT));
|
IntentExtras extras = IntentExtras.fromIntent(intent);
|
||||||
|
String script = extras.get(ARGUMENT_SCRIPT);
|
||||||
|
extras.clear();
|
||||||
|
handleRecordedScript(script);
|
||||||
break;
|
break;
|
||||||
case ACTION_IMPORT_SCRIPT:
|
case ACTION_IMPORT_SCRIPT:
|
||||||
handleImportScriptFile(intent);
|
handleImportScriptFile(intent);
|
||||||
@@ -442,6 +446,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
StorageScriptProvider.getDefault().notifyStoragePermissionGranted();
|
StorageScriptProvider.getDefault().notifyStoragePermissionGranted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,8 +461,10 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
public static void onRecordStop(Context context, String script) {
|
public static void onRecordStop(Context context, String script) {
|
||||||
Intent intent = new Intent(context, MainActivity_.class)
|
Intent intent = new Intent(context, MainActivity_.class)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
.putExtra(EXTRA_ACTION, ACTION_ON_ACTION_RECORD_STOPPED)
|
.putExtra(EXTRA_ACTION, ACTION_ON_ACTION_RECORD_STOPPED);
|
||||||
.putExtra(ARGUMENT_SCRIPT, script);
|
IntentExtras.newExtras()
|
||||||
|
.put(ARGUMENT_SCRIPT, script)
|
||||||
|
.putInIntent(intent);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
app/src/main/res/drawable/discard.png
Normal file
BIN
app/src/main/res/drawable/discard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 901 B |
@@ -148,6 +148,37 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="#c4c4c4"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/discard_record"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:src="@drawable/discard"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/text_stop_record"
|
||||||
|
android:textColor="@android:color/primary_text_dark"
|
||||||
|
android:textSize="16sp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
|
|||||||
69
common/src/main/java/com/stardust/util/IntentExtras.java
Normal file
69
common/src/main/java/com/stardust/util/IntentExtras.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package com.stardust.util;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Stardust on 2017/7/11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class IntentExtras implements Serializable {
|
||||||
|
|
||||||
|
private static int mMaxId = -1;
|
||||||
|
private static final String EXTRA_ID = "com.stardust.util.IntentExtras.id";
|
||||||
|
private static SparseArray<Map<String, Object>> extraStore = new SparseArray<>();
|
||||||
|
|
||||||
|
|
||||||
|
public static IntentExtras newExtras() {
|
||||||
|
return new IntentExtras();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntentExtras fromIntent(Intent intent) {
|
||||||
|
int id = intent.getIntExtra(EXTRA_ID, -1);
|
||||||
|
if (id < 0) {
|
||||||
|
throw new IllegalArgumentException("");
|
||||||
|
}
|
||||||
|
return new IntentExtras(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> mMap;
|
||||||
|
private int mId;
|
||||||
|
|
||||||
|
private IntentExtras() {
|
||||||
|
mMap = new HashMap<>();
|
||||||
|
mMaxId++;
|
||||||
|
mId = mMaxId;
|
||||||
|
extraStore.put(mId, mMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private IntentExtras(int id) {
|
||||||
|
mMap = extraStore.get(id);
|
||||||
|
mMaxId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T get(String key) {
|
||||||
|
return (T) mMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntentExtras put(String key, Object value) {
|
||||||
|
mMap.put(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Intent putInIntent(Intent intent) {
|
||||||
|
intent.putExtra(EXTRA_ID, mMaxId);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
extraStore.remove(mId);
|
||||||
|
mMap = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user