package com.dano.test1 import android.content.res.Configuration import android.os.Bundle import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private lateinit var openingScreenHandler: HandlerOpeningScreen var isInQuestionnaire: Boolean = false var isFirstQuestionnairePage: Boolean = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Opening Screen nur beim echten Start initialisieren. // Durch configChanges wird onCreate bei Drehung NICHT erneut aufgerufen. openingScreenHandler = HandlerOpeningScreen(this) openingScreenHandler.init() } // Wichtig: Bei Konfigurationsänderungen NICHT den Screen neu setzen. // So bleibt man auf der aktuellen Frage/Seite. override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) // Kein setContentView(), kein openingScreenHandler.init() hier! // Falls du Layout-Metriken bei Rotation neu berechnen willst, kannst du das gezielt hier tun. } /** * Starts the given questionnaire and attaches it to this activity. * @param questionnaire The questionnaire instance to start. * @param languageID The language identifier for localization. */ fun startQuestionnaire(questionnaire: QuestionnaireBase<*>, languageID: String) { isInQuestionnaire = true isFirstQuestionnairePage = true questionnaire.attach(this, languageID) questionnaire.startQuestionnaire() } /** * Handle the back button press. * If the openingScreenHandler can handle it, do not call super. * Otherwise, call the default back press behavior. */ override fun onBackPressed() { if (!openingScreenHandler.onBackPressed()) { super.onBackPressed() } } /** * Finish the questionnaire and return to the opening screen. */ fun finishQuestionnaire() { isInQuestionnaire = false isFirstQuestionnairePage = false openingScreenHandler.init() } }