77import android .graphics .Color ;
88import android .graphics .Path ;
99import android .graphics .Rect ;
10+ import android .graphics .drawable .BitmapDrawable ;
1011import android .graphics .drawable .Drawable ;
12+ import android .os .Handler ;
13+ import android .os .Looper ;
1114import android .util .AttributeSet ;
1215import android .view .KeyEvent ;
1316import android .view .MotionEvent ;
2023import android .widget .TextView ;
2124
2225import androidx .annotation .Nullable ;
26+ import androidx .core .os .HandlerCompat ;
2327
2428import com .bumptech .glide .Glide ;
2529import com .bumptech .glide .load .DataSource ;
2933import com .bumptech .glide .request .target .Target ;
3034
3135import java .util .Random ;
36+ import java .util .concurrent .ExecutorService ;
37+ import java .util .concurrent .Executors ;
3238
3339public class AndroidAvatar extends RelativeLayout {
3440 String text ;
@@ -119,81 +125,112 @@ private void initView() {
119125
120126 ViewGroup .LayoutParams LLParams = LLRipple .getLayoutParams ();
121127
122-
123128 if (text != null ) {
124129 char nS = text .charAt (0 );
125130 setChar (nS );
126131 }
127132 if (imageSrc != null ) {
128133 setImageSrc (imageSrc , R .drawable .ic_error , ImageView .ScaleType .CENTER_CROP );
129134 }
135+
136+ //set ripple length here
130137 if (backgroundHeight > 0 ) {
131- LLParams .height = backgroundHeight ;
138+ LLParams .width = backgroundWidth -20 ;
139+ LLParams .height = backgroundHeight -20 ;
132140 setBackgroundHeight (backgroundHeight );
133141 }
134142 if (backgroundWidth > 0 ) {
135- LLParams .width = backgroundWidth ;
143+ LLParams .width = backgroundWidth -20 ;
144+ LLParams .height = backgroundHeight -20 ;
136145 setBackgroundWidth (backgroundWidth );
137146 }
138147 if (textSize > 0 ) {
139148 setTextSize (textSize );
140149 }
141150
142- if (randomColor == true ) {
151+ if (randomColor != false ) {
143152 setRandomColor ();
144153 } else {
145154 setBackColor (backColor );
146155 setTextColor (textColor );
147156 }
148-
149-
150157 arr .recycle ();
151158 }
152159
160+ /**
161+ * @param color an integer color
162+ */
153163 public void setBackColor (int color ) {
154164 imageView .setImageBitmap (getRoundedShape (color ));
155165 }
156166
167+ /**
168+ * @param color an integer color
169+ */
157170 public void setTextColor (int color ) {
158171 textView .setTextColor (color );
159172 }
160173
174+ /**
175+ * @param c a single character
176+ */
161177 public void setChar (char c ) {
162178 textView .setText (String .valueOf (c ));
163179 }
164180
181+ /**
182+ * @param size size of textview measured in DP accepts int
183+ */
165184 public void setTextSize (int size ) {
166185 textView .setTextSize (size );
167186 }
168187
169188
170189 public void setRandomColor () {
171190 Random r = new Random ();
172- int R = r .nextInt (70 );
173- int G = r .nextInt (70 );
174- int B = r .nextInt (70 );
175- int color = Color .argb (75 , R , G , B );
176- imageView .setImageBitmap (getRoundedShape (color ));
191+ int [] colorList = getResources ().getIntArray (R .array .materialColor );
192+ // int R = r.nextInt(70);
193+ // int G = r.nextInt(70);
194+ // int B = r.nextInt(70);
195+ // int color = Color.argb(100, R, G, B);
196+
197+ imageView .setImageBitmap (getRoundedShape (colorList [r .nextInt (colorList .length )]));
177198 textView .setTextColor (Color .rgb (255 , 255 , 255 ));
178199 }
179200
201+
202+ /**
203+ * @param height height of avatar
204+ */
180205 public void setBackgroundHeight (int height ) {
181206 ViewGroup .LayoutParams params = imageView .getLayoutParams ();
182207 params .height = height ;
183208 imageView .setLayoutParams (params );
184209 }
185210
211+ /**
212+ * @param width height of avatar
213+ */
186214 public void setBackgroundWidth (int width ) {
187215 ViewGroup .LayoutParams params = imageView .getLayoutParams ();
188216 params .width = width ;
189217 imageView .setLayoutParams (params );
190218 }
191219
220+ /**
221+ * @param string an string, accepts username and sets first word to textview
222+ */
192223 public void setText (String string ) {
193224 char nS = string .charAt (0 );
194225 textView .setText (nS );
195226 }
196227
228+
229+ /**
230+ * @param imageFile a Drawable/Local JPEG,PNG..
231+ * @param imageError Drawable Resource XML invoked on error
232+ * @param scaleType used for scaling the bounds of an image to the bounds of the image view
233+ */
197234 public void setImageSrc (Drawable imageFile , int imageError , ImageView .ScaleType scaleType ) {
198235 imageView .setScaleType (scaleType );
199236 Glide .with (mContext )
@@ -217,6 +254,11 @@ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable>
217254 .into (imageView );
218255 }
219256
257+ /**
258+ * @param imageUrl an absolute URL giving the base location of the image
259+ * @param imageError Drawable Resource XML invoked on error
260+ * @param scaleType used for scaling the bounds of an image to the bounds of the image view
261+ */
220262 public void setImageUrl (String imageUrl , int imageError , ImageView .ScaleType scaleType ) {
221263 imageView .setScaleType (scaleType );
222264 Glide .with (mContext ).load (imageUrl ).circleCrop ().listener (new RequestListener <Drawable >() {
@@ -261,5 +303,6 @@ private Bitmap getRoundedShape(int color) {
261303 new Rect (0 , 0 , targetWidth ,
262304 targetHeight ), null );
263305 return targetBitmap ;
306+
264307 }
265308}
0 commit comments