Skip to content

Commit

Permalink
add number stepper version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kareemradwan committed Jul 4, 2020
1 parent 5940bad commit 02e20a0
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 146 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ You can Register The Activity as Controller to Notifiy When `SteeoerView` Finish
- [X] The Developer Can Custmise Color of Step.
- [X] Save State of View When Device Rotate.
- [X] Custmaize Color for `unChecked` and `Checked` status
- [X] Add Number Stepper View
- [ ] Add Animation for `CheckBox` When be Selected


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/kareemradwan/stepeer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.kradwan.stepeer.view.SteeperView
import com.kradwan.stepeer.view.verticalStepper.SteeperView
import kotlinx.android.synthetic.main.activity_main.*


Expand Down
9 changes: 4 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
tools:context=".MainActivity">


<com.kradwan.stepeer.view.NumberStepperView
<com.kradwan.stepeer.view.numberStepper.NumberStepperView
android:id="@+id/steeper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:step_icon_checked="@drawable/bg_rounded_fill"
app:step_icon_unchecked="@drawable/ic_radio_button_unchecked_black_24dp"

app:divider_color_checked="@color/colorAccent"
app:divider_color_unchecked="@android:color/black"
app:num_text_color_checked="@android:color/white"
app:num_text_color_checked="#fffff2"
app:num_text_color_unchecked="@android:color/black"
android:padding="20dp"
/>



<com.kradwan.stepeer.view.SteeperView
<com.kradwan.stepeer.view.verticalStepper.SteeperView
android:id="@+id/steeper2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
21 changes: 21 additions & 0 deletions stepeer/src/main/java/com/kradwan/stepeer/model/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kradwan.stepeer.model


class Constants {
companion object {
const val COLOR_CHECKED = "checked_color"
const val COLOR_UNCHECKED = "unchecked_color"

// For Number Step View

const val NUM_TEXT_COLOR_CHECKED = "NUM_TEXt_COLOR_CHECKED"
const val NUM_TEXT_COLOR_UNCHECKED = "NUM_TEXt_COLOR_UNCHECKED"

const val STEP_ICON_CHECKED = "STEP_ICON_CHECKED"
const val STEP_ICON_UNCHECKED = "STEP_ICON_UNCHECKED"

const val DIVIDER_COLOR_CHECKED = "DIVIDER_COLOR_CHECKED"
const val DIVIDER_COLOR_UNCHECKED = "DIVIDER_COLOR_UNCHECKED"

}
}
17 changes: 2 additions & 15 deletions stepeer/src/main/java/com/kradwan/stepeer/model/StepColor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,14 @@ import android.graphics.Color
data class StepColor(var color: Int) {

companion object {
const val COLOR_CHECKED = "checked_color"
const val COLOR_UNCHECKED = "unchecked_color"

// For Number Step View

const val NUM_TEXT_COLOR_CHECKED = "NUM_TEXt_COLOR_CHECKED"
const val NUM_TEXT_COLOR_UNCHECKED = "NUM_TEXt_COLOR_UNCHECKED"

const val STEP_ICON_CHECKED = "STEP_ICON_CHECKED"
const val STEP_ICON_UNCHECKED = "STEP_ICON_UNCHECKED"

const val DIVIDER_COLOR_CHECKED = "DIVIDER_COLOR_CHECKED"
const val DIVIDER_COLOR_UNCHECKED = "DIVIDER_COLOR_UNCHECKED"


val defaultColor = Color.parseColor("#1C8AFF")

fun default(): HashMap<String, StepColor> {
return hashMapOf(
Pair(COLOR_CHECKED, StepColor(defaultColor)),
Pair(COLOR_CHECKED, StepColor(defaultColor))
Pair(Constants.COLOR_CHECKED, StepColor(defaultColor)),
Pair(Constants.COLOR_CHECKED, StepColor(defaultColor))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.kradwan.stepeer.view
package com.kradwan.stepeer.view.numberStepper

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.Parcelable
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
Expand All @@ -15,10 +14,9 @@ import com.kradwan.stepeer.R
import com.kradwan.stepeer.StepperState
import com.kradwan.stepeer.adapter.StepAdapter
import com.kradwan.stepeer.model.IStep
import com.kradwan.stepeer.model.Constants
import com.kradwan.stepeer.model.StepColor
import com.kradwan.stepeer.model.StepDrawable
import com.kradwan.stepeer.model.StepResource
import kotlinx.android.synthetic.main.item_step.view.*
import java.lang.Exception

/**
Expand Down Expand Up @@ -88,18 +86,6 @@ class NumberStepperView(context: Context, private val attrs: AttributeSet?) :
* get First Value [ First from attr file not in XML Order ]
* In our Example the First attr is `check`
*/

/**
* <attr name="num_text_color_checked" format="color"/>
<attr name="num_text_color_unchecked" format="color"/>
<attr name="step_icon_checked" format="reference"/>
<attr name="step_icon_unchecked" format="reference"/>
<attr name="divider_color_checked" format="color"/>
<attr name="divider_color_unchecked" format="color"/>
*/

val numTextColorChecked =
style.getColor(R.styleable.NumberStepperView_num_text_color_checked, -1)
val numTextColorUnChecked =
Expand All @@ -110,71 +96,49 @@ class NumberStepperView(context: Context, private val attrs: AttributeSet?) :
style.getColor(R.styleable.NumberStepperView_divider_color_unchecked, -1)


val iconChecked = style.getResourceId(R.styleable.SteeperView_checked_icon, -1)
val iconUnChecked = style.getResourceId(R.styleable.SteeperView_unchecked_icon, -1)

colors[StepColor.NUM_TEXT_COLOR_CHECKED] =
colors[Constants.NUM_TEXT_COLOR_CHECKED] =
if (numTextColorChecked != -1) StepColor(numTextColorChecked) else StepColor(
Color.parseColor(
"#456333"
)
)

colors[StepColor.NUM_TEXT_COLOR_UNCHECKED] =
colors[Constants.NUM_TEXT_COLOR_UNCHECKED] =
if (numTextColorUnChecked != -1) StepColor(numTextColorUnChecked) else StepColor(
Color.parseColor("#456333")
)

colors[StepColor.DIVIDER_COLOR_CHECKED] =
colors[Constants.DIVIDER_COLOR_CHECKED] =
if (dividerColorChecked != -1) StepColor(dividerColorChecked) else StepColor(
Color.parseColor(
"#456333"
)
)
colors[StepColor.DIVIDER_COLOR_UNCHECKED] =
colors[Constants.DIVIDER_COLOR_UNCHECKED] =
if (dividerColorUnChecked != -1) StepColor(dividerColorUnChecked) else StepColor(
Color.parseColor("#456333")
)


icons[StepColor.STEP_ICON_UNCHECKED] = StepDrawable.fromId(context ,iconChecked)
icons[StepColor.STEP_ICON_CHECKED] = StepDrawable.fromId( context ,iconUnChecked)

// val stepIconChecked = style.getDrawable(R.styleable.NumberStepperView_step_icon_checked)
// val stepIconUnChecked = style.getDrawable(R.styleable.NumberStepperView_step_icon_unchecked)
//
// icons[StepColor.STEP_ICON_CHECKED] =
// if (stepIconChecked == null) StepDrawable(
// ContextCompat.getDrawable(
// context,
// R.drawable.ic_check_circle_black_24dp
// )!!
// ) else StepDrawable(stepIconChecked)
//
// icons[StepColor.STEP_ICON_UNCHECKED] =
// if (stepIconChecked == null) StepDrawable(
// ContextCompat.getDrawable(
// context,
// R.drawable.ic_check_circle_black_24dp
// )!!
// ) else StepDrawable(stepIconChecked)

// icons[StepColor.STEP_ICON_UNCHECKED] = StepDrawable(stepIconChecked!!)


// colors[StepColor.COLOR_CHECKED] =
// if (checkColor != -1) StepColor(checkColor) else StepColor(Color.parseColor("#456333"))

// colors[StepColor.COLOR_UNCHECKED] =
// if (unCheckColor != -1) StepColor(unCheckColor) else StepColor(Color.parseColor("#456333"))
val stepIconChecked = style.getDrawable(R.styleable.NumberStepperView_step_icon_checked)
val stepIconUnChecked =
style.getDrawable(R.styleable.NumberStepperView_step_icon_unchecked)
//
// icons[StepDrawable.DRAWABLE_CHECKED] =
// if (checkIcon != -1) StepResource(checkIcon) else StepResource(R.drawable.ic_check_circle_black_24dp)
//
//
// icons[StepDrawable.DRAWABLE_UNCHECKED] =
// if (unCheckIcon != -1) StepResource(unCheckIcon) else StepResource(R.drawable.ic_radio_button_unchecked_black_24dp)

icons[Constants.STEP_ICON_CHECKED] =
if (stepIconChecked == null) StepDrawable(
ContextCompat.getDrawable(
context,
R.drawable.bg_rounded_fill
)!!
) else StepDrawable(stepIconChecked)

icons[Constants.STEP_ICON_UNCHECKED] =
if (stepIconUnChecked == null) StepDrawable(
ContextCompat.getDrawable(
context,
R.drawable.ic_radio_button_unchecked_black_24dp
)!!
) else StepDrawable(stepIconUnChecked)

}
}
Expand Down Expand Up @@ -204,10 +168,13 @@ class NumberStepperView(context: Context, private val attrs: AttributeSet?) :
// Increase Indicator of Where Stepper is Stopped
currentStep++
}
Log.d("DDDD", icons.toString())
Log.d("DDDD", colors.toString())
// View of Single Step Without Any Actual Data
val step = SingleNumberStepView(view.context, colors, icons)
val step =
SingleNumberStepView(
view.context,
colors,
icons
)
// Assign Actual Data to Step View
step.setModel(
it,
Expand All @@ -220,9 +187,6 @@ class NumberStepperView(context: Context, private val attrs: AttributeSet?) :
containerSteeper.addView(step)
}
} catch (ex: Exception) {
ex.printStackTrace()
Log.d("DDDD", " EX 22 ${ex.localizedMessage}")
// Handle Any Error and return back to Activity
callback?.onError(ex.localizedMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.kradwan.stepeer.view
package com.kradwan.stepeer.view.numberStepper

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.View
import android.view.animation.AnimationUtils
import android.widget.*
import androidx.core.content.ContextCompat
import com.kradwan.stepeer.R
import com.kradwan.stepeer.model.Constants
import com.kradwan.stepeer.model.IStep
import com.kradwan.stepeer.model.StepColor
import com.kradwan.stepeer.model.StepDrawable
import com.kradwan.stepeer.model.StepResource

/**
* This Class Represent Each Step as View
* @param colors Get From Your XML [ 'checked_color' , 'unchecked_color']
*/

@SuppressLint("ViewConstructor")
class SingleNumberStepView(
internal class SingleNumberStepView(
context: Context,
private var colors: HashMap<String, StepColor>,
private var icons: HashMap<String, StepDrawable>
Expand Down Expand Up @@ -59,28 +57,11 @@ class SingleNumberStepView(
stepDividerSolid = view.findViewById(R.id.stepDividerSolid)
stepContentContainer = view.findViewById(R.id.stepContentContainer)

stepCheckBox.setBackgroundResource(R.drawable.ic_radio_button_unchecked_black_24dp)
// Init Default Values OF UI COLORS and IMAGES
stepCheckBox.background = (icons[Constants.STEP_ICON_UNCHECKED]!!.drawable)
stepDivider.setBackgroundColor(colors[Constants.DIVIDER_COLOR_UNCHECKED]!!.color)
stepDividerSolid.setBackgroundColor(colors[Constants.DIVIDER_COLOR_UNCHECKED]!!.color)

// if (icons[StepDrawable.DRAWABLE_UNCHECKED] != null) {
// stepCheckBox.setImageDrawable(icons[StepDrawable.DRAWABLE_UNCHECKED]?.drawable)
// }
/**
* Check if you Override Default Colors
*/
// Check if you override `Checked` state Color
// Change Default Color to your Custom Color

/**
* Check if you override `unChecked` state Color
* because UnCheck Color is Default and initial State you need Override View Color
*/
stepDivider.setBackgroundColor(colors[StepColor.DIVIDER_COLOR_UNCHECKED]!!.color)
stepDividerSolid.setBackgroundColor(colors[StepColor.DIVIDER_COLOR_UNCHECKED]!!.color)

/**
* Support sdk 15 and higher than it
* Change Tint of Checkbox to checkBoxUnSelectedColor
*/

}

Expand All @@ -92,7 +73,7 @@ class SingleNumberStepView(
*/
fun <T : IStep> setModel(model: T, view: View, last: Boolean, animated: Boolean, label: Int) {
// Set Init State of Checkbox
stepLabel.setTextColor(colors[StepColor.COLOR_UNCHECKED]!!.color)
// stepLabel.setTextColor(colors[StepColor.COLOR_UNCHECKED]!!.color)

// stepCheckBox.setBackgroundResource(R.drawable.ic_radio_button_unchecked_black_24dp)
stepDivider.visibility = if (last) View.GONE else View.VISIBLE
Expand Down Expand Up @@ -139,27 +120,21 @@ class SingleNumberStepView(
* Checked
*/
fun selectAsDone(animated: Boolean) {

// stepCheckBox.setBackgroundResource(icons[StepDrawable.DRAWABLE_CHECKED]!!.id)
// stepCheckBox.background = icons[StepColor.STEP_ICON_UNCHECKED]!!.drawable

// stepCheckBox.background =
// stepCheckBox.background
// stepCheckBox.setBackgroundResource(R.drawable.bg_rounded_fill)
stepLabel.setTextColor(colors[StepColor.COLOR_CHECKED]!!.color)
stepCheckBox.background = icons[Constants.STEP_ICON_CHECKED]!!.drawable
stepLabel.setTextColor(colors[Constants.NUM_TEXT_COLOR_CHECKED]!!.color)

/**
* Support sdk 15 and higher than it
* Change Tint of Checkbox to checkBoxSelectedColor
*/

if (animated) {
stepDividerSolid.setBackgroundColor(colors[StepColor.COLOR_CHECKED]!!.color)
stepDividerSolid.setBackgroundColor(colors[Constants.DIVIDER_COLOR_CHECKED]!!.color)
stepDividerSolid.visibility = View.VISIBLE
val move = AnimationUtils.loadAnimation(context, R.anim.move)
stepDividerSolid.animation = move
} else {
stepDividerSolid.setBackgroundColor(colors[StepColor.DIVIDER_COLOR_CHECKED]!!.color)
stepDividerSolid.setBackgroundColor(colors[Constants.DIVIDER_COLOR_CHECKED]!!.color)
stepDividerSolid.visibility = View.VISIBLE
}
}
Expand Down
Loading

0 comments on commit 02e20a0

Please sign in to comment.