修复 floaty.window悬浮窗位置不正确的问题

This commit is contained in:
hyb1996
2018-11-06 12:29:43 +08:00
parent 6b6fdd7ed9
commit f733ad75f1
4 changed files with 29 additions and 1 deletions

View File

@@ -37,10 +37,12 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
private VolatileDispose<RuntimeException> mInflateException = new VolatileDispose<>(); private VolatileDispose<RuntimeException> mInflateException = new VolatileDispose<>();
private View mCloseButton; private View mCloseButton;
private int mOffset;
public BaseResizableFloatyWindow(Context context, ViewSupplier viewSupplier) { public BaseResizableFloatyWindow(Context context, ViewSupplier viewSupplier) {
this(new MyFloaty(context, viewSupplier)); this(new MyFloaty(context, viewSupplier));
mOffset = context.getResources().getDimensionPixelSize(R.dimen.floaty_window_offset);
} }
private BaseResizableFloatyWindow(MyFloaty floaty) { private BaseResizableFloatyWindow(MyFloaty floaty) {
@@ -51,6 +53,26 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
return mInflateException.blockedGetOrThrow(ScriptInterruptedException.class); return mInflateException.blockedGetOrThrow(ScriptInterruptedException.class);
} }
@Override
protected WindowBridge onCreateWindowBridge(WindowManager.LayoutParams params) {
return new WindowBridge.DefaultImpl(params, getWindowManager(), getWindowView()) {
@Override
public int getX() {
return super.getX() + mOffset;
}
@Override
public int getY() {
return super.getY() + mOffset;
}
@Override
public void updatePosition(int x, int y) {
super.updatePosition(x - mOffset, y - mOffset);
}
};
}
@Override @Override
public void onCreate(FloatyService service, WindowManager manager) { public void onCreate(FloatyService service, WindowManager manager) {
try { try {
@@ -108,6 +130,7 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
private View mRootView; private View mRootView;
private Context mContext; private Context mContext;
public MyFloaty(Context context, ViewSupplier supplier) { public MyFloaty(Context context, ViewSupplier supplier) {
mContentViewSupplier = supplier; mContentViewSupplier = supplier;
mContext = context; mContext = context;

View File

@@ -18,6 +18,7 @@ import com.stardust.autojs.util.FloatingPermission;
import com.stardust.enhancedfloaty.FloatyService; 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 com.stardust.util.ViewUtils;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;

View File

@@ -9,7 +9,7 @@
android:id="@+id/container" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="12dp"> android:layout_margin="@dimen/floaty_window_offset">
</FrameLayout> </FrameLayout>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="floaty_window_offset">12dp</dimen>
</resources>