Permalink
Cannot retrieve contributors at this time
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
Fetching contributors…
| /* | |
| * 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.databinding.DataBindingUtil | |
| import android.os.Bundle | |
| import android.support.v4.view.GravityCompat | |
| import android.support.v4.widget.DrawerLayout | |
| import android.support.v7.app.AppCompatActivity | |
| 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() | |
| } | |
| } | |
| } |