|
@@ -5,6 +5,11 @@ import android.arch.lifecycle.MutableLiveData
|
|
import android.arch.lifecycle.ViewModel
|
|
import android.arch.lifecycle.ViewModel
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.graphics.Color
|
|
import android.graphics.Color
|
|
|
|
+import android.graphics.PointF
|
|
|
|
+import android.graphics.drawable.ColorDrawable
|
|
|
|
+import android.graphics.drawable.Drawable
|
|
|
|
+import android.graphics.drawable.GradientDrawable
|
|
|
|
+import android.graphics.drawable.StateListDrawable
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
import android.os.Build
|
|
import android.os.Build
|
|
import android.support.v4.content.ContextCompat
|
|
import android.support.v4.content.ContextCompat
|
|
@@ -545,13 +550,17 @@ class ReaderViewModel(private val readerModelManager: ReaderModelManager, val ur
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private fun setElevationBelowAndroidKitKat(context: Context, view: View?) {
|
|
|
|
|
|
+ private fun setElevationBelowAndroidKitKat(context: Context, view: View) {
|
|
val elevation = context.resources.getDimension(R.dimen.reader_context_menu_window_elevation)
|
|
val elevation = context.resources.getDimension(R.dimen.reader_context_menu_window_elevation)
|
|
val drawable = MyRoundRectDrawableWithShadow(context.resources, 0x00000000, 0f, elevation, elevation)
|
|
val drawable = MyRoundRectDrawableWithShadow(context.resources, 0x00000000, 0f, elevation, elevation)
|
|
|
|
+ setViewBackground(view, drawable)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun setViewBackground(view: View, drawable: Drawable) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
- view?.background = drawable
|
|
|
|
|
|
+ view.background = drawable
|
|
} else {
|
|
} else {
|
|
- view?.setBackgroundDrawable(drawable)
|
|
|
|
|
|
+ view.setBackgroundDrawable(drawable)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -612,19 +621,50 @@ class ReaderViewModel(private val readerModelManager: ReaderModelManager, val ur
|
|
private fun createTextBoxContextMenuView(context: Context): View {
|
|
private fun createTextBoxContextMenuView(context: Context): View {
|
|
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
val contentView = layoutInflater.inflate(R.layout.view_context_menu_textbox, null)
|
|
val contentView = layoutInflater.inflate(R.layout.view_context_menu_textbox, null)
|
|
- contentView.findViewById<TextView>(R.id.btnDelete_contextMenu).setOnClickListener {
|
|
|
|
|
|
+
|
|
|
|
+ fun createTextBoxSelector(topLeft: Boolean, topRight: Boolean, bottomRight: Boolean, bottomLeft: Boolean): Drawable {
|
|
|
|
+ val radius = context.resources.getDimension(R.dimen.reader_context_menu_text_box_radius)
|
|
|
|
+ val topLeftRadius = if (topLeft) PointF(radius, radius) else PointF()
|
|
|
|
+ val topRightRadius = if (topRight) PointF(radius, radius) else PointF()
|
|
|
|
+ val bottomRightRadius = if (bottomRight) PointF(radius, radius) else PointF()
|
|
|
|
+ val bottomLeftRadius = if (bottomLeft) PointF(radius, radius) else PointF()
|
|
|
|
+ val cornerRadii = floatArrayOf(topLeftRadius.x, topLeftRadius.y, topRightRadius.x, topRightRadius.y, bottomRightRadius.x, bottomRightRadius.y, bottomLeftRadius.x, bottomLeftRadius.y)
|
|
|
|
+
|
|
|
|
+ val normalDrawable = GradientDrawable()
|
|
|
|
+ normalDrawable.cornerRadii = cornerRadii
|
|
|
|
+ normalDrawable.setColor(ContextCompat.getColor(context, R.color.reader_contextMenu_bgNormal))
|
|
|
|
+ val pressedDrawable = GradientDrawable()
|
|
|
|
+ pressedDrawable.cornerRadii = cornerRadii
|
|
|
|
+ pressedDrawable.setColor(ContextCompat.getColor(context, R.color.reader_contextMenu_bgPressed))
|
|
|
|
+ val drawable = StateListDrawable()
|
|
|
|
+ drawable.addState(intArrayOf(android.R.attr.state_pressed), pressedDrawable)
|
|
|
|
+ drawable.addState(intArrayOf(android.R.attr.state_enabled), normalDrawable)
|
|
|
|
+ return drawable
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ val btnDelete = contentView.findViewById<TextView>(R.id.btnDelete_contextMenu)
|
|
|
|
+ val btnStyle = contentView.findViewById<TextView>(R.id.btnStyle_contextMenu)
|
|
|
|
+ val btnEdit = contentView.findViewById<TextView>(R.id.btnEdit_contextMenu)
|
|
|
|
+ val btnCopy = contentView.findViewById<TextView>(R.id.btnCopy_contextMenu)
|
|
|
|
+
|
|
|
|
+ setViewBackground(btnDelete, createTextBoxSelector(true, false, false, true))
|
|
|
|
+ setViewBackground(btnStyle, createTextBoxSelector(false, false, false, false))
|
|
|
|
+ setViewBackground(btnEdit, createTextBoxSelector(false, false, false, false))
|
|
|
|
+ setViewBackground(btnCopy, createTextBoxSelector(false, true, true, false))
|
|
|
|
+
|
|
|
|
+ btnDelete.setOnClickListener {
|
|
textBoxContextMenuActionListener?.onDelete()
|
|
textBoxContextMenuActionListener?.onDelete()
|
|
dismissPopupWindow()
|
|
dismissPopupWindow()
|
|
}
|
|
}
|
|
- contentView.findViewById<TextView>(R.id.btnStyle_contextMenu).setOnClickListener {
|
|
|
|
|
|
+ btnStyle.setOnClickListener {
|
|
textBoxContextMenuActionListener?.onEditStyle()
|
|
textBoxContextMenuActionListener?.onEditStyle()
|
|
dismissPopupWindow()
|
|
dismissPopupWindow()
|
|
}
|
|
}
|
|
- contentView.findViewById<TextView>(R.id.btnEdit_contextMenu).setOnClickListener {
|
|
|
|
|
|
+ btnEdit.setOnClickListener {
|
|
textBoxContextMenuActionListener?.onEditText()
|
|
textBoxContextMenuActionListener?.onEditText()
|
|
dismissPopupWindow()
|
|
dismissPopupWindow()
|
|
}
|
|
}
|
|
- contentView.findViewById<TextView>(R.id.btnCopy_contextMenu).setOnClickListener {
|
|
|
|
|
|
+ btnCopy.setOnClickListener {
|
|
textBoxContextMenuActionListener?.onCopy()
|
|
textBoxContextMenuActionListener?.onCopy()
|
|
dismissPopupWindow()
|
|
dismissPopupWindow()
|
|
}
|
|
}
|