Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.imaadv.rist_management;
- import android.os.PersistableBundle;
- import android.support.v4.view.GravityCompat;
- import android.support.v4.widget.DrawerLayout;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.support.v7.widget.Toolbar;
- import android.view.Gravity;
- import android.view.MenuItem;
- import android.view.View;
- import java.util.ArrayList;
- import android.support.v7.app.ActionBarDrawerToggle;
- import android.util.Log;
- import android.widget.AdapterView;
- import android.widget.ListView;
- import android.widget.Toast;
- import com.imaadv.rist_management.adapter.NavDrawerListAdapter;
- import com.imaadv.rist_management.fragments.AboutusFragment;
- import com.imaadv.rist_management.fragments.Home_fragment;
- import com.imaadv.rist_management.fragments.ReferenceFragment;
- import com.imaadv.rist_management.model.NavDrawerItem;
- public class ResultActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
- MyApplication myApplication;
- private DrawerLayout mDrawerLayout;
- private ListView mDrawerList;
- private ActionBarDrawerToggle mDrawerToggle;
- // nav drawer title
- private CharSequence mDrawerTitle;
- // used to store app title
- private CharSequence mTitle;
- // slide menu items
- private String[] navMenuTitles;
- private ArrayList<NavDrawerItem> navDrawerItems;
- private NavDrawerListAdapter adapter;
- Toolbar toolbar;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_result);
- toolbar = (Toolbar) findViewById(R.id.toolbar);
- myApplication = (MyApplication) getApplication();
- setSupportActionBar(toolbar);
- getSupportActionBar().setHomeButtonEnabled(true);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- // load slide menu items
- navMenuTitles = getResources().getStringArray(R.array.nav_items);
- mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
- navDrawerItems = new ArrayList<NavDrawerItem>();
- // adding nav drawer items to array
- navDrawerItems.add(new NavDrawerItem(navMenuTitles[0]));
- navDrawerItems.add(new NavDrawerItem(navMenuTitles[1]));
- navDrawerItems.add(new NavDrawerItem(navMenuTitles[2]));
- navDrawerItems.add(new NavDrawerItem(navMenuTitles[3]));
- toolbar.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (mDrawerLayout.isDrawerOpen(GravityCompat.START)){
- mDrawerLayout.closeDrawers();
- }else{
- mDrawerLayout.openDrawer(GravityCompat.START);
- }
- }
- });
- mDrawerList.setOnItemClickListener(this);
- // setting the nav drawer list adapter
- adapter = new NavDrawerListAdapter(this, navDrawerItems);
- mDrawerList.setAdapter(adapter);
- mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
- toolbar, //nav menu toggle icon
- R.string.app_name, // nav drawer open - description for accessibility
- R.string.app_name // nav drawer close - description for accessibility
- ) {
- @Override
- public void onDrawerClosed(View drawerView) {
- super.onDrawerClosed(drawerView);
- }
- @Override
- public void onDrawerOpened(View drawerView) {
- super.onDrawerOpened(drawerView);
- }
- };
- mDrawerLayout.setDrawerListener(mDrawerToggle);
- mDrawerToggle.setDrawerIndicatorEnabled(true);
- if (savedInstanceState == null) {
- // on first time display view for first nav item
- displayView(0);
- }
- }
- @Override
- public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
- super.onPostCreate(savedInstanceState, persistentState);
- mDrawerToggle.syncState();
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // toggle nav drawer on selecting action bar app icon/title
- // Handle action bar actions click
- switch (item.getItemId()) {
- case R.id.action_settings:
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- /**
- * Diplaying fragment view for selected nav drawer list item
- */
- private void displayView(int position) {
- // update the main content by replacing fragments
- android.support.v4.app.Fragment fragment = null;
- switch (position) {
- case 0:
- fragment = new Home_fragment();
- break;
- case 1:
- fragment = new AboutusFragment();
- break;
- case 2:
- fragment = new ReferenceFragment();
- break;
- case 3:
- myApplication.rest_test(getBaseContext());
- break;
- default:
- break;
- }
- if (fragment != null) {
- android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.frame_container, fragment).commit();
- // update selected item and title, then close the drawer
- mDrawerList.setItemChecked(position, true);
- mDrawerList.setSelection(position);
- setTitle(navMenuTitles[position]);
- mDrawerLayout.closeDrawer(mDrawerList);
- } else {
- // error in creating fragment
- Log.e("MainActivity", "Error in creating fragment");
- }
- }
- /**
- * When using the ActionBarDrawerToggle, you must call it during
- * onPostCreate() and onConfigurationChanged()...
- */
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- // Sync the toggle state after onRestoreInstanceState has occurred.
- mDrawerToggle.syncState();
- }
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
- displayView(position);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement