From c7e9d1662111ce2bc8d874ca06594d71121b34ae Mon Sep 17 00:00:00 2001 From: MuhammedRefaat Date: Thu, 26 Apr 2018 11:48:56 +0400 Subject: [PATCH 1/2] zoom in from outside sticker to be able to zoom in from outside sticker in case the sticker is too small and can't be grabbed using hand fingers, then you can zoom in using the right-bottom area of the sticker drawable. --- .../flying/sticker/DrawableSticker.java | 127 ++++++++++++------ 1 file changed, 83 insertions(+), 44 deletions(-) diff --git a/sticker/src/main/java/com/xiaopo/flying/sticker/DrawableSticker.java b/sticker/src/main/java/com/xiaopo/flying/sticker/DrawableSticker.java index 6a74b70..aab7eb6 100644 --- a/sticker/src/main/java/com/xiaopo/flying/sticker/DrawableSticker.java +++ b/sticker/src/main/java/com/xiaopo/flying/sticker/DrawableSticker.java @@ -1,58 +1,97 @@ package com.xiaopo.flying.sticker; +/** + * Mofified by M.Refaat on 3/25/2018. + */ + +import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.support.annotation.IntRange; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; + +import com.netaq.schoolvoice.R; +import com.xiaopo.flying.sticker.Sticker; /** * @author wupanjie */ public class DrawableSticker extends Sticker { - private Drawable drawable; - private Rect realBounds; - - public DrawableSticker(Drawable drawable) { - this.drawable = drawable; - realBounds = new Rect(0, 0, getWidth(), getHeight()); - } - - @NonNull @Override public Drawable getDrawable() { - return drawable; - } - - @Override public DrawableSticker setDrawable(@NonNull Drawable drawable) { - this.drawable = drawable; - return this; - } - - @Override public void draw(@NonNull Canvas canvas) { - canvas.save(); - canvas.concat(getMatrix()); - drawable.setBounds(realBounds); - drawable.draw(canvas); - canvas.restore(); - } - - @NonNull @Override public DrawableSticker setAlpha(@IntRange(from = 0, to = 255) int alpha) { - drawable.setAlpha(alpha); - return this; - } - - @Override public int getWidth() { - return drawable.getIntrinsicWidth(); - } - - @Override public int getHeight() { - return drawable.getIntrinsicHeight(); - } - - @Override public void release() { - super.release(); - if (drawable != null) { - drawable = null; - } - } + private Drawable drawable; + public Rect realBounds; + private Drawable allocationDrawable; + private Rect allocationBounds; + + public DrawableSticker(Drawable drawable, Context context) { + this.allocationDrawable = drawable; + this.drawable = ContextCompat.getDrawable(context, R.drawable.empty_sticker); // an invisble/empty view to be considered as the mainn drawable + realBounds = new Rect(300, 300, getAllocationWidth(), getAllocationHeight()); + int startX = (getAllocationWidth() / 2) - (getWidth() / 2); + int startY = (getAllocationHeight() / 2) - (getHeight() / 2); + allocationBounds = new Rect(startX - 300, startY - 300, + startX + getWidth() + 300, startY + getHeight() + 300); + } + + @NonNull + @Override + public Drawable getDrawable() { + return drawable; + } + + @Override + public DrawableSticker setDrawable(@NonNull Drawable drawable) { + this.drawable = drawable; + return this; + } + + @Override + public void draw(@NonNull Canvas canvas) { + canvas.save(); + canvas.concat(getMatrix()); + drawable.setBounds(allocationBounds); + drawable.draw(canvas); + canvas.restore(); + + canvas.save(); + canvas.concat(getMatrix()); + allocationDrawable.setBounds(realBounds); + allocationDrawable.draw(canvas); + canvas.restore(); + } + + @NonNull + @Override + public DrawableSticker setAlpha(@IntRange(from = 0, to = 255) int alpha) { + drawable.setAlpha(alpha); + return this; + } + + @Override + public int getWidth() { + return drawable.getIntrinsicWidth(); + } + + @Override + public int getHeight() { + return drawable.getIntrinsicHeight(); + } + + public int getAllocationWidth() { + return allocationDrawable.getIntrinsicWidth(); + } + + public int getAllocationHeight() { + return allocationDrawable.getIntrinsicHeight(); + } + + @Override + public void release() { + super.release(); + if (drawable != null) { + drawable = null; + } + } } From 95f4ff05523c94a0c7d3795269f4de3146f80bb1 Mon Sep 17 00:00:00 2001 From: MuhammedRefaat Date: Thu, 26 Apr 2018 11:50:41 +0400 Subject: [PATCH 2/2] Add files via upload to be used as a holder invisible drawable in case the sticker drawable became too small to be handled. --- sticker/src/main/res/drawable/empty_sticker.png | Bin 0 -> 3944 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 sticker/src/main/res/drawable/empty_sticker.png diff --git a/sticker/src/main/res/drawable/empty_sticker.png b/sticker/src/main/res/drawable/empty_sticker.png new file mode 100644 index 0000000000000000000000000000000000000000..f082072c682f35f588298e2ac2be567ab4e41d24 GIT binary patch literal 3944 zcmeHKO^X~w7_JR|Wlg-~VDunm2Z9oNx~e~?i;Qu%XUz^|)@3uW>&=?#nwe&&yL!8O zcV_n#a}WX^L=Z$4!JD9X@#rA|K|P2^Z=Urc`3t^1AMHd|4C2ihD5kpVsptKA>g}0( z+gmp;uD-a65W3jfZ0;a*?kbGupLq&aKL72bE%-X0ZoZu(^z5Z_te{U$FC+Bik5Ol@ z*lXWnLd7*6s;;b!;}p;cUB59-x!9Kl?#h0YG_;4`+}CgvHnd%*P1-hSZ0YNMaj>qvZ$=SG}O?Vm1%Vk5u6G*Y&(AG+Wc(1*U1C>ea)LdOq z+r*wKVi{sHGFih|4S=&psMh%fcSpX}&qL1y2oaP!uUMjL~RR8(B4# z^$qI#zCldGG<87e`EgS4v7Y2t<_t}li!4fuNF}&r@Y(}5~fK2U!{U2Q*N08-m-S2oV{C5|f- zd9iT>VayV8COYpNr_$JwxjM{*+&BU^uawcGEXX7;WD`b1gCf**V(F&Sp_EaJ+2k6r z86i_>TZK{YcoAwtu{zXb)Mj@55hy4iSm2j+-EkpMIp07;=3Xg zy6s6vm!4hM>#jv~>U%wDaktK$?)-dHiNms@<@u?&LnVOYPxmB&BaQ&klDe%s)OK}l zc8Tr_Q}|uaBhnFbwzskf?iU{}vX)+j!04KebX=S2U6&F)?AoF3Tb`>^*CDPneb=^V zsp5$+*k+U$Dm$Lti`(*GHXBBGq6Nl9sd2~*Ka!y~Ta3=g#$(x?ogWP(P%di3W2VWh zN+VO-x#|@op2@X7WNv=~3_wIiBi}f`^t3N$N=+5^aBlN;|PoN*jRrJPtfHdDfk3QhH z(47n7911UALipPyWSN(x7?zi0*%_AYaQT{8z8n89KL`$1_?J&#t82S2m;Z%Z8(Yn< I*5A4N2k9XL@Bjb+ literal 0 HcmV?d00001