mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Update to better FontAwesome functions
https://github.com/finnmglas/fontawesome-android
This commit is contained in:
parent
53a43f3eb2
commit
68b690aa31
3 changed files with 58 additions and 82 deletions
|
@ -7,87 +7,45 @@ import android.graphics.Typeface
|
|||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
|
||||
/** [FontAwesome] is just a type of TextView with special functions:
|
||||
*
|
||||
* `setText(str)` can be used to change the icon
|
||||
* `setIconType(Int)` changes the FontAwesome style ("solid", "regular" or "brand")
|
||||
* `setTextColor(Int)` changes the color
|
||||
* `setTextSize(Int, Float)` changes the icon size
|
||||
*/
|
||||
|
||||
class FontAwesomeSolid : AppCompatTextView {
|
||||
constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet?,
|
||||
defStyle: Int
|
||||
) : super(context, attrs, defStyle) {
|
||||
init()
|
||||
class FontAwesome : AppCompatTextView {
|
||||
|
||||
var type = "" // "solid", "regular" or "brand"
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int)
|
||||
: super(context, attrs, defStyle) { init(attrs) }
|
||||
constructor(context: Context?, attrs: AttributeSet?)
|
||||
: super(context, attrs) { init(attrs) }
|
||||
constructor(context: Context?)
|
||||
: super(context) { init(null) }
|
||||
|
||||
private fun init(attrs: AttributeSet?) {
|
||||
if (attrs != null) {
|
||||
val a = context!!.obtainStyledAttributes(attrs, R.styleable.FontAwesome)
|
||||
if (a.hasValue(R.styleable.FontAwesome_type))
|
||||
type = a.getString(R.styleable.FontAwesome_type)!!
|
||||
a.recycle()
|
||||
if (type == "") type = "solid"
|
||||
}
|
||||
setIconType(type)
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
||||
context,
|
||||
attrs
|
||||
) {
|
||||
init()
|
||||
}
|
||||
// Useful if you want to change between a regular and solid icon (example: star)
|
||||
fun setIconType(iconType : String){
|
||||
type = iconType
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
typeface = Typeface.createFromAsset(
|
||||
context.assets,
|
||||
"fontawesome/fa-solid-900.ttf"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class FontAwesomeRegular : AppCompatTextView {
|
||||
constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet?,
|
||||
defStyle: Int
|
||||
) : super(context, attrs, defStyle) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
||||
context,
|
||||
attrs
|
||||
) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
typeface = Typeface.createFromAsset(
|
||||
context.assets,
|
||||
"fontawesome/fa-regular-400.ttf"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class FontAwesomeBrand : AppCompatTextView {
|
||||
constructor(
|
||||
context: Context?,
|
||||
attrs: AttributeSet?,
|
||||
defStyle: Int
|
||||
) : super(context, attrs, defStyle) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
||||
context,
|
||||
attrs
|
||||
) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
typeface = Typeface.createFromAsset(
|
||||
context.assets,
|
||||
"fontawesome/fa-brands-400.ttf"
|
||||
)
|
||||
typeface = when (type) {
|
||||
"regular" -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-regular-400.ttf")
|
||||
"solid" -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-solid-900.ttf")
|
||||
"brands" -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-brands-400.ttf")
|
||||
else -> Typeface.createFromAsset(context!!.assets,"fontawesome/fa-solid-900.ttf")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
8
app/src/main/res/values/attrs.xml
Normal file
8
app/src/main/res/values/attrs.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- This declares attributes for the FontAwesome TextView -->
|
||||
<resources>
|
||||
<declare-styleable name="FontAwesome">
|
||||
<attr name="type" format="string" />
|
||||
</declare-styleable>
|
||||
</resources>
|
|
@ -1,11 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- icons that can be used with type="solid" -->
|
||||
<string name="fas_bars" translatable="false"></string>
|
||||
<string name="fas_home" translatable="false"></string>
|
||||
<string name="fas_globe" translatable="false"></string>
|
||||
<string name="fas_settings" translatable="false"></string>
|
||||
<string name="fas_close_window" translatable="false"></string>
|
||||
<string name="fas_star" translatable="false"></string>
|
||||
<string name="fas_globe" translatable="false"></string>
|
||||
<string name="fas_ad" translatable="false"></string>
|
||||
<string name="fas_backspace" translatable="false"></string>
|
||||
<string name="fas_calendar" translatable="false"></string>
|
||||
|
||||
<string name="far_star" translatable="false"></string>
|
||||
<!-- icons that can be used with type="brands" -->
|
||||
<string name="fab_apple" translatable="false"></string>
|
||||
<string name="fab_instagram" translatable="false"></string>
|
||||
|
||||
<!-- icons that can be used with type="solid" and type="regular" -->
|
||||
<string name="fa_close_window" translatable="false"></string>
|
||||
<string name="fa_square" translatable="false"></string>
|
||||
<string name="fa_star" translatable="false"></string>
|
||||
<string name="fa_clipboard" translatable="false"></string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue