Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Trace location icon custom view (DEV) #2597

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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>
Comment on lines +10 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage

Set text as caption by using android:text on TraceLocationCardHighlightView, and any qr codes or other text views that should be displayed on top of the gradient, can be added as child of TraceLocationCardHighlightView.

The container with the gradient as background has a fixed size, while the caption text has a fixed width, but will grow in height to wrap it's content (i.e. line breaks possible).


<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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>
3 changes: 3 additions & 0 deletions Corona-Warn-App/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@
<!-- Statistics -->
<color name="colorStatisticsValueLabel">#A7A7A7</color>
<color name="colorStatisticsPrimaryValue">#FFFFFF</color>

<!-- Trace location -->
<color name="colorTraceLocationIconDateBackground">#434445</color>
</resources>
4 changes: 4 additions & 0 deletions Corona-Warn-App/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 3 additions & 0 deletions Corona-Warn-App/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>