Java tutorial
/* MainActivity.java * * Copyright (c) 2014 Bjrn Schramke<bjoern@schramke-online.de>. * * 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 * * http://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 de.schramke.android.navdrawer.sample; import android.app.ActionBar; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.view.Menu; import android.view.MenuItem; import de.schramke.android.navdrawer.NavigationDrawer; import de.schramke.android.navdrawer.NavigationDrawerActivity; import de.schramke.android.utils.DefaultAndroidLogHandler; import de.schramke.android.utils.Log; public class MainActivity extends NavigationDrawerActivity implements NavigationDrawer.NavigationDrawerCreateListener, NavigationDrawer.NavigationDrawerItemListener { private static final String TAG = MainActivity.class.getSimpleName(); private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.addLogHandler(new DefaultAndroidLogHandler()); Log.setContext(this); setContentView(R.layout.activity_main); // enable ActionBar app icon to behave as action to toggle nav drawer final ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onCreateNavigationDrawerMenu(Menu menu) { // Inflate the menu; this adds items to the navigation drawer. getMenuInflater().inflate(R.menu.navdrawer, menu); } //****************************************************************** //* implement NavigationDrawer.NavigationDrawerItemListener interface //****************************************************************** @Override public void onDrawerItemClick(int position, long id) { // Handle navigation drawer item clicks here. Log.d("onDrawerItemClick(%d, %d)", position, id); if (id == R.id.action_sliding_tabs) { Intent intent = new Intent(this, SlidingTabsActivity.class); Log.d(intent); startActivity(intent); } } @Override public boolean onDrawerItemLongClick() { // Handle navigation drawer item long clicks here. return false; } @Override public void onDrawerItemSelected() { } }