parent
6d98e6748c
commit
878f512c51
@ -1,77 +0,0 @@ |
||||
package io.legado.app.ui.widget |
||||
|
||||
import android.content.Context |
||||
import android.graphics.Bitmap |
||||
import android.graphics.Canvas |
||||
import android.graphics.Rect |
||||
import android.graphics.drawable.GradientDrawable |
||||
import android.util.AttributeSet |
||||
import android.util.Log |
||||
import android.view.MotionEvent |
||||
import androidx.appcompat.widget.AppCompatTextView |
||||
import io.legado.app.utils.screenshot |
||||
import kotlin.math.abs |
||||
|
||||
class PageView(context: Context, attrs: AttributeSet) : AppCompatTextView(context, attrs) { |
||||
|
||||
private var bitmap: Bitmap? = null |
||||
|
||||
private var downX: Float = 0.toFloat() |
||||
private var offset: Float = 0.toFloat() |
||||
|
||||
private val srcRect: Rect = Rect() |
||||
private val destRect: Rect = Rect() |
||||
private val shadowDrawable: GradientDrawable |
||||
|
||||
init { |
||||
val shadowColors = intArrayOf(0x66111111, 0x00000000) |
||||
shadowDrawable = GradientDrawable( |
||||
GradientDrawable.Orientation.LEFT_RIGHT, shadowColors |
||||
) |
||||
shadowDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT |
||||
} |
||||
|
||||
override fun onDraw(canvas: Canvas?) { |
||||
canvas?.save() |
||||
super.onDraw(canvas) |
||||
canvas?.restore() |
||||
|
||||
|
||||
bitmap?.let { |
||||
srcRect.set(0, 0, width, height) |
||||
destRect.set(-width + offset.toInt(), 0, offset.toInt(), height) |
||||
canvas?.drawBitmap(it, srcRect, destRect, null) |
||||
addShadow(offset.toInt(), canvas) |
||||
} |
||||
} |
||||
|
||||
//添加阴影 |
||||
private fun addShadow(left: Int, canvas: Canvas?) { |
||||
canvas?.let { |
||||
shadowDrawable.setBounds(left, 0, left + 30, height) |
||||
shadowDrawable.draw(it) |
||||
} |
||||
} |
||||
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean { |
||||
when (event?.action) { |
||||
MotionEvent.ACTION_DOWN -> { |
||||
bitmap = screenshot() |
||||
Log.e("TAG", "bitmap == null: " + (bitmap == null)) |
||||
downX = event.x |
||||
offset = 0.toFloat() |
||||
invalidate() |
||||
} |
||||
MotionEvent.ACTION_MOVE -> { |
||||
offset = abs(event.x - downX) |
||||
invalidate() |
||||
} |
||||
MotionEvent.ACTION_UP -> { |
||||
bitmap = null |
||||
invalidate() |
||||
} |
||||
} |
||||
|
||||
return true |
||||
} |
||||
} |
@ -0,0 +1,12 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
interface DataSource { |
||||
|
||||
fun getChapterPosition() |
||||
|
||||
fun getChapter(position: Int): TextChapter |
||||
|
||||
fun getNextChapter(): TextChapter |
||||
|
||||
fun getPreviousChapter(): TextChapter |
||||
} |
@ -0,0 +1,39 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
import android.widget.Scroller |
||||
import androidx.interpolator.view.animation.FastOutLinearInInterpolator |
||||
|
||||
abstract class PageAnimDelegate(protected val pageView: PageView) { |
||||
|
||||
protected val scroller: Scroller = Scroller(pageView.context, FastOutLinearInInterpolator()) |
||||
|
||||
//起始点 |
||||
protected var startX: Float = 0.toFloat() |
||||
protected var startY: Float = 0.toFloat() |
||||
//触碰点 |
||||
protected var touchX: Float = 0.toFloat() |
||||
protected var touchY: Float = 0.toFloat() |
||||
//上一个触碰点 |
||||
protected var lastX: Float = 0.toFloat() |
||||
protected var lastY: Float = 0.toFloat() |
||||
|
||||
protected var isRunning = false |
||||
protected var isStarted = false |
||||
|
||||
|
||||
fun setStartPoint(x: Float, y: Float) { |
||||
startX = x |
||||
startY = y |
||||
|
||||
lastX = startX |
||||
lastY = startY |
||||
} |
||||
|
||||
fun setTouchPoint(x: Float, y: Float) { |
||||
lastX = touchX |
||||
lastY = touchY |
||||
|
||||
touchX = x |
||||
touchY = y |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
abstract class PageFactory<DATA>(protected val dataSource: DataSource) { |
||||
|
||||
abstract fun pageAt(index: Int): DATA |
||||
|
||||
abstract fun nextPage(): DATA |
||||
|
||||
abstract fun previousPage(): DATA |
||||
|
||||
} |
@ -0,0 +1,55 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
import android.content.Context |
||||
import android.graphics.Bitmap |
||||
import android.graphics.Canvas |
||||
import android.graphics.Rect |
||||
import android.graphics.drawable.GradientDrawable |
||||
import android.util.AttributeSet |
||||
import android.util.Log |
||||
import android.view.MotionEvent |
||||
import android.view.View |
||||
import android.widget.FrameLayout |
||||
import androidx.appcompat.widget.AppCompatTextView |
||||
import io.legado.app.R |
||||
import io.legado.app.utils.screenshot |
||||
import kotlin.math.abs |
||||
|
||||
class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) { |
||||
|
||||
private var bitmap: Bitmap? = null |
||||
|
||||
private var downX: Float = 0.toFloat() |
||||
private var offset: Float = 0.toFloat() |
||||
|
||||
private val srcRect: Rect = Rect() |
||||
private val destRect: Rect = Rect() |
||||
private val shadowDrawable: GradientDrawable |
||||
|
||||
init { |
||||
val shadowColors = intArrayOf(0x66111111, 0x00000000) |
||||
shadowDrawable = GradientDrawable( |
||||
GradientDrawable.Orientation.LEFT_RIGHT, shadowColors |
||||
) |
||||
shadowDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT |
||||
|
||||
inflate(context, R.layout.page_view, this) |
||||
} |
||||
|
||||
override fun onDraw(canvas: Canvas?) { |
||||
canvas?.save() |
||||
super.onDraw(canvas) |
||||
canvas?.restore() |
||||
|
||||
|
||||
} |
||||
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean { |
||||
|
||||
return true |
||||
} |
||||
|
||||
fun setPageFactory(factory: PageFactory<*>){ |
||||
|
||||
} |
||||
} |
@ -0,0 +1,3 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
data class TextChapter(val position: Int, val pages: List<TextPage>) |
@ -0,0 +1,3 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
data class TextPage(val index: Int, val text: String) |
@ -0,0 +1,26 @@ |
||||
package io.legado.app.ui.widget.page |
||||
|
||||
class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<TextPage>(dataSource) { |
||||
|
||||
companion object{ |
||||
fun create(dataSource: DataSource): TextPageFactory{ |
||||
return TextPageFactory(dataSource) |
||||
} |
||||
} |
||||
|
||||
private var index: Int = 0 |
||||
|
||||
override fun pageAt(index: Int): TextPage { |
||||
TODO("todo...") |
||||
} |
||||
|
||||
override fun nextPage(): TextPage { |
||||
return TextPage(index.plus(1), "index:$index") |
||||
} |
||||
|
||||
override fun previousPage(): TextPage { |
||||
return TextPage(index.minus(1), "index:$index") |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,42 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.appcompat.widget.LinearLayoutCompat |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:id="@+id/page_panel" |
||||
android:orientation="vertical" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
app:showDividers="middle" |
||||
app:divider="@drawable/ic_divider"> |
||||
|
||||
<View |
||||
android:id="@+id/top_status_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="25dp"/> |
||||
|
||||
|
||||
<FrameLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/text_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"/> |
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:visibility="gone" |
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/> |
||||
</FrameLayout> |
||||
|
||||
<View |
||||
android:id="@+id/bottom_status_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="25dp"/> |
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat> |
Loading…
Reference in new issue