opt: floaty
This commit is contained in:
1 parent
d6c9fe4f09
commit
401b8cbad0
5 files changed
+48
-40
No files matched your search
@@ -32,6 +32,7 @@
|
|||||||
<!-- 代码补全 -->
|
<!-- 代码补全 -->
|
||||||
<link rel="stylesheet" href="codemirror/addon/hint/show-hint.css">
|
<link rel="stylesheet" href="codemirror/addon/hint/show-hint.css">
|
||||||
<script src="codemirror/addon/autojs/autojs-hint.js"></script>
|
<script src="codemirror/addon/autojs/autojs-hint.js"></script>
|
||||||
|
<script src="codemirror/addon/hint/anyword-hint.js"></script>
|
||||||
<script src="codemirror/addon/hint/show-hint.js"></script>
|
<script src="codemirror/addon/hint/show-hint.js"></script>
|
||||||
|
|
||||||
<!-- 代码格式化 -->
|
<!-- 代码格式化 -->
|
||||||
|
|||||||
+7
-1
@@ -6,7 +6,9 @@ import android.preference.PreferenceManager;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
|
||||||
|
import com.stardust.autojs.script.AutoFileSource;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
|
import com.stardust.scriptdroid.model.script.ScriptFile;
|
||||||
import com.stardust.scriptdroid.model.script.Scripts;
|
import com.stardust.scriptdroid.model.script.Scripts;
|
||||||
import com.stardust.scriptdroid.storage.file.StorageFileProvider;
|
import com.stardust.scriptdroid.storage.file.StorageFileProvider;
|
||||||
import com.stardust.scriptdroid.tool.SimpleObserver;
|
import com.stardust.scriptdroid.tool.SimpleObserver;
|
||||||
@@ -53,7 +55,11 @@ public class MyScriptListFragment extends ViewPagerFragment implements BackPress
|
|||||||
ScriptList.SortConfig sortConfig = ScriptList.SortConfig.from(PreferenceManager.getDefaultSharedPreferences(getContext()));
|
ScriptList.SortConfig sortConfig = ScriptList.SortConfig.from(PreferenceManager.getDefaultSharedPreferences(getContext()));
|
||||||
mScriptFileList.setSortConfig(sortConfig);
|
mScriptFileList.setSortConfig(sortConfig);
|
||||||
mScriptFileList.setStorageFileProvider(StorageFileProvider.getDefault());
|
mScriptFileList.setStorageFileProvider(StorageFileProvider.getDefault());
|
||||||
mScriptFileList.setOnScriptFileClickListener((view, file) -> Scripts.edit(file));
|
mScriptFileList.setOnScriptFileClickListener((view, file) -> {
|
||||||
|
if (file.getType() == ScriptFile.TYPE_JAVA_SCRIPT) {
|
||||||
|
Scripts.edit(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.stardust.autojs.core.floaty;
|
package com.stardust.autojs.core.floaty;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import com.stardust.autojs.R;
|
import com.stardust.autojs.R;
|
||||||
import com.stardust.autojs.runtime.api.Floaty;
|
|
||||||
import com.stardust.enhancedfloaty.FloatyService;
|
import com.stardust.enhancedfloaty.FloatyService;
|
||||||
import com.stardust.enhancedfloaty.ResizableFloaty;
|
import com.stardust.enhancedfloaty.ResizableFloaty;
|
||||||
import com.stardust.enhancedfloaty.ResizableFloatyWindow;
|
import com.stardust.enhancedfloaty.ResizableFloatyWindow;
|
||||||
@@ -18,7 +16,7 @@ import com.stardust.enhancedfloaty.ResizableFloatyWindow;
|
|||||||
|
|
||||||
public class FloatyWindow extends ResizableFloatyWindow {
|
public class FloatyWindow extends ResizableFloatyWindow {
|
||||||
|
|
||||||
private static final Object LOCK = new Object();
|
private final Object mLock = new Object();
|
||||||
private View mView;
|
private View mView;
|
||||||
private boolean mCreated = false;
|
private boolean mCreated = false;
|
||||||
private View mMoveCursor;
|
private View mMoveCursor;
|
||||||
@@ -38,12 +36,12 @@ public class FloatyWindow extends ResizableFloatyWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void waitFor() {
|
public void waitFor() {
|
||||||
synchronized (LOCK) {
|
synchronized (mLock) {
|
||||||
if (mCreated) {
|
if (mCreated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
LOCK.wait();
|
mLock.wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -53,17 +51,17 @@ public class FloatyWindow extends ResizableFloatyWindow {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(FloatyService service, WindowManager manager) {
|
public void onCreate(FloatyService service, WindowManager manager) {
|
||||||
super.onCreate(service, manager);
|
super.onCreate(service, manager);
|
||||||
synchronized (LOCK) {
|
|
||||||
mCreated = true;
|
|
||||||
LOCK.notify();
|
|
||||||
}
|
|
||||||
View root = (View) mView.getParent().getParent();
|
View root = (View) mView.getParent().getParent();
|
||||||
mMoveCursor = root.findViewById(R.id.move_cursor);
|
mMoveCursor = root.findViewById(R.id.move_cursor);
|
||||||
mResizer = root.findViewById(R.id.resizer);
|
mResizer = root.findViewById(R.id.resizer);
|
||||||
mCloseButton = root.findViewById(R.id.close);
|
mCloseButton = root.findViewById(R.id.close);
|
||||||
|
synchronized (mLock) {
|
||||||
|
mCreated = true;
|
||||||
|
mLock.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnCloseButtonClickListener(View.OnClickListener listener){
|
public void setOnCloseButtonClickListener(View.OnClickListener listener) {
|
||||||
mCloseButton.setOnClickListener(listener);
|
mCloseButton.setOnClickListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ import com.stardust.enhancedfloaty.FloatyService;
|
|||||||
import com.stardust.util.UiHandler;
|
import com.stardust.util.UiHandler;
|
||||||
import com.stardust.util.ViewUtil;
|
import com.stardust.util.ViewUtil;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +29,7 @@ public class Floaty {
|
|||||||
private JsLayoutInflater mJsLayoutInflater;
|
private JsLayoutInflater mJsLayoutInflater;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private UiHandler mUiHandler;
|
private UiHandler mUiHandler;
|
||||||
private Set<JsFloatyWindow> mWindows = new CopyOnWriteArraySet<>();
|
private CopyOnWriteArraySet<JsFloatyWindow> mWindows = new CopyOnWriteArraySet<>();
|
||||||
private ScriptRuntime mRuntime;
|
private ScriptRuntime mRuntime;
|
||||||
|
|
||||||
public Floaty(UiHandler uiHandler, UI ui, ScriptRuntime runtime) {
|
public Floaty(UiHandler uiHandler, UI ui, ScriptRuntime runtime) {
|
||||||
@@ -73,7 +71,7 @@ public class Floaty {
|
|||||||
public class JsFloatyWindow {
|
public class JsFloatyWindow {
|
||||||
|
|
||||||
private View mView;
|
private View mView;
|
||||||
private FloatyWindow mWindow;
|
private volatile FloatyWindow mWindow;
|
||||||
private boolean mExitOnClose = false;
|
private boolean mExitOnClose = false;
|
||||||
|
|
||||||
public JsFloatyWindow(View view) {
|
public JsFloatyWindow(View view) {
|
||||||
@@ -109,31 +107,29 @@ public class Floaty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(int w, int h) {
|
public void setSize(int w, int h) {
|
||||||
|
runWithWindow(() -> ViewUtil.setViewMeasure(mWindow.getRootView(), w, h));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runWithWindow(Runnable r) {
|
||||||
|
if (mWindow == null)
|
||||||
|
return;
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
ViewUtil.setViewMeasure(mWindow.getRootView(), w, h);
|
r.run();
|
||||||
// mWindow.getWindowBridge().updateMeasure(w, h);
|
return;
|
||||||
} else {
|
|
||||||
mUiHandler.post(() -> {
|
|
||||||
ViewUtil.setViewMeasure(mWindow.getRootView(), w, h);
|
|
||||||
// mWindow.getWindowBridge().updateMeasure(w, h);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
mUiHandler.post(() -> {
|
||||||
|
if (mWindow == null)
|
||||||
|
return;
|
||||||
|
r.run();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(int x, int y) {
|
public void setPosition(int x, int y) {
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
runWithWindow(() -> mWindow.getWindowBridge().updatePosition(x, y));
|
||||||
mWindow.getWindowBridge().updatePosition(x, y);
|
|
||||||
} else {
|
|
||||||
mUiHandler.post(() -> mWindow.getWindowBridge().updatePosition(x, y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdjustEnabled(boolean enabled) {
|
public void setAdjustEnabled(boolean enabled) {
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
runWithWindow(() -> mWindow.setAdjustEnabled(enabled));
|
||||||
mWindow.setAdjustEnabled(enabled);
|
|
||||||
} else {
|
|
||||||
mUiHandler.post(() -> mWindow.setAdjustEnabled(enabled));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdjustEnabled() {
|
public boolean isAdjustEnabled() {
|
||||||
@@ -145,17 +141,16 @@ public class Floaty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (!mWindows.remove(this)) {
|
if (mWindow == null || !mWindows.remove(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
runWithWindow(() -> {
|
||||||
mWindow.close();
|
mWindow.close();
|
||||||
} else {
|
mWindow = null;
|
||||||
mUiHandler.post(() -> mWindow.close());
|
if (mExitOnClose) {
|
||||||
}
|
mRuntime.exit();
|
||||||
if (mExitOnClose) {
|
}
|
||||||
mRuntime.exit();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,6 +144,14 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
|||||||
return t == null ? "" : t.toString();
|
return t == null ? "" : t.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getText() {
|
||||||
|
if (isPassword()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return super.getText();
|
||||||
|
}
|
||||||
|
|
||||||
public String desc() {
|
public String desc() {
|
||||||
CharSequence d = getContentDescription();
|
CharSequence d = getContentDescription();
|
||||||
return d == null ? null : d.toString();
|
return d == null ? null : d.toString();
|
||||||
|
|||||||
Reference in new issue
Block a user