添加机器视角点击放大缩小功能

This commit is contained in:
tongchenfei
2020-10-30 17:20:32 +08:00
parent 1aad4e8901
commit 350a3af59c
8 changed files with 98 additions and 10 deletions

View File

@@ -39,6 +39,10 @@ class DialogImpl implements IWindowManagerView {
dialog.show();
}
@Override
public void update(WindowManagerView.WMViewParams params) {
}
@Override
public void hide() {
/*

View File

@@ -27,6 +27,12 @@ interface IWindowManagerView {
*/
void show();
/**
* 更新界面位置或大小
* @param params 具体参数
*/
void update(WindowManagerView.WMViewParams params);
/**
* 隐藏
*/

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
/**
@@ -16,6 +17,8 @@ class WindowManagerImpl implements IWindowManagerView {
private WindowManagerView.WMViewParams mParams;
private boolean isShowing;
private View rootView;
private float mLastX, mLastY;
private int mOldOffsetX, mOldOffsetY;
@@ -23,6 +26,10 @@ class WindowManagerImpl implements IWindowManagerView {
public void init( WindowManagerView.WMViewParams params ) {
mParams = params;
mWindowManager = ( WindowManager ) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
generateLayoutParams();
}
private void generateLayoutParams(){
mLayoutParams = new WindowManager.LayoutParams();
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
@@ -80,10 +87,20 @@ class WindowManagerImpl implements IWindowManagerView {
public void show() {
if ( !isShowing ) {
isShowing = true;
rootView = mParams.mContentView;
mWindowManager.addView( mParams.mContentView, mLayoutParams );
}
}
@Override
public void update(WindowManagerView.WMViewParams params) {
if (isShowing) {
mParams = params;
generateLayoutParams();
mWindowManager.updateViewLayout(rootView,mLayoutParams);
}
}
@Override
public void hide() {
if ( isShowing && mParams != null ) {

View File

@@ -116,4 +116,15 @@ public class WindowManagerView {
public int mY;
public int mGravity;
}
public void exchangeSizeAndPosition(int width, int height, int x, int y) {
if (isShowing()) {
mParams.mX = x;
mParams.mY = y;
mParams.mWidth = width;
mParams.mHeight = height;
mManagerView.update(mParams);
}
}
}