├── FoodOrderAPP.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cs442 │ │ └── yliu308 │ │ └── foodorderapp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cs442 │ │ │ └── yliu308 │ │ │ └── foodorderapp │ │ │ ├── DetailActivity.java │ │ │ ├── Item.java │ │ │ ├── ItemAdapter.java │ │ │ ├── MenuActivity.java │ │ │ ├── MenuCartFragment.java │ │ │ └── MenuListFragment.java │ └── res │ │ ├── drawable │ │ ├── barbecue.png │ │ ├── default_white.png │ │ ├── fries.png │ │ ├── lamb_soup.png │ │ ├── malatang.png │ │ ├── noodles.png │ │ ├── pho.png │ │ ├── pizza.png │ │ ├── spicy_fish.png │ │ ├── spicy_soup.png │ │ └── taco.png │ │ ├── layout │ │ ├── activity_detail.xml │ │ ├── activity_menu.xml │ │ ├── button.xml │ │ ├── fragment_menu_cart.xml │ │ ├── fragment_menu_item.xml │ │ └── fragment_menu_list.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── cs442 │ └── yliu308 │ └── foodorderapp │ └── ExampleUnitTest.java ├── build.gradle ├── build ├── android-profile │ ├── profile-2017-09-24-06-48-34-880.rawproto │ ├── profile-2017-09-24-06-48-47-845.rawproto │ ├── profile-2017-09-24-06-49-13-368.rawproto │ ├── profile-2017-09-24-06-49-54-061.rawproto │ ├── profile-2017-09-24-06-59-36-251.rawproto │ ├── profile-2017-09-24-07-02-28-425.rawproto │ ├── profile-2017-09-24-07-03-07-243.rawproto │ ├── profile-2017-09-24-07-03-39-413.rawproto │ ├── profile-2017-09-24-07-04-03-062.rawproto │ ├── profile-2017-09-24-07-04-43-206.rawproto │ ├── profile-2017-09-24-18-42-20-690.rawproto │ ├── profile-2017-09-24-18-54-37-620.rawproto │ ├── profile-2017-09-24-18-55-33-747.rawproto │ ├── profile-2017-09-24-18-55-52-230.rawproto │ ├── profile-2017-09-24-18-59-30-514.rawproto │ ├── profile-2017-09-24-19-06-29-868.rawproto │ ├── profile-2017-09-24-19-08-06-174.rawproto │ ├── profile-2017-09-24-19-17-46-955.rawproto │ ├── profile-2017-09-24-19-18-08-040.rawproto │ ├── profile-2017-09-24-19-18-27-453.rawproto │ ├── profile-2017-09-24-19-19-18-740.rawproto │ ├── profile-2017-09-24-19-23-06-650.rawproto │ ├── profile-2017-09-24-19-26-35-672.rawproto │ ├── profile-2017-09-24-19-29-28-925.rawproto │ ├── profile-2017-09-24-19-45-02-320.rawproto │ └── profile-2017-09-24-19-45-26-157.rawproto ├── generated │ └── mockable-android-26.jar └── intermediates │ └── dex-cache │ └── cache.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /FoodOrderAPP.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-Library-Management-System 2 | This is a library management system based on Android platform. All features implemented for two users, normal user and admin. 3 | 4 | General Description/ Feature 5 | 1. Two roles implemented in this app, user and admin. 6 | 2. Admin can add new books to the library (such as: book id, book name, book author, book category, book status(0:book unavailable, 1:book available), book sector(indicate the sector where this book located) and choose book cover for this book). 7 | 3. Admin can view all the books currently available in the library and manage books, edit book information and delete book. 8 | 4. Admin can manage user. Admin can view all the users currently in the library system, its id, password and type, also delete users in the system. 9 | 5. Admin will handle book return. Admin can use the return book button in main screen to initialize the camera and scan barcode to return this book back to library. 10 | 6. User can view all books in the library, click the book item to enter the detail page of this book. 11 | 7. User can rate this book by star rating bar and leave comment, also, user can issue this book by himself by clicking borrow button on detail page to initialize phone camera, scan book barcode and issue the book. 12 | 8. User can search the book he wants by typing in book id and click search button, the search result will show below. 13 | 9. First, under manage account function. User can view all the book he currently borrowed, book name, due date for return and pending current pending fine. 14 | 10. Second, under manage account function. User can change its account password by authenticate old password and twice-input of new password. If the old password does not match from database or two new password does not match, password change will fail. 15 | 16 | User Guide 17 | 18 | Prerequisite 19 | 1. When first enter the app, click into admin login page and click “create” below to create new admin account to proceed the following operations. Type in initial id and password, set user type as “admin”. 20 | 2. Second, you need to add books into database first to use and test the function. Book id should be the number of barcode. 21 | 22 | User 23 | 1. User can login with a given account, with initial id and password, and will required to change password the first time login. 24 | 2. In user main screen, there are three buttons, “Book list”, “Search” and “Manage account”. Under “Manage account activity”, there are two functions, “My book” and “Change password”. 25 | 3. In book list activity, user can view all the books currently in the library with its id, name, author and category. User can click the book he/she interested in and view the detail information about this book. 26 | 4. In the detail screen, user can rate this book using star rating bar and leave a comment below and submit. 27 | 5. User can borrow this book by clicking “Borrow” button on the detail page of the book, this’ll initiate the camera on the phone, user will have to scan the book barcode and click “Borrow”. By doing this, user have been issued the book successfully. 28 | 6. The book id is the number of barcode, use barcode number to generate barcode online and then use scan function. 29 | 7. In the Search function, user can search for a book by its id or name. The search result will show as a listview below, and user can click the search result and enter the screen of detail of the book and do the same operations as described in 4 and 5. 30 | 8. First, under manage account function. User can view all the books he/she borrowed, including book name, due date and pending fine of this book. 31 | 9. Second, under manage account function. User can change its own password, and will be required to enter old password, if old password is not matched from database or reentered new password does not match the new password, password changing will not success. 32 | 33 | Admin 34 | 1. Use admin account to login the admin main screen. 35 | 2. In admin main screen, there are four buttons, “Add book”, “Manage book”, “Manage user” and “Return book”. 36 | 3. Click “Add book” to add new books into bookDB.db database, book table. You need to add book ID(which will be the number of barcode), book name, book author, book category, book status(which marks if the book is available in the library or not, 0 marks unavailable, 1 marks available), book sector(in which location the book is, number from 1-9), and select a picture from gallery as book cover. Click “Submit” to save book information. 37 | 4. After adding book into table. In manage book screen, admin can see all books currently in the library, modify and delete basic information, book name, book author and book category. 38 | 5. In manage user screen, admin can add and delete user, both type user and admin, into user table. Normal user cannot create account, admin will create user account and assign account to individual user, user will have to change its password the first time he/she login. 39 | 6. In return book activity, admin will use camera to scan book barcode and choose “Return” after scan result shows, then the book will be returned. 40 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.1" 6 | 7 | aaptOptions { 8 | cruncherEnabled = false 9 | useNewCruncher = false 10 | } 11 | 12 | defaultConfig { 13 | applicationId "com.cs442.yliu308.foodorderapp" 14 | minSdkVersion 26 15 | targetSdkVersion 26 16 | versionCode 1 17 | versionName "1.0" 18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 31 | exclude group: 'com.android.support', module: 'support-annotations' 32 | }) 33 | compile 'com.android.support:appcompat-v7:26.+' 34 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 35 | testCompile 'junit:junit:4.12' 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/liuyi/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/cs442/yliu308/foodorderapp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.cs442.yliu308.foodorderapp", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/cs442/yliu308/foodorderapp/DetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.content.SharedPreferences; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.View.OnClickListener; 9 | import android.widget.Button; 10 | import android.widget.EditText; 11 | import android.widget.ImageView; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | public class DetailActivity extends Activity { 19 | public static int[] imgArr = { //pic src 20 | R.drawable.barbecue, 21 | R.drawable.fries, 22 | R.drawable.lamb_soup, 23 | R.drawable.malatang, 24 | R.drawable.noodles, 25 | R.drawable.pho, 26 | R.drawable.pizza, 27 | R.drawable.spicy_fish, 28 | R.drawable.spicy_soup, 29 | R.drawable.taco 30 | }; 31 | 32 | private SharedPreferences sp; 33 | 34 | private Intent intent; 35 | private OnClickListener clickHandler; 36 | 37 | private TextView mItemName; 38 | private ImageView mItemImg; 39 | private TextView mItemDescription; 40 | private EditText mItemOrdNum; 41 | private Button btnDetaiOrder; 42 | private Button btnDetailReset; 43 | 44 | private Item item; 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(R.layout.activity_detail); 50 | 51 | intent = getIntent(); 52 | 53 | intiDisplay(); 54 | 55 | mItemName.setText(item.strItemName); 56 | mItemImg.setImageResource(R.drawable.barbecue);//item.iItemImgId); 57 | mItemImg.setImageResource(intent.getIntExtra("iItemImgId", R.drawable.default_white)); 58 | 59 | btnDetaiOrder.setOnClickListener(clickHandler); 60 | btnDetailReset.setOnClickListener(clickHandler); 61 | 62 | mItemOrdNum.setText("1"); 63 | } 64 | 65 | private void intiDisplay(){ 66 | item = new Item(intent.getIntExtra("iItemSeqNum", 0), 67 | intent.getStringExtra("strItemName"), 68 | intent.getDoubleExtra("dItemPrice", 0), 69 | intent.getIntExtra("iItemOrdNumber", 0), 70 | intent.getIntExtra("iItemImgId", R.drawable.default_white)); 71 | 72 | mItemName = (TextView)findViewById(R.id.detail_item_name); 73 | mItemImg = (ImageView)findViewById(R.id.detail_item_img); 74 | mItemDescription = (TextView)findViewById(R.id.detail_item_description); 75 | mItemOrdNum = (EditText)findViewById(R.id.detail_item_ord_number); 76 | btnDetaiOrder = (Button)findViewById(R.id.detail_order); 77 | btnDetailReset = (Button)findViewById(R.id.detail_reset); 78 | 79 | clickHandler = new OnClickListener() { 80 | @Override 81 | public void onClick(View view) { 82 | switch (view.getId()){ 83 | case R.id.detail_reset: 84 | { 85 | resetOrderListDetail(); 86 | onBackPressed(); 87 | } 88 | break; 89 | case R.id.detail_order: 90 | { 91 | if(orderThisItemDetail(item, Integer.parseInt(mItemOrdNum.getText().toString()))) { 92 | onBackPressed(); 93 | } 94 | } 95 | break; 96 | default: 97 | break; 98 | } 99 | } 100 | }; 101 | } 102 | 103 | public void resetMenuList(){ 104 | MenuListFragment.itemList.clear(); 105 | for(int i = 0; i < 10; i++){ 106 | Item item = new Item(i + 1,"Food #" + Integer.toString(i + 1), 10.0 * (i + 1), 0, imgArr[i]); 107 | MenuListFragment.itemList.add(item); 108 | } 109 | saveToSharedPreference("itemList",MenuListFragment.itemList); 110 | } 111 | 112 | public void saveToSharedPreference(String key, List list){ 113 | int[] itemNum = new int[list.size()]; 114 | for(int i = 0; i < list.size(); i++){ 115 | itemNum[i] = list.get(i).iItemOrdNum; 116 | } 117 | StringBuffer sb = new StringBuffer(); 118 | for(int i : itemNum){ 119 | sb.append(i); 120 | sb.append('-'); 121 | } 122 | sp = this.getSharedPreferences("sharedPreference", MODE_PRIVATE); 123 | sp.edit().putString(key,sb.toString()).commit(); 124 | } 125 | 126 | private void resetOrderListDetail(){ 127 | //reset pane 1 128 | resetMenuList(); 129 | //reset pane 2 130 | MenuCartFragment.itemOrderedList.clear(); 131 | } 132 | 133 | private boolean orderThisItemDetail(Item item, int iItemNum){ 134 | // 135 | if(iItemNum > 10000){ 136 | Toast.makeText(this,"The number should be no more than 10000",Toast.LENGTH_SHORT).show(); 137 | return false; 138 | } 139 | //update pane 1 140 | for(Item tmpItem : MenuListFragment.itemList){ 141 | if(item.strItemName.equals(tmpItem.strItemName)){ 142 | int index = MenuListFragment.itemList.indexOf(tmpItem); 143 | MenuListFragment.itemList.remove(tmpItem); 144 | if(tmpItem.iItemOrdNum + iItemNum > 10000){ 145 | Toast.makeText(this,"The number should be no more than 10000",Toast.LENGTH_SHORT).show(); 146 | return false; 147 | } 148 | tmpItem.setItemOrdNum(tmpItem.iItemOrdNum + iItemNum); 149 | MenuListFragment.itemList.add(index,tmpItem); 150 | 151 | saveToSharedPreference("itemList",MenuListFragment.itemList); 152 | break; 153 | } 154 | } 155 | //update pane 2 156 | for(Item tmpItem : MenuCartFragment.itemOrderedList){ 157 | if(item.strItemName.equals(tmpItem.strItemName)){ 158 | MenuCartFragment.itemOrderedList.remove(tmpItem); 159 | if(tmpItem.iItemOrdNum + iItemNum > 10000){ 160 | Toast.makeText(this,"The number should be no more than 10000",Toast.LENGTH_SHORT).show(); 161 | return false; 162 | } 163 | tmpItem.setItemOrdNum(tmpItem.iItemOrdNum + iItemNum); 164 | MenuCartFragment.itemOrderedList.add(0,tmpItem); 165 | return true; 166 | } 167 | } 168 | item.setItemOrdNum(iItemNum); 169 | MenuCartFragment.itemOrderedList.add(0,item); 170 | return true; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /app/src/main/java/com/cs442/yliu308/foodorderapp/Item.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | /** 4 | * Created by liuyi on 9/23/17. 5 | */ 6 | 7 | public class Item { 8 | public int iItemSeqNum; 9 | public String strItemName; 10 | public double dItemPrice; 11 | public int iItemOrdNum; 12 | public int iItemImgId; 13 | 14 | public Item(int iItemSeqNum, String strItemName, double dItemPrice, int iItemOrdNum, int iItemImgId){ 15 | this.iItemSeqNum = iItemSeqNum; 16 | this.strItemName = strItemName; 17 | this.dItemPrice = dItemPrice; 18 | this.iItemOrdNum = iItemOrdNum; 19 | this.iItemImgId = iItemImgId; 20 | } 21 | 22 | public void setItemOrdNum(int iItemOrdNum){ 23 | this.iItemOrdNum = iItemOrdNum; 24 | } 25 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cs442/yliu308/foodorderapp/ItemAdapter.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.graphics.Color; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.TextView; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by liuyi on 9/24/17. 16 | */ 17 | 18 | public class ItemAdapter extends ArrayAdapter { 19 | private int resource; 20 | private boolean bIsMenuList; 21 | 22 | public ItemAdapter(Context context, int resource, List objects, boolean bIsMenuList) { 23 | super(context, resource, objects); 24 | // TODO Auto-generated constructor stub 25 | this.resource = resource;//resource为listView的每个子项的布局id 26 | this.bIsMenuList = bIsMenuList; 27 | } 28 | 29 | @Override 30 | public View getView(int position, View view, ViewGroup parent) { 31 | // TODO Auto-generated method stub 32 | 33 | final Item item = getItem(position); 34 | ViewHolder viewHolder; 35 | if(view == null){ 36 | view = LayoutInflater.from(getContext()).inflate(resource, null); 37 | viewHolder = new ViewHolder(); 38 | viewHolder.itemSeqNum = (TextView) view.findViewById(R.id.item_seq_number); 39 | viewHolder.itemName =(TextView) view.findViewById(R.id.item_name); 40 | viewHolder.itemPrice =(TextView) view.findViewById(R.id.item_price); 41 | viewHolder.itemOrdNum = (TextView) view.findViewById(R.id.item_ord_number); 42 | view.setTag(viewHolder); 43 | }else { 44 | viewHolder = (ViewHolder) view.getTag(); 45 | } 46 | viewHolder.itemSeqNum.setText(Integer.toString(item.iItemSeqNum)); 47 | viewHolder.itemName.setText(item.strItemName); 48 | viewHolder.itemPrice.setText(Double.toString(item.dItemPrice)); 49 | viewHolder.itemOrdNum.setText(Integer.toString(item.iItemOrdNum)); 50 | 51 | if(bIsMenuList){ 52 | if(0 != item.iItemOrdNum){ 53 | viewHolder.itemOrdNum.setBackgroundColor(Color.parseColor("#FF99FF")); 54 | } 55 | else{ 56 | viewHolder.itemOrdNum.setBackgroundColor(Color.parseColor("#FFFFFF")); 57 | } 58 | } 59 | 60 | return view; 61 | 62 | } 63 | class ViewHolder{ 64 | TextView itemSeqNum; 65 | TextView itemName; 66 | TextView itemPrice; 67 | TextView itemOrdNum; 68 | } 69 | } -------------------------------------------------------------------------------- /app/src/main/java/com/cs442/yliu308/foodorderapp/MenuActivity.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | import android.app.Fragment; 4 | import android.app.FragmentManager; 5 | import android.app.FragmentTransaction; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.view.Window; 10 | 11 | public class MenuActivity extends FragmentActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | requestWindowFeature(Window.FEATURE_NO_TITLE); 17 | setContentView(R.layout.activity_menu); 18 | 19 | FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); 20 | fragmentTransaction.add(R.id.id_fragment_list, new MenuListFragment()); 21 | fragmentTransaction.commit(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/cs442/yliu308/foodorderapp/MenuCartFragment.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | import android.app.Fragment; 4 | import android.app.FragmentTransaction; 5 | import android.content.SharedPreferences; 6 | import android.view.View; 7 | import android.view.View.OnClickListener; 8 | import android.os.Bundle; 9 | import android.view.LayoutInflater; 10 | import android.view.ViewGroup; 11 | import android.widget.Button; 12 | import android.widget.ListView; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | import static android.content.Context.MODE_PRIVATE; 20 | 21 | /** 22 | * Created by liuyi on 9/23/17. 23 | */ 24 | 25 | public class MenuCartFragment extends Fragment{ 26 | SharedPreferences sp; 27 | 28 | private int iTotalValue; 29 | private OnClickListener clickHandler; 30 | 31 | private ItemAdapter mCartAdapter = null; 32 | public static List itemOrderedList; 33 | private TextView cartTotalPrice; 34 | private ListView cartListView; 35 | private Button btnCartOrder; 36 | private Button btnCartReset; 37 | 38 | 39 | @Override 40 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 41 | Bundle savedInstanceState) { 42 | sp = this.getActivity().getSharedPreferences("sharedPreference", MODE_PRIVATE); 43 | 44 | initOrderedList(); 45 | View v = inflater.inflate(R.layout.fragment_menu_cart,null); 46 | 47 | cartTotalPrice = (TextView) v.findViewById(R.id.cart_total_price); 48 | cartTotalPrice.setText(Integer.toString(iTotalValue)); 49 | 50 | cartListView = (ListView) v.findViewById(R.id.cart_list); 51 | mCartAdapter = new ItemAdapter(getActivity(), R.layout.fragment_menu_item, itemOrderedList, false); 52 | cartListView.setAdapter(mCartAdapter); 53 | 54 | intiDisplay(v); 55 | btnCartOrder.setOnClickListener(clickHandler); 56 | btnCartReset.setOnClickListener(clickHandler); 57 | 58 | return v; 59 | } 60 | 61 | public void initOrderedList(){ 62 | itemOrderedList = new ArrayList(); 63 | 64 | int[] tmpArray = parseFromSharePreference(sp); 65 | if(null != tmpArray) { 66 | for (int i = 0; i < 10; i++) { 67 | if(0 != tmpArray[i]){ 68 | Item item = new Item(i + 1, "Item #" + Integer.toString(i + 1), 10.0 * (i + 1), tmpArray[i], DetailActivity.imgArr[i]); 69 | itemOrderedList.add(item); 70 | } 71 | } 72 | } 73 | //for(Item item : MenuListFragment.itemList){ 74 | // if(0 != item.iItemOrdNum){ 75 | // itemOrderedList.add(item); 76 | // } 77 | //} 78 | getTotalValue(); 79 | } 80 | 81 | public void getTotalValue(){ 82 | iTotalValue = 0; 83 | for(Item item : itemOrderedList){ 84 | iTotalValue += item.iItemOrdNum * item.dItemPrice; 85 | } 86 | } 87 | 88 | private void intiDisplay(View v){ 89 | btnCartOrder = (Button)v.findViewById(R.id.cart_order); 90 | btnCartReset = (Button)v.findViewById(R.id.cart_reset); 91 | 92 | clickHandler = new OnClickListener() { 93 | @Override 94 | public void onClick(View view) { 95 | switch (view.getId()){ 96 | case R.id.cart_reset: 97 | { 98 | resetOrderListCart(); 99 | } 100 | break; 101 | case R.id.cart_order: 102 | { 103 | orderThisItemCart(); 104 | } 105 | break; 106 | default: 107 | break; 108 | } 109 | } 110 | }; 111 | } 112 | 113 | private void resetOrderListCart(){ 114 | MenuListFragment.itemList.clear(); 115 | for (int i = 0; i < 10; i++) { 116 | Item item = new Item(i + 1, "Item #" + Integer.toString(i + 1), 10.0 * (i + 1), 0, DetailActivity.imgArr[i]); 117 | MenuListFragment.itemList.add(item); 118 | } 119 | saveToSharedPreference("itemList",MenuListFragment.itemList); 120 | 121 | 122 | FragmentTransaction fragmentTransaction = getActivity().getFragmentManager().beginTransaction(); 123 | fragmentTransaction.replace(R.id.id_fragment_list, new MenuListFragment()); 124 | fragmentTransaction.commit(); 125 | 126 | itemOrderedList.clear(); 127 | mCartAdapter.notifyDataSetChanged(); 128 | getTotalValue(); 129 | cartTotalPrice.setText(Integer.toString(iTotalValue)); 130 | } 131 | 132 | public void saveToSharedPreference(String key,List list){ 133 | int[] itemNum = new int[list.size()]; 134 | for(int i = 0; i < list.size(); i++){ 135 | itemNum[i] = list.get(i).iItemOrdNum; 136 | } 137 | 138 | StringBuffer sb = new StringBuffer(); 139 | for(int i : itemNum){ 140 | sb.append(i); 141 | sb.append('-'); 142 | } 143 | 144 | //sp = this.getActivity().getSharedPreferences("sharedPreference", MODE_PRIVATE); 145 | sp.edit().putString(key,sb.toString()).commit(); 146 | } 147 | 148 | public int[] parseFromSharePreference(SharedPreferences sp){ 149 | String strTmp = sp.getString("itemList", null); 150 | if(null == strTmp)return null; 151 | 152 | String[] tmpStrArray = strTmp.split("-"); 153 | 154 | int[] array = new int[tmpStrArray.length]; 155 | for(int i = 0; i < array.length; i++){ 156 | array[i] = Integer.parseInt(tmpStrArray[i]); 157 | } 158 | return array; 159 | } 160 | 161 | private void resetToInit(){ 162 | resetOrderListCart(); 163 | } 164 | 165 | private void orderThisItemCart(){ 166 | Toast.makeText(getActivity(), 167 | "Your order has been placed, total price is $" + Integer.toString(iTotalValue), 168 | Toast.LENGTH_SHORT).show(); 169 | resetToInit(); 170 | } 171 | 172 | @Override 173 | public void onResume(){ 174 | super.onResume(); 175 | mCartAdapter.notifyDataSetChanged(); 176 | 177 | getTotalValue(); 178 | cartTotalPrice.setText(Integer.toString(iTotalValue)); 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /app/src/main/java/com/cs442/yliu308/foodorderapp/MenuListFragment.java: -------------------------------------------------------------------------------- 1 | package com.cs442.yliu308.foodorderapp; 2 | 3 | /** 4 | * Created by liuyi on 9/23/17. 5 | */ 6 | 7 | import java.io.Serializable; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | import android.app.FragmentManager; 13 | import android.content.Intent; 14 | import android.app.Fragment; 15 | //import android.support.v4.app.Fragment;//不知为什么要加这个? 16 | import android.content.SharedPreferences; 17 | import android.content.SharedPreferences.Editor; 18 | import android.os.Bundle; 19 | import android.view.LayoutInflater; 20 | import android.view.View; 21 | import android.view.ViewGroup; 22 | import android.widget.AdapterView; 23 | import android.widget.AdapterView.OnItemClickListener; 24 | import android.widget.ListView; 25 | 26 | import static android.content.Context.MODE_PRIVATE; 27 | 28 | public class MenuListFragment extends Fragment { 29 | private SharedPreferences sp; 30 | 31 | private ItemAdapter mListMenuAdapter = null; 32 | public static List itemList; 33 | private ListView menuListView; 34 | 35 | 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | } 40 | 41 | @Override 42 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 43 | Bundle savedInstanceState) { 44 | sp = this.getActivity().getSharedPreferences("sharedPreference", MODE_PRIVATE); 45 | 46 | initItemList(); 47 | 48 | View v = inflater.inflate(R.layout.fragment_menu_list,null); 49 | 50 | menuListView = (ListView) v.findViewById(R.id.menu_list); 51 | mListMenuAdapter = new ItemAdapter(getActivity(), R.layout.fragment_menu_item, itemList, true); 52 | menuListView.setAdapter(mListMenuAdapter); 53 | 54 | menuListView.setOnItemClickListener(new OnItemClickListener(){ 55 | public void onItemClick (AdapterView arg0, View arg1, int arg2, long arg3){ 56 | Item item = mListMenuAdapter.getItem(arg2); 57 | 58 | if(null == item) return; 59 | 60 | Intent intent = new Intent(getActivity(), DetailActivity.class); 61 | intent.putExtra("iItemSeqNum", item.iItemSeqNum); 62 | intent.putExtra("strItemName", item.strItemName); 63 | intent.putExtra("dItemPrice", item.dItemPrice); 64 | intent.putExtra("iItemOrdNumber", item.iItemOrdNum); 65 | intent.putExtra("iItemImgId", item.iItemImgId); 66 | 67 | //intent.putExtra("itemOrderedList", (Serializable)MenuCartFragment.itemOrderedList); 68 | 69 | startActivity(intent); 70 | } 71 | 72 | }); 73 | 74 | return v; 75 | } 76 | 77 | public void initItemList(){ 78 | itemList = new ArrayList(); 79 | int[] tmpArray = parseFromSharePreference(sp); 80 | if(null != tmpArray) { 81 | for (int i = 0; i < 10; i++) { 82 | Item item = new Item(i + 1, "Food #" + Integer.toString(i + 1), 10.0 * (i + 1), tmpArray[i], DetailActivity.imgArr[i]); 83 | itemList.add(item); 84 | } 85 | } else { 86 | for (int i = 0; i < 10; i++) { 87 | Item item = new Item(i + 1, "Food #" + Integer.toString(i + 1), 10.0 * (i + 1), 0, DetailActivity.imgArr[i]); 88 | itemList.add(item); 89 | } 90 | saveToSharedPreference(itemList); 91 | } 92 | //item = new Item(2,"Item 2", 10.0, 0); 93 | //itemList.add(item); 94 | } 95 | 96 | @Override 97 | public void onResume(){ 98 | super.onResume(); 99 | mListMenuAdapter.notifyDataSetChanged(); 100 | saveToSharedPreference(itemList); 101 | } 102 | 103 | public int[] parseFromSharePreference(SharedPreferences sp){ 104 | String strTmp = sp.getString("itemList", null); 105 | if(null == strTmp)return null; 106 | 107 | String[] tmpStrArray = strTmp.split("-"); 108 | 109 | int[] array = new int[tmpStrArray.length]; 110 | for(int i = 0; i < array.length; i++){ 111 | array[i] = Integer.parseInt(tmpStrArray[i]); 112 | } 113 | return array; 114 | } 115 | 116 | public void saveToSharedPreference(List itemList){ 117 | int[] itemNum = new int[itemList.size()]; 118 | for(int i = 0; i < itemList.size(); i++){ 119 | itemNum[i] = itemList.get(i).iItemOrdNum; 120 | } 121 | 122 | StringBuffer sb = new StringBuffer(); 123 | for(int i : itemNum){ 124 | sb.append(i); 125 | sb.append('-'); 126 | } 127 | 128 | //sp = this.getActivity().getSharedPreferences("sharedPreference", MODE_PRIVATE); 129 | sp.edit().putString("itemList",sb.toString()).commit(); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/barbecue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/barbecue.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/default_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/default_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/fries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/fries.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/lamb_soup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/lamb_soup.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/malatang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/malatang.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/noodles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/noodles.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/pho.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/pho.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/pizza.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/pizza.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/spicy_fish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/spicy_fish.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/spicy_soup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/spicy_soup.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/taco.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiiiiil-fx717/Android-Library-Management-System/68afa42673a6c8647dab6e3196560264a1307afb/app/src/main/res/drawable/taco.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 22 | 23 | 28 | 29 | 36 | 37 | 42 |