Permalink
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up| /* | |
| * Copyright 2018 Google LLC | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * https://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package com.google.samples.apps.sunflower | |
| import android.os.Bundle | |
| import androidx.appcompat.app.AppCompatActivity | |
| import androidx.core.view.GravityCompat | |
| import androidx.databinding.DataBindingUtil | |
| import androidx.drawerlayout.widget.DrawerLayout | |
| import androidx.navigation.Navigation | |
| import androidx.navigation.ui.NavigationUI | |
| import androidx.navigation.ui.setupWithNavController | |
| import com.google.samples.apps.sunflower.databinding.ActivityGardenBinding | |
| class GardenActivity : AppCompatActivity() { | |
| private lateinit var drawerLayout: DrawerLayout | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| val binding: ActivityGardenBinding = DataBindingUtil.setContentView(this, | |
| R.layout.activity_garden) | |
| drawerLayout = binding.drawerLayout | |
| val navController = Navigation.findNavController(this, R.id.garden_nav_fragment) | |
| // Set up ActionBar | |
| setSupportActionBar(binding.toolbar) | |
| NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout) | |
| // Set up navigation menu | |
| binding.navigationView.setupWithNavController(navController) | |
| } | |
| override fun onSupportNavigateUp(): Boolean { | |
| return NavigationUI.navigateUp(drawerLayout, | |
| Navigation.findNavController(this, R.id.garden_nav_fragment)) | |
| } | |
| override fun onBackPressed() { | |
| if (drawerLayout.isDrawerOpen(GravityCompat.START)) { | |
| drawerLayout.closeDrawer(GravityCompat.START) | |
| } else { | |
| super.onBackPressed() | |
| } | |
| } | |
| } |