Skip to content

Commit 41c8369

Browse files
author
mobyiapps
committed
Update
1 parent 0e54710 commit 41c8369

File tree

3 files changed

+89
-11
lines changed

3 files changed

+89
-11
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,21 @@
118118
<com.dvinfosys.widgets.TextView.GradientTextView
119119
android:layout_width="match_parent"
120120
android:layout_height="wrap_content"
121+
android:gravity="center"
121122
android:text="Gradient TextView"
122123
android:textSize="18dp"
123-
android:gravity="center"
124124
app:gradientEnd="#6673E7"
125125
app:gradientStart="#FF0000" />
126126

127+
<com.dvinfosys.widgets.TextView.GradientBoldTextView
128+
android:layout_width="match_parent"
129+
android:layout_height="wrap_content"
130+
android:gravity="center"
131+
android:text="Gradient Bold TextView"
132+
android:textSize="18dp"
133+
app:endColor="@color/colorPrimaryDark"
134+
app:startColor="@color/colorAccent" />
135+
127136
<com.dvinfosys.widgets.VideoPlayer.VPVideoPlayerStandard
128137
android:id="@+id/vp_videoplayer"
129138
android:layout_width="match_parent"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.dvinfosys.widgets.TextView;
2+
3+
import android.annotation.TargetApi;
4+
import android.content.Context;
5+
import android.content.res.TypedArray;
6+
import android.graphics.LinearGradient;
7+
import android.graphics.Shader;
8+
import android.graphics.Typeface;
9+
import android.os.Build;
10+
import android.util.AttributeSet;
11+
import android.widget.TextView;
12+
13+
import com.dvinfosys.widgets.R;
14+
import com.dvinfosys.widgets.Utils.TextFontCache;
15+
16+
/**
17+
* Created by DV Bhuva on 27/06/19.
18+
*/
19+
20+
public class GradientBoldTextView extends TextView {
21+
22+
int startColor, endColor;
23+
Shader shader;
24+
25+
public GradientBoldTextView(Context context) {
26+
super(context);
27+
}
28+
29+
public GradientBoldTextView(Context context, AttributeSet attrs) {
30+
super(context, attrs);
31+
if (!isInEditMode())
32+
createShader(context, attrs, 0);
33+
}
34+
35+
public GradientBoldTextView(Context context, AttributeSet attrs, int defStyleAttr) {
36+
super(context, attrs, defStyleAttr);
37+
if (!isInEditMode())
38+
createShader(context, attrs, defStyleAttr);
39+
}
40+
41+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
42+
public GradientBoldTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
43+
super(context, attrs, defStyleAttr, defStyleRes);
44+
if (!isInEditMode())
45+
createShader(context, attrs, defStyleAttr);
46+
}
47+
48+
49+
public void createShader(Context context, AttributeSet attrs, int defStyleAttr) {
50+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GradientBoldTextView, defStyleAttr, 0);
51+
try {
52+
startColor = a.getInt(R.styleable.GradientBoldTextView_startColor, 0);
53+
endColor = a.getInt(R.styleable.GradientBoldTextView_endColor, 0);
54+
shader = new LinearGradient(0, 0, 0, getTextSize(),
55+
new int[]{startColor, endColor},
56+
new float[]{0, 1}, Shader.TileMode.CLAMP);
57+
getPaint().setShader(shader);
58+
} finally {
59+
a.recycle();
60+
}
61+
Typeface customFont = TextFontCache.getTypeface("Poppins_Bold.ttf", context);
62+
setTypeface(customFont);
63+
}
64+
}

libraries/src/main/res/values/attrs.xml

+15-10
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,42 @@
7070
<enum name="serif" value="3" />
7171
</attr>
7272
</declare-styleable>
73-
73+
7474
<declare-styleable name="CustomTextView">
75-
<attr name="font_name" format="string"/>
75+
<attr name="font_name" format="string" />
7676
</declare-styleable>
7777

7878
<declare-styleable name="CustomButton">
79-
<attr name="button_font" format="string"/>
79+
<attr name="button_font" format="string" />
8080
</declare-styleable>
8181

8282
<declare-styleable name="CustomEditText">
83-
<attr name="edittext_font" format="string"/>
83+
<attr name="edittext_font" format="string" />
8484
</declare-styleable>
8585

8686
<declare-styleable name="CustomCheckBox">
87-
<attr name="checkbox_font" format="string"/>
87+
<attr name="checkbox_font" format="string" />
8888
</declare-styleable>
8989

9090
<declare-styleable name="CustomRadioButton">
91-
<attr name="radiobutton_font" format="string"/>
91+
<attr name="radiobutton_font" format="string" />
9292
</declare-styleable>
9393

9494
<declare-styleable name="CustomSwitch">
95-
<attr name="switch_font" format="string"/>
95+
<attr name="switch_font" format="string" />
9696
</declare-styleable>
9797

9898
<declare-styleable name="CustomToggleButton">
99-
<attr name="togglebutton_font" format="string"/>
99+
<attr name="togglebutton_font" format="string" />
100100
</declare-styleable>
101101

102102
<declare-styleable name="GradientTextView">
103-
<attr name="gradientStart"/>
104-
<attr name="gradientEnd"/>
103+
<attr name="gradientStart" format="color" />
104+
<attr name="gradientEnd" format="color" />
105+
</declare-styleable>
106+
<declare-styleable name="GradientBoldTextView">
107+
<attr name="startColor" format="color" />
108+
<attr name="endColor" format="color" />
109+
105110
</declare-styleable>
106111
</resources>

0 commit comments

Comments
 (0)