From d4101c7bdf9fec3ed49f26561afa07c0f5ef93fa Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 20 Nov 2017 13:55:50 +0100 Subject: [PATCH] Page indicator now uses an outline instead of overlapping shadows --- .../ui/reader/PageIndicatorTextView.kt | 43 +++++++++++++++++-- app/src/main/res/layout/reader_activity.xml | 6 +-- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt index 7aff4c97e..9b8edcbfb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/PageIndicatorTextView.kt @@ -1,17 +1,54 @@ package eu.kanade.tachiyomi.ui.reader +import android.annotation.SuppressLint import android.content.Context import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint import android.support.v7.widget.AppCompatTextView +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ScaleXSpan import android.util.AttributeSet +import android.widget.TextView class PageIndicatorTextView(context: Context, attrs: AttributeSet? = null) : AppCompatTextView(context, attrs) { override fun onDraw(canvas: Canvas) { - // We want the shadow to look like an outline - for (i in 0..5) { - super.onDraw(canvas) + val textColor = textColors.defaultColor + textColorField.set(this, Color.BLACK) + paint.strokeWidth = 4f + paint.style = Paint.Style.STROKE + super.onDraw(canvas) + + textColorField.set(this, textColor) + paint.strokeWidth = 0f + paint.style = Paint.Style.FILL + super.onDraw(canvas) + } + + @SuppressLint("SetTextI18n") + override fun setText(text: CharSequence?, type: BufferType?) { + // Add spaces at the start & end of the text, otherwise the stroke is cut-off because it's + // not taken into account when measuring the text (view's padding doesn't help). + val currText = " $text " + + // Also add a bit of spacing between each character, as the stroke overlaps them + val finalText = SpannableString(currText.asIterable().joinToString("\u00A0")) + + for (i in 1..finalText.lastIndex step 2) { + finalText.setSpan(ScaleXSpan(0.1f), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) } + + super.setText(finalText, TextView.BufferType.SPANNABLE) + } + + private companion object { + // We need to use reflection to set the text color instead of using [setTextColor], + // otherwise the view is invalidated inside [onDraw] and there's an infinite loop + val textColorField = TextView::class.java.getDeclaredField("mCurTextColor").apply { + isAccessible = true + }!! } } \ No newline at end of file diff --git a/app/src/main/res/layout/reader_activity.xml b/app/src/main/res/layout/reader_activity.xml index b1040c4d4..ec5599a3a 100644 --- a/app/src/main/res/layout/reader_activity.xml +++ b/app/src/main/res/layout/reader_activity.xml @@ -31,11 +31,7 @@ android:layout_gravity="bottom|center_horizontal" android:padding="4dp" android:textColor="@color/md_white_1000" - android:textStyle="bold" - android:shadowRadius="3" - android:shadowDy="0" - android:shadowDx="0" - android:shadowColor="@color/md_black_1000"/> + android:textStyle="bold" />