Added getTexts and action recorder, fixed github issue report token
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.stardust.scriptdroid.bounds_assist;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/4.
|
||||
*/
|
||||
|
||||
public interface BoundsAssistClipList {
|
||||
|
||||
interface OnClipChangedListener {
|
||||
void onClipRemove(int position);
|
||||
|
||||
void onClipInsert(int position);
|
||||
|
||||
void onChange();
|
||||
}
|
||||
|
||||
int size();
|
||||
|
||||
String get(int i);
|
||||
|
||||
void add(String clip);
|
||||
|
||||
void setOnClipChangedListener(OnClipChangedListener listener);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.stardust.scriptdroid.bounds_assist;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/4.
|
||||
*/
|
||||
|
||||
public class BoundsAssistant {
|
||||
public static final String KEY_BOUNDS_ASSIST_ENABLE = "ASSIST_MODE_ENABLE";
|
||||
|
||||
|
||||
private static boolean assistModeEnable;
|
||||
private static BoundsAssistClipList boundsAssistClipList = SharedPrefBoundsAssistClipList.getInstance();
|
||||
|
||||
public static boolean isAssistModeEnable() {
|
||||
return assistModeEnable;
|
||||
}
|
||||
|
||||
public static void setAssistModeEnable(boolean assistModeEnable) {
|
||||
if (assistModeEnable && Pref.isFirstEnableAssistMode()) {
|
||||
showAssistModeInfoDialog();
|
||||
}
|
||||
BoundsAssistant.assistModeEnable = assistModeEnable;
|
||||
App.getStateObserver().setState(KEY_BOUNDS_ASSIST_ENABLE, assistModeEnable);
|
||||
}
|
||||
|
||||
private static void showAssistModeInfoDialog() {
|
||||
new MaterialDialog.Builder(App.currentActivity())
|
||||
.title(R.string.text_alert)
|
||||
.content(R.string.assist_mode_notice)
|
||||
.positiveText(R.string.ok)
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void performAssistance(AccessibilityEvent event) {
|
||||
if (!assistModeEnable) {
|
||||
return;
|
||||
}
|
||||
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED || event.getEventType() == AccessibilityEvent.TYPE_VIEW_LONG_CLICKED) {
|
||||
AccessibilityNodeInfo nodeInfo = event.getSource();
|
||||
if (nodeInfo == null) {
|
||||
return;
|
||||
}
|
||||
nodeInfo.refresh();
|
||||
Rect rect = getBoundsInScreen(nodeInfo);
|
||||
saveAndAlertBounds(rect);
|
||||
nodeInfo.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect getBoundsInScreen(AccessibilityNodeInfo nodeInfo) {
|
||||
Rect rect = new Rect();
|
||||
nodeInfo.getBoundsInScreen(rect);
|
||||
return rect;
|
||||
}
|
||||
|
||||
private static void saveAndAlertBounds(Rect rect) {
|
||||
String str = boundsToString(rect);
|
||||
boundsAssistClipList.add(str);
|
||||
Toast.makeText(App.getApp(), str, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public static String boundsToString(Rect rect) {
|
||||
return rect.toString().replace('-', ',').replace(" ", "").substring(4);
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
assistModeEnable = PreferenceManager.getDefaultSharedPreferences(App.getApp()).getBoolean(KEY_BOUNDS_ASSIST_ENABLE, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.stardust.scriptdroid.bounds_assist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.stardust.scriptdroid.App;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/4.
|
||||
*/
|
||||
|
||||
public class SharedPrefBoundsAssistClipList implements BoundsAssistClipList {
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
|
||||
private static SharedPrefBoundsAssistClipList instance = new SharedPrefBoundsAssistClipList(App.getApp());
|
||||
private OnClipChangedListener mOnClipChangedListener;
|
||||
|
||||
public static SharedPrefBoundsAssistClipList getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static final int MAX_SIZE = 10;
|
||||
private static final String SHARED_PREF_NAME = "SharedPrefBoundsAssistClipList";
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private List<String> mAssistClipList = new LinkedList<>();
|
||||
|
||||
public SharedPrefBoundsAssistClipList(Context context) {
|
||||
mSharedPreferences = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
|
||||
readFromSharedPref();
|
||||
}
|
||||
|
||||
private void readFromSharedPref() {
|
||||
Type type = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
List<String> l = GSON.fromJson(mSharedPreferences.getString(SHARED_PREF_NAME, ""), type);
|
||||
if (l != null)
|
||||
mAssistClipList.addAll(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int size() {
|
||||
return mAssistClipList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String get(int i) {
|
||||
return mAssistClipList.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void add(String clip) {
|
||||
mAssistClipList.add(0, clip);
|
||||
notifyInsert();
|
||||
if (mAssistClipList.size() > MAX_SIZE) {
|
||||
mAssistClipList.remove(mAssistClipList.size() - 1);
|
||||
notifyRemove();
|
||||
}
|
||||
syncWithSharedPref();
|
||||
}
|
||||
|
||||
private void notifyRemove() {
|
||||
if (mOnClipChangedListener != null)
|
||||
mOnClipChangedListener.onClipRemove(mAssistClipList.size());
|
||||
}
|
||||
|
||||
private void notifyInsert() {
|
||||
if (mOnClipChangedListener != null) {
|
||||
mOnClipChangedListener.onClipInsert(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClipChangedListener(OnClipChangedListener listener) {
|
||||
mOnClipChangedListener = listener;
|
||||
}
|
||||
|
||||
private void syncWithSharedPref() {
|
||||
mSharedPreferences.edit().putString(SHARED_PREF_NAME, GSON.toJson(mAssistClipList)).apply();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user