|
@@ -10,6 +10,11 @@ import android.support.v7.app.AppCompatActivity
|
|
|
import android.os.Bundle
|
|
|
import android.support.constraint.ConstraintLayout
|
|
|
import android.support.constraint.ConstraintSet
|
|
|
+import android.widget.Toast
|
|
|
+import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
|
|
|
+import com.kdanmobile.reader.Utils.applyConstraintSet
|
|
|
+import com.kdanmobile.reader.view.AnnotationAttributeView
|
|
|
+import com.kdanmobile.reader.view.AnnotationAttributeWindow
|
|
|
import android.support.v4.content.ContextCompat
|
|
|
import android.support.v7.app.AlertDialog
|
|
|
import android.view.Menu
|
|
@@ -20,8 +25,9 @@ import android.view.View
|
|
|
import android.widget.EditText
|
|
|
import android.widget.LinearLayout
|
|
|
import android.widget.TextView
|
|
|
-import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
|
|
|
-import com.kdanmobile.reader.Utils.applyConstraintSet
|
|
|
+import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
|
|
|
+import com.kdanmobile.reader.annotationattribute.AnnotationColor
|
|
|
+import com.kdanmobile.reader.annotationattribute.InkAttribute
|
|
|
import com.kdanmobile.reader.screen.view.BookmarkView
|
|
|
import com.kdanmobile.reader.screen.view.OutlineView
|
|
|
import com.kdanmobile.reader.screen.view.SearchView
|
|
@@ -87,12 +93,19 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
|
viewModel = ViewModelProviders.of(this, factory).get(ReaderViewModel::class.java)
|
|
|
viewModel.isOpenedFileLiveData.observe(this, Observer(this::onIsOpenedFileUpdate))
|
|
|
viewModel.fileNameLiveData.observe(this, Observer { tv_readerActivity_title.text = it })
|
|
|
+ viewModel.annotationModeLiveData.observe(this, Observer(this::onAnnotationModeUpdate))
|
|
|
+ viewModel.isCopyModeLiveData.observe(this, Observer (this::onIsCopyModeUpdate))
|
|
|
+ viewModel.highLightAttributeLiveData.observe(this, Observer(this::onHighlightAttributeUpdate))
|
|
|
+ viewModel.strikeAttributeLiveData.observe(this, Observer(this::onStrikeAttributeUpdate))
|
|
|
+ viewModel.underLineAttributeLiveData.observe(this, Observer(this::onUnderlineAttributeUpdate))
|
|
|
+ viewModel.inkAttributeLiveData.observe(this, Observer(this::onInkAttributeUpdate))
|
|
|
viewModel.isOpenedFileLiveData.value?.also { isOpened ->
|
|
|
if (isOpened) return@also
|
|
|
val filePath = intent.getStringExtra(KEY_FILE_ABSOLUTE)
|
|
|
val uri = Uri.parse(filePath)
|
|
|
viewModel.openPdfFile(this, uri, intent.type)
|
|
|
}
|
|
|
+ setupRightToolbar()
|
|
|
viewModel.pageIndexLiveData.observe(this, Observer(this::onPageIndexChanged))
|
|
|
viewModel.isPageInBookmarksLiveData.observe(this, Observer(this::onIsPageInBookmarksChanged))
|
|
|
}
|
|
@@ -139,6 +152,81 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun onIsCopyModeUpdate(isCopyMode: Boolean?) {
|
|
|
+ if (isCopyMode == null) return
|
|
|
+ when (isCopyMode) {
|
|
|
+ true -> {
|
|
|
+ val color = resources.getColor(R.color.reader_right_toolbar_selected_bg)
|
|
|
+ iv_readerActivity_copy.setBackgroundColor(color)
|
|
|
+ hideTopLeftBottomToolbars()
|
|
|
+ }
|
|
|
+ false -> {
|
|
|
+ iv_readerActivity_copy.setBackgroundDrawable(null)
|
|
|
+ showAllToolbars()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onHighlightAttributeUpdate(annotationAttribute: AnnotationAttribute?) {
|
|
|
+ if (annotationAttribute == null) return
|
|
|
+ view_readerActivity_highLightStroke.setBackgroundColor(annotationAttribute.color)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onStrikeAttributeUpdate(annotationAttribute: AnnotationAttribute?) {
|
|
|
+ if (annotationAttribute == null) return
|
|
|
+ view_readerActivity_strikeStroke.setBackgroundColor(annotationAttribute.color)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onUnderlineAttributeUpdate(annotationAttribute: AnnotationAttribute?) {
|
|
|
+ if (annotationAttribute == null) return
|
|
|
+ view_readerActivity_underlineStroke.setBackgroundColor(annotationAttribute.color)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onInkAttributeUpdate(inkAttribute: InkAttribute?) {
|
|
|
+ if (inkAttribute == null) return
|
|
|
+ val color = inkAttribute.color
|
|
|
+ AnnotationColor.values().forEach {
|
|
|
+ if (resources.getColor(it.colorResId) == color) {
|
|
|
+ val drawableResId = when (it) {
|
|
|
+ AnnotationColor.Color1 -> R.drawable.ic_tool_freehand_s1
|
|
|
+ AnnotationColor.Color2 -> R.drawable.ic_tool_freehand_s2
|
|
|
+ AnnotationColor.Color3 -> R.drawable.ic_tool_freehand_s3
|
|
|
+ AnnotationColor.Color4 -> R.drawable.ic_tool_freehand_s4
|
|
|
+ AnnotationColor.Color5 -> R.drawable.ic_tool_freehand_s5
|
|
|
+ AnnotationColor.Color6 -> R.drawable.ic_tool_freehand_s6
|
|
|
+ AnnotationColor.Color7 -> R.drawable.ic_tool_freehand_s7
|
|
|
+ AnnotationColor.Color8 -> R.drawable.ic_tool_freehand_s8
|
|
|
+ AnnotationColor.Color9 -> R.drawable.ic_tool_freehand_s9
|
|
|
+ AnnotationColor.Color10 -> R.drawable.ic_tool_freehand_s10
|
|
|
+ }
|
|
|
+ iv_readerActivity_inkStroke.setImageResource(drawableResId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onAnnotationModeUpdate(annotationMode: ReaderViewModel.AnnotationMode?) {
|
|
|
+ if (annotationMode == null) return
|
|
|
+ val map = HashMap<ReaderViewModel.AnnotationMode, View>().apply {
|
|
|
+ put(ReaderViewModel.AnnotationMode.Highlight, iv_readerActivity_highLight)
|
|
|
+ put(ReaderViewModel.AnnotationMode.Strike, iv_readerActivity_strike)
|
|
|
+ put(ReaderViewModel.AnnotationMode.Underline, iv_readerActivity_underline)
|
|
|
+ put(ReaderViewModel.AnnotationMode.Ink, iv_readerActivity_ink)
|
|
|
+ }
|
|
|
+ map.forEach {
|
|
|
+ if (it.key == annotationMode) {
|
|
|
+ val color = resources.getColor(R.color.reader_right_toolbar_selected_bg)
|
|
|
+ it.value.setBackgroundColor(color)
|
|
|
+ } else {
|
|
|
+ it.value.setBackgroundDrawable(null)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ when (annotationMode == ReaderViewModel.AnnotationMode.None) {
|
|
|
+ true -> showAllToolbars()
|
|
|
+ false -> hideTopLeftBottomToolbars()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private fun onIsOpenedFileUpdate(isOpened: Boolean?) {
|
|
|
if (isOpened == null) return
|
|
|
val container = viewGroup_readerActivity_container
|
|
@@ -146,6 +234,19 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
|
if (!isOpened) return
|
|
|
val context = this
|
|
|
val readerView = object : KMPDFReaderView(context) {
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
+ override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
|
|
|
+ if (motionEvent.action == MotionEvent.ACTION_UP) {
|
|
|
+ if (viewModel.isCopyModeLiveData.value == true) {
|
|
|
+ if (viewModel.copySelection()) {
|
|
|
+ val context = this@ReaderActivity
|
|
|
+ Toast.makeText(context, R.string.reader_copy_text_success, Toast.LENGTH_SHORT).show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onTouchEvent(motionEvent)
|
|
|
+ }
|
|
|
+
|
|
|
override fun onTapMainDocArea() {
|
|
|
super.onTapMainDocArea()
|
|
|
if (isBelowKitkat()) {
|
|
@@ -361,6 +462,119 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
|
Utils.setTintDrawableList(context, ib_readerActivity_bottomToolbarKdanCloud, R.drawable.ic_kdan_cloud, normalColor, pressColor)
|
|
|
}
|
|
|
|
|
|
+ private fun setupRightToolbar() {
|
|
|
+ iv_readerActivity_copy.setOnClickListener { viewModel.onClickCopyBtn() }
|
|
|
+ iv_readerActivity_highLight.apply {
|
|
|
+ setOnClickListener { viewModel.onClickHighlightBtn() }
|
|
|
+ setOnLongClickListener { btn ->
|
|
|
+ viewModel.onLongClickHighlightBtn()
|
|
|
+ val context = this@ReaderActivity
|
|
|
+ AnnotationAttributeWindow(context, true).also { window ->
|
|
|
+ viewModel.highLightAttributeLiveData.value?.let { attr ->
|
|
|
+ window.annotationAttributeView.annotationAttribute = attr
|
|
|
+ }
|
|
|
+ window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
|
+ override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
+ viewModel.setHighLightAttributes(annotationAttributeView.annotationAttribute)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val contentView = window.contentView.apply {
|
|
|
+ val w = Utils.makeDropDownMeasureSpec(window.width)
|
|
|
+ val y = Utils.makeDropDownMeasureSpec(window.height)
|
|
|
+ measure(w, y)
|
|
|
+ }
|
|
|
+ val space = resources.getDimension(R.dimen.reader_annotation_property_setting_window_right_toolbar_space)
|
|
|
+ val xOff = (-contentView.measuredWidth - space).toInt()
|
|
|
+ val yOff = -btn.height
|
|
|
+ window.showAsDropDown(btn, xOff, yOff)
|
|
|
+ }
|
|
|
+ return@setOnLongClickListener true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ iv_readerActivity_strike.apply {
|
|
|
+ setOnClickListener { viewModel.onClickStrikeBtn() }
|
|
|
+ setOnLongClickListener { btn ->
|
|
|
+ viewModel.onLongClickStrikeBtn()
|
|
|
+ val context = this@ReaderActivity
|
|
|
+ AnnotationAttributeWindow(context, true).also { window ->
|
|
|
+ viewModel.strikeAttributeLiveData.value?.let { attr ->
|
|
|
+ window.annotationAttributeView.annotationAttribute = attr
|
|
|
+ }
|
|
|
+ window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
|
+ override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
+ viewModel.setStrikeOutAttributes(annotationAttributeView.annotationAttribute)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val contentView = window.contentView.apply {
|
|
|
+ val w = Utils.makeDropDownMeasureSpec(window.width)
|
|
|
+ val y = Utils.makeDropDownMeasureSpec(window.height)
|
|
|
+ measure(w, y)
|
|
|
+ }
|
|
|
+ val space = resources.getDimension(R.dimen.reader_annotation_property_setting_window_right_toolbar_space)
|
|
|
+ val xOff = (-contentView.measuredWidth - space).toInt()
|
|
|
+ val yOff = -btn.height
|
|
|
+ window.showAsDropDown(btn, xOff, yOff)
|
|
|
+ }
|
|
|
+ return@setOnLongClickListener true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ iv_readerActivity_underline.apply {
|
|
|
+ setOnClickListener { viewModel.onClickUnderlineBtn() }
|
|
|
+ setOnLongClickListener { btn ->
|
|
|
+ viewModel.onLongClickUnderlineBtn()
|
|
|
+ val context = this@ReaderActivity
|
|
|
+ AnnotationAttributeWindow(context, true).also { window ->
|
|
|
+ viewModel.underLineAttributeLiveData.value?.let { attr ->
|
|
|
+ window.annotationAttributeView.annotationAttribute = attr
|
|
|
+ }
|
|
|
+ window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
|
+ override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
+ viewModel.setUnderLineAttributes(annotationAttributeView.annotationAttribute)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val contentView = window.contentView.apply {
|
|
|
+ val w = Utils.makeDropDownMeasureSpec(window.width)
|
|
|
+ val y = Utils.makeDropDownMeasureSpec(window.height)
|
|
|
+ measure(w, y)
|
|
|
+ }
|
|
|
+ val space = resources.getDimension(R.dimen.reader_annotation_property_setting_window_right_toolbar_space)
|
|
|
+ val xOff = (-contentView.measuredWidth - space).toInt()
|
|
|
+ val yOff = -btn.height
|
|
|
+ window.showAsDropDown(btn, xOff, yOff)
|
|
|
+ }
|
|
|
+ return@setOnLongClickListener true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ iv_readerActivity_ink.apply {
|
|
|
+ setOnClickListener { viewModel.onClickInkBtn() }
|
|
|
+ setOnLongClickListener { btn ->
|
|
|
+ viewModel.onLongClickInkBtn()
|
|
|
+ val context = this@ReaderActivity
|
|
|
+ AnnotationAttributeWindow(context, false).also { window ->
|
|
|
+ viewModel.inkAttributeLiveData.value?.let { attr ->
|
|
|
+ window.annotationAttributeView.inkAttribute = attr
|
|
|
+ }
|
|
|
+ window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
|
|
|
+ override fun onChange(annotationAttributeView: AnnotationAttributeView) {
|
|
|
+ viewModel.setInkAttributes(annotationAttributeView.inkAttribute)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val contentView = window.contentView.apply {
|
|
|
+ val w = Utils.makeDropDownMeasureSpec(window.width)
|
|
|
+ val y = Utils.makeDropDownMeasureSpec(window.height)
|
|
|
+ measure(w, y)
|
|
|
+ }
|
|
|
+ val space = resources.getDimension(R.dimen.reader_annotation_property_setting_window_right_toolbar_space)
|
|
|
+ val xOff = (-contentView.measuredWidth - space).toInt()
|
|
|
+ val yOff = -contentView.measuredHeight
|
|
|
+ window.showAsDropDown(btn, xOff, yOff)
|
|
|
+ }
|
|
|
+ return@setOnLongClickListener true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private fun setLeftToolbarWidth(width: Int) {
|
|
|
var params = viewGroup_readerActivity_leftToolbar.layoutParams as ConstraintLayout.LayoutParams
|
|
|
params.width = width + w_left
|
|
@@ -461,8 +675,7 @@ abstract class ReaderActivity : AppCompatActivity() {
|
|
|
leftToolbarType = type
|
|
|
}
|
|
|
|
|
|
- fun onClick(view: View)
|
|
|
- {
|
|
|
+ fun onClick(view: View) {
|
|
|
when (view.id) {
|
|
|
R.id.iv_readerActivity_thumbnail -> {
|
|
|
onThumbnailClick()
|