# Conflicts: # app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.ktpull/32/head
						commit
						f05cf0274d
					
				| @ -0,0 +1,77 @@ | ||||
| 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 | ||||
|     } | ||||
| } | ||||
| @ -1,7 +1,17 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:orientation="vertical" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent"> | ||||
|               android:orientation="vertical" | ||||
|               android:layout_width="match_parent" | ||||
|               android:layout_height="match_parent"> | ||||
| 
 | ||||
|     <io.legado.app.ui.widget.PageView | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="match_parent" | ||||
|             android:padding="30dp" | ||||
|             android:background="#C6BAA1" | ||||
|             android:textColor="@color/black" | ||||
|             android:lineSpacingExtra="4dp" | ||||
|             android:textSize="18dp" | ||||
|             android:text="2342343333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333323423433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333234234333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333332342343333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333323423433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333234234333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333332342343333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333323423433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"/> | ||||
| 
 | ||||
| </LinearLayout> | ||||
					Loading…
					
					
				
		Reference in new issue