1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.navigation.testapp 18 19 import android.os.Build 20 import android.os.Bundle 21 import android.transition.Fade 22 import android.view.LayoutInflater 23 import android.view.View 24 import android.view.ViewGroup 25 import android.widget.TextView 26 import androidx.appcompat.app.AppCompatActivity 27 import androidx.appcompat.graphics.drawable.DrawerArrowDrawable 28 import androidx.appcompat.widget.Toolbar 29 import androidx.navigation.ActivityNavigator 30 import androidx.navigation.NavController 31 import androidx.navigation.createGraph 32 import androidx.navigation.ui.setupWithNavController 33 import androidx.testutils.TestNavigator 34 import androidx.testutils.test 35 import com.google.android.material.bottomsheet.BottomSheetDialogFragment 36 import com.google.android.material.navigation.NavigationView 37 38 /** 39 * Simple 'Help' activity that shows the data URI passed to it. In a real world app, it would load 40 * the chosen help article, etc. 41 */ 42 class HelpActivity : AppCompatActivity() { 43 onCreatenull44 override fun onCreate(savedInstanceState: Bundle?) { 45 super.onCreate(savedInstanceState) 46 setContentView(R.layout.activity_help) 47 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 48 val fade = Fade() 49 fade.excludeTarget(android.R.id.statusBarBackground, true) 50 fade.excludeTarget(android.R.id.navigationBarBackground, true) 51 window.exitTransition = fade 52 window.enterTransition = fade 53 } 54 55 val toolbar = findViewById<Toolbar>(R.id.toolbar) 56 setSupportActionBar(toolbar) 57 supportActionBar?.setDisplayHomeAsUpEnabled(true) 58 59 findViewById<TextView>(R.id.data).text = intent.data?.toString() 60 61 val bottomToolbar = findViewById<Toolbar>(R.id.bottom_toolbar) 62 bottomToolbar.navigationIcon = DrawerArrowDrawable(this) 63 bottomToolbar.setNavigationOnClickListener { 64 BottomSheetNavigationView().show(supportFragmentManager, "bottom") 65 } 66 } 67 onSupportNavigateUpnull68 override fun onSupportNavigateUp(): Boolean { 69 finish() 70 ActivityNavigator.applyPopAnimationsToPendingTransition(this) 71 return true 72 } 73 74 @Suppress("DEPRECATION") 75 @Deprecated("Deprecated in ComponentActivity") onBackPressednull76 override fun onBackPressed() { 77 super.onBackPressed() 78 ActivityNavigator.applyPopAnimationsToPendingTransition(this) 79 } 80 } 81 82 class BottomSheetNavigationView : BottomSheetDialogFragment() { 83 @Suppress("DEPRECATION") onCreateViewnull84 override fun onCreateView( 85 inflater: LayoutInflater, 86 container: ViewGroup?, 87 savedInstanceState: Bundle? 88 ): View? { 89 val navigationView = 90 requireActivity().layoutInflater.inflate(R.layout.bottom_bar_menu, container, false) 91 as NavigationView 92 93 // Add a fake Navigation Graph just to test out the behavior but not 94 // actually navigate anywhere 95 navigationView.setupWithNavController( 96 NavController(requireContext()).apply { 97 navigatorProvider.addNavigator(TestNavigator()) 98 graph = 99 createGraph(startDestination = R.id.launcher_home) { 100 test(R.id.launcher_home) 101 test(R.id.android) 102 } 103 } 104 ) 105 return navigationView 106 } 107 } 108