diff --git a/README.md b/README.md index 660cae7..bed0ea4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/src/main/java/com/kareemradwan/stepeer/MainActivity.kt b/app/src/main/java/com/kareemradwan/stepeer/MainActivity.kt index 08aecdd..de84591 100644 --- a/app/src/main/java/com/kareemradwan/stepeer/MainActivity.kt +++ b/app/src/main/java/com/kareemradwan/stepeer/MainActivity.kt @@ -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.* diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bcd05b0..af9927a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,22 +15,21 @@ tools:context=".MainActivity"> - - { return hashMapOf( - Pair(COLOR_CHECKED, StepColor(defaultColor)), - Pair(COLOR_CHECKED, StepColor(defaultColor)) + Pair(Constants.COLOR_CHECKED, StepColor(defaultColor)), + Pair(Constants.COLOR_CHECKED, StepColor(defaultColor)) ) } } diff --git a/stepeer/src/main/java/com/kradwan/stepeer/view/NumberStepperView.kt b/stepeer/src/main/java/com/kradwan/stepeer/view/numberStepper/NumberStepperView.kt similarity index 69% rename from stepeer/src/main/java/com/kradwan/stepeer/view/NumberStepperView.kt rename to stepeer/src/main/java/com/kradwan/stepeer/view/numberStepper/NumberStepperView.kt index e218657..28887d6 100644 --- a/stepeer/src/main/java/com/kradwan/stepeer/view/NumberStepperView.kt +++ b/stepeer/src/main/java/com/kradwan/stepeer/view/numberStepper/NumberStepperView.kt @@ -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 @@ -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 /** @@ -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` */ - - /** - * - - - - - - - - */ - val numTextColorChecked = style.getColor(R.styleable.NumberStepperView_num_text_color_checked, -1) val numTextColorUnChecked = @@ -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) } } @@ -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, @@ -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) } } diff --git a/stepeer/src/main/java/com/kradwan/stepeer/view/SingleNumberStepView.kt b/stepeer/src/main/java/com/kradwan/stepeer/view/numberStepper/SingleNumberStepView.kt similarity index 71% rename from stepeer/src/main/java/com/kradwan/stepeer/view/SingleNumberStepView.kt rename to stepeer/src/main/java/com/kradwan/stepeer/view/numberStepper/SingleNumberStepView.kt index be308ad..7b936ae 100644 --- a/stepeer/src/main/java/com/kradwan/stepeer/view/SingleNumberStepView.kt +++ b/stepeer/src/main/java/com/kradwan/stepeer/view/numberStepper/SingleNumberStepView.kt @@ -1,18 +1,16 @@ -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 @@ -20,7 +18,7 @@ import com.kradwan.stepeer.model.StepResource */ @SuppressLint("ViewConstructor") -class SingleNumberStepView( +internal class SingleNumberStepView( context: Context, private var colors: HashMap, private var icons: HashMap @@ -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 - */ } @@ -92,7 +73,7 @@ class SingleNumberStepView( */ fun 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 @@ -139,14 +120,8 @@ 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 @@ -154,12 +129,12 @@ class SingleNumberStepView( */ 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 } } diff --git a/stepeer/src/main/java/com/kradwan/stepeer/view/SingleStepView.kt b/stepeer/src/main/java/com/kradwan/stepeer/view/verticalStepper/SingleStepView.kt similarity index 92% rename from stepeer/src/main/java/com/kradwan/stepeer/view/SingleStepView.kt rename to stepeer/src/main/java/com/kradwan/stepeer/view/verticalStepper/SingleStepView.kt index 5b48f9c..9c1bd8d 100644 --- a/stepeer/src/main/java/com/kradwan/stepeer/view/SingleStepView.kt +++ b/stepeer/src/main/java/com/kradwan/stepeer/view/verticalStepper/SingleStepView.kt @@ -1,4 +1,4 @@ -package com.kradwan.stepeer.view +package com.kradwan.stepeer.view.verticalStepper import android.annotation.SuppressLint import android.content.Context @@ -10,9 +10,7 @@ import android.widget.FrameLayout import android.widget.ImageView import android.widget.LinearLayout import com.kradwan.stepeer.R -import com.kradwan.stepeer.model.IStep -import com.kradwan.stepeer.model.StepColor -import com.kradwan.stepeer.model.StepDrawable +import com.kradwan.stepeer.model.* /** * This Class Represent Each Step as View @@ -20,7 +18,7 @@ import com.kradwan.stepeer.model.StepDrawable */ @SuppressLint("ViewConstructor") -class SingleStepView( +internal class SingleStepView( context: Context, private var colors: HashMap, private var icons: HashMap @@ -67,13 +65,13 @@ class SingleStepView( */ // Check if you override `Checked` state Color // Change Default Color to your Custom Color - checkBoxSelectedColor = colors[StepColor.COLOR_CHECKED]!! + checkBoxSelectedColor = colors[Constants.COLOR_CHECKED]!! /** * Check if you override `unChecked` state Color * because UnCheck Color is Default and initial State you need Override View Color */ - checkBoxUnSelectedColor = colors[StepColor.COLOR_UNCHECKED]!! + checkBoxUnSelectedColor = colors[Constants.COLOR_UNCHECKED]!! stepDivider.setBackgroundColor(checkBoxUnSelectedColor.color) stepDividerSolid.setBackgroundColor(checkBoxUnSelectedColor.color) @@ -140,7 +138,7 @@ class SingleStepView( */ if (animated) { - stepDividerSolid.setBackgroundColor(colors[StepColor.COLOR_CHECKED]!!.color) + stepDividerSolid.setBackgroundColor(colors[Constants.COLOR_CHECKED]!!.color) stepDividerSolid.visibility = View.VISIBLE val move = AnimationUtils.loadAnimation(context, R.anim.move) stepDividerSolid.animation = move diff --git a/stepeer/src/main/java/com/kradwan/stepeer/view/SteeperView.kt b/stepeer/src/main/java/com/kradwan/stepeer/view/verticalStepper/SteeperView.kt similarity index 90% rename from stepeer/src/main/java/com/kradwan/stepeer/view/SteeperView.kt rename to stepeer/src/main/java/com/kradwan/stepeer/view/verticalStepper/SteeperView.kt index f478967..3c48260 100644 --- a/stepeer/src/main/java/com/kradwan/stepeer/view/SteeperView.kt +++ b/stepeer/src/main/java/com/kradwan/stepeer/view/verticalStepper/SteeperView.kt @@ -1,11 +1,9 @@ -package com.kradwan.stepeer.view +package com.kradwan.stepeer.view.verticalStepper 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 @@ -13,10 +11,7 @@ import androidx.core.view.get 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.StepColor -import com.kradwan.stepeer.model.StepDrawable -import kotlinx.android.synthetic.main.item_step.view.* +import com.kradwan.stepeer.model.* import java.lang.Exception /** @@ -24,7 +19,7 @@ import java.lang.Exception * @param context passed to FrameLayout (parent) * @param attrs passed to FrameLayout (parent) */ -class SteeperView(context: Context, private val attrs: AttributeSet?) : + class SteeperView(context: Context, private val attrs: AttributeSet?) : FrameLayout(context, attrs) { // The Root View @@ -65,7 +60,7 @@ class SteeperView(context: Context, private val attrs: AttributeSet?) : // Get The List Of Steps if null [ First Time Open] Assign Empty List mAdapter.models = myState?.steps ?: listOf() // Pass Adapter to Build UI - setAdapter(mAdapter , false) + setAdapter(mAdapter, false) //redraw } @@ -91,9 +86,9 @@ class SteeperView(context: Context, private val attrs: AttributeSet?) : val unCheckIcon = style.getDrawable(R.styleable.SteeperView_unchecked_icon) - colors[StepColor.COLOR_CHECKED] = + colors[Constants.COLOR_CHECKED] = if (checkColor != -1) StepColor(checkColor) else StepColor(StepColor.defaultColor) - colors[StepColor.COLOR_UNCHECKED] = + colors[Constants.COLOR_UNCHECKED] = if (unCheckColor != -1) StepColor(unCheckColor) else StepColor(StepColor.defaultColor) @@ -117,7 +112,7 @@ class SteeperView(context: Context, private val attrs: AttributeSet?) : * and Show in screen * @param adapter Any Class Inherited [StepAdapter] */ - fun setAdapter(adapter: StepAdapter , animated: Boolean = true) { + fun setAdapter(adapter: StepAdapter, animated: Boolean = true) { try { // because we need assign adapter to global variable // we need Cast generic Type to IStep @@ -136,9 +131,14 @@ class SteeperView(context: Context, private val attrs: AttributeSet?) : currentStep++ } // View of Single Step Without Any Actual Data - val step = SingleStepView(view.context, colors, icons) + val step = + SingleStepView( + view.context, + colors, + icons + ) // Assign Actual Data to Step View - step.setModel(it, adapter.onCreateView(it), adapter.models.last() == it , animated) + step.setModel(it, adapter.onCreateView(it), adapter.models.last() == it, animated) // Add Step in Container of Steps containerSteeper.addView(step) } diff --git a/stepeer/src/main/res/layout/item_num_step.xml b/stepeer/src/main/res/layout/item_num_step.xml index 5ee0862..7c65039 100644 --- a/stepeer/src/main/res/layout/item_num_step.xml +++ b/stepeer/src/main/res/layout/item_num_step.xml @@ -29,6 +29,7 @@ android:layout_gravity="center" android:gravity="center" android:minWidth="35dp" + android:textStyle="bold" android:minHeight="35dp" tools:text="2" android:textAlignment="center" />