-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/lab/keyneez/presentation/custom/CardFrameView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/lab/keyneez/presentation/preview/PreviewActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |