Skip to content

Commit 440769b

Browse files
authored
Merge pull request #1 from lazycoder-21/font_awesome_icon
Font awesome icon
2 parents d2f1f54 + 482f0b9 commit 440769b

File tree

15 files changed

+184
-26
lines changed

15 files changed

+184
-26
lines changed

.idea/misc.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@ repositories {
77
```
88

99
Now in build.gradle -> <br/>
10-
11-
<li>
12-
font awesome icon, for more detail switch to `font_awesome_icon` branch
13-
</li>
14-
1510
```
1611
com.github.lostankit7:androidCustomView:font_awesome_icon_v1.1
1712
```
1813

14+
To use font awesome icon through XML
15+
16+
```
17+
<lostankit7.droid.customview.FontAwesomeIcon
18+
android:id="@+id/textView"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_centerInParent="true"
22+
android:gravity="center"
23+
android:padding="10dp"
24+
android:text="\uf058"
25+
android:textColor="@color/purple_200"
26+
android:textSize="25sp"
27+
app:background_circular="true"
28+
app:background_color="@color/white"
29+
app:corner_radius="10dp"
30+
android:clickable="true"
31+
app:icon_type="fa_solid"
32+
app:show_ripple="true"
33+
app:show_stroke="true"
34+
app:stroke_color="#A5B439"
35+
app:stroke_width="1dp" />
36+
37+
```

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ android {
3434
dependencies {
3535

3636
implementation 'androidx.appcompat:appcompat:1.4.1'
37-
//implementation project(path: ':customView')
37+
implementation project(path: ':customView')
3838
}

app/src/main/java/lostankit7/droid/androidcustomview/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package lostankit7.droid.androidcustomview
22

33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
5+
import lostankit7.droid.customview.FontAwesomeIcon
56

67
class MainActivity : AppCompatActivity() {
78
override fun onCreate(savedInstanceState: Bundle?) {

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9-
<TextView
9+
<lostankit7.droid.customview.FontAwesomeIcon
1010
android:id="@+id/textView"
11-
android:layout_width="100dp"
12-
android:gravity="center"
13-
android:textColor="@color/white"
14-
android:layout_height="50dp"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
1513
android:layout_centerInParent="true"
16-
android:text="Hello World!" />
14+
android:gravity="center"
15+
android:padding="10dp"
16+
android:text="\uf058"
17+
android:textColor="@color/purple_200"
18+
android:textSize="25sp"
19+
app:background_circular="true"
20+
app:background_color="@color/white"
21+
app:corner_radius="10dp"
22+
android:clickable="true"
23+
app:icon_type="fa_solid"
24+
app:show_ripple="true"
25+
app:show_stroke="true"
26+
app:stroke_color="#A5B439"
27+
app:stroke_width="1dp" />
1728

1829
</RelativeLayout>

customView/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ afterEvaluate {
4545
from components.release
4646

4747
groupId = 'com.github.lostankit7'
48-
artifactId = ''
48+
artifactId = 'font-aweomse-icon'
4949
version = '1.1'
5050
}
5151
}
32.9 KB
Binary file not shown.
198 KB
Binary file not shown.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package lostankit7.droid.customview
2+
3+
import android.content.Context
4+
import android.content.res.TypedArray
5+
import android.util.AttributeSet
6+
import androidx.appcompat.widget.AppCompatTextView
7+
import lostankit7.droid.utils.*
8+
import lostankit7.droid.utils.DEF_BG_CIRCULAR
9+
import lostankit7.droid.utils.DEF_CORNER_RADIUS
10+
import lostankit7.droid.utils.NO_COLOR
11+
12+
/**
13+
* @property p change fontawesome icon type : from xml [icon_type] or updateTypeface(@FontAwesomeIconType),
14+
* border properties - [show_stroke] , [stroke_width], [stroke_color],
15+
* ripple effect on click - [show_ripple], [ripple_color], [mask_color],
16+
* background properties - [background_color] , [background_circular], [corner_radius]
17+
* @author AnkitKumar
18+
*/
19+
class FontAwesomeIcon
20+
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
21+
AppCompatTextView(context, attrs, defStyleAttr) {
22+
23+
init {
24+
text = "\uf058"
25+
val arr = context.obtainStyledAttributes(attrs, R.styleable.FontAwesomeIcon)
26+
manageAttributes(arr)
27+
arr.recycle()
28+
}
29+
30+
private fun manageAttributes(arr: TypedArray) = with(arr) {
31+
32+
try {
33+
updateTypeface(
34+
getInt(R.styleable.FontAwesomeIcon_icon_type, FontAwesomeIconType.REGULAR)
35+
)
36+
37+
val bgColor = getColor(R.styleable.FontAwesomeIcon_background_color, NO_COLOR)
38+
39+
val isBgCircular =
40+
getBoolean(R.styleable.FontAwesomeIcon_background_circular, DEF_BG_CIRCULAR)
41+
val cornerRadius =
42+
getDimension(R.styleable.FontAwesomeIcon_corner_radius, DEF_CORNER_RADIUS)
43+
44+
val setStroke = getBoolean(R.styleable.FontAwesomeIcon_show_stroke, DEF_SET_STROKE)
45+
val strokeWidth =
46+
getDimension(R.styleable.FontAwesomeIcon_stroke_width, DEF_STROKE_WIDTH)
47+
val strokeColor = getColor(R.styleable.FontAwesomeIcon_stroke_color, DEF_STROKE_COLOR)
48+
49+
val showRipple = getBoolean(R.styleable.FontAwesomeIcon_show_ripple, DEF_SHOW_RIPPLE)
50+
val rippleColor = getColor(R.styleable.FontAwesomeIcon_ripple_color, DEF_RIPPLE_COLOR)
51+
val maskColor = getColor(R.styleable.FontAwesomeIcon_mask_color, DEF_MASK_COLOR)
52+
53+
if(!setStroke && !showRipple) return@with
54+
55+
if (isBgCircular) setCircularBackground(
56+
bgColor, strokeColor, strokeWidth, showRipple, rippleColor, maskColor
57+
) else
58+
setCustomBackground(
59+
bgColor, cornerRadius, strokeColor, strokeWidth,
60+
showRipple, rippleColor, maskColor
61+
)
62+
63+
} catch (e: Exception) {
64+
}
65+
}
66+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package lostankit7.droid.customview
2+
3+
import androidx.annotation.IntDef
4+
5+
@IntDef(FontAwesomeIconType.REGULAR, FontAwesomeIconType.SOLID, FontAwesomeIconType.BRAND)
6+
@Retention(AnnotationRetention.SOURCE)
7+
annotation class FontAwesomeIconType {
8+
companion object {
9+
const val REGULAR = 0
10+
const val SOLID = 1
11+
const val BRAND = 2
12+
}
13+
}

0 commit comments

Comments
 (0)