Skip to content

Commit

Permalink
Support text switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Vacxe committed Jun 8, 2023
1 parent e67cf3b commit 4a2505e
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 1 deletion.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@file:Suppress("unused")

package io.github.kakaocup.kakao.viewswitcher

import android.view.View
import android.widget.EditText
import androidx.test.espresso.DataInteraction
import io.github.kakaocup.kakao.common.builders.ViewBuilder
import io.github.kakaocup.kakao.common.views.KBaseView
import io.github.kakaocup.kakao.edit.KEditText
import io.github.kakaocup.kakao.text.KTextView
import org.hamcrest.Matcher

class KTextSwitcher : KBaseView<KTextSwitcher>, TextSwitcherAssertions {
constructor(function: ViewBuilder.() -> Unit) : super(function)
constructor(parent: Matcher<View>, function: ViewBuilder.() -> Unit) : super(parent, function)
constructor(parent: DataInteraction, function: ViewBuilder.() -> Unit) : super(parent, function)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.kakaocup.sample

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import io.github.kakaocup.kakao.screen.Screen
import io.github.kakaocup.sample.screen.SwitchersScreen
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4ClassRunner::class)
class SwitchersViewTest {
@Rule
@JvmField
val rule = ActivityScenarioRule(SwitchersActivity::class.java)

@Test
fun testTextSwitcher() {
Screen.onScreen<SwitchersScreen> {
textSwitcher {
hasText("Counter: 1")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.kakaocup.sample.screen

import io.github.kakaocup.kakao.screen.Screen
import io.github.kakaocup.kakao.viewswitcher.ViewSwitcher
import io.github.kakaocup.sample.R

class SwitchersScreen : Screen<SwitchersScreen>() {
val textSwitcher = ViewSwitcher { withId(R.id.text_switcher) }
}
5 changes: 4 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
android:name="io.github.kakaocup.sample.TabLayoutActivity"
android:label="Tab Layout Activity"
android:theme="@style/MaterialAppTheme" />

<activity
android:name="io.github.kakaocup.sample.SwitchersActivity"
android:label="Text Switcher Activity"
android:theme="@style/MaterialAppTheme" />
<activity
android:name="io.github.kakaocup.sample.LinearLayoutActivity"
android:label="Linear Layout activity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.kakaocup.sample

import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import android.widget.Button
import android.widget.TextSwitcher
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class SwitchersActivity : AppCompatActivity() {

private val textSwitcher: TextSwitcher by lazy { findViewById(R.id.text_switcher) }
private val nextButton: Button by lazy { findViewById(R.id.next) }

private var counter = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_textswitcher)
textSwitcher.setFactory {
val textView = TextView(this)
textView.textSize = 24f
textView.gravity = Gravity.CENTER_HORIZONTAL
textView.setTextColor(Color.parseColor("#0F9D58"))
textView
}
textSwitcher.setCurrentText(getNextText())
nextButton.setOnClickListener {
textSwitcher.setText(getNextText())
}
}

private fun getNextText(): String {
counter++
return "Counter: $counter"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TestActivity : AppCompatActivity() {
addRoute(R.id.slider_button, SliderActivity::class.java)
addRoute(R.id.text_input_layout, TextInputLayoutActivity::class.java)
addRoute(R.id.text_activity, TextActivity::class.java)
addRoute(R.id.switchers_button, SwitchersActivity::class.java)

findViewById<Button>(R.id.snackbar_button).setOnClickListener {
val snackbar = Snackbar.make(
Expand Down
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
android:layout_height="wrap_content"
android:text="TEXT VIEWS" />

<Button
android:id="@+id/switchers_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SWITCHERS"/>

<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
Expand Down
16 changes: 16 additions & 0 deletions sample/src/main/res/layout/activity_textswitcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/top_layout">

<TextSwitcher android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_switcher"/>

<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/next"
android:text="Next"/>

</LinearLayout>

0 comments on commit 4a2505e

Please sign in to comment.