Skip to content

Commit

Permalink
[FEAT/#9] CardFrameView 커스텀뷰 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Jan 1, 2023
1 parent 9801d9e commit bc644b4
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- Add uses-permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

<application
android:name=".KeyneezApplication"
Expand All @@ -17,6 +17,10 @@
android:theme="@style/Theme.Keyneez"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.preview.PreviewActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.verification.VerificationActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.lab.keyneez.presentation.custom

import android.content.Context
import android.graphics.* // ktlint-disable no-wildcard-imports
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import com.lab.keyneez.R

class CardFrameView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val path = Path()
private val rect = RectF()
private val stroke = Paint().apply {
isAntiAlias = false
strokeWidth = 4f
color = ContextCompat.getColor(context, R.color.gray050)
style = Paint.Style.STROKE
}
private val eraser = Paint().apply {
isAntiAlias = true
xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
}

private val holeBorderRadius = 48f

override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)

drawBorder(requireNotNull(canvas))
drawHole(canvas)
}

private fun drawBorder(canvas: Canvas) {
path.rewind()
path.addRoundRect(
rect.apply {
setRect(4f/*border width*/)
},
holeBorderRadius,
holeBorderRadius,
Path.Direction.CW
)

canvas.drawPath(path, stroke)
}

private fun drawHole(canvas: Canvas) {
canvas.drawRoundRect(
rect.apply {
setRect()
},
holeBorderRadius,
holeBorderRadius,
eraser
)
}

private fun setRect(offset: Float = 4f) {
val holeWidth = width - 96
val holeHeight = width * 0.611f

rect.set(
((width - holeWidth) / 2) - offset,
((height - holeHeight) / 2) - offset,
((width - holeWidth) / 2 + holeWidth) + offset,
((height - holeHeight) / 2 + holeHeight) + offset
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class CardFragment : BindingFragment<FragmentCardBinding>(R.layout.fragment_card

private fun initIssueBtnClickListener() {
binding.btnCardIssue.setOnSingleClickListener {
val toVertification = Intent(activity, VerificationActivity::class.java)
startActivity(toVertification)
val toVerification = Intent(activity, VerificationActivity::class.java)
startActivity(toVerification)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.lab.keyneez.presentation.preview

import android.os.Bundle
import android.view.View
import com.lab.keyneez.R
import com.lab.keyneez.databinding.ActivityPreviewBinding
import com.lab.keyneez.util.binding.BindingActivity

class PreviewActivity : BindingActivity<ActivityPreviewBinding>(R.layout.activity_preview) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding.cfvPreview.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.lab.keyneez.presentation.verification

import android.content.Intent
import android.os.Bundle
import com.lab.keyneez.R
import com.lab.keyneez.databinding.ActivityVerificationBinding
import com.lab.keyneez.presentation.preview.PreviewActivity
import com.lab.keyneez.util.binding.BindingActivity
import com.lab.keyneez.util.extension.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -22,6 +24,7 @@ class VerificationActivity :
}

private fun initStartCameraBtnClickListener() {
// ocr 기능 구현
val toPreview = Intent(this, PreviewActivity::class.java)
startActivity(toPreview)
}
}
35 changes: 35 additions & 0 deletions app/src/main/res/layout/activity_preview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".presentation.preview.PreviewActivity">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_preview"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/tv_preview_dummy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="100sp"
android:textColor="@color/red600"
android:text="ㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉㅉ"/>

<com.lab.keyneez.presentation.custom.CardFrameView
android:id="@+id/cfv_preview"
android:background="#DD000000"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingHorizontal="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit bc644b4

Please sign in to comment.