-
Notifications
You must be signed in to change notification settings - Fork 1
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
Zdeněk Balák
committed
Jul 9, 2020
1 parent
d54a970
commit c79f23c
Showing
7 changed files
with
143 additions
and
2 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
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
110 changes: 110 additions & 0 deletions
110
...ry/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationWithErrorElement.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,110 @@ | ||
package cz.qase.android.formbuilderlibrary.element | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import cz.qase.android.formbuilderlibrary.FormStyleBundle | ||
import cz.qase.android.formbuilderlibrary.R | ||
import cz.qase.android.formbuilderlibrary.common.setBackgroundColorResourceId | ||
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 NavigationWithErrorElement( | ||
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 warningSymbolComponent: Int = R.layout.form_error_symbol, | ||
private val symbolComponent: Int = R.layout.form_navigation_symbol, | ||
private val formStyleBundle: FormStyleBundle? = null | ||
) : FormElementNoValue() { | ||
|
||
private var viewGroup: ViewGroup? = null | ||
|
||
override fun hide() { | ||
viewGroup?.visibility = View.GONE | ||
} | ||
|
||
override fun show() { | ||
viewGroup?.visibility = View.VISIBLE | ||
} | ||
|
||
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 errorView = inflater.inflate(warningSymbolComponent, view, false) as ImageView | ||
val symbolView = prepareSymbol( | ||
inflater, context, this.formStyleBundle | ||
?: formStyleBundle, view | ||
) | ||
view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) | ||
view.addView(headerView) | ||
view.addView(errorView) | ||
view.addView(symbolView) | ||
|
||
view.isClickable = true | ||
view.setOnClickListener { | ||
actionCallback.callback() | ||
} | ||
view.setOnTouchListener { _, event -> | ||
when (event.action) { | ||
MotionEvent.ACTION_UP -> { | ||
view.setBackgroundColorResourceId( | ||
context, | ||
formStyleBundle.secondaryBackgroundColor | ||
) | ||
view.performClick() | ||
} | ||
MotionEvent.ACTION_CANCEL -> { | ||
view.setBackgroundColorResourceId( | ||
context, | ||
formStyleBundle.secondaryBackgroundColor | ||
) | ||
} | ||
MotionEvent.ACTION_DOWN -> { | ||
view.setBackgroundColorResourceId( | ||
context, | ||
formStyleBundle.primaryBackgroundColor | ||
) | ||
} | ||
} | ||
true | ||
} | ||
viewGroup = view | ||
return view | ||
} | ||
|
||
private fun prepareSymbol( | ||
inflater: LayoutInflater, | ||
context: Context, | ||
formStyleBundle: FormStyleBundle, | ||
root: ViewGroup | ||
): ImageView { | ||
val symbolView = inflater.inflate(symbolComponent, root, false) as ImageView | ||
val color = ContextCompat.getColor(context, formStyleBundle.primaryTextColor) | ||
symbolView.setColorFilter(color) | ||
return symbolView | ||
} | ||
|
||
private fun prepareLabel( | ||
inflater: LayoutInflater, | ||
context: Context, | ||
formStyleBundle: FormStyleBundle, | ||
root: ViewGroup | ||
): TextView { | ||
val headerView = inflater.inflate(headerComponent, root, false) as TextView | ||
headerView.setTextColorResourceId(context, formStyleBundle.primaryTextColor) | ||
headerView.text = label | ||
return headerView | ||
} | ||
} |
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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z" /> | ||
</vector> |
14 changes: 14 additions & 0 deletions
14
formbuilderlibrary/src/main/res/layout/form_error_symbol.xml
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,14 @@ | ||
<?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" /> |
2 changes: 1 addition & 1 deletion
2
formbuilderlibrary/src/main/res/layout/form_navigation_symbol.xml
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