-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support text switcher * Support text switcher
- Loading branch information
Showing
9 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
kakao/src/main/kotlin/io/github/kakaocup/kakao/common/matchers/SwitcherCurrentViewMatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@file:Suppress("unused") | ||
|
||
package io.github.kakaocup.kakao.common.matchers | ||
|
||
import android.view.View | ||
import android.widget.ViewSwitcher | ||
import androidx.test.espresso.matcher.BoundedMatcher | ||
import org.hamcrest.Description | ||
|
||
/** | ||
* Matches current view in View Switcher | ||
*/ | ||
class SwitcherCurrentViewMatcher : BoundedMatcher<View, View>(View::class.java) { | ||
override fun matchesSafely(view: View?) = view?.let { | ||
(it.parent as ViewSwitcher).currentView.equals(it) | ||
} ?: false | ||
|
||
override fun describeTo(description: Description) { | ||
description.appendText("Can't match current view for Switcher") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
sample/src/androidTest/kotlin/io/github/kakaocup/sample/SwitchersViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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") | ||
} | ||
|
||
nextButton.click() | ||
|
||
textSwitcher { | ||
hasText("Counter: 2") | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
sample/src/androidTest/kotlin/io/github/kakaocup/sample/screen/SwitchersScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.kakaocup.sample.screen | ||
|
||
import io.github.kakaocup.kakao.common.matchers.SwitcherCurrentViewMatcher | ||
import io.github.kakaocup.kakao.screen.Screen | ||
import io.github.kakaocup.kakao.text.KButton | ||
import io.github.kakaocup.kakao.text.KTextView | ||
import io.github.kakaocup.sample.R | ||
|
||
class SwitchersScreen : Screen<SwitchersScreen>() { | ||
val textSwitcher: KTextView | ||
get() { | ||
return KTextView { | ||
withParent { | ||
withId(R.id.text_switcher) | ||
} | ||
withMatcher(SwitcherCurrentViewMatcher()) | ||
} | ||
} | ||
|
||
val nextButton = KButton { | ||
withId(R.id.next) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sample/src/main/kotlin/io/github/kakaocup/sample/SwitchersActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |