move 'record toast' to prefs

This commit is contained in:
hyb1996 2017-08-12 14:29:15 +08:00
parent 4129f83cb1
commit af752d5e4c
6 changed files with 33 additions and 11 deletions

View File

@ -124,4 +124,8 @@ public class Pref {
public static boolean isRecordWithRootEnabled() {
return def().getBoolean(getString(R.string.key_record_with_root), false);
}
public static boolean isRecordToastEnabled() {
return def().getBoolean(getString(R.string.key_record_toast), true);
}
}

View File

@ -14,11 +14,13 @@ import com.stardust.app.DialogUtils;
import com.stardust.autojs.core.inputevent.InputEventCodes;
import com.stardust.autojs.core.inputevent.ShellKeyObserver;
import com.stardust.autojs.core.record.Recorder;
import com.stardust.autojs.core.record.accessibility.AccessibilityActionRecorder;
import com.stardust.autojs.core.record.inputevent.TouchRecorder;
import com.stardust.autojs.runtime.api.Shell;
import com.stardust.scriptdroid.App;
import com.stardust.scriptdroid.Pref;
import com.stardust.scriptdroid.R;
import com.stardust.scriptdroid.accessibility.AccessibilityEventHelper;
import com.stardust.scriptdroid.autojs.AutoJs;
import com.stardust.scriptdroid.ui.common.ScriptOperations;
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
@ -26,6 +28,9 @@ import com.stardust.util.ClipboardUtil;
import com.stardust.view.accessibility.AccessibilityService;
import com.stardust.view.accessibility.OnKeyListener;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.concurrent.CopyOnWriteArrayList;
/**
@ -59,6 +64,7 @@ public class GlobalRecorder implements Recorder.OnStateChangedListener {
mContext = new ContextThemeWrapper(context.getApplicationContext(), R.style.AppTheme);
mTouchRecorder = new TouchRecorder(context);
addKeyListeners();
EventBus.getDefault().register(this);
}
private void addKeyListeners() {
@ -90,6 +96,9 @@ public class GlobalRecorder implements Recorder.OnStateChangedListener {
private void onVolumeDown() {
if (!Pref.isRecordVolumeControlEnable()) {
return;
}
if (System.currentTimeMillis() - mLastVolumeDownEventTime < 300) {
return;
}
@ -147,7 +156,8 @@ public class GlobalRecorder implements Recorder.OnStateChangedListener {
@Override
public void onStart() {
App.getApp().getUiHandler().toast(R.string.text_start_record);
if (Pref.isRecordToastEnabled())
App.getApp().getUiHandler().toast(R.string.text_start_record);
for (Recorder.OnStateChangedListener listener : mOnStateChangedListeners) {
listener.onStart();
}
@ -182,6 +192,13 @@ public class GlobalRecorder implements Recorder.OnStateChangedListener {
stop();
}
@Subscribe
public void onAccessibilityActionRecordEvent(AccessibilityActionRecorder.AccessibilityActionRecordEvent event) {
if (Pref.isRecordToastEnabled()) {
App.getApp().getUiHandler().toast(AccessibilityEventHelper.getEventTypeNameResId(event.getAccessibilityEvent()));
}
}
private void handleRecordedScript(final String script) {
if (Looper.myLooper() == Looper.getMainLooper()) {
showRecordHandleDialog(script);

View File

@ -55,7 +55,7 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
PrefSwitch mRecordedByRootSwitch;
@BindView(R.id.sw_record_toast)
SwitchCompat mRecordToastSwitch;
PrefSwitch mRecordToastSwitch;
@BindView(R.id.img_pause_or_resume)
ImageView mPauseOrResumeImage;
@ -163,13 +163,6 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
mRecorder.removeOnStateChangedListener(this);
}
@Subscribe
public void onAccessibilityActionRecordEvent(AccessibilityActionRecorder.AccessibilityActionRecordEvent event) {
if (mRecordToastSwitch.isChecked()) {
Toast.makeText(mContext, AccessibilityEventHelper.getEventTypeNameResId(event.getAccessibilityEvent()), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onStart() {
setState(Recorder.STATE_RECORDING);

View File

@ -62,13 +62,15 @@
android:gravity="center_vertical"
android:padding="16dp">
<android.support.v7.widget.SwitchCompat
<com.stardust.widget.PrefSwitch
android:id="@+id/sw_record_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textOff="@string/text_off"
android:textOn="@string/text_on"/>
android:textOn="@string/text_on"
app:defaultValue="true"
app:key="@string/key_record_toast"/>
<TextView
android:layout_width="wrap_content"

View File

@ -217,6 +217,7 @@
<string name="text_run_script">运行脚本</string>
<string name="text_import_script">导入脚本文件</string>
<string name="key_record_with_root">key_record_with_root</string>
<string name="key_record_toast">key_record_toast</string>
<string-array name="record_control_keys">

View File

@ -13,6 +13,11 @@
android:defaultValue="false"
android:key="@string/key_record_with_root"
android:title="@string/text_record_with_root"/>
<com.stardust.theme.preference.ThemeColorSwitchPreference
android:defaultValue="true"
android:key="@string/key_record_toast"
android:title="@string/text_record_msg"/>
</com.stardust.theme.preference.ThemeColorPreferenceCategory>
<com.stardust.theme.preference.ThemeColorPreferenceCategory android:title="@string/text_script_running">