Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drawer Updates
Browse files Browse the repository at this point in the history
Removed the Options menu and placed all items within the Drawer pullout panel.

Updated the UI of the pullout panel and sectioned off items to increase usability.
xLaMbChOpSx committed Jun 30, 2014
1 parent 2702971 commit 90d5cfb
Showing 11 changed files with 475 additions and 101 deletions.
187 changes: 113 additions & 74 deletions app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java
Original file line number Diff line number Diff line change
@@ -19,19 +19,22 @@

import com.SecUpwN.AIMSICD.activities.MapViewer;
import com.SecUpwN.AIMSICD.activities.PrefActivity;
import com.SecUpwN.AIMSICD.adapters.DrawerMenuAdapter;
import com.SecUpwN.AIMSICD.fragments.AboutFragment;
import com.SecUpwN.AIMSICD.fragments.AtCommandFragment;
import com.SecUpwN.AIMSICD.fragments.CellInfoFragment;
import com.SecUpwN.AIMSICD.fragments.DbViewerFragment;
import com.SecUpwN.AIMSICD.fragments.DeviceFragment;
import com.SecUpwN.AIMSICD.fragments.DrawerMenuItem;
import com.SecUpwN.AIMSICD.fragments.DrawerMenuSection;
import com.SecUpwN.AIMSICD.service.AimsicdService;
import com.SecUpwN.AIMSICD.utils.DrawerMenuActivityConfiguration;
import com.SecUpwN.AIMSICD.utils.Helpers;
import com.SecUpwN.AIMSICD.utils.RequestTask;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.ComponentName;
import android.content.Context;
@@ -56,7 +59,6 @@
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
@@ -86,54 +88,41 @@ public class AIMSICD extends Activity {
//Back press to exit timer
private long mLastPress = 0;

private DrawerMenuActivityConfiguration mNavConf ;

public interface NavDrawerItem {
public int getId();
public String getLabel();
public int getType();
public boolean isEnabled();
public boolean updateActionBarTitle();
}

/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mNavConf = getNavDrawerConfiguration();

setContentView(mNavConf.getMainLayout());

// Bind to LocalService
Intent intent = new Intent(this, AimsicdService.class);
//Start Service before binding to keep it resident when activity is destroyed
startService(intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);


mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerLayout = (DrawerLayout) findViewById(mNavConf.getDrawerLayoutId());
mDrawerList = (ListView) findViewById(mNavConf.getLeftDrawerId());
mActionBar = getActionBar();

mNavigationTitles = getResources().getStringArray(R.array.navigation_array);
mTitle = mDrawerTitle = getTitle();

//Declare Drawer Icons
int[] mIcons = new int[]{
R.drawable.ic_action_phone,
R.drawable.cell_tower,
R.drawable.ic_action_computer,
R.drawable.ic_action_storage,
R.drawable.ic_action_map,
R.drawable.ic_action_about,
};



List<HashMap<String, String>> navigationItems = new ArrayList<>();
for (int i = 0; i < 6; i++) {
HashMap<String, String> hm = new HashMap<>();
hm.put("title", mNavigationTitles[i]);
hm.put("icon", Integer.toString(mIcons[i]));
navigationItems.add(hm);
}

String[] from = {"title", "icon"};
int[] to = {R.id.navigation_item, R.id.icon};
mDrawerList.setAdapter(mNavConf.getBaseAdapter());

// Set the adapter for the list view
mDrawerList.setAdapter(new SimpleAdapter(mContext,
navigationItems, R.layout.drawer_layout, from, to));
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
@@ -146,12 +135,14 @@ public void onCreate(Bundle savedInstanceState) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
mActionBar.setTitle(mTitle);
invalidateOptionsMenu();
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
mActionBar.setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};

@@ -237,51 +228,72 @@ protected void onDestroy() {
}

private class DrawerItemClickListener implements ListView.OnItemClickListener {

@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}

/** Swaps fragments in the main content view */
private void selectItem(int position) {
public void selectItem(int position) {
NavDrawerItem selectedItem = mNavConf.getNavItems()[position];

// Create a new fragment
Fragment fragment;
switch (position) {
case 0:
fragment = new DeviceFragment();
switch (selectedItem.getId()) {
case 101:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new DeviceFragment()).commit();
break;
case 1:
fragment = new CellInfoFragment();
case 102:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new CellInfoFragment()).commit();
break;
case 2:
fragment = new AtCommandFragment();
case 103:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new AtCommandFragment()).commit();
break;
case 3:
fragment = new DbViewerFragment();
case 104:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new DbViewerFragment()).commit();
break;
case 5:
fragment = new AboutFragment();
case 302:
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, new AboutFragment()).commit();
break;
default:
fragment = new DeviceFragment();
}

