Change the way of action pefrom(no longer wait for event), add loading jar file support, fix simple action memory leak
This commit is contained in:
@@ -14,6 +14,8 @@ import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/14.
|
||||
@@ -25,45 +27,10 @@ public class AccessibilityWatchDogService extends AccessibilityService {
|
||||
|
||||
private static final SortedMap<Integer, AccessibilityDelegate> mDelegates = new TreeMap<>();
|
||||
private static WeakReference<AccessibilityWatchDogService> instance;
|
||||
private Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
public static void addDelegate(AccessibilityDelegate delegate, int uniquePriority) {
|
||||
synchronized (mDelegates) {
|
||||
mDelegates.put(uniquePriority, delegate);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean containsPriority(int priority) {
|
||||
synchronized (mDelegates) {
|
||||
return mDelegates.containsKey(priority);
|
||||
}
|
||||
}
|
||||
|
||||
public static AccessibilityDelegate getDelegate(int priority) {
|
||||
synchronized (mDelegates) {
|
||||
return mDelegates.get(priority);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDelegateIfNeeded(int priority, Class<? extends AccessibilityDelegate> delegateClass) {
|
||||
try {
|
||||
addDelegateIfNeeded(priority, delegateClass.newInstance());
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDelegateIfNeeded(int priority, AccessibilityDelegate delegate) {
|
||||
synchronized (mDelegates) {
|
||||
if (!mDelegates.containsKey(priority)) {
|
||||
mDelegates.put(priority, delegate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean removeDelegate(int priority) {
|
||||
synchronized (mDelegates) {
|
||||
return mDelegates.remove(priority) != null;
|
||||
}
|
||||
public static void addDelegate(int uniquePriority, AccessibilityDelegate delegate) {
|
||||
mDelegates.put(uniquePriority, delegate);
|
||||
}
|
||||
|
||||
public static boolean isEnable() {
|
||||
@@ -77,15 +44,18 @@ public class AccessibilityWatchDogService extends AccessibilityService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccessibilityEvent(AccessibilityEvent event) {
|
||||
public void onAccessibilityEvent(final AccessibilityEvent event) {
|
||||
Log.v(TAG, "onAccessibilityEvent: " + event);
|
||||
synchronized (mDelegates) {
|
||||
for (Map.Entry<Integer, AccessibilityDelegate> entry : mDelegates.entrySet()) {
|
||||
//Log.v(TAG, "delegate: " + entry.getValue().getClass().getName());
|
||||
if (entry.getValue().onAccessibilityEvent(this, event))
|
||||
break;
|
||||
mExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Map.Entry<Integer, AccessibilityDelegate> entry : mDelegates.entrySet()) {
|
||||
Log.v(TAG, "delegate: " + entry.getValue().getClass().getName());
|
||||
if (entry.getValue().onAccessibilityEvent(AccessibilityWatchDogService.this, event))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.stardust.scriptdroid.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
||||
import com.stardust.scriptdroid.record.Recorder;
|
||||
import com.stardust.scriptdroid.record.accessibility.AccessibilityActionRecorder;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/16.
|
||||
*/
|
||||
|
||||
public class VolumeChangeObverseService extends Service {
|
||||
|
||||
public interface OnVolumeChangeListener {
|
||||
|
||||
void onVolumeChange();
|
||||
}
|
||||
|
||||
private static final String ACTION_VOLUME_CHANGE = "android.media.VOLUME_CHANGED_ACTION";
|
||||
private static List<OnVolumeChangeListener> mOnVolumeChangeListenerList = new ArrayList<>();
|
||||
|
||||
public static void addOnVolumeChangeListener(OnVolumeChangeListener listener) {
|
||||
mOnVolumeChangeListenerList.add(listener);
|
||||
}
|
||||
|
||||
public static void removeOnVolumeChangeListener(OnVolumeChangeListener listener) {
|
||||
mOnVolumeChangeListenerList.remove(listener);
|
||||
}
|
||||
|
||||
private VolumeChangeReceiver mVolumeChangeReceiver;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mVolumeChangeReceiver = new VolumeChangeReceiver();
|
||||
registerReceiver(mVolumeChangeReceiver, new IntentFilter(ACTION_VOLUME_CHANGE));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mVolumeChangeReceiver);
|
||||
}
|
||||
|
||||
private class VolumeChangeReceiver extends BroadcastReceiver {
|
||||
|
||||
private long mLastChangeMillis;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ACTION_VOLUME_CHANGE)) {
|
||||
if (System.currentTimeMillis() - mLastChangeMillis < 400) {
|
||||
return;
|
||||
}
|
||||
mLastChangeMillis = System.currentTimeMillis();
|
||||
for (OnVolumeChangeListener listener : mOnVolumeChangeListenerList) {
|
||||
listener.onVolumeChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user