Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

更改sticker的双指手势 #139

Open
wens-jie opened this issue Mar 19, 2019 · 1 comment
Open

更改sticker的双指手势 #139

wens-jie opened this issue Mar 19, 2019 · 1 comment

Comments

@wens-jie
Copy link

public class StickerView extends com.xiaopo.flying.sticker.StickerView {

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

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

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

@Override
protected void handleCurrentMode(@NonNull MotionEvent event) {
    try {
        int currentMode;
        Sticker handlingSticker;
        Matrix moveMatrix;
        Class mClass = Class.forName("com.xiaopo.flying.sticker.StickerView");
        Field field = mClass.getDeclaredField("currentMode");
        field.setAccessible(true);
        currentMode = field.getInt(this);
        field = mClass.getDeclaredField("handlingSticker");
        field.setAccessible(true);
        handlingSticker = (Sticker) field.get(this);
        field = mClass.getDeclaredField("moveMatrix");
        field.setAccessible(true);
        moveMatrix = (Matrix) field.get(this);
        if (currentMode == 2)
            if (handlingSticker != null && moveMatrix != null) {
                float newDistance = calculateDistance(event);
                float newRotation = calculateRotation(event);
                field = mClass.getDeclaredField("downMatrix");
                field.setAccessible(true);
                Matrix downMatrix = (Matrix) field.get(this);
                field = mClass.getDeclaredField("oldDistance");
                field.setAccessible(true);
                float oldDistance = field.getFloat(this);

                field = mClass.getDeclaredField("oldRotation");
                field.setAccessible(true);
                float oldRotation = field.getFloat(this);

                field = mClass.getDeclaredField("midPoint");
                field.setAccessible(true);

                PointF midPoint = (PointF) field.get(this);
                moveMatrix.set(downMatrix);
                moveMatrix.postScale(newDistance / oldDistance, newDistance / oldDistance, midPoint.x,
                        midPoint.y);
                moveMatrix.postRotate(newRotation - oldRotation, midPoint.x, midPoint.y);
                field = mClass.getDeclaredField("downX");
                field.setAccessible(true);
                float downX = field.getFloat(this);
                field = mClass.getDeclaredField("downY");
                field.setAccessible(true);
                float downY = field.getFloat(this);
                moveMatrix.postTranslate(event.getX() - downX, event.getY() - downY);
                handlingSticker.setMatrix(moveMatrix);
                return;
            }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    super.handleCurrentMode(event);
}

}

@wens-jie
Copy link
Author

可以保证同时移动缩放旋转

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant