Commit 8d784c96 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added to statusprogress view attributes and default behaviour

parent b29f0f10
......@@ -7,6 +7,7 @@ import android.graphics.Paint
import android.graphics.PointF
import android.util.AttributeSet
import android.view.View
import com.biganto.visual.roompark.R
/**
* Created by Vladislav Bogdashkin on 19.09.2019.
......@@ -15,37 +16,140 @@ class StatusProgressCeil @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private var direction:StatusProgressDirection = StatusProgressDirection.HORIZONTAL
private val array =
getContext().obtainStyledAttributes(attrs, R.styleable.StatusProgressCeil)
private var direction:StatusProgressDirection =
StatusProgressDirection.fromInt(array.getInt(R.styleable.StatusProgressCeil_direction,1))
private var animateState:StatusProgressAnimationState =
StatusProgressAnimationState.fromInt(array.getInt(R.styleable.StatusProgressCeil_anim_state,1))
private val hasStart:Boolean =
array.getBoolean(R.styleable.StatusProgressCeil_hasStart,false)
private val hasEnd:Boolean =
array.getBoolean(R.styleable.StatusProgressCeil_hasEnd,false)
private val isEnable:Boolean =
array.getBoolean(R.styleable.StatusProgressCeil_isEnable,false)
private val nextEnable:Boolean =
array.getBoolean(R.styleable.StatusProgressCeil_nextEnable,false)
val animationTimeMills:Long = 80L
var lastAnimateStateChanged:Long = 0L
val ifAnimateEnd:Boolean get(){
return (System.currentTimeMillis()-lastAnimateStateChanged) > animationTimeMills
}
private val fillEnableColor:Int = Color.WHITE
private val fillDisableColor:Int = Color.CYAN
private val enablePaint:Paint = Paint()
get(){
field.style = Paint.Style.STROKE
field.strokeWidth = 3F
field.style = Paint.Style.FILL_AND_STROKE
field.color = fillEnableColor
return field
}
private val disablePaint:Paint = Paint()
get(){
field.style = Paint.Style.STROKE
field.strokeWidth = 3F
field.color = fillEnableColor
field.style = Paint.Style.FILL_AND_STROKE
field.color = fillDisableColor
return field
}
private val prorgressHalfW:Float
get() { return when(direction){
StatusProgressDirection.HORIZONTAL -> measuredHeight/8f
StatusProgressDirection.VERTICAL -> measuredWidth/8f
}}
private val enableRadius:Float
get() { return when(direction){
StatusProgressDirection.HORIZONTAL -> height/2f
StatusProgressDirection.VERTICAL -> width/2f
StatusProgressDirection.HORIZONTAL -> measuredHeight/4f
StatusProgressDirection.VERTICAL -> measuredWidth/4f
}}
private val crossRadius:Float
get() { return when(direction){
StatusProgressDirection.HORIZONTAL -> measuredHeight/2.1f
StatusProgressDirection.VERTICAL -> measuredWidth/2.1f
}}
private val disableRadius:Float
get() { return when(direction){
StatusProgressDirection.HORIZONTAL -> height/2f
StatusProgressDirection.VERTICAL -> width/2f
StatusProgressDirection.HORIZONTAL -> measuredHeight/2f
StatusProgressDirection.VERTICAL -> measuredWidth/2f
}}
//region startProgressRect
private val progressStartLeft:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> 0f
StatusProgressDirection.VERTICAL -> measuredWidth / 2f - prorgressHalfW
}
}
private val progressStartTop:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> measuredHeight / 2f - prorgressHalfW
StatusProgressDirection.VERTICAL -> 0f
}
}
private val progressStartRight:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> measuredWidth/2f
StatusProgressDirection.VERTICAL -> measuredWidth / 2f + prorgressHalfW
}
}
private val progressStartBottom:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> measuredHeight / 2f + prorgressHalfW
StatusProgressDirection.VERTICAL -> measuredHeight / 2f
}
}
//endregion
//region endProgressRect
private val progressEndLeft:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> width/2f
StatusProgressDirection.VERTICAL -> width / 2f - prorgressHalfW
}
}
private val progressEndTop:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> height / 2f - prorgressHalfW
StatusProgressDirection.VERTICAL -> height / 2f
}
}
private val progressEndRight:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> width.toFloat()
StatusProgressDirection.VERTICAL -> width / 2f + prorgressHalfW
}
}
private val progressEndBottom:Float
get() {
return when (direction) {
StatusProgressDirection.HORIZONTAL -> height / 2f + prorgressHalfW
StatusProgressDirection.VERTICAL -> height.toFloat()
}
}
//endregion
private var enableDisableCrossRadius:Int = 0
private val centerStatus:PointF
get() {
......@@ -61,15 +165,88 @@ class StatusProgressCeil @JvmOverloads constructor(
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
canvas?.drawColor(Color.TRANSPARENT)
when(animateState){
StatusProgressAnimationState.ENABLE -> drawEnable(canvas)
StatusProgressAnimationState.DISABLE -> drawDisable(canvas)
StatusProgressAnimationState.TOENABLE -> drawToEnable(canvas)
StatusProgressAnimationState.TODISABLE -> drawToDisable(canvas)
}
}
fun drawStartProgress(canvas: Canvas?){
if (hasStart)
canvas?.drawRect(
progressStartLeft,
progressStartTop,
progressStartRight,
progressStartBottom,
enablePaint
)
}
fun drawEndProgress(canvas: Canvas?){
if (hasEnd)
canvas?.drawRect(
progressEndLeft,
progressEndTop,
progressEndRight,
progressEndBottom,
enablePaint
)
}
private fun drawEnable(canvas: Canvas?){
drawStartProgress(canvas)
drawEndProgress(canvas)
canvas?.drawCircle(centerStatus.x,centerStatus.y
,if (nextEnable) enableRadius else crossRadius
,enablePaint)
}
private fun drawDisable(canvas: Canvas?){
drawStartProgress(canvas)
drawEndProgress(canvas)
canvas?.drawCircle(centerStatus.x,centerStatus.y,enableRadius,disablePaint)
}
private fun drawToEnable(canvas: Canvas?){
drawStartProgress(canvas)
drawEndProgress(canvas)
canvas?.drawCircle(centerStatus.x,centerStatus.y,enableRadius,enablePaint)
}
private fun drawToDisable(canvas: Canvas?){
drawStartProgress(canvas)
drawEndProgress(canvas)
canvas?.drawCircle(centerStatus.x,centerStatus.y,enableRadius,disablePaint)
}
}
enum class StatusProgressDirection{
HORIZONTAL,
VERTICAL
}
\ No newline at end of file
enum class StatusProgressDirection(val dir:Int){
HORIZONTAL(1),
VERTICAL(2);
companion object {
fun fromInt(value: Int) = values().first { it.dir == value }
}
}
enum class StatusProgressAnimationState(val state:Int){
ENABLE(1),
DISABLE(2),
TOENABLE(3),
TODISABLE(4);
companion object {
fun fromInt(value: Int) = StatusProgressAnimationState.values().first { it.state == value }
}
}
......@@ -65,9 +65,10 @@
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" >
<include layout="@layout/authentication_screen"
<include
layout="@layout/progress_deal_state_pattern_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="125dp" />
</FrameLayout>
......
......@@ -21,8 +21,8 @@
<ImageView
android:id="@+id/imageView4"
android:layout_width="125"
android:layout_height="125"
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_marginStart="27dp"
android:layout_marginTop="44dp"
app:layout_constraintStart_toStartOf="parent"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sum"
android:layout_width="wrap_content"
android:layout_height="64dp"
android:layout_height="24dp"
android:background="@color/colorCheckListGradientEnd"
android:orientation="horizontal">
android:orientation="horizontal"
android:weightSum="3">
<com.biganto.visual.roompark.view_utils.status_progress_view.StatusProgressCeil
android:layout_width="66dp"
android:layout_height="match_parent"
android:scaleType="fitEnd"
app:direction="horizontal"
app:hasEnd="true"
app:hasStart="false"
app:isEnable="true"
app:nextEnable="true" />
<TextView
android:id="@+id/imageView7"
android:layout_width="58dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/horizontal_patch"
android:scaleType="fitEnd" />
<TextView
android:id="@+id/imageView8"
android:layout_width="122dp"
android:layout_height="wrap_content"
<com.biganto.visual.roompark.view_utils.status_progress_view.StatusProgressCeil
android:layout_width="125dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/horizontal_patch" />
android:scaleType="fitEnd"
app:direction="horizontal"
app:hasEnd="true"
app:hasStart="true"
app:isEnable="false"
app:nextEnable="false" />
<FrameLayout
android:id="@+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<com.biganto.visual.roompark.view_utils.status_progress_view.StatusProgressCeil
android:layout_width="88dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/horizontal_patch"
android:scaleType="fitEnd" />
android:scaleType="fitEnd"
app:direction="horizontal"
app:hasEnd="false"
app:hasStart="true"
app:isEnable="true"
app:nextEnable="false" />
</LinearLayout>
\ No newline at end of file
......@@ -3,4 +3,22 @@
<declare-styleable name="RoundedImageView">
<attr name="image_corner_radius" format="dimension"/>
</declare-styleable>
</resources>
\ No newline at end of file
<declare-styleable name="StatusProgressCeil">
<attr name="hasStart" format="boolean"/>
<attr name="hasEnd" format="boolean"/>
<attr name="isEnable" format="boolean"/>
<attr name="nextEnable" format="boolean"/>
<attr name="direction">
<enum name="horizontal" value="1" />
<enum name="vertical" value="2" />
</attr>
<attr name="anim_state">
<enum name="enable" value="1" />
<enum name="disable" value="2" />
<enum name="toEnable" value="3" />
<enum name="toDisable" value="4" />
</attr>
</declare-styleable>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment