Skip to content

Commit

Permalink
FEAT: rework text alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
balakz committed Feb 23, 2021
1 parent c79f23c commit 627fc32
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ class MainActivity : AppCompatActivity() {
private lateinit var form: Form

private val charPool: List<Char> = ('a'..'z') + ('A'..'Z')
private val stringValues = arrayOf("one", "two", "three", "four", "five").map { "Option $it" }.toList()
private val stringValues = arrayOf(
"one",
"two",
"three",
"four",
"really long long long long long five"
).map { "Option $it" }.toList()
private val longerStringValues = (1..5).map { randomString(25) }

private val notEmptyValidator = NotBlankFormValidator("This field is empty")
private val emailValidator = EmailValidator("This is not valid email!")
private val maxLengthValidator = MaxLengthFormValidator("This filed has more than 10 characters.", 10)
private val maxLengthValidator =
MaxLengthFormValidator("This filed has more than 10 characters.", 10)

private val validateActionCallback = object : ActionCallback, Form.Callback {
override fun successCallback() {
Expand Down Expand Up @@ -115,15 +122,57 @@ class MainActivity : AppCompatActivity() {
addElement(HeaderElement("Static elements"), true)
addElement(TextElement("TextElement value"), true)
addElement(LabelTextElement("LabelTextElement label", "LabelTextElement text"), true)
addElement(
LabelTextElement(
"LabelTextElement label with very long text which needs to overflow",
"LabelTextElement text with very long text which needs to overflow"
), true
)
addElement(
LabelTextElement(
"Label",
"LabelTextElement text with very long text which needs to overflow"
), true
)
addElement(OpenableHeaderTextElement("OpenableHeaderTextElement label", longerStringValues))
addSpace()

//input elements
addElement(HeaderElement("Input elements"), true)
addElement(LabelSwitchElement("LabelSwitchElement label", true, showToastCheckboxCallback), true)
addElement(LabelSpinnerElement("LabelSpinnerElement label", "Option one", arrayListOf("Select...").plus(stringValues), null, formValidators = mutableListOf<FormValidator<String>>(NotEqualToValidator("Select...", "You have to select a value!"))), true)
addElement(LabelCheckboxElement("LabelCheckboxElement label", true, showToastCheckboxCallback), true)
addElement(LabelDateTimeElement("Date picker", "Vyberte datum...", supportFragmentManager, showToastDateTimeValueCallback, formValidators = arrayListOf(NotInPastValidator("Date cannot be in past"))))
addElement(
LabelSwitchElement("LabelSwitchElement label", true, showToastCheckboxCallback),
true
)
addElement(
LabelSpinnerElement(
"LabelSpinnerElement label",
"Option one",
arrayListOf("Select...").plus(stringValues),
null,
formValidators = mutableListOf<FormValidator<String>>(
NotEqualToValidator(
"Select...",
"You have to select a value!"
)
)
), true
)
addElement(
LabelCheckboxElement(
"LabelCheckboxElement label",
true,
showToastCheckboxCallback
), true
)
addElement(
LabelDateTimeElement(
"Date picker",
"Vyberte datum...",
supportFragmentManager,
showToastDateTimeValueCallback,
formValidators = arrayListOf(NotInPastValidator("Date cannot be in past"))
)
)
addSpace()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ import cz.qase.android.formbuilderlibrary.R
import cz.qase.android.formbuilderlibrary.element.generic.ActionCallback


class ActionElement(actionCallback: ActionCallback,
label: String,
groupComponent: Int = R.layout.form_group_item_inline,
headerComponent: Int = R.layout.form_inline_label,
symbolComponent: Int = R.layout.form_button_symbol,
formStyleBundle: FormStyleBundle? = null
) : NavigationElement(actionCallback, label, groupComponent, headerComponent, symbolComponent, formStyleBundle)
class ActionElement(
actionCallback: ActionCallback,
label: String,
groupComponent: Int = R.layout.form_group_item_inline,
headerComponent: Int = R.layout.form_inline_label,
symbolComponent: Int = R.layout.form_button_symbol,
groupComponentEnd: Int = R.layout.form_group_item_inline_end,
formStyleBundle: FormStyleBundle? = null
) : NavigationElement(
actionCallback,
label,
groupComponent,
headerComponent,
symbolComponent,
groupComponentEnd,
formStyleBundle
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import cz.qase.android.formbuilderlibrary.element.generic.CheckboxCallback
import cz.qase.android.formbuilderlibrary.element.generic.FormElementValid

class LabelCheckboxElement(
private val label: String,
private val checked: Boolean,
private val checkboxCallback: CheckboxCallback,
private val groupComponent: Int = R.layout.form_group_item_inline,
private val labelComponent: Int = R.layout.form_inline_label,
private val checkboxComponent: Int = R.layout.form_checkbox_item,
private val formStyleBundle: FormStyleBundle? = null
private val label: String,
private val checked: Boolean,
private val checkboxCallback: CheckboxCallback,
private val groupComponent: Int = R.layout.form_group_item_inline,
private val labelComponent: Int = R.layout.form_inline_label,
private val checkboxComponent: Int = R.layout.form_checkbox_item,
private val groupComponentEnd: Int = R.layout.form_group_item_inline_end,
private val formStyleBundle: FormStyleBundle? = null
) : FormElementValid<Boolean>() {

private var checkbox: CheckBox? = null
Expand All @@ -45,28 +46,43 @@ class LabelCheckboxElement(
override fun createView(context: Context, formStyleBundle: FormStyleBundle): View {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(groupComponent, null) as ViewGroup
val labelView = prepareLabel(inflater, context, this.formStyleBundle
?: formStyleBundle, view)
val checkboxView = prepareCheckbox(inflater, context, this.formStyleBundle
?: formStyleBundle, view)
val groupEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup
val labelView = prepareLabel(
inflater, context, this.formStyleBundle
?: formStyleBundle, view
)
val checkboxView = prepareCheckbox(
inflater, context, this.formStyleBundle
?: formStyleBundle, groupEnd
)
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
view.addView(labelView)
view.addView(checkboxView)
groupEnd.addView(checkboxView)
view.addView(groupEnd)
viewGroup = view
return view
}

private fun prepareLabel(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): TextView {
private fun prepareLabel(
inflater: LayoutInflater,
context: Context,
formStyleBundle: FormStyleBundle,
root: ViewGroup
): TextView {
val headerView = inflater.inflate(labelComponent, root, false) as TextView
headerView.setTextColorResourceId(context, formStyleBundle.primaryTextColor)
headerView.text = label
return headerView
}

private fun prepareCheckbox(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): CheckBox {
val checkbox = inflater.inflate(checkboxComponent, root, false) as CheckBox

private fun prepareCheckbox(
inflater: LayoutInflater,
context: Context,
formStyleBundle: FormStyleBundle,
root: ViewGroup
): CheckBox {

val checkbox = inflater.inflate(checkboxComponent, root, false) as CheckBox
val color = ContextCompat.getColor(context, formStyleBundle.primaryBackgroundColor)
CompoundButtonCompat.setButtonTintList(checkbox, ColorStateList.valueOf(color))
checkbox.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import cz.qase.android.formbuilderlibrary.common.setTextColorResourceId
import cz.qase.android.formbuilderlibrary.element.generic.CheckboxCallback
import cz.qase.android.formbuilderlibrary.element.generic.FormElementValid

class LabelSwitchElement(private val label: String,
private var initialValue: Boolean,
private val checkboxCallback: CheckboxCallback,
private val groupComponent: Int = R.layout.form_group_item_inline,
private val headerComponent: Int = R.layout.form_inline_label,
private val switchComponent: Int = R.layout.form_inline_switch,
private val formStyleBundle: FormStyleBundle? = null) : FormElementValid<Boolean>() {
class LabelSwitchElement(
private val label: String,
private var initialValue: Boolean,
private val checkboxCallback: CheckboxCallback,
private val groupComponent: Int = R.layout.form_group_item_inline,
private val headerComponent: Int = R.layout.form_inline_label,
private val switchComponent: Int = R.layout.form_inline_switch,
private val groupComponentEnd: Int = R.layout.form_group_item_inline_end,
private val formStyleBundle: FormStyleBundle? = null
) : FormElementValid<Boolean>() {

private var switchView: SwitchCompat? = null
private var viewGroup: ViewGroup? = null
Expand All @@ -43,13 +46,19 @@ class LabelSwitchElement(private val label: String,
override fun createView(context: Context, formStyleBundle: FormStyleBundle): View {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(groupComponent, null) as ViewGroup
val headerView = prepareHeader(inflater, context, this.formStyleBundle
?: formStyleBundle, view)
val textView = prepareSwitch(inflater, context, this.formStyleBundle
?: formStyleBundle, view)
val groupEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup
val headerView = prepareHeader(
inflater, context, this.formStyleBundle
?: formStyleBundle, view
)
val textView = prepareSwitch(
inflater, context, this.formStyleBundle
?: formStyleBundle, groupEnd
)
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
view.addView(headerView)
view.addView(textView)
groupEnd.addView(textView)
view.addView(groupEnd)
viewGroup = view
return view
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import cz.qase.android.formbuilderlibrary.common.setTextColorResourceId
import cz.qase.android.formbuilderlibrary.element.generic.ActionCallback
import cz.qase.android.formbuilderlibrary.element.generic.FormElementNoValue

open class NavigationElement(private val actionCallback: ActionCallback,
private val label: String,
private val groupComponent: Int = R.layout.form_group_item_inline,
private val headerComponent: Int = R.layout.form_inline_label,
private val symbolComponent: Int = R.layout.form_navigation_symbol,
private val formStyleBundle: FormStyleBundle? = null) : FormElementNoValue() {
open class NavigationElement(
private val actionCallback: ActionCallback,
private val label: String,
private val groupComponent: Int = R.layout.form_group_item_inline,
private val headerComponent: Int = R.layout.form_inline_label,
private val symbolComponent: Int = R.layout.form_navigation_symbol,
private val groupComponentEnd: Int = R.layout.form_group_item_inline_end,
private val formStyleBundle: FormStyleBundle? = null
) : FormElementNoValue() {

private var viewGroup: ViewGroup? = null

Expand All @@ -35,26 +38,37 @@ open class NavigationElement(private val actionCallback: ActionCallback,
override fun createView(context: Context, formStyleBundle: FormStyleBundle): View {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(groupComponent, null) as ViewGroup
val headerView = prepareLabel(inflater, context, this.formStyleBundle
?: formStyleBundle, view)
val symbolView = prepareSymbol(inflater, context, this.formStyleBundle
?: formStyleBundle, view)
val groupEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup
val headerView = prepareLabel(
inflater, context, this.formStyleBundle
?: formStyleBundle, view
)
val symbolView = prepareSymbol(
inflater, context, this.formStyleBundle
?: formStyleBundle, groupEnd
)
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
view.addView(headerView)
view.addView(symbolView)

groupEnd.addView(symbolView)
view.addView(groupEnd)
view.isClickable = true
view.setOnClickListener {
actionCallback.callback()
}
view.setOnTouchListener { _, event ->
when (event.action) {
MotionEvent.ACTION_UP -> {
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
view.setBackgroundColorResourceId(
context,
formStyleBundle.secondaryBackgroundColor
)
view.performClick()
}
MotionEvent.ACTION_CANCEL -> {
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
view.setBackgroundColorResourceId(
context,
formStyleBundle.secondaryBackgroundColor
)
}
MotionEvent.ACTION_DOWN -> {
view.setBackgroundColorResourceId(context, formStyleBundle.primaryBackgroundColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ open class NavigationWithErrorElement(
private val headerComponent: Int = R.layout.form_inline_label,
private val warningSymbolComponent: Int = R.layout.form_error_symbol,
private val symbolComponent: Int = R.layout.form_navigation_symbol,
private val groupComponentEnd: Int = R.layout.form_group_item_inline_end,
private val formStyleBundle: FormStyleBundle? = null
) : FormElementNoValue() {

Expand All @@ -38,19 +39,21 @@ open class NavigationWithErrorElement(
override fun createView(context: Context, formStyleBundle: FormStyleBundle): View {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(groupComponent, null) as ViewGroup
val viewEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup
val headerView = prepareLabel(
inflater, context, this.formStyleBundle
?: formStyleBundle, view
)
val errorView = inflater.inflate(warningSymbolComponent, view, false) as ImageView
val errorView = inflater.inflate(warningSymbolComponent, viewEnd, false) as ImageView
val symbolView = prepareSymbol(
inflater, context, this.formStyleBundle
?: formStyleBundle, view
?: formStyleBundle, viewEnd
)
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor)
view.addView(headerView)
view.addView(errorView)
view.addView(symbolView)
viewEnd.addView(errorView)
viewEnd.addView(symbolView)
view.addView(viewEnd)

view.isClickable = true
view.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatCheckBox xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:gravity="end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
/>

7 changes: 1 addition & 6 deletions formbuilderlibrary/src/main/res/layout/form_error_symbol.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/errorSymbol"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:tint="@color/colorRed"
android:contentDescription="@string/navigation"
android:src="@drawable/ic_error"
android:textAlignment="gravity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/navigationSymbol"
app:layout_constraintTop_toTopOf="parent" />
/>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:minHeight="@dimen/all_min_height"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/form_group_item_inline_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end|center_vertical">

</LinearLayout>
Loading

0 comments on commit 627fc32

Please sign in to comment.