Browse Source

Add signature UI

cooperku_kdanmobile 5 years ago
parent
commit
ead43ecad0

+ 103 - 0
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/SignatureDrawView.kt

@@ -0,0 +1,103 @@
+package com.kdanmobile.reader.screen.view.edit
+
+import android.content.Context
+import android.graphics.Bitmap
+import android.graphics.Canvas
+import android.graphics.Paint
+import android.graphics.Path
+import android.util.AttributeSet
+import android.view.View
+import android.graphics.Paint.Cap
+import android.support.v4.content.ContextCompat
+import android.view.MotionEvent
+
+
+
+class SignatureDrawView : View {
+
+    private lateinit var paint: Paint
+    private var currentPath: Path? = null
+    private val datas = ArrayList<SignaturePathData>()
+    var onSignatureDrawListener: OnSignatureDrawListener? = null
+
+    var paintColor: Int = android.R.color.black
+    var strokeWidth: Float = 10f
+
+    constructor(context: Context) : super(context) {
+        initView()
+    }
+
+    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
+        initView()
+    }
+
+    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
+        initView()
+    }
+
+    private fun initView() {
+        paint = Paint()
+        paint.isAntiAlias = true
+        paint.style = Paint.Style.STROKE
+        paint.strokeCap = Cap.ROUND
+        paint.color = ContextCompat.getColor(context, paintColor)
+        paint.strokeWidth = strokeWidth
+    }
+
+    fun clear() {
+        datas.clear()
+        invalidate()
+        onSignatureDrawListener?.onClearSignature()
+    }
+
+    fun getBitmap(): Bitmap {
+        val bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888)
+        draw(Canvas(bitmap))
+        return bitmap
+    }
+
+    override fun onDraw(canvas: Canvas?) {
+        super.onDraw(canvas)
+
+        for (data in datas) {
+            paint.color = data.color
+            paint.strokeWidth = data.strokeWidth
+            canvas?.drawPath(data.path, paint)
+        }
+    }
+
+    override fun onTouchEvent(event: MotionEvent?): Boolean {
+        if (null != event) {
+            val actionIndex = event.actionIndex
+            val pointerId = event.getPointerId(actionIndex)
+            if (pointerId == 0) {
+                val x = event.getX(actionIndex)
+                val y = event.getY(actionIndex)
+                when (event.action) {
+                    MotionEvent.ACTION_DOWN -> {
+                        currentPath = Path()
+                        datas.add(SignaturePathData(currentPath!!, paintColor, strokeWidth))
+                        currentPath?.moveTo(x, y)
+                        onSignatureDrawListener?.onStartSignature()
+                    }
+                    MotionEvent.ACTION_MOVE -> {
+                        currentPath?.lineTo(x, y)
+                    }
+                    MotionEvent.ACTION_UP -> {
+                    }
+                }
+                invalidate()
+            }
+        }
+
+        return true
+    }
+
+    interface OnSignatureDrawListener {
+        fun onClearSignature()
+
+        fun onStartSignature()
+    }
+
+    data class SignaturePathData(val path: Path, val color: Int, val strokeWidth: Float)
+}

BIN
reader/src/main/res/drawable-hdpi/signature_ic_add.webp


BIN
reader/src/main/res/drawable-mdpi/signature_ic_add.webp


BIN
reader/src/main/res/drawable-xhdpi/signature_ic_add.webp


BIN
reader/src/main/res/drawable-xxhdpi/signature_ic_add.webp


BIN
reader/src/main/res/drawable-xxxhdpi/signature_ic_add.webp


+ 12 - 0
reader/src/main/res/drawable/ic_close.xml

@@ -0,0 +1,12 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M19,6.41l-1.41,-1.41l-5.59,5.59l-5.59,-5.59l-1.41,1.41l5.59,5.59l-5.59,5.59l1.41,1.41l5.59,-5.59l5.59,5.59l1.41,-1.41l-5.59,-5.59z"
+      android:strokeWidth="1"
+      android:fillColor="#FFFFFF"
+      android:fillType="evenOdd"
+      android:strokeColor="#00000000"/>
+</vector>

+ 14 - 0
reader/src/main/res/drawable/ic_close_dark.xml

@@ -0,0 +1,14 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:pathData="M19,6.41l-1.41,-1.41l-5.59,5.59l-5.59,-5.59l-1.41,1.41l5.59,5.59l-5.59,5.59l1.41,1.41l5.59,-5.59l5.59,5.59l1.41,-1.41l-5.59,-5.59z"
+      android:strokeAlpha="0.6"
+      android:strokeWidth="1"
+      android:fillColor="#000000"
+      android:fillType="evenOdd"
+      android:strokeColor="#00000000"
+      android:fillAlpha="0.6"/>
+</vector>

+ 12 - 0
reader/src/main/res/drawable/shape_rec_gray_border_rcorner.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+
+    <solid android:color="#ffffff" />
+
+    <stroke
+        android:width="1dp"
+        android:color="#cccccc" />
+
+    <corners android:radius="4dp"/>
+</shape>

+ 128 - 0
reader/src/main/res/layout/activity_view_signature_create.xml

