changed layout for every device
This commit is contained in:
@ -4,6 +4,9 @@ import android.view.View
|
||||
import android.widget.*
|
||||
import android.text.Html
|
||||
import kotlinx.coroutines.*
|
||||
import android.util.TypedValue
|
||||
import android.widget.TextView
|
||||
import androidx.core.widget.TextViewCompat
|
||||
|
||||
class HandlerLastPage(
|
||||
private val answers: Map<String, Any>,
|
||||
@ -21,23 +24,27 @@ class HandlerLastPage(
|
||||
this.layout = layout
|
||||
currentQuestion = question as QuestionItem.LastPage
|
||||
|
||||
// Set localized text for the last page
|
||||
layout.findViewById<TextView>(R.id.textView).text =
|
||||
LanguageManager.getText(languageID, currentQuestion.textKey)
|
||||
val titleTv = layout.findViewById<TextView>(R.id.textView)
|
||||
val questionTv = layout.findViewById<TextView>(R.id.question)
|
||||
|
||||
// Set question text with HTML formatting
|
||||
layout.findViewById<TextView>(R.id.question).text =
|
||||
Html.fromHtml(
|
||||
LanguageManager.getText(languageID, currentQuestion.question),
|
||||
Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
// Texte setzen
|
||||
titleTv.text = LanguageManager.getText(languageID, currentQuestion.textKey)
|
||||
questionTv.text = Html.fromHtml(
|
||||
LanguageManager.getText(languageID, currentQuestion.question),
|
||||
Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
|
||||
// Setup previous button
|
||||
// ==== Schriftgrößen prozentual zur Bildschirmhöhe ====
|
||||
// Passe die Faktoren bei Bedarf an (z. B. 0.032f für etwas größer)
|
||||
setTextSizePercentOfScreenHeight(titleTv, 0.03f)
|
||||
setTextSizePercentOfScreenHeight(questionTv, 0.03f)
|
||||
// =====================================================
|
||||
|
||||
// Buttons
|
||||
layout.findViewById<Button>(R.id.Qprev).setOnClickListener {
|
||||
goToPreviousQuestion()
|
||||
}
|
||||
|
||||
// Setup finish button
|
||||
layout.findViewById<Button>(R.id.Qfinish).setOnClickListener {
|
||||
showLoading(true) // Show loading indicator
|
||||
|
||||
@ -74,6 +81,15 @@ class HandlerLastPage(
|
||||
override fun validate(): Boolean = true // No validation needed on last page
|
||||
override fun saveAnswer() {} // No answers to save here
|
||||
|
||||
// Helper: Textgröße prozentual zur Bildschirmhöhe setzen (in sp)
|
||||
private fun setTextSizePercentOfScreenHeight(view: TextView, percentOfHeight: Float) {
|
||||
val dm = (view.context ?: layout.context).resources.displayMetrics
|
||||
val sp = (dm.heightPixels * percentOfHeight) / dm.scaledDensity
|
||||
// AutoSize ausschalten, damit unsere Größe nicht überschrieben wird
|
||||
TextViewCompat.setAutoSizeTextTypeWithDefaults(view, TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE)
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_SP, sp)
|
||||
}
|
||||
|
||||
// Calculate the sum of all keys ending with "_points"
|
||||
private fun sumPoints(): Int =
|
||||
answers.filterKeys { it.endsWith("_points") }
|
||||
|
||||
Reference in New Issue
Block a user