title: Move, Scale and Rotate ImageView OnTouch not working
body: <p>i have days trying to make this work, checked out some other answers and none seem to work for me :S</p>
  
  <p>i add a sticker to a RelativeLayout, i want the sticker to Move, Scale and Rotate with OnTouch Methods once it is selected (it has an OnClickListener that calls a setOnTouchListener)
  keeping in mind that i can have N stickers added.</p>
  
  <pre><code>private void addSticker(ImageView sticker)
  {
  
      flMemeFrame.addView(sticker);
  
      sticker.setOnClickListener(new View.OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
              {
                  if (selectedView != null)
                  {
                      CancelSelection(selectedView);
                  }
                  selectedView = v;
  
                  v.setOnTouchListener(new View.OnTouchListener()
                  {
                      private float mScaleFactor = 0.5f;
                      private float mRotationDegree = 0.f;
                      private float mFocusX = 0.f;
                      private float mFocusY = 0.f;
                      private int mScreenHeight;
                      private int mScreenWidth;
                      private Matrix matrix = new Matrix();//Các lớp Matrix giữ một ma trận 3x3 để di chuyển tọa độ.
                      private int mImageWidth, mImageHeight;
                      private ScaleGestureDetector mScaleDetector;
                      private RotateGestureDetector mRotateDetector;
                      private MoveGestureDetector mMoveDetector;
  
                      class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
                          @Override
                          public boolean onScale(ScaleGestureDetector detector) {
                              mScaleFactor *= detector.getScaleFactor();
                              mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 1.0f));
                              return true;
                          }
                      }
  
                      class RotateListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
                          @Override
                          public boolean onRotate(RotateGestureDetector detector) {
                              mRotationDegree -= detector.getRotationDegreesDelta();
                              return true;
                          }
                      }
  
                      class MoveListener extends MoveGestureDetector.SimpleOnMoveGestureListener {
                          @Override
                          public boolean onMove(MoveGestureDetector detector) {
                              PointF d = detector.getFocusDelta();
                              mFocusX += d.x;
                              mFocusY += d.y;
  
                              return true;
                          }
                      }
                      @Override
                      public boolean onTouch(View v, MotionEvent event)
                      {
                          mImageHeight = v.getHeight();
                          mImageWidth = v.getWidth();
  
                          mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
                          mRotateDetector = new RotateGestureDetector(context, new RotateListener());
                          mMoveDetector = new MoveGestureDetector(context, new MoveListener());
  
                          mScaleDetector.onTouchEvent(event);
                          mRotateDetector.onTouchEvent(event);
                          mMoveDetector.onTouchEvent(event);
                          float scaleImageCenterX = (mImageWidth * mScaleFactor) / 2;
                          float scaleImageCenterY = (mImageHeight * mScaleFactor) / 2;
  
                          matrix.reset();
                          matrix.postScale(mScaleFactor, mScaleFactor);
                          matrix.postRotate(mRotationDegree, scaleImageCenterX, scaleImageCenterY);
                          matrix.postTranslate(mFocusX - scaleImageCenterX, mFocusY - scaleImageCenterY);
  
                          ImageView view = (ImageView) v;
                          view.setScaleType(ImageView.ScaleType.MATRIX);
                          view.setImageMatrix(matrix);
  
                          return true;
                      }
                  });
              }
          }
      });
  }
  </code></pre>
  
  <p>here is where i set the image</p>
  
  <pre><code>ImageView sticker = new ImageView(context);
                  RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT);
                  rlp.addRule(RelativeLayout.CENTER_IN_PARENT);
                  sticker.setLayoutParams(rlp);
  addSticker(sticker);
  </code></pre>
  
  <p>the app compiles and no crashes, but the sticker does NOTHING OnTouch :(</p>
  
  <p>links that i have tried:</p>
  
  <p><a href="http://code.almeros.com/android-multitouch-gesture-detectors#.V1Y0sZMrLMW" rel="nofollow noreferrer">http://code.almeros.com/android-multitouch-gesture-detectors#.V1Y0sZMrLMW</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16690572/rotation-and-scaling-and-move-using-multi-touch-in-android">rotation and scaling and move using multi touch in android</a></p>
  
  <p>and some other links that i can't find now</p>
  
  <p>anyone that can help?</p>
  
  <p>EDIT: the code for CancelSelection (completely unrelated, as the only thing i'm doing is setting selectedView as null and removing the background, i also remove the OnTouchListener, because i don't want to move/scale/rotate the view if it's not selected)</p>
  
  <pre><code>@SuppressWarnings("deprecation")
  public void CancelSelection(View v)
  {
      if(isCaptionEditPanelOpen)
      {
          rlQuickEdit.setVisibility(View.GONE);
          rlQuickEdit = null;
          isCaptionEditPanelOpen = false;
      }
      //toogleButtonVisibility(false);
      v.setBackgroundColor(getResources().getColor(android.R.color.transparent));
      selectedView = null;
      v.setOnTouchListener(null);
  }
  </code></pre>
  
  <p>i wrote this class, to see if i can make it work without all the complexity of my app, same results:</p>
  
  <pre><code>package com.andujardev.imagerotation;
  
  import android.content.Context;
  import android.graphics.Matrix;
  import android.graphics.PointF;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.view.ScaleGestureDetector;
  import android.view.View;
  import android.widget.ImageView;
  
  public class MainActivity extends AppCompatActivity
  {
      Context context;
      ImageView imgRotate;
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          context = this;
  
          imgRotate = (ImageView) findViewById(R.id.imgRotate);
  
          imgRotate.setOnTouchListener(new View.OnTouchListener()
          {
              private float mScaleFactor = 0.5f;
              private float mRotationDegree = 0.f;
              private float mFocusX = 0.f;
              private float mFocusY = 0.f;
              private int mScreenHeight;
              private int mScreenWidth;
              private Matrix matrix = new Matrix();
              private int mImageWidth, mImageHeight;
              private ScaleGestureDetector mScaleDetector;
              private RotateGestureDetector mRotateDetector;
              private MoveGestureDetector mMoveDetector;
  
              class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
                  @Override
                  public boolean onScale(ScaleGestureDetector detector) {
                      mScaleFactor *= detector.getScaleFactor();
                      mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 1.0f));
                      return true;
                  }
              }
  
              class RotateListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
                  @Override
                  public boolean onRotate(RotateGestureDetector detector) {
                      mRotationDegree -= detector.getRotationDegreesDelta();
                      return true;
                  }
              }
  
              class MoveListener extends MoveGestureDetector.SimpleOnMoveGestureListener {
                  @Override
                  public boolean onMove(MoveGestureDetector detector) {
                      PointF d = detector.getFocusDelta();
                      mFocusX += d.x;
                      mFocusY += d.y;
  
                      return true;
                  }
              }
              @Override
              public boolean onTouch(View v, MotionEvent event)
              {
                  mImageHeight = v.getHeight();
                  mImageWidth = v.getWidth();
  
                  mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
                  mRotateDetector = new RotateGestureDetector(context, new RotateListener());
                  mMoveDetector = new MoveGestureDetector(context, new MoveListener());
  
                  mScaleDetector.onTouchEvent(event);
                  mRotateDetector.onTouchEvent(event);
                  mMoveDetector.onTouchEvent(event);
                  float scaleImageCenterX = (mImageWidth * mScaleFactor) / 2;
                  float scaleImageCenterY = (mImageHeight * mScaleFactor) / 2;
  
                  matrix.reset();
                  matrix.postScale(mScaleFactor, mScaleFactor);
                  matrix.postRotate(mRotationDegree, scaleImageCenterX, scaleImageCenterY);
                  matrix.postTranslate(mFocusX - scaleImageCenterX, mFocusY - scaleImageCenterY);
  
                  ImageView view = (ImageView) v;
                  view.setImageMatrix(matrix);
  
                  return true;
              }
          });
      }
  }
  </code></pre>