Получить все максимальные баллы (сверху, снизу, слева, справа) из массива пути - PullRequest
0 голосов
/ 03 апреля 2019

я пытаюсь воспроизвести видео в произвольной форме (рисование фигуры пользователем с использованием точки касания события движения). Траектория рисуется правильно, а видео воспроизводится внутри фигуры, нарисованной пользователем ... но проблема в том, что ширина и Высота видеовьюва заполнена макетом. я хочу установить параметры макета в соответствии с максимальным верхом, низом, слева и справа от пути.

public class VideoSurfaceView extends SurfaceView {
private final static String TAG = "VideoSurfaceView";
private boolean inOtherShape ;
private Path shapePath;

public VideoSurfaceView(Context context) {
    super(context);
}

public VideoSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public VideoSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.clipPath(CanvasView.mPath);
    super.dispatchDraw(canvas);
} 
}

public class CanvasView  extends View {
public int width;
public int height;
private Bitmap mBitmap,workingBitmap;
private Canvas mCanvas;
static Path mPath;
static Paint mPaint;
private Paint mBitmapPaint;
private float mX, mY;
static float startingpointx,startingpointy,endingpointx,endingpointy ;
private static final float TOLERANCE = 5;
Context context;
Region r;
static ArrayList<Path> paths = new ArrayList<Path>();

public CanvasView(Context c, AttributeSet attrs) {
    super(c, attrs);
    context = c;
    mPaint = new Paint(Paint.DITHER_FLAG);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(Color.parseColor("#37A1D1"));
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(2);
    mPath = new Path();
    mPaint.setStrokeWidth(4f);
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);

}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.home);
    mCanvas = new Canvas(mBitmap.copy(Bitmap.Config.ARGB_8888, true));

}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawBitmap(mBitmap,0,0,mBitmapPaint);
    canvas.drawPath(mPath, mPaint);
}

private void startTouch(float x, float y) {
    mPath.reset();
    mPath.moveTo(x, y);
    startingpointx = x;
    startingpointy = y;
    mY = y;
    mX = x;
}

private void moveTouch(float x, float y) {
    float dx = Math.abs(x - mX);
    float dy = Math.abs(y - mY);
    if (dx >= TOLERANCE || dy >= TOLERANCE) {
        mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
        mX = x;
        mY = y;
    }
}
private void upTouch() {

    mPath.lineTo(mX, mY);
    mPath.lineTo(startingpointx,startingpointy);
 //   mCanvas.drawPath(mPath, mPaint);
 //   paths.add(mPath);
 }

//override the onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            startTouch(x, y);
            invalidate();
            break;
        case MotionEvent.ACTION_MOVE:
            moveTouch(x, y);
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            upTouch();
            invalidate();
            break;
    }
    return true;
}


}


      private void setVideoLayout(Shape shape, int width, int height){
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) videoView.getLayoutParams();
    layoutParams.width = width;
    layoutParams.height = height;

    RectF bounds = new RectF();
    CanvasView.mPath.computeBounds(bounds, true);
    layoutParams.setMargins((int) bounds.left,(int)bounds.top,(int)bounds.right,(int)bounds.bottom);
...