Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityPrincipal.java
- This file was added.
package it.reyboz.bustorino; | |||||
import android.content.res.Configuration; | |||||
import android.content.res.Resources; | |||||
import android.os.Bundle; | |||||
import android.util.Log; | |||||
import android.view.MenuItem; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import androidx.appcompat.app.ActionBarDrawerToggle; | |||||
import androidx.appcompat.widget.Toolbar; | |||||
import androidx.core.app.NavUtils; | |||||
import androidx.core.view.GravityCompat; | |||||
import androidx.drawerlayout.widget.DrawerLayout; | |||||
import com.google.android.material.navigation.NavigationView; | |||||
import it.reyboz.bustorino.middleware.GeneralActivity; | |||||
public class ActivityPrincipal extends GeneralActivity { | |||||
private DrawerLayout mDrawer; | |||||
private NavigationView mNavView; | |||||
private ActionBarDrawerToggle drawerToggle; | |||||
private final static String DEBUG_TAG="BusTO Act Principal"; | |||||
@Override | |||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.new_main_activity); | |||||
Toolbar mToolbar = findViewById(R.id.default_toolbar); | |||||
setSupportActionBar(mToolbar); | |||||
if (getSupportActionBar()!=null) | |||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |||||
else Log.w(DEBUG_TAG, "NO ACTION BAR"); | |||||
mDrawer = findViewById(R.id.drawer_layout); | |||||
drawerToggle = setupDrawerToggle(mToolbar); | |||||
// Setup toggle to display hamburger icon with nice animation | |||||
drawerToggle.setDrawerIndicatorEnabled(true); | |||||
drawerToggle.syncState(); | |||||
mDrawer.addDrawerListener(drawerToggle); | |||||
mNavView = findViewById(R.id.nvView); | |||||
setupDrawerContent(mNavView); | |||||
} | |||||
private ActionBarDrawerToggle setupDrawerToggle(Toolbar toolbar) { | |||||
// NOTE: Make sure you pass in a valid toolbar reference. ActionBarDrawToggle() does not require it | |||||
// and will not render the hamburger icon without it. | |||||
return new ActionBarDrawerToggle(this, mDrawer, toolbar, R.string.drawer_open, R.string.drawer_close); | |||||
} | |||||
private void setupDrawerContent(NavigationView navigationView) { | |||||
navigationView.setNavigationItemSelectedListener( | |||||
menuItem -> { | |||||
//selectDrawerItem(menuItem); | |||||
Log.d(DEBUG_TAG, "pressed item "+menuItem.toString()); | |||||
return true; | |||||
}); | |||||
} | |||||
// `onPostCreate` called when activity start-up is complete after `onStart()` | |||||
// NOTE 1: Make sure to override the method with only a single `Bundle` argument | |||||
// Note 2: Make sure you implement the correct `onPostCreate(Bundle savedInstanceState)` method. | |||||
// There are 2 signatures and only `onPostCreate(Bundle state)` shows the hamburger icon. | |||||
@Override | |||||
protected void onPostCreate(Bundle savedInstanceState) { | |||||
super.onPostCreate(savedInstanceState); | |||||
// Sync the toggle state after onRestoreInstanceState has occurred. | |||||
drawerToggle.syncState(); | |||||
} | |||||
@Override | |||||
public void onConfigurationChanged(@NonNull Configuration newConfig) { | |||||
super.onConfigurationChanged(newConfig); | |||||
// Pass any configuration change to the drawer toggles | |||||
drawerToggle.onConfigurationChanged(newConfig); | |||||
} | |||||
@Override | |||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) { | |||||
int[] cases = {R.id.nav_arrivals, R.id.nav_favorites_item}; | |||||
switch (item.getItemId()){ | |||||
case android.R.id.home: | |||||
mDrawer.openDrawer(GravityCompat.START); | |||||
return true; | |||||
case R.id.nav_arrivals: | |||||
//do something | |||||
break; | |||||
default: | |||||
} | |||||
if (drawerToggle.onOptionsItemSelected(item)) { | |||||
return true; | |||||
} | |||||
return super.onOptionsItemSelected(item); | |||||
} | |||||
@Override | |||||
public void onBackPressed() { | |||||
if (mDrawer.isDrawerOpen(GravityCompat.START)) | |||||
mDrawer.closeDrawer(GravityCompat.START); | |||||
else | |||||
super.onBackPressed(); | |||||
} | |||||
} |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register