@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="#FFFFFFFF">
+
+    <android.support.v7.widget.Toolbar
+        android:id="@+id/toolbar_signature"
+        android:layout_width="match_parent"
+        android:layout_height="?attr/actionBarSize"
+        android:background="#0077fd"
+        app:title="Create signature"
+        app:titleTextColor="@android:color/white"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <TextView
+        android:id="@+id/btn_save_signature"
+        android:layout_width="wrap_content"
+        android:layout_height="?attr/actionBarSize"
+        android:paddingLeft="16dp"
+        android:paddingStart="16dp"
+        android:paddingRight="16dp"
+        android:paddingEnd="16dp"
+        android:textColor="@android:color/white"
+        android:textSize="14sp"
+        android:text="SAVE"
+        android:gravity="center"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <TextView
+        android:id="@+id/tv_writeHere"
+        android:layout_width="match_parent"
+        android:layout_height="48dp"
+        android:layout_marginTop="8dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        android:gravity="center"
+        android:textColor="#61000000"
+        android:textSize="16sp"
+        android:text="Write here"
+        app:layout_constraintTop_toBottomOf="@id/toolbar_signature"
+        app:layout_constraintBottom_toTopOf="@id/btn_clear_signature"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <com.kdanmobile.reader.screen.view.edit.SignatureDrawView
+        android:id="@+id/drawView"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        app:layout_constraintTop_toBottomOf="@id/toolbar_signature"
+        app:layout_constraintBottom_toTopOf="@id/separator"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <LinearLayout
+        android:id="@+id/separator"
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:orientation="horizontal"
+        android:background="#1e000000"
+        android:layout_marginBottom="70dp"
+        app:layout_constraintBottom_toBottomOf="parent" />
+
+    <android.support.constraint.Guideline
+        android:id="@+id/guideline"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:orientation="vertical"
+        app:layout_constraintGuide_percent="0.5" />
+
+    <com.kdanmobile.reader.screen.view.ColorSelectView
+        android:id="@+id/colorChooser_signature"
+        android:layout_width="wrap_content"
+        android:layout_height="48dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        android:gravity="center"
+        android:paddingTop="12dp"
+        android:layout_marginBottom="8dp"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toLeftOf="@+id/guideline" />
+
+    <com.kdanmobile.reader.screen.view.edit.TextSeekBar
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:id="@+id/seekBar_signature"
+        android:layout_marginTop="10dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        app:title="Brush Size"
+        app:unit="px"
+        app:maxValue="24"
+        app:minValue="2"
+        app:initValue="10"
+        app:layout_constraintTop_toBottomOf="@+id/separator"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toRightOf="@+id/guideline"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <Button
+        android:id="@+id/btn_clear_signature"
+        android:layout_width="72dp"
+        android:layout_height="32dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        android:layout_marginBottom="87dp"
+        android:background="@drawable/shape_rec_blue_border_rcorner"
+        android:textColor="#0077fd"
+        android:textSize="14sp"
+        android:textStyle="bold"
+        android:text="CLEAR"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent" />
+
+</android.support.constraint.ConstraintLayout>

+ 46 - 0
reader/src/main/res/layout/view_viewer_edit_item_signature.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="48dp">
+
+    <ImageView
+        android:id="@+id/iv_signatureBorder"
+        android:layout_width="0dp"
+        android:layout_height="48dp"
+        android:background="@drawable/shape_rec_gray_border_rcorner"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toLeftOf="@id/btn_close" />
+
+    <ImageView
+        android:id="@+id/iv_signature"
+        android:layout_width="0dp"
+        android:layout_height="48dp"
+        android:scaleType="matrix"
+        android:paddingTop="4dp"
+        android:paddingBottom="4dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        app:layout_constraintTop_toTopOf="@id/iv_signatureBorder"
+        app:layout_constraintBottom_toBottomOf="@id/iv_signatureBorder"
+        app:layout_constraintLeft_toLeftOf="@id/iv_signatureBorder"
+        app:layout_constraintRight_toRightOf="@id/iv_signatureBorder" />
+
+    <ImageButton
+        android:id="@+id/btn_close"
+        android:layout_width="48dp"
+        android:layout_height="48dp"
+        android:padding="12dp"
+        android:background="@null"
+        android:src="@drawable/ic_close_dark"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toRightOf="@id/iv_signatureBorder"
+        app:layout_constraintRight_toRightOf="parent" />
+
+
+</android.support.constraint.ConstraintLayout>

+ 71 - 0
reader/src/main/res/layout/view_viewer_edit_tab_signature.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:clickable="true"
+    android:focusable="true"
+    android:background="#FFFFFFFF">
+
+    <TextView
+        android:id="@+id/tv_title_signature"
+        android:layout_width="match_parent"
+        android:layout_height="56dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        android:gravity="center_vertical"
+        android:textColor="#de000000"
+        android:textSize="14sp"
+        android:text="Signature Library" />
+
+    <TextView
+        android:id="@+id/tv_noSignature"
+        android:layout_width="match_parent"
+        android:layout_height="48dp"
+        android:layout_marginTop="8dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        android:gravity="center_vertical"
+        android:textColor="#61000000"
+        android:textSize="16sp"
+        android:text="No signature created"
+        app:layout_constraintTop_toBottomOf="@id/tv_title_signature"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/recyclerView_signature"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_marginTop="8dp"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        app:layout_constraintTop_toBottomOf="@id/tv_title_signature"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <android.support.design.widget.FloatingActionButton
+        android:id="@+id/btn_add_signature"
+        android:layout_width="56dp"
+        android:layout_height="56dp"
+        android:src="@drawable/signature_ic_add"
+        android:layout_marginLeft="16dp"
+        android:layout_marginStart="16dp"
+        android:layout_marginRight="16dp"
+        android:layout_marginEnd="16dp"
+        android:layout_marginBottom="16dp"
+        app:fabSize="normal"
+        app:elevation="5dp"
+        app:backgroundTint="#0077fd"
+        app:rippleColor="#eeeeee"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintRight_toRightOf="parent" />
+
+</android.support.constraint.ConstraintLayout>