Page MenuHomec4science

MuGUI.java
No OneTemporary

File Metadata

Created
Thu, Jan 2, 21:30

MuGUI.java

package com.example.genomicprivacy;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
/**
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public class MuGUI extends Activity {
/**
* Array of all the menu for the navigation drawer
*/
private String[] menuList;
/**
* Layout for the drawer
*/
private DrawerLayout mDrawerLayout;
/**
* List view for the navigation drawer
*/
private ListView mDrawerList;
/**
* Title for the navigation drawer
*/
private CharSequence mTitle;
/**
* This class provides a handy way to tie together the functionality of DrawerLayout and the framework ActionBar to implement the recommended design for navigation drawers.
*/
private ActionBarDrawerToggle mDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
menuList = new String[] { "Search Patient", "Request pending",
"Request accepted", "Request refused", "Result"};
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_layout);
mTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerList.setAdapter(new ArrayAdapter<String>(
ContextApp.getContext(), R.layout.drawer_list_item, menuList));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("Menu");
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.mu, menu);
return true;
}
/**
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
selectItem(position);
}
}
/** Swaps fragments in the main content view
* @param position of the selected fragment
*/
private void selectItem(int position) {
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager;
Fragment fragment;
switch (position) {
case 0:
fragmentManager = getFragmentManager();
fragment = new Search();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mTitle = "Search For Patient";
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 1:
fragmentManager = getFragmentManager();
fragment = new RequestPending();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mTitle = "Requests Pending";
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 2:
fragmentManager = getFragmentManager();
fragment = new RequestOk();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mTitle = "Request Ok";
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 3:
fragmentManager = getFragmentManager();
fragment = new RequestRefused();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mTitle = "Request Refused";
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 4:
fragmentManager = getFragmentManager();
fragment = new Results();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mTitle = "Results";
mDrawerLayout.closeDrawer(mDrawerList);
break;
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = (String) title;
getActionBar().setTitle(mTitle);
}
}

Event Timeline