├── bin
├── classes.dex
├── AndRedMenu.apk
├── resources.ap_
├── com
│ └── mindflakes
│ │ └── andredmenu
│ │ ├── R.class
│ │ ├── R$attr.class
│ │ ├── R$layout.class
│ │ ├── R$string.class
│ │ └── R$drawable.class
└── main
│ └── java
│ └── com
│ └── mindflakes
│ └── andredmenu
│ └── AndRedMenuActivity.class
├── res
├── drawable
│ └── icon.png
├── layout
│ ├── quick_row.xml
│ ├── menu_list.xml
│ ├── main.xml
│ ├── search_list.xml
│ ├── quick_view.xml
│ ├── main_row.xml
│ ├── search_view.xml
│ └── settings_view.xml
└── values
│ └── strings.xml
├── .gitignore
├── default.properties
├── AndroidManifest.xml
├── pom.xml
└── src
└── main
└── java
└── com
└── mindflakes
└── TeamRED
└── AndRedMenu
├── FullMenuListActivity.java
├── SearchActivity.java
├── SearchMenuListActivity.java
├── SettingsActivity.java
├── MainViewActivity.java
├── QuickViewActivity.java
├── MenuViewActivity.java
└── MealMenuDBAdapter.java
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/classes.dex
--------------------------------------------------------------------------------
/bin/AndRedMenu.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/AndRedMenu.apk
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/resources.ap_
--------------------------------------------------------------------------------
/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/res/drawable/icon.png
--------------------------------------------------------------------------------
/bin/com/mindflakes/andredmenu/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/com/mindflakes/andredmenu/R.class
--------------------------------------------------------------------------------
/bin/com/mindflakes/andredmenu/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/com/mindflakes/andredmenu/R$attr.class
--------------------------------------------------------------------------------
/bin/com/mindflakes/andredmenu/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/com/mindflakes/andredmenu/R$layout.class
--------------------------------------------------------------------------------
/bin/com/mindflakes/andredmenu/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/com/mindflakes/andredmenu/R$string.class
--------------------------------------------------------------------------------
/bin/com/mindflakes/andredmenu/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/com/mindflakes/andredmenu/R$drawable.class
--------------------------------------------------------------------------------
/bin/main/java/com/mindflakes/andredmenu/AndRedMenuActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nelsonjchen/AndRedMenu/master/bin/main/java/com/mindflakes/andredmenu/AndRedMenuActivity.class
--------------------------------------------------------------------------------
/res/layout/quick_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata
2 | tmp/**
3 | .DS_Store
4 | *.tmp
5 | *.bak
6 | tmp/**/*
7 | *.swp
8 | *~.nib
9 | Thumbs.db
10 | Desktop.ini
11 | *~
12 | *.apk
13 | bin
14 | gen
15 | local.properties
16 | *.jar
17 | .classpath
18 | .project
19 | .settings/
20 | target/
--------------------------------------------------------------------------------
/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=Google Inc.:Google APIs:8
12 |
--------------------------------------------------------------------------------
/res/layout/menu_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/res/layout/search_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/res/layout/quick_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/res/layout/main_row.xml:
--------------------------------------------------------------------------------
1 |
5 |
12 |
19 |
26 |
27 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/res/layout/search_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
13 |
19 |
25 |
29 |
34 |
--------------------------------------------------------------------------------
/res/layout/settings_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
14 |
18 |
22 |
26 |
27 |
28 |
33 |
34 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.mindflakes.redmenu.android
6 | android
7 | RedMenu
8 | 0.1.0
9 | apk
10 |
11 |
12 | AndRedMenu
13 | src/main/java
14 |
15 |
16 | maven-compiler-plugin
17 |
18 | 1.5
19 | 1.5
20 |
21 |
22 |
23 | com.jayway.maven.plugins.android.generation2
24 | maven-android-plugin
25 | 2.4.0
26 |
27 |
28 | 8
29 |
30 | true
31 |
32 | true
33 |
34 |
35 |
36 | org.apache.maven.plugins
37 | maven-release-plugin
38 | 2.0-beta-9
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | android
50 | android
51 | 2.2_r1
52 | provided
53 |
54 |
55 | joda-time
56 | joda-time
57 | 1.6
58 |
59 |
60 | junit
61 | junit
62 | 4.8.1
63 |
64 |
65 | com.mindflakes.redmenu
66 | redmenulib
67 | 0.1.0
68 |
69 |
70 |
71 |
72 | scm:git:git@github.com:crazysim/AndRedMenu.git
73 | scm:git:git@github.com:crazysim/AndRedMenu.git
74 | scm:git:git@github.com:crazysim/AndRedMenu.git
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, AndRedMenuActivity!
4 | AndRedMenu
5 |
6 | Carrillo
7 | De La Guerra
8 | Ortega
9 | Portola
10 | Carrillo Commons
11 | De La Guerra Commons
12 | Ortega Commons
13 | Portola Commons
14 | DLGAll Commonshttp://web.me.com/jomanscool2/outfiles/CombinedNextTwoWeeks.xml.gz
15 | CombinedNextTwoWeeks.xml.gz
16 | CombinedNextTwoWeeks.xml
17 | serializedMenus.sz.gz
18 | serializedMenus.sz
19 | http://web.me.com/jomanscool2/outfiles/serializedMenus.sz.gz
20 | Commons
21 |
22 |
23 | Your search yielded no results.
24 | - @string/commons_name_all_commons
25 | - @string/commons_name_short_carrillo
26 | - @string/commons_name_short_dlg
27 | - @string/commons_name_short_ortega
28 | - @string/commons_name_short_portola
29 |
30 |
31 | Select food preference:Full MenusVegetarian Menus (includes vegan food)
32 | Vegan MenusNote that Vegan (mostly) only contains foods with the keyword \'Vegan\' and Vegetarian may occasionally have non vegetarian foods.Submit Search
33 | Please enter a food name:
34 | Please select a dining common:
35 |
36 |
37 |
38 |
39 | Menu database is empty for current selection.
40 |
41 | Quick View
42 | Settings
43 | Main View
44 | menu_preferences
45 | Clear SQL
46 | Update Menus
47 |
48 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/FullMenuListActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import android.app.ListActivity;
4 | import android.content.Intent;
5 | import android.content.res.Resources;
6 | import android.database.Cursor;
7 | import android.os.Bundle;
8 | import android.view.KeyEvent;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.ListView;
13 | import android.widget.SimpleCursorAdapter;
14 |
15 | public class FullMenuListActivity extends ListActivity {
16 |
17 | private static final int QUICK_VIEW = 1234;
18 | private static final int MAIN_VIEW = 1235;
19 | private static final int SETTINGS = 1236;
20 |
21 | private MealMenuDBAdapter mDbAdapter;
22 | private String common;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 |
27 | Bundle extras = getIntent().getExtras();
28 | common = extras.getString(MealMenuDBAdapter.KEY_MEALMENU_NAME);
29 | // TODO Auto-generated method stub
30 | super.onCreate(savedInstanceState);
31 | mDbAdapter = new MealMenuDBAdapter(this);
32 | mDbAdapter.open();
33 | setContentView(R.layout.menu_list);
34 | fillData();
35 | }
36 |
37 | private void fillData() {
38 | Cursor c = mDbAdapter.fetchMenusForMainList(common);
39 | startManagingCursor(c);
40 | String[] from = new String[] { MealMenuDBAdapter.KEY_MEALMENU_MEALNAME,
41 | MealMenuDBAdapter.KEY_MEALMENU_STARTSTRING };
42 | int[] to = new int[] { R.id.maintext1, R.id.maintext2 };
43 | SimpleCursorAdapter menus = new SimpleCursorAdapter(this,
44 | R.layout.main_row, c, from, to);
45 | setListAdapter(menus);
46 | }
47 |
48 | @Override
49 | protected void onListItemClick(ListView l, View v, int position, long id) {
50 | super.onListItemClick(l, v, position, id);
51 | Intent i = new Intent(this, MenuViewActivity.class);
52 | i.putExtra(MenuViewActivity.KEY_MODE, MenuViewActivity.MODE_ROWID);
53 | i.putExtra(MealMenuDBAdapter.KEY_ROWID,id);
54 | startActivity(i);
55 | }
56 |
57 | /* Creates the menu items */
58 | public boolean onCreateOptionsMenu(Menu menu) {
59 | Resources res = getResources();
60 | menu.add(0, QUICK_VIEW, 0, res.getString(R.string.quick_view));
61 | menu.add(0, MAIN_VIEW, 0, res.getString(R.string.main_view));
62 | menu.add(0, SETTINGS, 0, res.getString(R.string.settings));
63 | return true;
64 | }
65 |
66 | /* Handles item selections */
67 | public boolean onOptionsItemSelected(MenuItem item) {
68 | switch (item.getItemId()) {
69 | case SETTINGS:
70 | Intent i = new Intent(this, SettingsActivity.class);
71 | startActivity(i);
72 | return true;
73 | case QUICK_VIEW:
74 | Intent i2 = new Intent(this, QuickViewActivity.class);
75 | startActivity(i2);
76 | return true;
77 | case MAIN_VIEW:
78 | return true;
79 |
80 | }
81 | return false;
82 | }
83 |
84 |
85 |
86 | @Override
87 | public boolean onKeyDown(int keyCode, KeyEvent event) {
88 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
89 | Intent i3 = new Intent(this, SearchActivity.class);
90 | startActivity(i3);
91 | return true;
92 | }
93 | return super.onKeyDown(keyCode, event);
94 | }
95 | @Override
96 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
97 | if(keyCode == KeyEvent.KEYCODE_BACK){
98 | Intent i2 = new Intent(this, QuickViewActivity.class);
99 | startActivity(i2);
100 | return true;
101 | }
102 | // TODO Auto-generated method stub
103 | return super.onKeyLongPress(keyCode, event);
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/SearchActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.content.res.Resources;
6 | import android.os.Bundle;
7 | import android.view.KeyEvent;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.view.View.OnClickListener;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.Button;
14 | import android.widget.EditText;
15 | import android.widget.Spinner;
16 | import android.widget.TextView;
17 |
18 | public class SearchActivity extends Activity {
19 | private static final int QUICK_VIEW = 1234;
20 | private static final int MAIN_VIEW = 1235;
21 | private static final int SETTINGS = 1236;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | // TODO Auto-generated method stub
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.search_view);
28 | final Spinner spinner = (Spinner) findViewById(R.id.spinner);
29 | ArrayAdapter adapter = ArrayAdapter.createFromResource(
30 | this, R.array.commons_array, android.R.layout.simple_spinner_item);
31 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
32 |
33 | spinner.setAdapter(adapter);
34 |
35 | final EditText ef = (EditText)findViewById(R.id.edittext);
36 |
37 | Button submitbutton = (Button) findViewById(R.id.submit);
38 | submitbutton.setOnClickListener(new OnClickListener() {
39 | @Override
40 | public void onClick(View v) {
41 | Intent i2 = new Intent(v.getContext(), SearchMenuListActivity.class);
42 | try{
43 | i2.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME, (String)spinner.getSelectedItem());
44 |
45 | }catch(ClassCastException e){
46 | i2.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME, ((TextView)spinner.getSelectedItem()).toString());
47 | }
48 | i2.putExtra(MealMenuDBAdapter.KEY_FOODITEM_NAME, ef.getText().toString());
49 | startActivity(i2);
50 | }
51 | });
52 |
53 |
54 | }
55 |
56 | /* Creates the menu items */
57 | public boolean onCreateOptionsMenu(Menu menu) {
58 | Resources res = getResources();
59 | menu.add(0, QUICK_VIEW, 0, res.getString(R.string.quick_view));
60 | menu.add(0, MAIN_VIEW, 0, res.getString(R.string.main_view));
61 | menu.add(0, SETTINGS, 0, res.getString(R.string.settings));
62 | return true;
63 | }
64 |
65 |
66 |
67 | /* Handles item selections */
68 | public boolean onOptionsItemSelected(MenuItem item) {
69 | switch (item.getItemId()) {
70 | case SETTINGS:
71 | Intent i = new Intent(this, SettingsActivity.class);
72 | startActivity(i);
73 | return true;
74 | case QUICK_VIEW:
75 | Intent i2 = new Intent(this, QuickViewActivity.class);
76 | startActivity(i2);
77 | return true;
78 | case MAIN_VIEW:
79 | Intent i4 = new Intent(this, MainViewActivity.class);
80 | startActivity(i4);
81 | return true;
82 | }
83 | return false;
84 | }
85 |
86 | @Override
87 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
88 | if(keyCode == KeyEvent.KEYCODE_BACK){
89 | Intent i2 = new Intent(this, QuickViewActivity.class);
90 | startActivity(i2);
91 | return true;
92 | }
93 | // TODO Auto-generated method stub
94 | return super.onKeyLongPress(keyCode, event);
95 | }
96 |
97 | @Override
98 | public boolean onKeyDown(int keyCode, KeyEvent event) {
99 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
100 | return true;
101 | }
102 | return super.onKeyDown(keyCode, event);
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/SearchMenuListActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import android.app.ListActivity;
4 | import android.content.Intent;
5 | import android.content.res.Resources;
6 | import android.database.Cursor;
7 | import android.os.Bundle;
8 | import android.view.KeyEvent;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.ListView;
13 | import android.widget.SimpleCursorAdapter;
14 | import android.widget.TextView;
15 |
16 | public class SearchMenuListActivity extends ListActivity {
17 | MealMenuDBAdapter mDbAdapter;
18 | String common;
19 | String foodname;
20 | TextView titleText;
21 | private static final int QUICK_VIEW = 1234;
22 | private static final int MAIN_VIEW = 1235;
23 | private static final int SETTINGS = 1236;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 |
29 | Bundle extras = getIntent().getExtras();
30 | common = extras.getString(MealMenuDBAdapter.KEY_MEALMENU_NAME);
31 | foodname = extras.getString(MealMenuDBAdapter.KEY_FOODITEM_NAME);
32 | // TODO Auto-generated method stub
33 | mDbAdapter = new MealMenuDBAdapter(this);
34 | mDbAdapter.open();
35 | setContentView(R.layout.search_list);
36 | titleText = (TextView) findViewById(R.id.search_title_text);
37 | titleText.setText("Searching for "+foodname+" at "+common);
38 | fillData();
39 | }
40 |
41 | private void fillData() {
42 | Cursor c = mDbAdapter.search(common, foodname,getResources().getString(R.string.commons_name_all_commons));
43 | startManagingCursor(c);
44 | String[] from = new String[] { MealMenuDBAdapter.KEY_MEALMENU_NAME, MealMenuDBAdapter.KEY_MEALMENU_MEALNAME,
45 | MealMenuDBAdapter.KEY_MEALMENU_STARTSTRING };
46 | int[] to = new int[] { R.id.maintext1, R.id.maintext2, R.id.maintext3 };
47 | SimpleCursorAdapter menus = new SimpleCursorAdapter(this,
48 | R.layout.main_row, c, from, to);
49 | setListAdapter(menus);
50 | }
51 |
52 | @Override
53 | protected void onListItemClick(ListView l, View v, int position, long id) {
54 | super.onListItemClick(l, v, position, id);
55 | Intent i = new Intent(this, MenuViewActivity.class);
56 | i.putExtra(MenuViewActivity.KEY_MODE, MenuViewActivity.MODE_ROWID);
57 | i.putExtra(MealMenuDBAdapter.KEY_ROWID,id);
58 | startActivity(i);
59 | }
60 |
61 | /* Creates the menu items */
62 | public boolean onCreateOptionsMenu(Menu menu) {
63 | Resources res = getResources();
64 | menu.add(0, QUICK_VIEW, 0, res.getString(R.string.quick_view));
65 | menu.add(0, MAIN_VIEW, 0, res.getString(R.string.main_view));
66 | menu.add(0, SETTINGS, 0, res.getString(R.string.settings));
67 | return true;
68 | }
69 |
70 |
71 |
72 | /* Handles item selections */
73 | public boolean onOptionsItemSelected(MenuItem item) {
74 | switch (item.getItemId()) {
75 | case SETTINGS:
76 | Intent i = new Intent(this, SettingsActivity.class);
77 | startActivity(i);
78 | return true;
79 | case QUICK_VIEW:
80 | Intent i2 = new Intent(this, QuickViewActivity.class);
81 | startActivity(i2);
82 | return true;
83 | case MAIN_VIEW:
84 | Intent i4 = new Intent(this, MainViewActivity.class);
85 | startActivity(i4);
86 | return true;
87 | }
88 | return false;
89 | }
90 |
91 | @Override
92 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
93 | if(keyCode == KeyEvent.KEYCODE_BACK){
94 | Intent i2 = new Intent(this, QuickViewActivity.class);
95 | startActivity(i2);
96 | return true;
97 | }
98 | // TODO Auto-generated method stub
99 | return super.onKeyLongPress(keyCode, event);
100 | }
101 |
102 | @Override
103 | public boolean onKeyDown(int keyCode, KeyEvent event) {
104 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
105 | Intent i3 = new Intent(this, SearchActivity.class);
106 | startActivity(i3);
107 | return true;
108 | }
109 | return super.onKeyDown(keyCode, event);
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import java.io.FileNotFoundException;
4 | import java.io.FileOutputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.PrintStream;
8 | import java.net.HttpURLConnection;
9 | import java.net.URL;
10 |
11 | import android.app.Activity;
12 | import android.content.Intent;
13 | import android.content.res.Resources;
14 | import android.content.res.Resources.NotFoundException;
15 | import android.os.Bundle;
16 | import android.view.KeyEvent;
17 | import android.view.Menu;
18 | import android.view.MenuItem;
19 | import android.view.View;
20 | import android.view.View.OnClickListener;
21 | import android.widget.RadioButton;
22 |
23 | import com.mindflakes.TeamRED.MenuXML.Reader;
24 |
25 | public class SettingsActivity extends Activity {
26 | MealMenuDBAdapter mDbAdapter;
27 | Resources res;
28 |
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | res = getResources();
33 | mDbAdapter = new MealMenuDBAdapter(this);
34 | mDbAdapter.open();
35 | // TODO Auto-generated method stub
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.settings_view);
38 | OnClickListener radio_listener = new OnClickListener() {
39 | public void onClick(View v) {
40 | // Perform action on clicks
41 | RadioButton rb = (RadioButton) v;
42 | PrintStream ps;
43 | try {
44 | ps = new PrintStream(openFileOutput(res.getString(R.string.menu_preference_file),MODE_PRIVATE));
45 | } catch (FileNotFoundException e) {
46 | // TODO Auto-generated catch block
47 | ps=null;
48 | e.printStackTrace();
49 | }
50 | if(rb.getText().toString().equals(res.getString(R.string.select_full))) ps.println(0);
51 | else if(rb.getText().toString().equals(res.getString(R.string.select_vgt))) ps.println(1);
52 | else if(rb.getText().toString().equals(res.getString(R.string.select_vegan))) ps.println(2);
53 | ps.close();
54 | }
55 | };
56 |
57 | final RadioButton radio_full = (RadioButton) findViewById(R.id.radio_full);
58 | final RadioButton radio_vegan = (RadioButton) findViewById(R.id.radio_vegan);
59 | final RadioButton radio_veget = (RadioButton) findViewById(R.id.radio_vegetarian);
60 | radio_full.setOnClickListener(radio_listener);
61 | radio_vegan.setOnClickListener(radio_listener);
62 | radio_veget.setOnClickListener(radio_listener);
63 | }
64 |
65 |
66 | /* Creates the menu items */
67 | public boolean onCreateOptionsMenu(Menu menu) {
68 | menu.add(0, 1234, 0, res.getString(R.string.clear_sql));
69 | menu.add(0, 1235, 0, res.getString(R.string.update_menus));
70 | return true;
71 | }
72 |
73 | /* Handles item selections */
74 | public boolean onOptionsItemSelected(MenuItem item) {
75 | switch (item.getItemId()) {
76 | case 1234:
77 | mDbAdapter.clear();
78 | return true;
79 | case 1235:
80 | updateMenuFiles();
81 | return true;
82 | }
83 | return false;
84 | }
85 |
86 |
87 |
88 | private void updateMenuFiles(){
89 | try{
90 | URL remoteFile = new URL(getResources().getString(R.string.serialized_menus_remote));
91 |
92 | HttpURLConnection c = (HttpURLConnection) remoteFile.openConnection();
93 | c.setRequestMethod("GET");
94 | c.setDoOutput(true);
95 | c.connect();
96 | FileOutputStream f = openFileOutput(getResources().getString(R.string.local_file_serialized_zipped),MODE_PRIVATE);
97 | InputStream in = c.getInputStream();
98 |
99 | byte[] buffer = new byte[1024];
100 | int len1 = 0;
101 | while ( (len1 = in.read(buffer)) > 0 ) {
102 | f.write(buffer,0, len1);
103 | }
104 | f.close();
105 | in.close();
106 | Reader.uncompressFile(openFileInput(getResources().getString(R.string.local_file_serialized_zipped)),
107 | openFileOutput(getResources().getString(R.string.local_file_serialized),MODE_PRIVATE));
108 | loadMenusToSQL();
109 | }catch(IOException e){
110 | e.printStackTrace();
111 | }
112 | }
113 |
114 |
115 | private void loadMenusToSQL() throws FileNotFoundException, NotFoundException{
116 | mDbAdapter.clear();
117 | mDbAdapter.addMenus(Reader.readSerialized(openFileInput(getResources().getString(R.string.local_file_serialized))));
118 | }
119 |
120 | @Override
121 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
122 | if(keyCode == KeyEvent.KEYCODE_BACK){
123 | Intent i2 = new Intent(this, QuickViewActivity.class);
124 | startActivity(i2);
125 | return true;
126 | }
127 | // TODO Auto-generated method stub
128 | return super.onKeyLongPress(keyCode, event);
129 | }
130 |
131 | @Override
132 | public boolean onKeyDown(int keyCode, KeyEvent event) {
133 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
134 | return true;
135 | }
136 | return super.onKeyDown(keyCode, event);
137 | }
138 |
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/MainViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import org.joda.time.DateTime;
4 |
5 | import android.app.TabActivity;
6 | import android.content.Intent;
7 | import android.content.res.Resources;
8 | import android.os.Bundle;
9 | import android.view.KeyEvent;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.widget.TabHost;
13 |
14 | public class MainViewActivity extends TabActivity {
15 | private static final int QUICK_VIEW = 1234;
16 | private static final int MAIN_VIEW = 1235;
17 | private static final int SETTINGS = 1236;
18 |
19 |
20 | private Resources res;
21 | private TabHost mTabHost;
22 | /** Called when the activity is first created. */
23 | @Override
24 | public void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.main);
27 | res = getResources();
28 |
29 | mTabHost = getTabHost();
30 | addTabs();
31 | mTabHost.setCurrentTab(0);
32 | }
33 |
34 |
35 | @Override
36 | protected void onResume() {
37 | super.onResume();
38 | int currentTab = mTabHost.getCurrentTab();
39 | if(mTabHost==null) mTabHost=getTabHost();
40 | mTabHost.setCurrentTab(0);
41 | mTabHost.clearAllTabs();
42 | addTabs();
43 | mTabHost.setCurrentTab(currentTab);
44 | }
45 |
46 | private void addTabs(){
47 | TabHost.TabSpec spec; // Resusable TabSpec for each tab
48 | Intent intent; // Reusable Intent for each tab
49 | long millis = new DateTime().getMillis();
50 |
51 |
52 | // Create an Intent to launch an Activity for the tab (to be reused)
53 | intent = new Intent().setClass(this, FullMenuListActivity.class);
54 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME, res.getString(R.string.commons_name_short_carrillo));
55 |
56 | // Initialize a TabSpec for each tab and add it to the TabHost
57 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_short_carrillo)+millis).setIndicator(res.getString(R.string.commons_name_short_carrillo))
58 | .setContent(intent);
59 | mTabHost.addTab(spec);
60 |
61 | // Do the same for the other tabs
62 | intent = new Intent().setClass(this, FullMenuListActivity.class);
63 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME,res.getString(R.string.commons_name_short_dlg));
64 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_supershort_dlg)+millis).setIndicator(res.getString(R.string.commons_name_supershort_dlg))
65 | .setContent(intent);
66 | mTabHost.addTab(spec);
67 |
68 |
69 | intent = new Intent().setClass(this, FullMenuListActivity.class);
70 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME, res.getString(R.string.commons_name_short_ortega));
71 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_short_ortega)+millis).setIndicator(res.getString(R.string.commons_name_short_ortega))
72 | .setContent(intent);
73 | mTabHost.addTab(spec);
74 |
75 | intent = new Intent().setClass(this, FullMenuListActivity.class);
76 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME, res.getString(R.string.commons_name_short_portola));
77 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_short_portola)+millis).setIndicator(res.getString(R.string.commons_name_short_portola))
78 | .setContent(intent);
79 | mTabHost.addTab(spec);
80 |
81 | mTabHost.setCurrentTab(0);
82 |
83 | }
84 |
85 |
86 |
87 | /* Creates the menu items */
88 | public boolean onCreateOptionsMenu(Menu menu) {
89 | menu.add(0, QUICK_VIEW, 0, res.getString(R.string.quick_view));
90 | menu.add(0, MAIN_VIEW, 0, res.getString(R.string.main_view));
91 | menu.add(0, SETTINGS, 0, res.getString(R.string.settings));
92 | return true;
93 | }
94 |
95 | /* Handles item selections */
96 | public boolean onOptionsItemSelected(MenuItem item) {
97 | switch (item.getItemId()) {
98 | case SETTINGS:
99 | Intent i = new Intent(this, SettingsActivity.class);
100 | startActivity(i);
101 | return true;
102 | case QUICK_VIEW:
103 | Intent i2 = new Intent(this, QuickViewActivity.class);
104 | startActivity(i2);
105 | return true;
106 | case MAIN_VIEW:
107 | return true;
108 |
109 | }
110 | return false;
111 | }
112 |
113 |
114 |
115 | @Override
116 | public boolean onKeyDown(int keyCode, KeyEvent event) {
117 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
118 | Intent i3 = new Intent(this, SearchActivity.class);
119 | startActivity(i3);
120 | return true;
121 | }
122 | return super.onKeyDown(keyCode, event);
123 | }
124 | @Override
125 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
126 | if(keyCode == KeyEvent.KEYCODE_BACK){
127 | Intent i2 = new Intent(this, QuickViewActivity.class);
128 | startActivity(i2);
129 | return true;
130 | }
131 | // TODO Auto-generated method stub
132 | return super.onKeyLongPress(keyCode, event);
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/QuickViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import java.io.FileNotFoundException;
4 |
5 | import org.joda.time.DateTime;
6 |
7 | import android.app.TabActivity;
8 | import android.content.Intent;
9 | import android.content.res.Resources;
10 | import android.content.res.Resources.NotFoundException;
11 | import android.os.Bundle;
12 | import android.view.KeyEvent;
13 | import android.view.Menu;
14 | import android.view.MenuItem;
15 | import android.widget.TabHost;
16 |
17 | import com.mindflakes.TeamRED.MenuXML.Reader;
18 |
19 | public class QuickViewActivity extends TabActivity {
20 |
21 | private static final int QUICK_VIEW = 1234;
22 | private static final int MAIN_VIEW = 1235;
23 | private static final int SETTINGS = 1236;
24 |
25 | private Resources res;
26 | private TabHost mTabHost;
27 | private MealMenuDBAdapter mDbAdapter;
28 | // private NotesDbAdapter mDbAdapter;
29 | /** Called when the activity is first created. */
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | res = getResources();
34 | setContentView(R.layout.quick_view);
35 | mTabHost = getTabHost();
36 |
37 | try{
38 | mDbAdapter = new MealMenuDBAdapter(this);
39 | mDbAdapter.open();
40 | } catch(Exception e){
41 | }
42 | // readMenus();
43 |
44 | addTabs();
45 | mTabHost.setCurrentTab(0);
46 | }
47 |
48 |
49 |
50 | @Override
51 | protected void onResume() {
52 | super.onResume();
53 | int currentTab = mTabHost.getCurrentTab();
54 | if(mTabHost==null) mTabHost=getTabHost();
55 | mTabHost.setCurrentTab(0);
56 | mTabHost.clearAllTabs();
57 | addTabs();
58 | mTabHost.setCurrentTab(currentTab);
59 | }
60 |
61 |
62 | private void addTabs(){
63 | TabHost.TabSpec spec; // Reusable TabSpec for each tab
64 | Intent intent; // Reusable Intent for each tab
65 | long millis = new DateTime().getMillis();
66 |
67 | // Create an Intent to launch an Activity for the tab (to be reused)
68 | intent = new Intent().setClass(this, MenuViewActivity.class);
69 | intent.putExtra(MenuViewActivity.KEY_MODE, MenuViewActivity.MODE_COMMONS);
70 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME,res.getString(R.string.commons_name_short_carrillo));
71 |
72 | // Initialize a TabSpec for each tab and add it to the TabHost
73 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_short_carrillo)+millis)
74 | .setIndicator(res.getString(R.string.commons_name_short_carrillo))
75 | .setContent(intent);
76 | mTabHost.addTab(spec);
77 |
78 | // Do the same for the other tabs
79 | intent = new Intent().setClass(this, MenuViewActivity.class);
80 | intent.putExtra(MenuViewActivity.KEY_MODE, MenuViewActivity.MODE_COMMONS);
81 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME,res.getString(R.string.commons_name_short_dlg));
82 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_supershort_dlg)+millis)
83 | .setIndicator(res.getString(R.string.commons_name_supershort_dlg))
84 | .setContent(intent);
85 | mTabHost.addTab(spec);
86 |
87 |
88 | intent = new Intent().setClass(this, MenuViewActivity.class);
89 | intent.putExtra(MenuViewActivity.KEY_MODE, MenuViewActivity.MODE_COMMONS);
90 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME,res.getString(R.string.commons_name_short_ortega));
91 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_short_ortega)+millis)
92 | .setIndicator(res.getString(R.string.commons_name_short_ortega))
93 | .setContent(intent);
94 | mTabHost.addTab(spec);
95 |
96 | intent = new Intent().setClass(this, MenuViewActivity.class);
97 | intent.putExtra(MenuViewActivity.KEY_MODE, MenuViewActivity.MODE_COMMONS);
98 | intent.putExtra(MealMenuDBAdapter.KEY_MEALMENU_NAME,res.getString(R.string.commons_name_short_portola));
99 | spec = mTabHost.newTabSpec(res.getString(R.string.commons_name_short_portola)+millis)
100 | .setIndicator(res.getString(R.string.commons_name_short_portola))
101 | .setContent(intent);
102 | mTabHost.addTab(spec);
103 |
104 | mTabHost.setCurrentTab(0);
105 |
106 | }
107 |
108 | /* Creates the menu items */
109 | public boolean onCreateOptionsMenu(Menu menu) {
110 | menu.add(0, QUICK_VIEW, 0, res.getString(R.string.quick_view));
111 | menu.add(0, MAIN_VIEW, 0, res.getString(R.string.main_view));
112 | menu.add(0, SETTINGS, 0, res.getString(R.string.settings));
113 | return true;
114 | }
115 |
116 | /* Handles item selections */
117 | public boolean onOptionsItemSelected(MenuItem item) {
118 | switch (item.getItemId()) {
119 | case SETTINGS:
120 | Intent i = new Intent(this, SettingsActivity.class);
121 | startActivity(i);
122 | return true;
123 | case QUICK_VIEW:
124 | return true;
125 | case MAIN_VIEW:
126 | Intent i4 = new Intent(this, MainViewActivity.class);
127 | startActivity(i4);
128 | return true;
129 |
130 | }
131 | return false;
132 | }
133 |
134 |
135 |
136 | @Override
137 | public boolean onKeyDown(int keyCode, KeyEvent event) {
138 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
139 | Intent i3 = new Intent(this, SearchActivity.class);
140 | startActivity(i3);
141 | return true;
142 | }
143 | return super.onKeyDown(keyCode, event);
144 | }
145 |
146 | @Override
147 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
148 | if(keyCode == KeyEvent.KEYCODE_BACK){
149 | return true;
150 | }
151 | // TODO Auto-generated method stub
152 | return super.onKeyLongPress(keyCode, event);
153 | }
154 |
155 |
156 | }
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/MenuViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.mindflakes.TeamRED.AndRedMenu;
2 |
3 | import java.io.FileNotFoundException;
4 | import java.util.ArrayList;
5 | import java.util.Scanner;
6 |
7 | import org.joda.time.DateTime;
8 | import org.joda.time.format.DateTimeFormat;
9 | import org.joda.time.format.DateTimeFormatter;
10 |
11 | import android.app.Activity;
12 | import android.content.Intent;
13 | import android.content.res.Resources;
14 | import android.os.Bundle;
15 | import android.view.Gravity;
16 | import android.view.KeyEvent;
17 | import android.view.Menu;
18 | import android.view.MenuItem;
19 | import android.view.ViewGroup.LayoutParams;
20 | import android.widget.ArrayAdapter;
21 | import android.widget.LinearLayout;
22 | import android.widget.ListView;
23 | import android.widget.TextView;
24 |
25 | import com.mindflakes.TeamRED.menuClasses.FoodItem;
26 | import com.mindflakes.TeamRED.menuClasses.MealMenu;
27 | import com.mindflakes.TeamRED.menuClasses.Venue;
28 |
29 | public class MenuViewActivity extends Activity {
30 | private static final int QUICK_VIEW = 1234;
31 | private static final int MAIN_VIEW = 1235;
32 | private static final int SETTINGS = 1236;
33 |
34 |
35 | public static final String KEY_MODE = "mode";
36 | public static final int MODE_ROWID = 0;
37 | public static final int MODE_COMMONS = 1;
38 | private MealMenuDBAdapter mDbAdapter;
39 | private Long mRowId;
40 | private String mCommons;
41 | private Integer mMode;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | // TODO Auto-generated method stub
46 | super.onCreate(savedInstanceState);
47 | mDbAdapter = new MealMenuDBAdapter(this);
48 | mDbAdapter.open();
49 |
50 | Bundle extras = getIntent().getExtras();
51 | mMode = extras != null ? extras.getInt(KEY_MODE)
52 | : null;
53 | switch(mMode){
54 | case MODE_ROWID:
55 | mRowId = extras.getLong(MealMenuDBAdapter.KEY_ROWID);
56 | break;
57 | case MODE_COMMONS:
58 | mCommons = extras.getString(MealMenuDBAdapter.KEY_MEALMENU_NAME);
59 | break;
60 | }
61 |
62 |
63 | setLayout();
64 |
65 | }
66 |
67 | @Override
68 | protected void onResume() {
69 | super.onResume();
70 | setLayout();
71 | }
72 |
73 | private void setLayout(){
74 | MealMenu menu = null;
75 | DateTimeFormatter dtf = DateTimeFormat.forPattern("'on' EEE, MMM dd");
76 | int food_type=0;
77 | try {
78 | food_type = new Scanner(openFileInput("menu_preferences")).nextInt();
79 | } catch (FileNotFoundException e) {
80 |
81 | }
82 | if(mMode==MODE_ROWID){
83 | menu=mDbAdapter.fetchMenu(mRowId,food_type);
84 | } else if(mMode==MODE_COMMONS){
85 | menu=mDbAdapter.selectFirstMeal(mCommons, new DateTime().getMillis(),food_type);
86 | }
87 | LinearLayout mainLayout = new LinearLayout(this);
88 | mainLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
89 | LayoutParams.FILL_PARENT));
90 | mainLayout.setOrientation(LinearLayout.VERTICAL);
91 | TextView text;
92 | if(menu!=null){
93 | if(mMode==MODE_ROWID){
94 | text = new TextView(this);
95 | text.setText(menu.getCommonsName());
96 | text.setGravity(Gravity.CENTER_HORIZONTAL);
97 | mainLayout.addView(text);
98 | }
99 | text = new TextView(this);
100 | text.setText(menu.getMealName()+" "+dtf.print(menu.getMealInterval().getStart()));
101 | text.setGravity(Gravity.CENTER_HORIZONTAL);
102 | mainLayout.addView(text);
103 | }
104 |
105 | ListView view = new ListView(this);
106 | ArrayList toSet = toArrayHelper(menu);
107 | ArrayAdapter adapter = new ArrayAdapter(this,R.layout.quick_row,toSet);
108 | view.setAdapter(adapter);
109 |
110 | mainLayout.addView(view);
111 | setContentView(mainLayout);
112 | }
113 |
114 | private ArrayList toArrayHelper(MealMenu menu){
115 | if(menu==null) return new ArrayList();
116 | ArrayList arr = new ArrayList();
117 | for(Venue ven:menu.getVenues()){
118 | arr.add(ven.getName());
119 | for(FoodItem food:ven.getFoodItems()){
120 | arr.add(" "+food.getName());
121 | }
122 | }
123 | return arr;
124 | }
125 | /* Creates the menu items */
126 | public boolean onCreateOptionsMenu(Menu menu) {
127 | Resources res = getResources();
128 | menu.add(0, QUICK_VIEW, 0, res.getString(R.string.quick_view));
129 | menu.add(0, MAIN_VIEW, 0, res.getString(R.string.main_view));
130 | menu.add(0, SETTINGS, 0, res.getString(R.string.settings));
131 | return true;
132 | }
133 |
134 |
135 |
136 | /* Handles item selections */
137 | public boolean onOptionsItemSelected(MenuItem item) {
138 | switch (item.getItemId()) {
139 | case SETTINGS:
140 | Intent i = new Intent(this, SettingsActivity.class);
141 | startActivity(i);
142 | return true;
143 | case QUICK_VIEW:
144 | if(mMode!=MODE_COMMONS){
145 | Intent i2 = new Intent(this, QuickViewActivity.class);
146 | startActivity(i2);
147 | }
148 | return true;
149 | case MAIN_VIEW:
150 | if(mMode!=MODE_ROWID){
151 | Intent i4 = new Intent(this, MainViewActivity.class);
152 | startActivity(i4);
153 | }
154 | return true;
155 | }
156 | return false;
157 | }
158 |
159 | @Override
160 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
161 | if(keyCode == KeyEvent.KEYCODE_BACK){
162 | Intent i2 = new Intent(this, QuickViewActivity.class);
163 | startActivity(i2);
164 | return true;
165 | }
166 | // TODO Auto-generated method stub
167 | return super.onKeyLongPress(keyCode, event);
168 | }
169 |
170 | @Override
171 | public boolean onKeyDown(int keyCode, KeyEvent event) {
172 | if(keyCode == KeyEvent.KEYCODE_SEARCH){
173 | Intent i3 = new Intent(this, SearchActivity.class);
174 | startActivity(i3);
175 | return true;
176 | }
177 | return super.onKeyDown(keyCode, event);
178 | }
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/src/main/java/com/mindflakes/TeamRED/AndRedMenu/MealMenuDBAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.mindflakes.TeamRED.AndRedMenu;
18 |
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 | import java.util.Set;
23 |
24 | import org.joda.time.DateTime;
25 | import org.joda.time.format.DateTimeFormat;
26 | import org.joda.time.format.DateTimeFormatter;
27 |
28 | import android.content.ContentValues;
29 | import android.content.Context;
30 | import android.database.Cursor;
31 | import android.database.SQLException;
32 | import android.database.sqlite.SQLiteDatabase;
33 | import android.database.sqlite.SQLiteOpenHelper;
34 | import android.util.Log;
35 |
36 | import com.mindflakes.TeamRED.menuClasses.FoodItem;
37 | import com.mindflakes.TeamRED.menuClasses.MealMenu;
38 | import com.mindflakes.TeamRED.menuClasses.Venue;
39 |
40 | /**
41 | * Simple notes database access helper class. Defines the basic CRUD operations
42 | * for the notepad example, and gives the ability to list all notes as well as
43 | * retrieve or modify a specific note.
44 | *
45 | * This has been improved from the first version of this tutorial through the
46 | * addition of better error handling and also using returning a Cursor instead
47 | * of using a collection of inner classes (which is less scalable and not
48 | * recommended).
49 | */
50 | public class MealMenuDBAdapter {
51 |
52 | private static final DateTimeFormatter dtf = DateTimeFormat.forPattern("'on' EEE, MMM dd");
53 |
54 | public static final String KEY_MEALMENU_NAME = "menuname";
55 | public static final String KEY_MEALMENU_MEALNAME = "mealname";
56 | public static final String KEY_MEALMENU_START = "start";
57 | public static final String KEY_MEALMENU_END = "end";
58 | public static final String KEY_MEALMENU_MOD = "mod";
59 | public static final String KEY_MEALMENU_STARTSTRING = "startstring";
60 | public static final String KEY_ROWID = "_id";
61 |
62 | public static final String KEY_VENUE_NAME = "venuename";
63 | public static final String KEY_VENUE_MENUROWID = "menurowid";
64 |
65 | public static final String KEY_FOODITEM_NAME = "foodname";
66 | //Should be 0 if not either, 1 if vegetarian, and 2 if vegan (vegan implies vegetarian)
67 | public static final String KEY_FOODITEM_FOOD_TYPE = "foodtype";
68 | public static final String KEY_FOODITEM_VENUEROWID = "venuerowid";
69 |
70 | private static final String TAG = "MealMenuDBAdapter";
71 | private DatabaseHelper mDbHelper;
72 |
73 |
74 | private SQLiteDatabase mDb;
75 |
76 | private static final String MENU_DATABASE_TABLE = "menutable";
77 | private static final String VENUE_DATABASE_TABLE = "venuetable";
78 | private static final String FOOD_DATABASE_TABLE = "foodtable";
79 |
80 | private static final String DATABASE_NAME = "data";
81 | private static final int DATABASE_VERSION = 2;
82 |
83 | private final Context mCtx;
84 |
85 | /**
86 | * Database creation sql statement
87 | */
88 |
89 | private static final String MENU_DATABASE_CREATE =
90 | "create table "+MENU_DATABASE_TABLE+" ("+KEY_ROWID+" integer primary key autoincrement, "
91 | + KEY_MEALMENU_START+" integer, "
92 | + KEY_MEALMENU_END+" integer, "
93 | + KEY_MEALMENU_MOD+" integer, "
94 | + KEY_MEALMENU_NAME + " text not null, "
95 | + KEY_MEALMENU_STARTSTRING + " text not null, "
96 | + KEY_MEALMENU_MEALNAME+" text not null);";
97 |
98 | private static final String VENUE_DATABASE_CREATE =
99 | "create table "+VENUE_DATABASE_TABLE+" ("+KEY_ROWID+" integer primary key autoincrement, "
100 | + KEY_VENUE_NAME + " text not null, "
101 | + KEY_VENUE_MENUROWID+" integer not null);";
102 |
103 | private static final String FOOD_DATABASE_CREATE =
104 | "create table "+FOOD_DATABASE_TABLE+" ("+KEY_ROWID+" integer primary key autoincrement, "
105 | + KEY_FOODITEM_NAME + " text not null, "
106 | + KEY_FOODITEM_FOOD_TYPE+" integer not null, "
107 | + KEY_FOODITEM_VENUEROWID+" integer not null);";
108 |
109 | private static class DatabaseHelper extends SQLiteOpenHelper {
110 |
111 | DatabaseHelper(Context context) {
112 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
113 | }
114 |
115 | @Override
116 | public void onCreate(SQLiteDatabase db) {
117 |
118 | // db.execSQL(DATABASE_CREATE);
119 | db.execSQL(MENU_DATABASE_CREATE);
120 | db.execSQL(VENUE_DATABASE_CREATE);
121 | db.execSQL(FOOD_DATABASE_CREATE);
122 |
123 | }
124 |
125 | @Override
126 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
127 | Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
128 | + newVersion + ", which will destroy all old data");
129 | db.execSQL("DROP TABLE IF EXISTS "+MENU_DATABASE_TABLE);
130 | db.execSQL("DROP TABLE IF EXISTS "+VENUE_DATABASE_TABLE);
131 | db.execSQL("DROP TABLE IF EXISTS "+FOOD_DATABASE_TABLE);
132 | onCreate(db);
133 | }
134 | }
135 |
136 | /**
137 | * Constructor - takes the context to allow the database to be
138 | * opened/created
139 | *
140 | * @param ctx the Context within which to work
141 | */
142 | public MealMenuDBAdapter(Context ctx) {
143 | this.mCtx = ctx;
144 | }
145 |
146 | /**
147 | * Open the menus database. If it cannot be opened, try to create a new
148 | * instance of the database. If it cannot be created, throw an exception to
149 | * signal the failure
150 | *
151 | * @return this (self reference, allowing this to be chained in an
152 | * initialization call)
153 | * @throws SQLException if the database could be neither opened or created
154 | */
155 | public MealMenuDBAdapter open() throws SQLException {
156 | mDbHelper = new DatabaseHelper(mCtx);
157 | mDb = mDbHelper.getWritableDatabase();
158 | return this;
159 | }
160 |
161 | /**
162 | * Closes the database;
163 | */
164 | public void close() {
165 | mDbHelper.close();
166 | }
167 |
168 | public void clear(){
169 | mDb.delete(MENU_DATABASE_TABLE, null, null);
170 | mDb.delete(FOOD_DATABASE_TABLE, null, null);
171 | mDb.delete(VENUE_DATABASE_TABLE, null, null);
172 | }
173 |
174 |
175 | /**
176 | * Create entries in the databases for the MealMenu. If the menu is
177 | * successfully created return the new rowId for that menu, otherwise return
178 | * a -1 to indicate failure.
179 | *
180 | * @param menu MealMenu to be added to the database
181 | * @return rowId or -1 if failed
182 | */
183 | public long addMenu(MealMenu menu) {
184 | // mDb.beginTransaction();
185 | ContentValues initialValues = new ContentValues();
186 | initialValues.put(KEY_MEALMENU_NAME, menu.getCommonsName());
187 | initialValues.put(KEY_MEALMENU_MEALNAME, menu.getMealName());
188 | initialValues.put(KEY_MEALMENU_START, menu.getMealInterval().getStartMillis());
189 | initialValues.put(KEY_MEALMENU_END, menu.getMealInterval().getEndMillis());
190 | initialValues.put(KEY_MEALMENU_MOD, menu.getModDate().getMillis());
191 | initialValues.put(KEY_MEALMENU_STARTSTRING, dtf.print(menu.getMealInterval().getStart()));
192 |
193 | long menuID = mDb.insert(MENU_DATABASE_TABLE, null, initialValues);
194 | for(Venue ven : menu.getVenues()){
195 | initialValues = new ContentValues();
196 | initialValues.put(KEY_VENUE_NAME,ven.getName());
197 | initialValues.put(KEY_VENUE_MENUROWID, menuID);
198 | long venueID=mDb.insert(VENUE_DATABASE_TABLE, null, initialValues);
199 | for(FoodItem food:ven.getFoodItems()){
200 | initialValues = new ContentValues();
201 | initialValues.put(KEY_FOODITEM_NAME, food.getName());
202 | initialValues.put(KEY_FOODITEM_FOOD_TYPE, (food.isVegetarian()?1:0)+(food.isVegan()?1:0));
203 | initialValues.put(KEY_FOODITEM_VENUEROWID, venueID);
204 | mDb.insert(FOOD_DATABASE_TABLE, null, initialValues);
205 | }
206 | }
207 | // mDb.setTransactionSuccessful();
208 | // mDb.endTransaction();
209 | return menuID;
210 | }
211 |
212 | /**
213 | * Adds multiple MealMenus to the database by calling addMenu on each one, and grouping 10 into each sql transaction.
214 | * Returns an array of the rowId's for each meal menu
215 | * @param menu multiple menus to be added to the database.
216 | * @return the rowIDs
217 | */
218 | public long[] addMenus(ArrayList menu){
219 | long[] result = new long[menu.size()];
220 | mDb.beginTransaction();
221 | for(int i = 0; i 0;
242 | if(result){
243 | Cursor venCursor = mDb.query(true, VENUE_DATABASE_TABLE, new String[]{
244 | KEY_ROWID}, KEY_VENUE_MENUROWID+"="+rowId,
245 | null,null,null,null,null);
246 | if (venCursor != null) {
247 | boolean hasMoreVens =venCursor.moveToFirst();
248 | while(hasMoreVens){
249 | long venRowId = venCursor.getLong(venCursor.getColumnIndexOrThrow(KEY_ROWID));
250 | mDb.delete(FOOD_DATABASE_TABLE, KEY_FOODITEM_VENUEROWID + "=" + venRowId, null);
251 | hasMoreVens = venCursor.moveToNext();
252 | }
253 | }
254 | mDb.delete(VENUE_DATABASE_TABLE, KEY_VENUE_MENUROWID+"="+rowId,null);
255 | }
256 | return result;
257 | }
258 | /**
259 | * Return a Cursor over the list of all menus in the database
260 | *
261 | * @return Cursor over all menus
262 | */
263 | public Cursor fetchAllMenuCursor() {
264 |
265 | return mDb.query(MENU_DATABASE_TABLE, new String[] {KEY_ROWID, KEY_MEALMENU_NAME,
266 | KEY_MEALMENU_START,KEY_MEALMENU_MEALNAME},
267 | null, null, null, null, null);
268 | }
269 |
270 |
271 | /**
272 | * Searches for Meals that end Between the dates given, in the Long wrapper class. Null means to not use that value.
273 | * Ordered by the column name given.
274 | * @param start start of the endMillis range
275 | * @param stop end of the endMillis range
276 | * @param orderBy what field to order the results by
277 | * @return a new Query for the fetch
278 | */
279 | public Cursor fetchMenusEndBetween(String commonsName,Long start, Long stop, String orderBy){
280 | String selection = "";
281 | if(commonsName!=null) selection = KEY_MEALMENU_NAME+"=\'"+commonsName+"\'";
282 | if(start!=null) selection = addCondition(selection,KEY_MEALMENU_END+">="+start.longValue());
283 | if(stop!=null) selection = addCondition(selection,KEY_MEALMENU_END+"<="+stop.longValue());
284 | return mDb.query(MENU_DATABASE_TABLE, new String[] {KEY_ROWID, KEY_MEALMENU_NAME, KEY_MEALMENU_MEALNAME,
285 | KEY_MEALMENU_START,KEY_MEALMENU_END,KEY_MEALMENU_MOD}, (selection.equals(""))?null:selection, null,null, null, orderBy);
286 | }
287 |
288 | /**
289 | * Method designed for the use in the FullMenuListActivity. Creates a cursor for all the menus at the
290 | * specified common that end after the current time.
291 | * @param commonsName the commons used in the query
292 | * @return a new cursor with all the future meals at the specified common
293 | */
294 | public Cursor fetchMenusForMainList(String commonsName){
295 | if(commonsName==null) return null;
296 | return mDb.query(MENU_DATABASE_TABLE, new String[] {KEY_ROWID, KEY_MEALMENU_MEALNAME,
297 | KEY_MEALMENU_STARTSTRING}, KEY_MEALMENU_NAME+"=\'"+commonsName+"\' AND "+KEY_MEALMENU_END+">="+(new DateTime().getMillis()), null,null, null, KEY_MEALMENU_START);
298 | }
299 |
300 | /**
301 | * Selects the first meal that ends after the given end time, at the common.
302 | * @param commonName common to search for
303 | * @param end end time that will be used in search, in millis
304 | * @param mode mode (0/1/2) representing (normal/vegetarian/vegan) food choices for the MealMenu
305 | * @return the first MealMenu that ends after the given date at the given commons
306 | */
307 | public MealMenu selectFirstMeal(String commonName,Long end, int mode){
308 | if(commonName==null||end==null){
309 | throw new NullPointerException("Parameters to selectFirstMeal cannot be null");
310 | }
311 | Cursor mCursor=null;
312 | try{
313 | mCursor= mDb.query(true, MENU_DATABASE_TABLE, new String[] {KEY_ROWID,
314 | KEY_MEALMENU_NAME, KEY_MEALMENU_MEALNAME, KEY_MEALMENU_START, KEY_MEALMENU_END,
315 | KEY_MEALMENU_MOD}, KEY_MEALMENU_NAME+"=\'"+commonName+"\' AND "+KEY_MEALMENU_END+">="+end.longValue(), null,
316 | null, null,KEY_MEALMENU_START, "1");
317 | }catch(Exception e){
318 | String type = e.getClass().toString();
319 | System.out.println(type);
320 | }
321 | if(mCursor!=null && mCursor.moveToFirst()){
322 | return returnNextFromCursor(mCursor,mCursor.getLong((mCursor.getColumnIndexOrThrow(KEY_ROWID))),mode);
323 | }
324 | return null;
325 | }
326 |
327 | private static String addCondition(String start, String add){
328 | return ((start!=null&&!start.equals(""))?start+" AND ":"")+add;
329 | }
330 | /**
331 | * Return a Cursor positioned at the menu that matches the given rowId
332 | *
333 | * @param rowId id of menu to retrieve
334 | * @param mode mode (0/1/2) representing (normal/vegetarian/vegan) food choices for the MealMenu
335 | * @return MealMenu of matching menu, if found
336 | * @throws SQLException if menu could not be found/retrieved
337 | */
338 | public MealMenu fetchMenu(long rowId, int mode) throws SQLException {
339 | Cursor mCursor =
340 |
341 | mDb.query(true, MENU_DATABASE_TABLE, new String[] {
342 | KEY_MEALMENU_NAME, KEY_MEALMENU_MEALNAME, KEY_MEALMENU_START, KEY_MEALMENU_END,
343 | KEY_MEALMENU_MOD}, KEY_ROWID + "=" + rowId, null,
344 | null, null, null, null);
345 | if (mCursor != null && mCursor.moveToFirst()) {
346 | return returnNextFromCursor(mCursor,rowId, mode);
347 | } else{
348 | return null;
349 | }
350 | }
351 |
352 | private String prepareSearchSelection(String foodSearch){
353 | String result = "";
354 | String[] tmp = foodSearch.split(" ");
355 | for(String s:tmp){
356 | if(result.length()!=0){
357 | result+=" AND ";
358 | }
359 | result+=KEY_FOODITEM_NAME+" LIKE '%"+s+"%'";
360 | }
361 | return result;
362 | }
363 |
364 | /**
365 | * Starts a sql query at the given dining commons, for the given foods. The foodsearch is split by spaces, and the returned cursor requires that each mealmenu has each
366 | * of the words in at least one food item. if commonsName == allCommons, it searches regardless of commons name.
367 | * @param commonsName commons to be searched at
368 | * @param foodSearch food string to search for
369 | * @param allCommons string that represents all commons
370 | * @return
371 | */
372 | public Cursor search(String commonsName, String foodSearch, String allCommons){
373 | String selection = prepareSearchSelection(foodSearch);
374 | Cursor mFoodCursor = mDb.query(true, FOOD_DATABASE_TABLE, new String[]{
375 | KEY_FOODITEM_VENUEROWID}, selection,
376 | null,null,null,null,null);
377 | Map map = new HashMap();
378 | if(mFoodCursor!=null&&mFoodCursor.moveToFirst()){
379 | do{
380 | map.put(mFoodCursor.getLong(mFoodCursor.getColumnIndexOrThrow(KEY_FOODITEM_VENUEROWID)), true);
381 | }while(mFoodCursor.moveToNext());
382 | } else{
383 | return mDb.query(MENU_DATABASE_TABLE, new String[] {KEY_ROWID, KEY_MEALMENU_NAME,KEY_MEALMENU_MEALNAME, KEY_MEALMENU_STARTSTRING}, KEY_MEALMENU_MEALNAME+"=\'FAKENAME\'", null,null, null, KEY_MEALMENU_START);
384 |
385 | }
386 | Set vens = map.keySet();
387 | selection = "";
388 | for(Long l: vens){
389 | if(selection.length()!=0){
390 | selection +=" OR ";
391 | }
392 | selection+=KEY_ROWID+"="+l.longValue();
393 | }
394 | selection = selection.length()!=0?selection:KEY_MEALMENU_NAME+"=\'asdfasdfasdfasdf\'";
395 | mFoodCursor = mDb.query(true, VENUE_DATABASE_TABLE, new String[]{
396 | KEY_VENUE_MENUROWID}, selection,
397 | null,null,null,null,null);
398 |
399 | map = new HashMap();
400 | if(mFoodCursor!=null&&mFoodCursor.moveToFirst()){
401 | do{
402 | map.put(mFoodCursor.getLong(mFoodCursor.getColumnIndexOrThrow(KEY_VENUE_MENUROWID)), true);
403 | }while(mFoodCursor.moveToNext());
404 | }else{
405 | return mDb.query(MENU_DATABASE_TABLE, new String[] {KEY_ROWID, KEY_MEALMENU_NAME,KEY_MEALMENU_MEALNAME, KEY_MEALMENU_STARTSTRING}, KEY_MEALMENU_MEALNAME+"=\'FAKENAME\'", null,null, null, KEY_MEALMENU_START);
406 |
407 | }
408 |
409 | vens = map.keySet();
410 | selection = "";
411 | for(Long l: vens){
412 | if(selection.length()!=0){
413 | selection +=" OR ";
414 | }
415 | selection+=KEY_ROWID+"="+l.longValue();
416 | }
417 |
418 | selection = selection.length()!=0?"("+selection+")":KEY_MEALMENU_NAME+"=\'asdfasdfasdfasdf\'";
419 | selection += (!commonsName.equals(allCommons))?" AND "+KEY_MEALMENU_NAME+"=\'"+commonsName+"\'":"";
420 | selection += " AND "+KEY_MEALMENU_END+">="+(new DateTime()).getMillis();
421 |
422 | return mDb.query(MENU_DATABASE_TABLE, new String[] {KEY_ROWID, KEY_MEALMENU_NAME,KEY_MEALMENU_MEALNAME, KEY_MEALMENU_STARTSTRING}, (selection.equals(""))?null:selection, null,null, null, KEY_MEALMENU_START);
423 | }
424 |
425 | private MealMenu returnNextFromCursor(Cursor mCursor, long rowId, int mode){
426 | String foodType = " AND "+KEY_FOODITEM_FOOD_TYPE+">="+ mode;
427 | ArrayList vens = new ArrayList();
428 | Cursor mVenCursor = mDb.query(true, VENUE_DATABASE_TABLE, new String[]{
429 | KEY_ROWID,KEY_VENUE_NAME}, KEY_VENUE_MENUROWID+"="+rowId,
430 | null,null,null,null,null);
431 | boolean hasMoreVens = mVenCursor.moveToFirst();
432 | while(hasMoreVens){
433 | ArrayList foods = new ArrayList();
434 | long venRowId = mVenCursor.getLong(mVenCursor.getColumnIndexOrThrow(KEY_ROWID));
435 | Cursor mFoodCursor = mDb.query(true, FOOD_DATABASE_TABLE, new String[]{
436 | KEY_FOODITEM_NAME,KEY_FOODITEM_FOOD_TYPE}, KEY_FOODITEM_VENUEROWID+"="+venRowId+foodType,
437 | null,null,null,null,null);
438 | boolean hasMoreFoods = mFoodCursor.moveToFirst();
439 | while(hasMoreFoods){
440 | short type = mFoodCursor.getShort(mFoodCursor.getColumnIndex(KEY_FOODITEM_FOOD_TYPE));
441 | foods.add(new FoodItem(mFoodCursor.getString(mFoodCursor.getColumnIndexOrThrow(KEY_FOODITEM_NAME)),
442 | (type==2)?true:false,(type>0 && type <=2)?true:false));
443 | hasMoreFoods = mFoodCursor.moveToNext();
444 | }
445 | vens.add(new Venue(mVenCursor.getString(mVenCursor.getColumnIndexOrThrow(KEY_VENUE_NAME)), foods));
446 | hasMoreVens = mVenCursor.moveToNext();
447 | }
448 | return new MealMenu(
449 | mCursor.getString(mCursor.getColumnIndexOrThrow(KEY_MEALMENU_NAME)),
450 | mCursor.getLong(mCursor.getColumnIndexOrThrow(KEY_MEALMENU_START)),
451 | mCursor.getLong(mCursor.getColumnIndexOrThrow(KEY_MEALMENU_END)),
452 | mCursor.getLong(mCursor.getColumnIndexOrThrow(KEY_MEALMENU_MOD)),
453 | vens,
454 | mCursor.getString(mCursor.getColumnIndexOrThrow(KEY_MEALMENU_MEALNAME)));
455 | }
456 | }
457 |
--------------------------------------------------------------------------------