1 /** 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * ``` 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * ``` 10 * 11 * Unless required by applicable law or agreed to in writing, software distributed under the License 12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 13 * or implied. See the License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 package com.android.healthconnect.controller 17 18 import android.os.Bundle 19 import android.view.WindowManager 20 import androidx.activity.viewModels 21 import androidx.navigation.findNavController 22 import com.android.healthconnect.controller.migration.MigrationActivity.Companion.maybeRedirectToMigrationActivity 23 import com.android.healthconnect.controller.migration.MigrationViewModel 24 import com.android.healthconnect.controller.navigation.DestinationChangedListener 25 import com.android.healthconnect.controller.utils.logging.HealthConnectLogger 26 import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity 27 import dagger.hilt.android.AndroidEntryPoint 28 import javax.inject.Inject 29 30 /** Entry point activity for Health Connect. */ 31 @AndroidEntryPoint(CollapsingToolbarBaseActivity::class) 32 class MainActivity : Hilt_MainActivity() { 33 34 @Inject lateinit var logger: HealthConnectLogger 35 36 private val migrationViewModel: MigrationViewModel by viewModels() 37 onCreatenull38 override fun onCreate(savedInstanceState: Bundle?) { 39 super.onCreate(savedInstanceState) 40 // This flag ensures a non system app cannot show an overlay on Health Connect. b/313425281 41 window.addSystemFlags( 42 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS 43 ) 44 45 setContentView(R.layout.activity_main) 46 47 setTitle(R.string.app_label) 48 49 val currentMigrationState = migrationViewModel.getCurrentMigrationUiState() 50 51 if (maybeRedirectToMigrationActivity(this, currentMigrationState)) { 52 return 53 } 54 } 55 onStartnull56 override fun onStart() { 57 super.onStart() 58 findNavController(R.id.nav_host_fragment) 59 .addOnDestinationChangedListener(DestinationChangedListener(this)) 60 } 61 onResumenull62 override fun onResume() { 63 super.onResume() 64 val currentMigrationState = migrationViewModel.getCurrentMigrationUiState() 65 66 if (maybeRedirectToMigrationActivity(this, currentMigrationState)) { 67 return 68 } 69 } 70 onBackPressednull71 override fun onBackPressed() { 72 val navController = findNavController(R.id.nav_host_fragment) 73 if (!navController.popBackStack()) { 74 finish() 75 } 76 } 77 onNavigateUpnull78 override fun onNavigateUp(): Boolean { 79 val navController = findNavController(R.id.nav_host_fragment) 80 if (!navController.popBackStack()) { 81 finish() 82 } 83 84 return true 85 } 86 87 // TODO (b/270864219): implement interaction logging for the menu button 88 // override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { 89 // logger.logInteraction(ElementName.TOOLBAR_SETTINGS_BUTTON) 90 // return super.onMenuOpened(featureId, menu) 91 // } 92 93 } 94