| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
import android.os.Bundle; |
| 4 |
<#if hasAppBar> |
| 5 |
import android.support.design.widget.FloatingActionButton; |
| 6 |
import android.support.design.widget.Snackbar; |
| 7 |
import android.view.View; |
| 8 |
</#if> |
| 9 |
import android.support.design.widget.NavigationView; |
| 10 |
import android.support.v4.view.GravityCompat; |
| 11 |
import android.support.v4.widget.DrawerLayout; |
| 12 |
import android.support.v7.app.ActionBarDrawerToggle; |
| 13 |
import android.support.v7.app.AppCompatActivity; |
| 14 |
import android.support.v7.widget.Toolbar; |
| 15 |
import android.view.Menu; |
| 16 |
import android.view.MenuItem; |
| 17 |
|
| 18 |
public class ${activityClass} extends ${superClass} |
| 19 |
implements NavigationView.OnNavigationItemSelectedListener { |
| 20 |
|
| 21 |
@Override |
| 22 |
protected void onCreate(Bundle savedInstanceState) { |
| 23 |
super.onCreate(savedInstanceState); |
| 24 |
setContentView(R.layout.${layoutName}); |
| 25 |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
| 26 |
setSupportActionBar(toolbar); |
| 27 |
<#if hasAppBar> |
| 28 |
|
| 29 |
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); |
| 30 |
fab.setOnClickListener(new View.OnClickListener() { |
| 31 |
@Override |
| 32 |
public void onClick(View view) { |
| 33 |
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) |
| 34 |
.setAction("Action", null).show(); |
| 35 |
} |
| 36 |
}); |
| 37 |
</#if> |
| 38 |
|
| 39 |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
| 40 |
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( |
| 41 |
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); |
| 42 |
drawer.setDrawerListener(toggle); |
| 43 |
toggle.syncState(); |
| 44 |
|
| 45 |
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); |
| 46 |
navigationView.setNavigationItemSelectedListener(this); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public void onBackPressed() { |
| 51 |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
| 52 |
if (drawer.isDrawerOpen(GravityCompat.START)) { |
| 53 |
drawer.closeDrawer(GravityCompat.START); |
| 54 |
} else { |
| 55 |
super.onBackPressed(); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public boolean onCreateOptionsMenu(Menu menu) { |
| 61 |
// Inflate the menu; this adds items to the action bar if it is present. |
| 62 |
getMenuInflater().inflate(R.menu.${menuName}, menu); |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public boolean onOptionsItemSelected(MenuItem item) { |
| 68 |
// Handle action bar item clicks here. The action bar will |
| 69 |
// automatically handle clicks on the Home/Up button, so long |
| 70 |
// as you specify a parent activity in AndroidManifest.xml. |
| 71 |
int id = item.getItemId(); |
| 72 |
|
| 73 |
//noinspection SimplifiableIfStatement |
| 74 |
if (id == R.id.action_settings) { |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
return super.onOptionsItemSelected(item); |
| 79 |
} |
| 80 |
|
| 81 |
@SuppressWarnings("StatementWithEmptyBody") |
| 82 |
@Override |
| 83 |
public boolean onNavigationItemSelected(MenuItem item) { |
| 84 |
// Handle navigation view item clicks here. |
| 85 |
int id = item.getItemId(); |
| 86 |
|
| 87 |
if (id == R.id.nav_camera) { |
| 88 |
// Handle the camera action |
| 89 |
} else if (id == R.id.nav_gallery) { |
| 90 |
|
| 91 |
} else if (id == R.id.nav_slideshow) { |
| 92 |
|
| 93 |
} else if (id == R.id.nav_manage) { |
| 94 |
|
| 95 |
} else if (id == R.id.nav_share) { |
| 96 |
|
| 97 |
} else if (id == R.id.nav_send) { |
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
| 102 |
drawer.closeDrawer(GravityCompat.START); |
| 103 |
return true; |
| 104 |
} |
| 105 |
} |