fix: EditText of floaty window cannot request focus
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
var window = floaty.window(
|
var window = floaty.window(
|
||||||
<vertical>
|
<vertical>
|
||||||
<input id="input" text="请输入你的名字" textSize="16sp" />
|
<input id="input" text="请输入你的名字" textSize="16sp" focusable="true"/>
|
||||||
<button id="ok" text="确定"/>
|
<button id="ok" text="确定"/>
|
||||||
</vertical>
|
</vertical>
|
||||||
);
|
);
|
||||||
@@ -9,8 +9,21 @@ window.exitOnClose();
|
|||||||
|
|
||||||
toast("长按确定键可调整位置");
|
toast("长按确定键可调整位置");
|
||||||
|
|
||||||
|
window.input.on("key", function(keyCode, event){
|
||||||
|
if(event.getAction() == event.ACTION_DOWN && keyCode == keys.back){
|
||||||
|
window.disableFocus();
|
||||||
|
event.consumed = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.input.on("touch_down", ()=>{
|
||||||
|
window.requestFocus();
|
||||||
|
window.input.requestFocus();
|
||||||
|
});
|
||||||
|
|
||||||
window.ok.on("click", ()=>{
|
window.ok.on("click", ()=>{
|
||||||
toast("傻瓜! " + window.input.text());
|
toast("傻瓜! " + window.input.text());
|
||||||
|
window.disableFocus();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.ok.on("long_click", ()=>{
|
window.ok.on("long_click", ()=>{
|
||||||
|
|||||||
@@ -122,6 +122,9 @@ module.exports = function(__runtime__, scope){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
view.setOnTouchListener(function(v, event){
|
view.setOnTouchListener(function(v, event){
|
||||||
|
if(gestureDetector.onTouchEvent(event)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
event = wrapMotionEvent(event);
|
event = wrapMotionEvent(event);
|
||||||
event.consumed = false;
|
event.consumed = false;
|
||||||
scope.__exitIfError__(function(){
|
scope.__exitIfError__(function(){
|
||||||
@@ -140,6 +143,13 @@ module.exports = function(__runtime__, scope){
|
|||||||
view.setOnClickListener(function(v){
|
view.setOnClickListener(function(v){
|
||||||
view.emit("click", view);
|
view.emit("click", view);
|
||||||
});
|
});
|
||||||
|
view.setOnKeyListener(function(v, keyCode, event){
|
||||||
|
event = wrapMotionEvent(event);
|
||||||
|
scope.__exitIfError__(function(){
|
||||||
|
view.emit("key", keyCode, event, v);
|
||||||
|
});
|
||||||
|
return event.consumed;
|
||||||
|
});
|
||||||
if(typeof(view.setOnCheckedChangeListener) == 'function'){
|
if(typeof(view.setOnCheckedChangeListener) == 'function'){
|
||||||
view.setOnCheckedChangeListener(function(v, isChecked){
|
view.setOnCheckedChangeListener(function(v, isChecked){
|
||||||
view.emit("check", isChecked, view);
|
view.emit("check", isChecked, view);
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
package com.stardust.autojs.core.floaty;
|
package com.stardust.autojs.core.floaty;
|
||||||
|
|
||||||
|
import android.graphics.PixelFormat;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.view.Gravity;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import com.stardust.autojs.R;
|
import com.stardust.autojs.R;
|
||||||
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;
|
||||||
|
import com.stardust.enhancedfloaty.WindowBridge;
|
||||||
|
import com.stardust.enhancedfloaty.gesture.DragGesture;
|
||||||
|
import com.stardust.enhancedfloaty.gesture.ResizeGesture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/12/5.
|
* Created by Stardust on 2017/12/5.
|
||||||
@@ -19,17 +24,21 @@ import com.stardust.enhancedfloaty.ResizableFloatyWindow;
|
|||||||
public class FloatyWindow extends ResizableFloatyWindow {
|
public class FloatyWindow extends ResizableFloatyWindow {
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
private View mView;
|
|
||||||
private boolean mCreated = false;
|
private boolean mCreated = false;
|
||||||
private View mMoveCursor;
|
|
||||||
private View mResizer;
|
|
||||||
private View mCloseButton;
|
private View mCloseButton;
|
||||||
|
private static final String TAG = "ResizableFloatyWindow";
|
||||||
|
private WindowManager mWindowManager;
|
||||||
|
private WindowManager.LayoutParams mWindowLayoutParams;
|
||||||
|
private ViewGroup mWindowView;
|
||||||
|
private View mRootView;
|
||||||
|
private View mResizer;
|
||||||
|
private View mMoveCursor;
|
||||||
|
private WindowBridge mWindowBridge;
|
||||||
private MyFloaty mFloaty;
|
private MyFloaty mFloaty;
|
||||||
|
|
||||||
|
|
||||||
public FloatyWindow(View view) {
|
public FloatyWindow(View view) {
|
||||||
this(new MyFloaty(view));
|
this(new MyFloaty(view));
|
||||||
mView = view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FloatyWindow(MyFloaty floaty) {
|
private FloatyWindow(MyFloaty floaty) {
|
||||||
@@ -52,11 +61,15 @@ 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);
|
this.mWindowManager = manager;
|
||||||
View root = (View) mView.getParent().getParent();
|
this.mWindowLayoutParams = this.createWindowLayoutParams();
|
||||||
mMoveCursor = root.findViewById(R.id.move_cursor);
|
if (this.mFloaty == null) {
|
||||||
mResizer = root.findViewById(R.id.resizer);
|
throw new IllegalStateException("Must start this service by static method ResizableExpandableFloatyWindow.startService");
|
||||||
mCloseButton = root.findViewById(R.id.close);
|
} else {
|
||||||
|
this.initWindowView(service);
|
||||||
|
this.mWindowBridge = new WindowBridge.DefaultImpl(this.mWindowLayoutParams, this.mWindowManager, this.mWindowView);
|
||||||
|
this.initGesture();
|
||||||
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mCreated = true;
|
mCreated = true;
|
||||||
mLock.notify();
|
mLock.notify();
|
||||||
@@ -84,7 +97,66 @@ public class FloatyWindow extends ResizableFloatyWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public View getRootView() {
|
public View getRootView() {
|
||||||
return mFloaty.mRootView;
|
return mRootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initWindowView(FloatyService service) {
|
||||||
|
this.mWindowView = (ViewGroup) View.inflate(service, com.stardust.lib.R.layout.ef_floaty_container, (ViewGroup) null);
|
||||||
|
this.mRootView = this.mFloaty.inflateView(service, this);
|
||||||
|
this.mResizer = this.mFloaty.getResizerView(this.mRootView);
|
||||||
|
this.mMoveCursor = this.mFloaty.getMoveCursorView(this.mRootView);
|
||||||
|
this.mCloseButton = mRootView.findViewById(R.id.close);
|
||||||
|
android.view.ViewGroup.LayoutParams params = new android.view.ViewGroup.LayoutParams(-2, -2);
|
||||||
|
this.mWindowView.addView(this.mRootView, params);
|
||||||
|
this.mWindowView.setFocusableInTouchMode(true);
|
||||||
|
this.mWindowManager.addView(this.mWindowView, this.mWindowLayoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WindowManager.LayoutParams createWindowLayoutParams() {
|
||||||
|
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||||
|
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||||
|
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||||
|
WindowManager.LayoutParams.TYPE_PHONE,
|
||||||
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
||||||
|
PixelFormat.TRANSLUCENT);
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.START;
|
||||||
|
return layoutParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableWindowFocus() {
|
||||||
|
mWindowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||||
|
mWindowManager.updateViewLayout(mWindowView, mWindowLayoutParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestWindowFocus() {
|
||||||
|
mWindowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||||
|
mWindowManager.updateViewLayout(mWindowView, mWindowLayoutParams);
|
||||||
|
mWindowView.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initGesture() {
|
||||||
|
if (this.mResizer != null) {
|
||||||
|
ResizeGesture.enableResize(this.mResizer, this.mRootView, this.mWindowBridge);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.mMoveCursor != null) {
|
||||||
|
DragGesture gesture = new DragGesture(this.mWindowBridge, this.mMoveCursor);
|
||||||
|
gesture.setPressedAlpha(1.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowBridge getWindowBridge() {
|
||||||
|
return this.mWindowBridge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onServiceDestroy(FloatyService service) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
this.mWindowManager.removeView(this.mWindowView);
|
||||||
|
FloatyService.removeWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MyFloaty implements ResizableFloaty {
|
private static class MyFloaty implements ResizableFloaty {
|
||||||
|
|||||||
@@ -151,6 +151,14 @@ public class Floaty {
|
|||||||
mExitOnClose = true;
|
mExitOnClose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void requestFocus() {
|
||||||
|
mWindow.requestWindowFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableFocus() {
|
||||||
|
mWindow.disableWindowFocus();
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
close(true);
|
close(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user