Skip to content

Commit 5ccb4cf

Browse files
author
Ayush Naik
committed
material colors only, @params
1 parent d71aaba commit 5ccb4cf

11 files changed

Lines changed: 137 additions & 30 deletions

File tree

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
app:text="James"
2424
android:layout_centerHorizontal="true"
2525
android:layout_centerVertical="true"
26-
app:backgroundWidth="400"
27-
app:backgroundHeight="400"
28-
app:textSize="56"
26+
app:backgroundWidth="220"
27+
app:backgroundHeight="220"
28+
app:textSize="26"
2929
app:imageSrc="@drawable/jordan" />
3030

3131
<com.RevelationCoding.mylibrary.AndroidAvatar

art/avatar_back.svg

Lines changed: 21 additions & 0 deletions
Loading

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ allprojects {
1616
repositories {
1717
google()
1818
mavenCentral()
19-
19+
maven { url 'https://jitpack.io' }
2020
}
2121
}
2222

mylibrary/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
targetSdkVersion 30
1212
versionCode 1
1313
versionName "1.0"
14-
14+
vectorDrawables.useSupportLibrary = true
1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
consumerProguardFiles "consumer-rules.pro"
1717
}
@@ -37,4 +37,5 @@ dependencies {
3737
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
3838
implementation 'com.github.bumptech.glide:glide:4.12.0'
3939
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
40+
4041
}

mylibrary/src/main/java/com/RevelationCoding/mylibrary/AndroidAvatar.java

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import android.graphics.Color;
88
import android.graphics.Path;
99
import android.graphics.Rect;
10+
import android.graphics.drawable.BitmapDrawable;
1011
import android.graphics.drawable.Drawable;
12+
import android.os.Handler;
13+
import android.os.Looper;
1114
import android.util.AttributeSet;
1215
import android.view.KeyEvent;
1316
import android.view.MotionEvent;
@@ -20,6 +23,7 @@
2023
import android.widget.TextView;
2124

2225
import androidx.annotation.Nullable;
26+
import androidx.core.os.HandlerCompat;
2327

2428
import com.bumptech.glide.Glide;
2529
import com.bumptech.glide.load.DataSource;
@@ -29,6 +33,8 @@
2933
import com.bumptech.glide.request.target.Target;
3034

3135
import java.util.Random;
36+
import java.util.concurrent.ExecutorService;
37+
import java.util.concurrent.Executors;
3238

3339
public 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
}

mylibrary/src/main/res/drawable/oval.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
xmlns:android="http://schemas.android.com/apk/res/android"
77
android:shape="oval">
88

9-
<!-- <solid-->
10-
<!-- android:color="#000000"/>-->
9+
<solid
10+
android:color="@color/light_blue"/>
1111

1212
<size
1313
android:width="480dp"
@@ -17,6 +17,7 @@
1717

1818
</shape>
1919
</item>
20+
2021
<!-- <item-->
2122
<!-- android:id="@+id/ripple_item"-->
2223
<!-- android:drawable="?attr/selectableItemBackgroundBorderless"-->

mylibrary/src/main/res/drawable/ripple.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
<item
2121
android:id="@+id/ripple_item"
2222
android:drawable="?attr/selectableItemBackgroundBorderless"
23-
android:gravity="center" />
23+
android:gravity="center"/>
2424
</layer-list>

mylibrary/src/main/res/layout/avatar_layout.xml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
android:layout_height="wrap_content"
55
xmlns:app="http://schemas.android.com/apk/res-auto"
66
android:layout_centerInParent="true"
7-
android:layout_gravity="center"
8-
>
7+
android:layout_gravity="center">
98
<ProgressBar
109
android:layout_centerInParent="true"
1110
android:layout_width="wrap_content"
@@ -15,15 +14,23 @@
1514
android:id="@+id/progress_bar"
1615
android:visibility="invisible"/>
1716

17+
<LinearLayout
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_centerInParent="true"
21+
android:elevation="6dp" />
22+
1823
<ImageButton
1924
android:orientation="vertical"
2025
android:id="@+id/LLRipple"
2126
android:layout_width="wrap_content"
2227
android:layout_height="wrap_content"
23-
android:elevation="15dp"
24-
android:translationZ="2dp"
28+
android:elevation="5dp"
29+
android:layout_centerInParent="true"
30+
android:translationZ="1dp"
2531
android:outlineProvider="background"
26-
android:background="@drawable/ripple"/>
32+
android:background="@drawable/ripple"
33+
android:layout_margin="5dp"/>
2734

2835
<ImageButton
2936
android:layout_centerInParent="true"
@@ -32,10 +39,9 @@
3239
android:layout_height="200dp"
3340
android:background="@drawable/oval"
3441
android:outlineProvider="background"
35-
android:translationZ="2dp"
36-
android:elevation="14dp">
37-
38-
</ImageButton>
42+
android:translationZ="1dp"
43+
android:elevation="4dp"
44+
android:layout_margin="5dp"/>
3945

4046

4147
<TextView
@@ -49,6 +55,12 @@
4955
android:fontFamily="@font/titillium_web_bold"
5056
android:text="A"
5157
android:textAlignment="center"
52-
android:textColor="#fff"
53-
android:textSize="65dp" />
58+
android:textColor="#FFF"
59+
android:textSize="85dp"
60+
android:shadowColor="@color/transparent"
61+
android:shadowDx="8"
62+
android:shadowDy="8"
63+
android:shadowRadius="10"
64+
android:paddingRight="6dp"
65+
android:paddingLeft="6dp" />
5466
</RelativeLayout>

0 commit comments

Comments
 (0)