if (position == 4) {
if (selectedItem.getId() == 901) {
trackcell();
} else if (selectedItem.getId() == 105) {
showmap();
} else if (selectedItem.getId() == 202) {
Intent intent = new Intent(this, PrefActivity.class);
startActivity(intent);
} else if (selectedItem.getId() == 203) {
new RequestTask(mContext, RequestTask.BACKUP_DATABASE).execute();
} else if (selectedItem.getId() == 204) {
new RequestTask(mContext, RequestTask.RESTORE_DATABASE).execute();
} else if (selectedItem.getId() == 301) {
Location loc = mAimsicdService.lastKnownLocation();
if (loc != null && loc.hasAccuracy()) {
Helpers.msgShort(mContext, "Contacting OpenCellID.org for data...");
Helpers.getOpenCellData(mContext, loc.getLatitude(), loc.getLongitude(),
RequestTask.OPEN_CELL_ID_REQUEST);
} else {
Helpers.msgShort(mContext,
"Unable to determine your last location. \nEnable Location Services and try again.");
}
}

// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();

// Highlight the selected item, update the title, and close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mNavigationTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);

if ( selectedItem.updateActionBarTitle()) {
setTitle(selectedItem.getLabel());
}

if ( this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
}
}

@Override
@@ -290,6 +302,38 @@ public void setTitle(CharSequence title) {
mActionBar.setTitle(mTitle);
}

protected DrawerMenuActivityConfiguration getNavDrawerConfiguration() {

NavDrawerItem[] menu = new NavDrawerItem[] {
DrawerMenuSection.create(900, "Tracking"),
DrawerMenuItem.create(901, getString(R.string.track_cell), "untrack_cell", false, this),
DrawerMenuSection.create(100, "Main"),
DrawerMenuItem
.create(101, getString(R.string.device_info), "ic_action_phone", true, this),
DrawerMenuItem.create(102, getString(R.string.cell_info_title), "cell_tower", true, this),
DrawerMenuItem.create(103, getString(R.string.at_command_title), "ic_action_computer", true, this),
DrawerMenuItem.create(104, getString(R.string.db_viewer), "ic_action_storage", true, this),
DrawerMenuItem.create(105, getString(R.string.map_view), "ic_action_map", true, this),
DrawerMenuSection.create(200, "Settings"),
DrawerMenuItem.create(202, getString(R.string.preferences), "ic_action_settings", false, this),
DrawerMenuItem.create(203, getString(R.string.backup_database), "ic_action_import_export", false, this),
DrawerMenuItem.create(204, getString(R.string.restore_database), "ic_action_import_export", false, this),
DrawerMenuSection.create(300, "Application"),
DrawerMenuItem.create(301, getString(R.string.get_opencellid), "stat_sys_download_anim0", false, this),
DrawerMenuItem.create(302, getString(R.string.about_aimsicd), "ic_action_about", true, this),
DrawerMenuItem.create(303, getString(R.string.quit), "ic_action_remove", false, this)};

DrawerMenuActivityConfiguration navDrawerActivityConfiguration = new DrawerMenuActivityConfiguration();
navDrawerActivityConfiguration.setMainLayout(R.layout.main);
navDrawerActivityConfiguration.setDrawerLayoutId(R.id.drawer_layout);
navDrawerActivityConfiguration.setLeftDrawerId(R.id.left_drawer);
navDrawerActivityConfiguration.setNavItems(menu);
navDrawerActivityConfiguration.setDrawerOpenDesc(R.string.drawer_open);
navDrawerActivityConfiguration.setDrawerCloseDesc(R.string.drawer_close);
navDrawerActivityConfiguration.setBaseAdapter(
new DrawerMenuAdapter(this, R.layout.drawer_item, menu ));
return navDrawerActivityConfiguration;
}

