133 lines
5.6 KiB
Java
133 lines
5.6 KiB
Java
package cn.com.magnity.magnitycx;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Point;
|
|
import android.util.AttributeSet;
|
|
import android.view.MotionEvent;
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceView;
|
|
import android.widget.RelativeLayout;
|
|
import cn.com.magnity.magnitycx.sdk.MagParameter;
|
|
import cn.com.magnity.magnitycx.sdk.SharedPreferencesManager;
|
|
import cn.com.magnity.magnitycx.sdk.VisibleCamera;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ImageViewerVisible extends SurfaceView implements SurfaceHolder.Callback {
|
|
private SurfaceHolder holder_;
|
|
private int leftMargin_;
|
|
private int mouseDownX_;
|
|
private int mouseDownY_;
|
|
private int topMargin_;
|
|
|
|
public ImageViewerVisible(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
this.holder_ = null;
|
|
this.holder_ = getHolder();
|
|
this.holder_.addCallback(this);
|
|
this.holder_.setFormat(-2);
|
|
this.holder_.setType(3);
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
int width;
|
|
int height;
|
|
this.leftMargin_ = MagApplication.magParameter.visWndLeftMargin;
|
|
this.topMargin_ = MagApplication.magParameter.visWndTopMargin;
|
|
switch (MagApplication.magParameter.visWndSize) {
|
|
case 0:
|
|
width = ((MagApplication.magParameter.portraitScreenWidth / 4) / 12) * 12;
|
|
break;
|
|
case 1:
|
|
width = ((MagApplication.magParameter.portraitScreenWidth / 3) / 12) * 12;
|
|
break;
|
|
case 2:
|
|
width = ((MagApplication.magParameter.portraitScreenWidth / 2) / 12) * 12;
|
|
break;
|
|
default:
|
|
width = ((MagApplication.magParameter.portraitScreenWidth / 4) / 12) * 12;
|
|
break;
|
|
}
|
|
if (getResources().getConfiguration().orientation == 2) {
|
|
height = width;
|
|
width = (height * 4) / 3;
|
|
VisibleCamera.initCamera(MagApplication.magParameter.visCameraId, this.holder_, height);
|
|
} else {
|
|
height = (width * 4) / 3;
|
|
VisibleCamera.initCamera(MagApplication.magParameter.visCameraId, this.holder_, width);
|
|
}
|
|
Point outSize = new Point();
|
|
MagApplication.windowManager.getDefaultDisplay().getSize(outSize);
|
|
RelativeLayout layout = (RelativeLayout) getParent();
|
|
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
lp.width = width;
|
|
lp.height = height;
|
|
if (this.leftMargin_ < 0 || this.leftMargin_ > outSize.x - lp.width) {
|
|
this.leftMargin_ = outSize.x - lp.width;
|
|
}
|
|
if (this.topMargin_ < 0) {
|
|
this.topMargin_ = 0;
|
|
} else if (this.topMargin_ > layout.getHeight() - lp.height) {
|
|
this.topMargin_ = layout.getHeight() - lp.height;
|
|
}
|
|
lp.leftMargin = this.leftMargin_;
|
|
lp.topMargin = this.topMargin_;
|
|
setLayoutParams(lp);
|
|
Canvas canvas = this.holder_.lockCanvas();
|
|
if (canvas != null) {
|
|
Paint pint = new Paint();
|
|
pint.setColor(getResources().getColor(R.color.black));
|
|
canvas.drawRect(0.0f, 0.0f, lp.width, lp.height, pint);
|
|
this.holder_.unlockCanvasAndPost(canvas);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
MagApplication.magParameter.visWndLeftMargin = params.leftMargin;
|
|
MagApplication.magParameter.visWndTopMargin = params.topMargin;
|
|
SharedPreferencesManager.putInt(MagParameter.KEY_VISWNDLEFTMARGIN, params.leftMargin);
|
|
SharedPreferencesManager.putInt(MagParameter.KEY_VISWNDTOPMARGIN, params.topMargin);
|
|
SharedPreferencesManager.commit();
|
|
VisibleCamera.deinitCamera();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
switch (event.getAction()) {
|
|
case 0:
|
|
this.mouseDownX_ = (int) event.getRawX();
|
|
this.mouseDownY_ = (int) event.getRawY();
|
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
this.leftMargin_ = params.leftMargin;
|
|
this.topMargin_ = params.topMargin;
|
|
break;
|
|
case 2:
|
|
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) getLayoutParams();
|
|
params2.leftMargin = (this.leftMargin_ + ((int) event.getRawX())) - this.mouseDownX_;
|
|
params2.topMargin = (this.topMargin_ + ((int) event.getRawY())) - this.mouseDownY_;
|
|
RelativeLayout layout = (RelativeLayout) getParent();
|
|
if (params2.leftMargin < 0) {
|
|
params2.leftMargin = 0;
|
|
} else if (params2.leftMargin > layout.getWidth() - params2.width) {
|
|
params2.leftMargin = layout.getWidth() - params2.width;
|
|
}
|
|
if (params2.topMargin < 0) {
|
|
params2.topMargin = 0;
|
|
} else if (params2.topMargin > layout.getHeight() - params2.height) {
|
|
params2.topMargin = layout.getHeight() - params2.height;
|
|
}
|
|
setLayoutParams(params2);
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
}
|