예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mCoordinator = (CoordinatorLayout) findViewById(R.id.coordinator);

    // Setting the Navigation Drawer
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this, drawer, null, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    FloatingActionButton btnNav = (FloatingActionButton) findViewById(R.id.btn_nav);
    btnNav.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawer(GravityCompat.START);
            } else {
              drawer.openDrawer(GravityCompat.START);
            }
          }
        });

    // Set main content to margin fit system window with transparent status bar
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
      FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) drawer.getLayoutParams();
      layoutParams.setMargins(0, -getStatusBarHeight(), 0, 0);
      navigationView.setPadding(0, getStatusBarHeight(), 0, 0);
    }

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    // Get user location data
    buildGoogleApiClient();
  }