Skip to content

Commit

Permalink
added sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
santaevpavel committed Jun 29, 2018
1 parent 456bb8d commit ae37e5a
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 12 deletions.
13 changes: 10 additions & 3 deletions Sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

android {
Expand All @@ -25,13 +24,21 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

dataBinding {
enabled = true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation project(':OutlineSpanLib')

kapt "com.android.databinding:compiler:3.1.3"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
13 changes: 11 additions & 2 deletions Sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="santaev.ru.outlinespan">

<application
Expand All @@ -8,8 +9,16 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="ru.santaev.outlinespan.MainActivity"></activity>
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">

<activity android:name="ru.santaev.outlinespan.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
75 changes: 75 additions & 0 deletions Sample/src/main/kotlin/ru/santaev/outlinespan/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package ru.santaev.outlinespan

import android.annotation.SuppressLint
import android.databinding.DataBindingUtil
import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.Spannable
import android.text.SpannableString
import santaev.ru.outlinespan.R
import santaev.ru.outlinespan.databinding.ActivityMainBinding
import java.util.*


class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initUi()
}

@SuppressLint("SetTextI18n")
private fun initUi() {
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)


val outlineSpan = OutlineSpan(
strokeColor = Color.RED,
strokeWidth = 4F
)
val outlineSpanBlue = OutlineSpan(
strokeColor = Color.BLUE,
strokeWidth = 2F
)
val text = "Outlined text"
val spannable = SpannableString(text)
spannable.setSpan(outlineSpan, 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
spannable.setSpan(outlineSpanBlue, 9, text.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

binding.simpleText.text = "Simple text"
binding.outlinedText.text = spannable

updateText()

binding.root.setOnClickListener { updateText() }
}


private fun updateText() {
val outlineSpan = OutlineSpan(
strokeColor = Color.RED,
strokeWidth = 2F
)
val text = getString(R.string.text)
val spannable = SpannableString(text)
val words = text.split(' ')
val idx = Random().nextInt(words.size)
val charIdx = words
.asSequence()
.take(idx)
.sumBy { it.length + 1 }
spannable.setSpan(
outlineSpan,
charIdx,
charIdx + words[idx].length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

binding.outlinedText2.text = spannable
}

}
67 changes: 61 additions & 6 deletions Sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
xmlns:tools="http://schemas.android.com/tools">

</android.support.constraint.ConstraintLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="ru.santaev.outlinespan.MainActivity">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:ignore="UselessParent">

<android.support.v7.widget.AppCompatTextView
android:id="@+id/simpleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="48sp"
app:layout_constraintBottom_toTopOf="@+id/outlinedText2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Simple text" />

<android.support.v7.widget.AppCompatTextView
android:id="@+id/outlinedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="48sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/simpleText"
android:textColor="@android:color/white"
tools:text="Outlined text" />

<android.support.v7.widget.AppCompatTextView
android:id="@+id/outlinedText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/outlinedText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/simpleText"
tools:text="Outlined text" />

</LinearLayout>

</FrameLayout>
</layout>
3 changes: 2 additions & 1 deletion Sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">OutlineSpan</string>
<string name="text" tools:ignore="Typos">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam lectus massa, fermentum at ante quis, finibus bibendum augue. Ut hendrerit porttitor libero vel tincidunt. Ut cursus quam et dui sollicitudin faucibus consectetur non libero. Praesent vel ipsum feugiat, accumsan risus non, pellentesque mauris. Vivamus ut nibh ac arcu blandit auctor finibus eget urna. Phasellus quis metus at purus ultrices varius. Pellentesque ac lacus a ligula ornare ultrices. Sed eu auctor eros. Etiam lobortis ut nibh et auctor. Praesent vitae nibh nibh. Cras ultrices nisi vel ante tincidunt egestas.</string>
</resources>

0 comments on commit ae37e5a

Please sign in to comment.