Commit 3b6cd416 authored by Mygod's avatar Mygod

Prevent status text from overflowing

parent 9b876446
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package com.github.shadowsocks.widget package com.github.shadowsocks.widget
import android.content.Context import android.content.Context
import android.os.Build
import android.text.format.Formatter import android.text.format.Formatter
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
...@@ -70,21 +71,26 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet? ...@@ -70,21 +71,26 @@ class StatsBar @JvmOverloads constructor(context: Context, attrs: AttributeSet?
super.setOnClickListener(l) super.setOnClickListener(l)
} }
private fun setStatus(text: CharSequence) {
statusText.text = text
if (Build.VERSION.SDK_INT >= 26) statusText.tooltipText = text
}
fun changeState(state: BaseService.State) { fun changeState(state: BaseService.State) {
val activity = context as MainActivity val activity = context as MainActivity
if (state != BaseService.State.Connected) { if (state != BaseService.State.Connected) {
updateTraffic(0, 0, 0, 0) updateTraffic(0, 0, 0, 0)
tester.status.removeObservers(activity) tester.status.removeObservers(activity)
if (state != BaseService.State.Idle) tester.invalidate() if (state != BaseService.State.Idle) tester.invalidate()
statusText.setText(when (state) { setStatus(context.getText(when (state) {
BaseService.State.Connecting -> R.string.connecting BaseService.State.Connecting -> R.string.connecting
BaseService.State.Stopping -> R.string.stopping BaseService.State.Stopping -> R.string.stopping
else -> R.string.not_connected else -> R.string.not_connected
}) }))
} else { } else {
behavior.slideUp(this) behavior.slideUp(this)
tester.status.observe(activity, Observer { tester.status.observe(activity, Observer {
it.retrieve(statusText::setText) { activity.snackbar(it).show() } it.retrieve(this::setStatus) { activity.snackbar(it).show() }
}) })
} }
} }
......
...@@ -106,13 +106,14 @@ ...@@ -106,13 +106,14 @@
android:id="@+id/status" android:id="@+id/status"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="marquee" android:maxLines="1"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp" android:textSize="16sp"
android:layout_gravity="fill_horizontal" android:layout_gravity="fill_horizontal"
android:layout_row="2" android:layout_row="2"
android:layout_column="0" android:layout_column="0"
android:layout_columnSpan="3" android:layout_columnSpan="3"
style="@style/stats_status"
tools:text="@string/connection_test_available"/> tools:text="@string/connection_test_available"/>
</GridLayout> </GridLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="stats_status">
<item name="android:ellipsize">end</item>
</style>
</resources>
...@@ -4,4 +4,7 @@ ...@@ -4,4 +4,7 @@
<item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:statusBarColor">@android:color/transparent</item>
</style> </style>
<style name="stats_status">
<item name="android:ellipsize">marquee</item>
</style>
</resources> </resources>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment