Add sticker only once using invalidate()

88 Views Asked by At

On clicking 2nd sticker it should display the second sticker alone (the first one should be removed). current output when clicking in sticker 1(yellow),it display sticker 1 on screen and when sticker 2 (red) is clicked the previous sticker is still on the screen(which i do not want) The output must be sticker 2 alone I have tried implementing a for loop but it does not work. Full Activity source code Figure 1 is the current output,fig 2 and 3 are expected output for 1st and 2nd clicks respectively

public void addSticker(final Sticker sticker) {
  if (sticker == null) {
     Log.e(TAG, "Sticker to be added is null!");
     return;
   }

    float offsetX = (getWidth() - sticker.getWidth());
    float offsetY = (getHeight() - sticker.getHeight());
    sticker.getMatrix().postTranslate(offsetX, offsetY);
    float scaleFactor;
    if (getWidth() < getHeight()) {
         scaleFactor = (float) getWidth() / sticker.getDrawable().getIntrinsicWidth();
    } 
    else {
          scaleFactor = (float) getHeight() / sticker.getDrawable().getIntrinsicHeight();
      }
    sticker.getMatrix().postScale(scaleFactor, scaleFactor, getWidth(), getHeight());

    mHandlingSticker = sticker;
    mStickers.add(sticker);
    invalidate();
}
0

There are 0 best solutions below