Skip to content

Commit

Permalink
add letter spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
AndroidLab committed Nov 25, 2023
1 parent 6c037eb commit 289f315
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ plugins {
}

android {
compileSdkVersion 33
compileSdkVersion 34
namespace 'com.a_lab.textarc'

defaultConfig {
applicationId "com.a_lab.textarc"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 34
versionCode 1
versionName "1.0"

Expand All @@ -34,10 +35,7 @@ android {
dependencies {
implementation project(path: ':textarc')


implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.10.0'

testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 24 22:29:14 MSK 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
6 changes: 3 additions & 3 deletions textarc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ plugins {
}

android {
compileSdkVersion 33
compileSdkVersion 34
namespace 'com.a_lab.textarc'

defaultConfig {
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 34
versionCode 1
versionName "1.0"

Expand All @@ -33,7 +34,6 @@ android {
dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
3 changes: 1 addition & 2 deletions textarc/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.a_lab.textarc">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
18 changes: 14 additions & 4 deletions textarc/src/main/java/com/a_lab/textarc/TextArc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.a_lab.textarc
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.util.Log
import android.view.View
import androidx.core.content.res.ResourcesCompat

Expand All @@ -29,6 +30,7 @@ class TextArc @JvmOverloads constructor(

private var textColor = Color.WHITE
private var fontFamily: Typeface? = null
private var letterSpacing: Float = 0f

private val paintText = Paint(Paint.ANTI_ALIAS_FLAG)
private var offset = 0
Expand All @@ -54,13 +56,11 @@ class TextArc @JvmOverloads constructor(
}
}

letterSpacing = typedArray.getFloat(R.styleable.TextArc_letter_spacing, letterSpacing)

typedArray.recycle();
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()

}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
Expand All @@ -76,6 +76,7 @@ class TextArc @JvmOverloads constructor(
paintText.color = textColor
paintText.typeface = fontFamily
paintText.textSize = textSize.toFloat()
paintText.letterSpacing = letterSpacing

super.onLayout(changed, left, top, right, bottom)
}
Expand Down Expand Up @@ -151,4 +152,13 @@ class TextArc @JvmOverloads constructor(
invalidate()
}

/**
* Sets letter spacing.
* @param letterSpacing Letter spacing.
*/
fun setLetterSpacing(letterSpacing: Float) {
this.letterSpacing = letterSpacing
invalidate()
}

}
1 change: 1 addition & 0 deletions textarc/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<attr name="text_size" format="dimension"/>
<attr name="text_color" format="color"/>
<attr name="font_family" format="reference"/>
<attr name="letter_spacing" format="float"/>
<attr name="text" format="string"/>

</declare-styleable>
Expand Down

0 comments on commit 289f315

Please sign in to comment.