修改windowManagerView内部实现,改用BaseFloadDialog
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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 extends View> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user