Skip to content
Snippets Groups Projects
Unverified Commit 46bccade authored by AlexanderAlferov's avatar AlexanderAlferov Committed by GitHub
Browse files

Trace location icon custom view (DEV) (#2597)


* Initial commit

* Initial commit

* Add "HighLightView" that allows setting caption text and allows children to be added to a constraint layout with gradient background.

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
Co-authored-by: default avatarMatthias Urhahn <matthias.urhahn@sap.com>
parent 9bff3aa5
No related branches found
No related tags found
No related merge requests found
Showing with 225 additions and 0 deletions
package de.rki.coronawarnapp.ui.eventregistration.common
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.withStyledAttributes
import androidx.core.view.children
import de.rki.coronawarnapp.R
class TraceLocationCardHighlightView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val captionView: TextView by lazy { findViewById(R.id.caption) }
private val containerView: ConstraintLayout by lazy { findViewById(R.id.container) }
init {
LayoutInflater.from(context).inflate(R.layout.trace_location_view_cardhighlight, this, true)
background = ContextCompat.getDrawable(context, R.drawable.trace_location_view_cardhighlight_background)
context.withStyledAttributes(attrs, R.styleable.TraceLocationHighlightView) {
val captionText = getText(R.styleable.TraceLocationHighlightView_android_text) ?: ""
captionView.text = captionText
}
}
override fun onFinishInflate() {
children
.filter { it != captionView && it != containerView }
.forEach {
removeView(it)
containerView.addView(it)
}
super.onFinishInflate()
}
fun setCaption(caption: String) {
captionView.text = caption
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="42dp"
android:height="42dp"
android:viewportWidth="42"
android:viewportHeight="42">
<path
android:pathData="M0,18.6667H18.6667V0H0V18.6667ZM4.6667,4.6667H14V14H4.6667V4.6667Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M0,41.9987H18.6667V23.332H0V41.9987ZM4.6667,27.9987H14V37.332H4.6667V27.9987Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M23.333,0V18.6667H41.9997V0H23.333ZM37.333,14H27.9997V4.6667H37.333V14Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M41.9997,37.332H37.333V41.9987H41.9997V37.332Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M27.9997,23.332H23.333V27.9987H27.9997V23.332Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M32.6667,28H28V32.6667H32.6667V28Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M27.9997,32.668H23.333V37.3346H27.9997V32.668Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M32.6667,37.332H28V41.9987H32.6667V37.332Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M37.3337,32.668H32.667V37.3346H37.3337V32.668Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M37.3337,23.332H32.667V27.9987H37.3337V23.332Z"
android:fillColor="#ffffff"/>
<path
android:pathData="M41.9997,28H37.333V32.6667H41.9997V28Z"
android:fillColor="#ffffff"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="@dimen/radius_card"
android:bottomRightRadius="@dimen/radius_card"
android:radius="0dp" />
<solid android:color="@color/colorTraceLocationIconDateBackground" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="0dp"
android:topLeftRadius="@dimen/radius_card"
android:topRightRadius="@dimen/radius_card" />
<gradient
android:angle="135"
android:centerColor="#6C648C"
android:endColor="#3C8CBB"
android:startColor="#A93F45" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_box"
style="@style/ContactDiaryExpandableListItem"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.rki.coronawarnapp.ui.eventregistration.common.TraceLocationCardHighlightView
android:id="@+id/icon"
android:layout_width="88dp"
android:layout_height="136dp"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="21.01.2021">
<ImageView
android:layout_width="42dp"
android:layout_height="42dp"
android:importantForAccessibility="no"
android:src="@drawable/ic_qr_code_list_item_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</de.rki.coronawarnapp.ui.eventregistration.common.TraceLocationCardHighlightView>
<TextView
android:id="@+id/title"
style="@style/subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="Jahrestreffen der deutschen SAP Anwendergruppe" />
<TextView
android:id="@+id/location"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="18dp"
android:textColor="#6D7072"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toBottomOf="@+id/title"
tools:text="Hauptstr. 3, 69115 Heidelberg" />
<TextView
android:id="@+id/duration"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toBottomOf="@+id/location"
tools:text="18:00 - 21:00 Uhr" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/trace_location_view_cardhighlight_background"
tools:layout_height="wrap_content"
tools:layout_width="wrap_content"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="88dp"
android:layout_height="96dp"
android:background="@drawable/trace_location_view_cardhighlight_gradient"
android:padding="16dp"
app:layout_constraintBottom_toTopOf="@+id/caption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/caption"
style="@style/TextAppearance.MaterialComponents.Body2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="40dp"
android:paddingHorizontal="8dp"
android:paddingVertical="8dp"
android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/container"
app:layout_constraintStart_toStartOf="@id/container"
app:layout_constraintTop_toBottomOf="@id/container"
tools:text="21.01.2021" />
</merge>
\ No newline at end of file
......@@ -68,4 +68,7 @@
<!-- Statistics -->
<color name="colorStatisticsValueLabel">#A7A7A7</color>
<color name="colorStatisticsPrimaryValue">#FFFFFF</color>
<!-- Trace location -->
<color name="colorTraceLocationIconDateBackground">#434445</color>
</resources>
......@@ -46,4 +46,8 @@
<attr name="titleText" format="string" localization="suggested" />
<attr name="subtitleText" format="string" />
</declare-styleable>
<declare-styleable name="TraceLocationHighlightView">
<attr name="android:text" />
</declare-styleable>
</resources>
\ No newline at end of file
......@@ -88,4 +88,7 @@
<!-- Bottom Nav bar-->
<color name="navItemColorSelected">@color/colorAccent</color>
<color name="navItemColorNormal">#999999</color>
<!-- Trace location -->
<color name="colorTraceLocationIconDateBackground">#FFFFFF</color>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment