From 8ea35670e75e9ba2bfbc2fa3907ca8bf3e2d74d3 Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Wed, 22 Jul 2020 17:55:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9windowManagerView=E5=86=85?= =?UTF-8?q?=E9=83=A8=E5=AE=9E=E7=8E=B0=EF=BC=8C=E6=94=B9=E7=94=A8BaseFload?= =?UTF-8?q?Dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mogo/module/common/wm/DialogImpl.java | 36 ++++++++++ .../module/common/wm/IWindowManagerView.java | 25 +++++++ .../module/common/wm/WindowManagerImpl.java | 67 +++++++++++++++++ .../module/common/wm/WindowManagerView.java | 71 ++++++------------- 4 files changed, 148 insertions(+), 51 deletions(-) create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/DialogImpl.java create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/IWindowManagerView.java create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerImpl.java diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/DialogImpl.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/DialogImpl.java new file mode 100644 index 0000000000..330249f65d --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/DialogImpl.java @@ -0,0 +1,36 @@ +package com.mogo.module.common.wm; + + +import android.app.Dialog; +import android.content.Context; + +import com.mogo.module.common.dialog.BaseFloatDialog; +import com.mogo.utils.logger.Logger; + +/** + * 采用Dialog实现接口 + */ +class DialogImpl implements IWindowManagerView { + private Dialog dialog; + @Override + public void init(WindowManagerView.WMViewParams params) { + Logger.d("DialogImpl", "init===="); + dialog = new BaseFloatDialog(params.mContext); + dialog.setContentView(params.mContentView); + } + + @Override + public boolean isShowing() { + return dialog.isShowing(); + } + + @Override + public void show() { + dialog.show(); + } + + @Override + public void hide() { + dialog.dismiss(); + } +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/IWindowManagerView.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/IWindowManagerView.java new file mode 100644 index 0000000000..d610cea67a --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/IWindowManagerView.java @@ -0,0 +1,25 @@ +package com.mogo.module.common.wm; + +interface IWindowManagerView { + /** + * 初始化 + * @param params contentView包装类 + */ + void init(WindowManagerView.WMViewParams params); + + /** + * 是否显示 + * @return true - 显示中 + */ + boolean isShowing(); + + /** + * 显示 + */ + void show(); + + /** + * 隐藏 + */ + void hide(); +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerImpl.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerImpl.java new file mode 100644 index 0000000000..4821f6b0a2 --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerImpl.java @@ -0,0 +1,67 @@ +package com.mogo.module.common.wm; + +import android.content.Context; +import android.graphics.PixelFormat; +import android.os.Build; +import android.view.Gravity; +import android.view.WindowManager; + +import com.mogo.module.common.utils.CarSeries; +import com.mogo.utils.WindowUtils; + +/** + * 采用windowManager实现接口 + */ +class WindowManagerImpl implements IWindowManagerView { + private WindowManager mWindowManager; + private WindowManager.LayoutParams mLayoutParams; + private WindowManagerView.WMViewParams mParams; + private boolean isShowing; + @Override + public void init(WindowManagerView.WMViewParams params) { + mParams = params; + mWindowManager = (WindowManager) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); + mLayoutParams = new WindowManager.LayoutParams(); + if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { + mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + } else { + mLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; + } + mLayoutParams.format = PixelFormat.TRANSLUCENT; + mLayoutParams.gravity = Gravity.CENTER; + mLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + + if ( CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X ) { + mLayoutParams.width = 1920; + mLayoutParams.height = 1080; + } else { + mLayoutParams.width = WindowUtils.getScreenWidth( mParams.mContext ); + mLayoutParams.height = WindowUtils.getScreenHeight( mParams.mContext ); + } + mLayoutParams.dimAmount = 0.5f; + mLayoutParams.x = 0; + mLayoutParams.y = 0; + } + + @Override + public boolean isShowing() { + return isShowing; + } + + @Override + public void show() { + if(!isShowing){ + isShowing = true; + mWindowManager.addView(mParams.mContentView,mLayoutParams); + } + } + + @Override + public void hide() { + if (isShowing && mParams != null) { + mWindowManager.removeView(mParams.mContentView); + isShowing = false; + } + + } +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerView.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerView.java index 4c60022b5d..d3c054a2ca 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerView.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/wm/WindowManagerView.java @@ -11,6 +11,7 @@ import android.view.WindowManager; import androidx.annotation.IdRes; import androidx.annotation.LayoutRes; +import com.mogo.commons.debug.DebugConfig; import com.mogo.module.common.utils.CarSeries; import com.mogo.utils.WindowUtils; @@ -23,89 +24,57 @@ import com.mogo.utils.WindowUtils; public class WindowManagerView { private WMViewParams mParams; - private boolean mIsShowing; - private WindowManager mWindowManager; - private WindowManager.LayoutParams mLayoutParams; - private WindowManagerView( WMViewParams params ) { + private IWindowManagerView managerView; + + private WindowManagerView(WMViewParams params) { this.mParams = params; - init(); - } - - private void init() { - mWindowManager = ( WindowManager ) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE ); - mLayoutParams = new WindowManager.LayoutParams(); - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) { - mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; - } else { - mLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; - } - mLayoutParams.format = PixelFormat.TRANSLUCENT; - mLayoutParams.gravity = Gravity.CENTER; - mLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - - if ( CarSeries.getSeries() == CarSeries.CAR_SERIES_F80X ) { - mLayoutParams.width = 1920; - mLayoutParams.height = 1080; - } else { - mLayoutParams.width = WindowUtils.getScreenWidth( mParams.mContext ); - mLayoutParams.height = WindowUtils.getScreenHeight( mParams.mContext ); - } - mLayoutParams.dimAmount = 0.5f; - mLayoutParams.x = 0; - mLayoutParams.y = 0; + managerView = new DialogImpl(); + managerView.init(params); +// init(); } public boolean isShowing() { - return mIsShowing; + return managerView.isShowing(); } - public < T extends View > T findViewById( @IdRes int id ) { - return mParams.mContentView.findViewById( id ); + public T findViewById(@IdRes int id) { + return mParams.mContentView.findViewById(id); } public void show() { - if ( mIsShowing ) { - return; - } - mIsShowing = true; - mWindowManager.addView( mParams.mContentView, mLayoutParams ); + managerView.show(); } public void dismiss() { - if ( !mIsShowing ) { - return; - } - if ( mParams != null ) { - mWindowManager.removeViewImmediate( mParams.mContentView ); - } - mIsShowing = false; + managerView.hide(); } public static class Builder { private WMViewParams mParams = null; - public Builder( Context context ) { + public Builder(Context context) { mParams = new WMViewParams(); mParams.mContext = context; } - public Builder contentView( View contentView ) { + public Builder contentView(View contentView) { mParams.mContentView = contentView; return this; } - public Builder contentView( @LayoutRes int contentViewId ) { - mParams.mContentView = LayoutInflater.from( mParams.mContext ).inflate( contentViewId, null ); + public Builder contentView(@LayoutRes int contentViewId) { + mParams.mContentView = LayoutInflater.from(mParams.mContext).inflate(contentViewId, + null); return this; } public WindowManagerView build() { - if ( mParams.mContentView == null ) { - throw new NullPointerException( "WMViewParams#mContentView must not be null." ); + if (mParams.mContentView == null) { + throw new NullPointerException("WMViewParams#mContentView must not be null."); } - return new WindowManagerView( mParams ); + return new WindowManagerView(mParams); } }