fix: floating window cannot show
This commit is contained in:
@@ -46,7 +46,7 @@ dependencies {
|
||||
exclude group: 'com.android.support'
|
||||
})
|
||||
api 'com.android.support:design:28.0.0'
|
||||
api 'com.github.hyb1996:EnhancedFloaty:0.21'
|
||||
api 'com.github.hyb1996:EnhancedFloaty:0.31'
|
||||
api 'com.github.hyb1996:OpenCvLib:2.4.13.4-imgproc'
|
||||
api 'com.makeramen:roundedimageview:2.3.0'
|
||||
// OkHttp
|
||||
|
||||
@@ -37,15 +37,6 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
|
||||
|
||||
private VolatileDispose<RuntimeException> mInflateException = new VolatileDispose<>();
|
||||
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;
|
||||
|
||||
|
||||
public BaseResizableFloatyWindow(Context context, ViewSupplier viewSupplier) {
|
||||
@@ -54,7 +45,6 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
|
||||
|
||||
private BaseResizableFloatyWindow(MyFloaty floaty) {
|
||||
super(floaty);
|
||||
mFloaty = floaty;
|
||||
}
|
||||
|
||||
public RuntimeException waitForCreation() {
|
||||
@@ -63,19 +53,11 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
|
||||
|
||||
@Override
|
||||
public void onCreate(FloatyService service, WindowManager manager) {
|
||||
this.mWindowManager = manager;
|
||||
this.mWindowLayoutParams = this.createWindowLayoutParams();
|
||||
if (this.mFloaty == null) {
|
||||
throw new IllegalStateException("Must start this service by static method ResizableExpandableFloatyWindow.startService");
|
||||
} else {
|
||||
try {
|
||||
this.initWindowView(service);
|
||||
} catch (RuntimeException e) {
|
||||
mInflateException.setAndNotify(e);
|
||||
return;
|
||||
}
|
||||
this.mWindowBridge = new WindowBridge.DefaultImpl(this.mWindowLayoutParams, this.mWindowManager, this.mWindowView);
|
||||
this.initGesture();
|
||||
try {
|
||||
super.onCreate(service, manager);
|
||||
} catch (RuntimeException e) {
|
||||
mInflateException.setAndNotify(e);
|
||||
return;
|
||||
}
|
||||
mInflateException.setAndNotify(Exceptions.NO_EXCEPTION);
|
||||
}
|
||||
@@ -86,88 +68,37 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
|
||||
|
||||
public void setAdjustEnabled(boolean enabled) {
|
||||
if (!enabled) {
|
||||
mMoveCursor.setVisibility(View.GONE);
|
||||
mResizer.setVisibility(View.GONE);
|
||||
getMoveCursor().setVisibility(View.GONE);
|
||||
getResizer().setVisibility(View.GONE);
|
||||
mCloseButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
mMoveCursor.setVisibility(View.VISIBLE);
|
||||
mResizer.setVisibility(View.VISIBLE);
|
||||
getMoveCursor().setVisibility(View.VISIBLE);
|
||||
getResizer().setVisibility(View.VISIBLE);
|
||||
mCloseButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAdjustEnabled() {
|
||||
return mMoveCursor.getVisibility() == View.VISIBLE;
|
||||
return getMoveCursor().getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
public View getRootView() {
|
||||
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() {
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_PHONE;
|
||||
}
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
type,
|
||||
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;
|
||||
@Override
|
||||
protected void onViewCreated(View view) {
|
||||
super.onViewCreated(view);
|
||||
mCloseButton = view.findViewById(R.id.close);
|
||||
}
|
||||
|
||||
public void disableWindowFocus() {
|
||||
mWindowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
mWindowManager.updateViewLayout(mWindowView, mWindowLayoutParams);
|
||||
WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
|
||||
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
updateWindowLayoutParams(windowLayoutParams);
|
||||
}
|
||||
|
||||
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() {
|
||||
if (mWindowView != null)
|
||||
this.mWindowManager.removeView(this.mWindowView);
|
||||
FloatyService.removeWindow(this);
|
||||
WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
|
||||
windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
updateWindowLayoutParams(windowLayoutParams);
|
||||
getWindowView().requestLayout();
|
||||
}
|
||||
|
||||
private static class MyFloaty implements ResizableFloaty {
|
||||
@@ -185,7 +116,7 @@ public class BaseResizableFloatyWindow extends ResizableFloatyWindow {
|
||||
@Override
|
||||
public View inflateView(FloatyService floatyService, ResizableFloatyWindow resizableFloatyWindow) {
|
||||
mRootView = View.inflate(mContext, R.layout.floaty_window, null);
|
||||
FrameLayout container = (FrameLayout) mRootView.findViewById(R.id.container);
|
||||
FrameLayout container = mRootView.findViewById(R.id.container);
|
||||
View contentView = mContentViewSupplier.inflate(mContext, container);
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.FloatyWindow;
|
||||
import com.stardust.enhancedfloaty.WindowBridge;
|
||||
import com.stardust.enhancedfloaty.util.WindowTypeCompat;
|
||||
|
||||
public class RawWindow extends FloatyWindow {
|
||||
|
||||
public class RawWindow implements FloatyWindow {
|
||||
|
||||
|
||||
public interface RawFloaty {
|
||||
@@ -24,13 +26,9 @@ public class RawWindow implements FloatyWindow {
|
||||
View inflateWindowView(FloatyService service, ViewGroup parent);
|
||||
}
|
||||
|
||||
private WindowBridge mWindowBridge;
|
||||
private VolatileDispose<RuntimeException> mInflateException = new VolatileDispose<>();
|
||||
private WindowManager mWindowManager;
|
||||
private ViewGroup mWindowView;
|
||||
private View mWindowContent;
|
||||
private RawFloaty mRawFloaty;
|
||||
private WindowManager.LayoutParams mWindowLayoutParams;
|
||||
private View mContentView;
|
||||
|
||||
public RawWindow(RawFloaty rawFloaty) {
|
||||
mRawFloaty = rawFloaty;
|
||||
@@ -38,26 +36,32 @@ public class RawWindow implements FloatyWindow {
|
||||
|
||||
@Override
|
||||
public void onCreate(FloatyService floatyService, WindowManager windowManager) {
|
||||
mWindowManager = windowManager;
|
||||
mWindowView = (ViewGroup) View.inflate(floatyService, R.layout.raw_window, null);
|
||||
mWindowLayoutParams = createWindowLayoutParams();
|
||||
try {
|
||||
mWindowContent = mRawFloaty.inflateWindowView(floatyService, mWindowView);
|
||||
mWindowManager.addView(mWindowView, mWindowLayoutParams);
|
||||
super.onCreate(floatyService, windowManager);
|
||||
} catch (RuntimeException e) {
|
||||
mInflateException.setAndNotify(e);
|
||||
return;
|
||||
}
|
||||
mWindowBridge = new WindowBridge.DefaultImpl(mWindowLayoutParams, windowManager, mWindowView);
|
||||
mInflateException.setAndNotify(Exceptions.NO_EXCEPTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateView(FloatyService floatyService) {
|
||||
ViewGroup windowView = (ViewGroup) View.inflate(floatyService, R.layout.raw_window, null);
|
||||
mContentView = mRawFloaty.inflateWindowView(floatyService, windowView);
|
||||
return windowView;
|
||||
}
|
||||
|
||||
public RuntimeException waitForCreation() {
|
||||
return mInflateException.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
public View getContentView() {
|
||||
return mContentView;
|
||||
}
|
||||
|
||||
protected WindowManager.LayoutParams createWindowLayoutParams() {
|
||||
@Override
|
||||
protected WindowManager.LayoutParams onCreateWindowLayoutParams() {
|
||||
int flags =
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
||||
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
||||
@@ -66,64 +70,37 @@ public class RawWindow implements FloatyWindow {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
|
||||
}
|
||||
int type;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
} else {
|
||||
type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
}
|
||||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
type,
|
||||
WindowTypeCompat.getWindowType(),
|
||||
flags,
|
||||
PixelFormat.TRANSLUCENT);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.START;
|
||||
return layoutParams;
|
||||
}
|
||||
|
||||
|
||||
public void disableWindowFocus() {
|
||||
mWindowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
mWindowManager.updateViewLayout(mWindowView, mWindowLayoutParams);
|
||||
WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
|
||||
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
updateWindowLayoutParams(windowLayoutParams);
|
||||
}
|
||||
|
||||
public void requestWindowFocus() {
|
||||
mWindowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
mWindowManager.updateViewLayout(mWindowView, mWindowLayoutParams);
|
||||
mWindowView.requestFocus();
|
||||
WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
|
||||
windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
updateWindowLayoutParams(windowLayoutParams);
|
||||
getWindowView().requestLayout();
|
||||
}
|
||||
|
||||
public void setTouchable(boolean touchable) {
|
||||
WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
|
||||
if (touchable) {
|
||||
mWindowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||
windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||
} else {
|
||||
mWindowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||
}
|
||||
mWindowManager.updateViewLayout(mWindowView, mWindowLayoutParams);
|
||||
updateWindowLayoutParams(windowLayoutParams);
|
||||
}
|
||||
|
||||
public WindowBridge getWindowBridge() {
|
||||
return mWindowBridge;
|
||||
}
|
||||
|
||||
public ViewGroup getWindowView() {
|
||||
return mWindowView;
|
||||
}
|
||||
|
||||
public View getWindowContent() {
|
||||
return mWindowContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDestroy(FloatyService floatyService) {
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (mWindowView != null)
|
||||
mWindowManager.removeView(mWindowView);
|
||||
FloatyService.removeWindow(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class Floaty {
|
||||
}
|
||||
|
||||
public View findView(String id) {
|
||||
return JsViewHelper.findViewByStringId(mWindow.getWindowContent(), id);
|
||||
return JsViewHelper.findViewByStringId(mWindow.getContentView(), id);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
|
||||
Reference in New Issue
Block a user