diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 92b27f3ed..5c23674e2 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -6,9 +6,9 @@ import android.view.MenuItem import android.view.View import io.legado.app.R import io.legado.app.base.BaseFragment -import io.legado.app.ui.search.SearchActivity +import io.legado.app.ui.read.ReadActivity +import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.view_title_bar.* -import org.jetbrains.anko.startActivity class MyFragment : BaseFragment(R.layout.fragment_my_config) { @@ -26,7 +26,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { - R.id.action_settings -> requireContext().startActivity() + R.id.action_settings -> startActivity() } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/PageView.kt new file mode 100644 index 000000000..7844f7e3f --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/PageView.kt @@ -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 + } +} diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index c81c734ad..f233929fb 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -1,5 +1,8 @@ package io.legado.app.utils +import android.app.Activity +import android.app.Service +import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable import androidx.annotation.ColorRes @@ -8,6 +11,7 @@ import androidx.core.content.edit import androidx.fragment.app.Fragment import org.jetbrains.anko.connectivityManager import org.jetbrains.anko.defaultSharedPreferences +import org.jetbrains.anko.internals.AnkoInternals fun Fragment.isOnline() = requireContext().connectivityManager.activeNetworkInfo?.isConnected == true @@ -54,4 +58,21 @@ val Fragment.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") val Fragment.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar") \ No newline at end of file + get() = getPrefBoolean("transparentStatusBar") + + +inline fun Fragment.startActivity(vararg params: Pair) = + AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) + + +inline fun Fragment.startActivityForResult(requestCode: Int, vararg params: Pair) = + startActivityForResult(AnkoInternals.createIntent(requireActivity(), T::class.java, params), requestCode) + +inline fun Fragment.startService(vararg params: Pair) = + AnkoInternals.internalStartService(requireActivity(), T::class.java, params) + +inline fun Fragment.stopService(vararg params: Pair) = + AnkoInternals.internalStopService(requireActivity(), T::class.java, params) + +inline fun Fragment.intentFor(vararg params: Pair): Intent = + AnkoInternals.createIntent(requireActivity(), T::class.java, params) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 50944d224..cbde9e3f1 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -55,7 +55,7 @@ fun View.visible() { fun View.screenshot(): Bitmap? { return runCatching { - val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565) + val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val c = Canvas(screenshot) c.translate(-scrollX.toFloat(), -scrollY.toFloat()) draw(c) diff --git a/app/src/main/res/layout/activity_read.xml b/app/src/main/res/layout/activity_read.xml index d829e291c..fc9704d8b 100644 --- a/app/src/main/res/layout/activity_read.xml +++ b/app/src/main/res/layout/activity_read.xml @@ -1,7 +1,17 @@ + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + \ No newline at end of file