/**
* Service Connection to bind the activity to the service
@@ -321,20 +365,16 @@ public void onResume() {
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem mTrackCell = menu.findItem(R.id.track_cell);
MenuItem mTrackFemtocell = menu.findItem(R.id.track_femtocell);
if ( mNavConf.getActionMenuItemsToHideWhenDrawerOpen() != null ) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
for( int iItem : mNavConf.getActionMenuItemsToHideWhenDrawerOpen()) {
menu.findItem(iItem).setVisible(!drawerOpen);
}
}

if (mBound) {
/* if (mBound) {
if (mAimsicdService.isTrackingCell()) {
if (mTrackCell != null) {
mTrackCell.setTitle(R.string.untrack_cell);
@@ -364,19 +404,17 @@ public boolean onPrepareOptionsMenu(Menu menu) {
mTrackFemtocell.setVisible(false);
}
}
}
}*/
return super.onPrepareOptionsMenu(menu);
}

@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 item selection
/* // Handle item selection
Intent intent;
switch (item.getItemId()) {
case R.id.track_cell:
@@ -413,7 +451,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
default:
return super.onOptionsItemSelected(item);
}
}*/
return super.onOptionsItemSelected(item);
}

/**
115 changes: 115 additions & 0 deletions app/src/main/java/com/SecUpwN/AIMSICD/adapters/DrawerMenuAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.SecUpwN.AIMSICD.adapters;

import com.SecUpwN.AIMSICD.AIMSICD.NavDrawerItem;
import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.fragments.DrawerMenuItem;
import com.SecUpwN.AIMSICD.fragments.DrawerMenuSection;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DrawerMenuAdapter extends ArrayAdapter<NavDrawerItem> {
private LayoutInflater inflater;

public DrawerMenuAdapter(Context context, int textViewResourceId, NavDrawerItem[] objects ) {
super(context, textViewResourceId, objects);
this.inflater = LayoutInflater.from(context);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null ;
NavDrawerItem menuItem = this.getItem(position);
if ( menuItem.getType() == DrawerMenuItem.ITEM_TYPE ) {
view = getItemView(convertView, parent, menuItem );
}
else {
view = getSectionView(convertView, parent, menuItem);
}
return view ;
}

public View getItemView( View convertView, ViewGroup parentView, NavDrawerItem navDrawerItem ) {

DrawerMenuItem menuItem = (DrawerMenuItem) navDrawerItem ;
NavMenuItemHolder navMenuItemHolder = null;

if (convertView == null) {
convertView = inflater.inflate( R.layout.drawer_item, parentView, false);
TextView labelView = (TextView) convertView
.findViewById( R.id.drawer_menu_item_label );
ImageView iconView = (ImageView) convertView
.findViewById( R.id.drawer_menu_item_icon );

navMenuItemHolder = new NavMenuItemHolder();
navMenuItemHolder.labelView = labelView ;
navMenuItemHolder.iconView = iconView ;

convertView.setTag(navMenuItemHolder);
}

if ( navMenuItemHolder == null ) {
navMenuItemHolder = (NavMenuItemHolder) convertView.getTag();
}

navMenuItemHolder.labelView.setText(menuItem.getLabel());
navMenuItemHolder.iconView.setImageResource(menuItem.getIcon());

return convertView ;
}

public View getSectionView(View convertView, ViewGroup parentView,
NavDrawerItem navDrawerItem) {

DrawerMenuSection menuSection = (DrawerMenuSection) navDrawerItem ;
NavMenuSectionHolder navMenuItemHolder = null;

if (convertView == null) {
convertView = inflater.inflate( R.layout.drawer_section, parentView, false);
TextView labelView = (TextView) convertView
.findViewById( R.id.drawer_menu_section_label );

navMenuItemHolder = new NavMenuSectionHolder();
navMenuItemHolder.labelView = labelView ;
convertView.setTag(navMenuItemHolder);
}

if ( navMenuItemHolder == null ) {
navMenuItemHolder = (NavMenuSectionHolder) convertView.getTag();
}

navMenuItemHolder.labelView.setText(menuSection.getLabel());

return convertView ;
}

@Override
public int getViewTypeCount() {
return 2;
}

@Override
public int getItemViewType(int position) {
return this.getItem(position).getType();
}

@Override
public boolean isEnabled(int position) {
return getItem(position).isEnabled();
}


private static class NavMenuItemHolder {
private TextView labelView;
private ImageView iconView;
}

private class NavMenuSectionHolder {
private TextView labelView;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.SecUpwN.AIMSICD.fragments;

import com.SecUpwN.AIMSICD.AIMSICD.NavDrawerItem;

import android.content.Context;

public class DrawerMenuItem implements NavDrawerItem {

public static final int ITEM_TYPE = 1 ;

private int id ;
private String label ;
private int icon ;
private boolean updateActionBarTitle ;

private DrawerMenuItem() {
}

public static DrawerMenuItem create( int id, String label, String icon, boolean updateActionBarTitle, Context context ) {
DrawerMenuItem item = new DrawerMenuItem();
item.setId(id);
item.setLabel(label);
item.setIcon(context.getResources().getIdentifier( icon, "drawable", context.getPackageName()));
item.setUpdateActionBarTitle(updateActionBarTitle);
return item;
}

@Override
public int getType() {
return ITEM_TYPE;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public int getIcon() {
return icon;
}

public void setIcon(int icon) {
this.icon = icon;
}

@Override
public boolean isEnabled() {
return true;
}

@Override
public boolean updateActionBarTitle() {
return this.updateActionBarTitle;
}

public void setUpdateActionBarTitle(boolean updateActionBarTitle) {
this.updateActionBarTitle = updateActionBarTitle;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.SecUpwN.AIMSICD.fragments;

import com.SecUpwN.AIMSICD.AIMSICD.NavDrawerItem;

public class DrawerMenuSection implements NavDrawerItem {

public static final int SECTION_TYPE = 0;
private int id;
private String label;

private DrawerMenuSection() {
}

public static DrawerMenuSection create( int id, String label ) {
DrawerMenuSection section = new DrawerMenuSection();
section.setLabel(label);
return section;
}

@Override
public int getType() {
return SECTION_TYPE;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

@Override
public boolean isEnabled() {
return false;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Override
public boolean updateActionBarTitle() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.SecUpwN.AIMSICD.utils;

import com.SecUpwN.AIMSICD.AIMSICD.NavDrawerItem;

import android.widget.BaseAdapter;

public class DrawerMenuActivityConfiguration {

private int mainLayout;
private int drawerLayoutId;
private int leftDrawerId;
private int[] actionMenuItemsToHideWhenDrawerOpen;
private NavDrawerItem[] navItems;
private int drawerOpenDesc;
private int drawerCloseDesc;
private BaseAdapter baseAdapter;

public int getMainLayout() {
return mainLayout;
}

public void setMainLayout(int mainLayout) {
this.mainLayout = mainLayout;
}

public int getDrawerLayoutId() {
return drawerLayoutId;
}

public void setDrawerLayoutId(int drawerLayoutId) {
this.drawerLayoutId = drawerLayoutId;
}

public int getLeftDrawerId() {
return leftDrawerId;
}

public void setLeftDrawerId(int leftDrawerId) {
this.leftDrawerId = leftDrawerId;
}

public int[] getActionMenuItemsToHideWhenDrawerOpen() {
return actionMenuItemsToHideWhenDrawerOpen;
}

public void setActionMenuItemsToHideWhenDrawerOpen(
int[] actionMenuItemsToHideWhenDrawerOpen) {
this.actionMenuItemsToHideWhenDrawerOpen = actionMenuItemsToHideWhenDrawerOpen;
}

public NavDrawerItem[] getNavItems() {
return navItems;
}

public void setNavItems(NavDrawerItem[] navItems) {
this.navItems = navItems;
}

public int getDrawerOpenDesc() {
return drawerOpenDesc;
}

public void setDrawerOpenDesc(int drawerOpenDesc) {
this.drawerOpenDesc = drawerOpenDesc;
}

public int getDrawerCloseDesc() {
return drawerCloseDesc;
}

public void setDrawerCloseDesc(int drawerCloseDesc) {
this.drawerCloseDesc = drawerCloseDesc;
}

public BaseAdapter getBaseAdapter() {
return baseAdapter;
}

public void setBaseAdapter(BaseAdapter baseAdapter) {
this.baseAdapter = baseAdapter;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions app/src/main/res/layout/drawer_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingRight="10dp"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
>

<ImageView
android:id="@+id/drawer_menu_item_icon"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:paddingLeft="15dp" android:contentDescription="icon"/>

<TextView
android:id="@+id/drawer_menu_item_label"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_toRightOf="@id/drawer_menu_item_icon"
android:gravity="center_vertical"
android:text="TextView"
android:textColor="#FFFFFF"/>

</RelativeLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/drawer_section.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/drawer_menu_section_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Section"
android:textSize="18sp"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:textColor="#FFFFFF"
style="?android:attr/listSeparatorTextViewStyle"/>

</RelativeLayout>
27 changes: 0 additions & 27 deletions app/src/main/res/menu/main_menu.xml

This file was deleted.

0 comments on commit 90d5cfb

Please sign in to comment.