Branch_QYJ
李雨轩 2 years ago
parent 213b2fecce
commit 1f681c800c

@ -0,0 +1,2 @@
#Fri Oct 21 23:04:16 GMT+08:00 2022
gradle.version=6.4.1

@ -0,0 +1,17 @@
### 简介
- 2018年天津市大学生创新训练项目—“基于Android的无线点餐系统的设计与研究”。本课题旨在研究并设计一基于Android的无线点餐系统系统能实现顾客就餐全过程的自动化管理。
- 对于系统功能设计:主要包括功能框架和设计模块,其中功能框架主要包括登录模块、点餐模块、结账模块和餐台管理;功能模块设计分为服务器和客户端,具体包括登录功能、用户管理、菜谱管理、系统管理。各模块之间互相依赖,形成一个完整的无线点餐系统手机(平板)客户端与服务器的交互设计系统。
### 研究内容
- A、确立物理架构Android系统客户端通过无线网络访问后台Web服务器如果需要数据访问则访问后台数据库服务器
- B、确立技术选型Android客户端选用JAVA技术网络通信选用Apache Http协议而中间Web服务器采用Servlet响应可客户请求。后台数据库使用JDBC来访问数据库Android客户端部分数据的存储则采用SQLite数据库
- C、进行系统规划和需求分析通过数据流程图、实体属性图分析数据间的关系设计并创建一个合理可靠的数据库
- D、实现客户端功能设计基于Android开发平台前端客户端功能模块大概分为锁定桌号、桌号查询、菜品查询、加菜功能、退菜功能、结算功能
- E、实现服务器端功能设计后端服务器功能模块大概分为用户评价管理、桌号管理、菜品管理、订单管理、信息管理
- F、后端服务器采用Tomcat服务器利用JDBC访问后台数据库Servlet响应HttpRequest请求并返回响应结果在此过程中采用MVC+DAO的设计模式及分层的开发思想。
### 系统页面
![输入图片说明](https://images.gitee.com/uploads/images/2019/0516/160858_7c04667b_2108662.png "2.png")

@ -0,0 +1 @@
/build

@ -0,0 +1,40 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.sbw.atrue.Order"
minSdkVersion 16
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation files('libs\\mysql-connector-java-5.1.38.jar')
implementation files('libs\\mysql-connector-java-5.1.38.jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-beta01'
implementation 'com.google.android.material:material:1.2.0-alpha06'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha03'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'org.litepal.android:core:1.3.2'
/*implementation 'org.litepal.guolindev:core:3.2.3'*/
implementation 'com.yanzhenjie.nohttp:nohttp:1.1.4'
implementation 'com.google.code.gson:gson:2.8.6'
}

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

Binary file not shown.

@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

@ -0,0 +1,26 @@
package com.sbw.atrue.Order;
import android.content.Context;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {//做测试的
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.sbw.atrue.toolbartest", appContext.getPackageName());
}
}

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<!--基本结构-->
<!--
<manifest>
<application
android:name="com.example.MyApplication"
...
>
...
</application>
</manifest>
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sbw.atrue.Order">
<!--获取联网许可-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:name=".Activity.MyApplication"
android:allowBackup="true"
android:icon="@drawable/fengmian"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- 将登录活动设置为程序的主活动和启动项 -->
<activity
android:name=".Activity.LoginActivity"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 定义了使用ToolBar控件的布局的标题为food -->
<activity
android:name=".Activity.OrderActivity"
android:label="潮汕牛肉"></activity>
<activity
android:name=".Activity.FoodActivity"
android:theme="@style/foodActivityTheme"></activity>
<!--声明其他各项活动-->
<activity android:name=".Activity.RegisterActivity" />
<activity android:name=".Activity.ShoppingActivity" />
<activity android:name=".Activity.InputActivity" />
<activity android:name=".Activity.SuccessActivity" />
<activity android:name=".Activity.ReadOrderActivity" />
<activity android:name=".Activity.MyMoneyActivity" />
<activity android:name=".Activity.SettingActivity" />
</application>
</manifest>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<litepal>
<!--注释快捷键 ctrl shift /-->
<!--dbname 标签用来指定数据库的名称-->
<dbname value="order" />
<!--version 标签是指定数据库版本,更新表的时候需要增大该值-->
<version value="8" />
<!--list 标签是用来指定映射模型,即实体类的路径用 mapping标签放进来-->
<list>
<mapping class="com.sbw.atrue.Order.Entity.ProductOrder">
</mapping>
<mapping class="com.sbw.atrue.Order.Entity.Order">
</mapping>
</list>
</litepal>

@ -0,0 +1,61 @@
package com.sbw.atrue.Order.Activity;
import android.util.Log;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connection {
private static final String TAG = "mysql11111";
java.sql.Connection conn=null;
public static void mymysql(){
final Thread thread =new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.interrupted()) {
try {
Thread.sleep(100); // 每隔0.1秒尝试连接
} catch (InterruptedException e) {
Log.e(TAG, e.toString());
}
// 1.加载JDBC驱动
try {
Class.forName("com.mysql.jdbc.Driver");
Log.v(TAG, "加载JDBC驱动成功");
} catch (ClassNotFoundException e) {
Log.e(TAG, "加载JDBC驱动失败");
return;
}
// 2.设置好IP/端口/数据库名/用户名/密码等必要的连接信息
String ip = "10.11.169.231";
int port = 3306;
String dbName = "mysql";
String url = "jdbc:mysql://" + ip + ":" + port
+ "/" + dbName+"?useUnicode=true&characterEncoding=utf-8&useSSL=false";
// 构建连接mysql的字符串
String user = "root";
String password = "123456";
// 3.连接JDBC
try {
java.sql.Connection conn = DriverManager.getConnection(url, user, password);
Log.d(TAG, "数据库连接成功");
conn.close();
return;
}
catch (SQLException e) {
Log.e(TAG, e.getMessage());
}
}
}
});
thread.start();
}
}

@ -0,0 +1,67 @@
package com.sbw.atrue.Order.Activity;
import android.content.Intent;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.sbw.atrue.Order.Entity.Food;
import com.sbw.atrue.Order.R;
/**
* ClassName: FoodActivity <br>
* description: <br>
* author: -13042299081 <br>
* Date: 2019/2/18 20:59
*/
public class FoodActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food); // 这里连到界面
//获取各布局控件的实例
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
ImageView foodImageView = (ImageView) findViewById(R.id.food_image_view);
TextView foodContentText = (TextView) findViewById(R.id.food_content_text);
//从上一级活动获取用户点击的菜品的对象
Intent intent = getIntent();
Food food=(Food)intent.getSerializableExtra("Food_Choose");
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//显示标题栏最左侧的系统默认自带的返回导航键,用于返回上一级活动
actionBar.setDisplayHomeAsUpEnabled(true);
}
//设置菜品的名称、图片
collapsingToolbar.setTitle(food.getName());
Glide.with(this).load(food.getImageId()).into(foodImageView);
//设置菜品详情介绍
foodContentText.setText(food.getDescription());
}
/**
*
* @param item
* @return
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//R.id.home是系统默认的ActionBar标题栏最左侧按键HomeAsUp键的Id
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

@ -0,0 +1,159 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Entity.Product;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.MyListener;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONException;
import org.json.JSONObject;
//订单确认
public class InputActivity extends Activity {
private EditText etname; //姓名输入框
private EditText etPhone; //手机号输入框
private EditText ettable; //桌号输入框
private Button btnInputCompleted; //输入完成按钮
private ArrayList<Product> selectedProducts = new ArrayList<Product>(); //被选择的的商品数据
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input);
initViews(); //初始化页面控件
initEvents(); //初始化控件事件
}
//初始化控件事件
private void initEvents() {
Intent otherIntent = getIntent(); //获取信息输入界面传来的意图
selectedProducts = otherIntent.getParcelableArrayListExtra("selectedProducts"); //从意图中获取被选择的的商品数据
etPhone.setSelection(etPhone.getText().length()); //将光标移动到电话输入框最后面
etname.setText(ShareUtils.getString(InputActivity.this, "user_true_name", ""));//从本地读取客户姓名
etPhone.setText(ShareUtils.getString(InputActivity.this, "user_true_phone", ""));//从本地读取客户电话
//给输入完成按钮设置点击事件
btnInputCompleted.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String address = ettable.getText().toString(); //获取输入框中的桌号
final String name = etname.getText().toString(); //获取输入框中的客户姓名
final String phone = etPhone.getText().toString(); //获取输入框中的手机号
if (!TextUtils.isEmpty(phone)
&& !TextUtils.isEmpty(address)
&& phone.length() >= 7) { //手机号和地址不为空且手机号大于等于7位
addOrder(selectedProducts, name, phone, address, new MyListener<String>() {
@Override
public void onSuccess(String data) {
Intent intent = new Intent(getApplicationContext(), SuccessActivity.class); //新建意图
intent.putParcelableArrayListExtra("selectedProducts", selectedProducts); //给意图添加被选择的的商品数据
intent.putExtra("name", name); //给意图设置客户姓名
intent.putExtra("phone", phone); //给意图设置联系电话
intent.putExtra("orderId", data); //给意图设置用餐桌号
intent.putExtra("table", address); //给意图设置用餐桌号
startActivity(intent); //跳转到购买成功页面
ShoppingActivity.mInstance.finish(); //结束购物界面
InputActivity.this.finish(); //结束信息输入界面
}
});
} else { //输入手机号或地址不正确
//Toast.makeText(InputActivity.this, "手机号或地址输入不正确手机号至少7位", Toast.LENGTH_SHORT).show();
showDialog("手机号或地址输入不正确手机号至少7位!");
}
}
});
}
private void addOrder(List<Product> productList, String name, String phone, String address, final MyListener<String> literer) {
String postUrl = HttpUtil.HOST + "api/order/addOrder";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("userId", ShareUtils.getInt(getApplicationContext(), "user_id", 0));
request.add("name", name);
request.add("phone", phone);
request.add("tableId", address);
request.add("productList", new Gson().toJson(productList));
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
literer.onSuccess(res.getString("data"));
} else {
showDialog(res.getString("msg"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
//初始化页面控件
private void initViews() {
etname = (EditText) findViewById(R.id.et_name);
etPhone = (EditText) findViewById(R.id.et_phone);
ettable = (EditText) findViewById(R.id.et_table);
btnInputCompleted = (Button) findViewById(R.id.btn_input_completed);
}
/**
* 便
*
* @param msg
*/
private void showDialog(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
}

@ -0,0 +1,169 @@
package com.sbw.atrue.Order.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map;
/**
* ClassName: LoginActivity <br>
* description: <br>
* author: -13042299081 <br>
* Date: 2019/2/18 14:54
*/
public class LoginActivity extends AppCompatActivity {
private EditText accountEdit;
private EditText passwordEdit;
private Button btnlogin;
private Button btnRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initViews(); //初始化页面控件
initEvents(); //初始化控件事件
}
//初始化页面控件
private void initViews() {
accountEdit = (EditText) findViewById(R.id.account);
passwordEdit = (EditText) findViewById(R.id.password);
btnlogin = (Button) findViewById(R.id.login);
btnRegister = (Button) findViewById(R.id.register);
}
//初始化控件事件
private void initEvents() {
//给登录按钮设置点击事件
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String account = accountEdit.getText().toString();
String password = passwordEdit.getText().toString();
//判断用户名和密码是否正确
if (!TextUtils.isEmpty(account) && !TextUtils.isEmpty(password)) { //用户名和密码都不为空
//尝试登陆
tryToLogin(account, password);
} else {
showDialog("用户名或密码不能为空!");
}
}
});
//给注册按钮设置点击事件
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//跳转到注册界面
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
LoginActivity.this.finish(); //结束当前界面
}
});
}
/**
*
*
* @param username
* @param password
*/
private void tryToLogin(String username, String password) {
String postUrl = HttpUtil.HOST + "api/user/login";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("username", username);
request.add("password", password);
//直接连本地数据库呢?直接从本地数据库获取信息
/**/queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
JSONObject data = res.getJSONObject("data");
//给用户的钱包余额设定金额
ShareUtils.putInt(getApplicationContext(), "money", data.getInt("money"));
ShareUtils.putInt(getApplicationContext(), "user_id", data.getInt("id"));
ShareUtils.putString(getApplicationContext(), "user_true_name", data.getString("nickname"));
ShareUtils.putString(getApplicationContext(), "user_true_phone", data.getString("phone"));
ShareUtils.putString(getApplicationContext(), "user_true_mail", data.getString("email"));
//登录成功,跳转到菜单展示的主页面
Intent intent = new Intent(LoginActivity.this, OrderActivity.class);
startActivity(intent);
finish();
} else {
showDialog(res.getString("msg"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
//登录成功,跳转到菜单展示的主页面
Intent intent = new Intent(LoginActivity.this, OrderActivity.class);
startActivity(intent);
}
@Override
public void onFinish(int what) {
//登录成功,跳转到菜单展示的主页面
Intent intent = new Intent(LoginActivity.this, OrderActivity.class);
startActivity(intent);
}
});
}
/**
* 便
*
* @param msg
*/
private void showDialog(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
}

@ -0,0 +1,29 @@
package com.sbw.atrue.Order.Activity;
import com.yanzhenjie.nohttp.InitializationConfig;
import com.yanzhenjie.nohttp.NoHttp;
import org.litepal.LitePalApplication;
import org.litepal.util.Const;
public class MyApplication extends LitePalApplication {
@Override
public void onCreate() {//可理解为我们之前的主函数
super.onCreate();
Connection.mymysql();
InitializationConfig config = InitializationConfig.newBuilder(this)
.connectionTimeout(30 * 1000)
.readTimeout(30 * 1000)
.retry(10)
.build();
NoHttp.initialize(config);
}
}
/*public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
LitePal.initialize(this);
}
...
}*/

@ -0,0 +1,102 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONException;
import org.json.JSONObject;
/**
* FileName: MyMoneyActivity <br>
* Description: <br>
* Author: -13042299081 <br>
* Date: 2019/4/12 16:51
*/
public class MyMoneyActivity extends Activity {
//账户余额显示文字控件
private TextView myMoney;
private Button btnSure;
private Button btnsaveMoney;
private int nowMoney;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_money);
myMoney = (TextView) findViewById(R.id.my_money);
btnSure = (Button) findViewById(R.id.btn_Sure);
btnsaveMoney = (Button) findViewById(R.id.btn_SaveMoney);
//读取本地文件中的账户余额
nowMoney = ShareUtils.getInt(MyMoneyActivity.this, "money", 1);
myMoney.setText(String.valueOf(nowMoney));
//给确定按钮设置点击事件
btnSure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//结束当前界面,将自动返回系统上一级未被销毁的活动!比如结账活动或者主页面活动
MyMoneyActivity.this.finish();
}
});
//给充值按钮设置点击事件
btnsaveMoney.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String postUrl = HttpUtil.HOST + "api/user/addMoney";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("userId", ShareUtils.getInt(getApplicationContext(), "user_id", 0));
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
int data = res.getInt("data");
ShareUtils.putInt(MyMoneyActivity.this, "money", data);
myMoney.setText(String.valueOf(data));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
});
}
}

@ -0,0 +1,5 @@
package com.sbw.atrue.Order.Activity;
//健康结算界面
public class NutritionActivity {
}

@ -0,0 +1,398 @@
package com.sbw.atrue.Order.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.sbw.atrue.Order.Entity.Food;
import com.sbw.atrue.Order.Entity.Product;
import com.sbw.atrue.Order.Util.FoodAdapter;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.FoodFctory;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.MyListener;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* ClassName: OrderActivity <br>
* description: <br>
* author: -13042299081 <br>
* Date: 2019/2/18 21:03
*/
public class OrderActivity extends AppCompatActivity {
//从生产类中加载系统存储的菜单列表
// private Food[] foods = FoodFctory.Beef;
private List<Food> foodList = new ArrayList<>();
private DrawerLayout mDrawerLayout;
private FoodAdapter adapter;
private SwipeRefreshLayout swipeRefresh;
private int first = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
//导入Toolbar的自定义布局形式
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//导入滑动菜单
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
//获得ActionBar的实例虽然此ActionBar具体实现是由ToolBar来完成的
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//将ActionBar的导航按钮HomeAsUp显示出来Toolbar标题栏最左侧的按钮图标默认为箭头含义为返回上一级活动
actionBar.setDisplayHomeAsUpEnabled(true);
//更改导航按钮HomeAsUp的默认图标箭头改为导航键
//actionBar.setHomeAsUpIndicator(R.drawable.ic_comment);
}
//设置滑动菜单的按钮点击事件
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
//点击任意菜单选项,则将滑动菜单关闭
// mDrawerLayout.closeDrawers();
menuItem.setChecked(true);
switch (menuItem.getItemId()) {
case R.id.nav_Order:
//跳转到订单界面
orderDetail(new MyListener<JSONArray>() {
@Override
public void onSuccess(JSONArray array) throws JSONException {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length(); i++) {
sb.append(getDataString(array.getJSONObject(i)));
}
Log.e("demo", "onSuccess: "+sb.toString() );
Intent intent = new Intent(OrderActivity.this, ReadOrderActivity.class);
intent.putExtra("content", sb.toString());
startActivity(intent);
}
});
break;
case R.id.nav_money:
//跳转到钱包界面
startActivity(new Intent(OrderActivity.this, MyMoneyActivity.class));
break;
case R.id.nav_setting:
//跳转到钱包界面
startActivity(new Intent(OrderActivity.this, SettingActivity.class));
break;
case R.id.nav_logout:
//跳转到登陆界面
startActivity(new Intent(OrderActivity.this, LoginActivity.class));
//结束当前界面
OrderActivity.this.finish();
break;
default:
break;
}
return true;
}
});
//悬浮按键的设置
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//跳转到登陆界面
startActivity(new Intent(OrderActivity.this, ShoppingActivity.class));
}
});
//显示菜单的控件逻辑
initFruits();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(layoutManager);
adapter = new FoodAdapter(foodList);
recyclerView.setAdapter(adapter);
//刷新菜单的控件逻辑
swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);
swipeRefresh.setColorSchemeResources(R.color.colorPrimary);
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshfoods();
}
});
}
/**
*
*/
private void initDatas(String demo) {
}
private String getDataString(JSONObject data) throws JSONException {
double totalPrice = 0; //购买商品总价
ArrayList<Product> selectedProducts = new ArrayList<>();
JSONArray array = data.getJSONArray("selectedProducts");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
int id = 0;
String name = jsonObject.getString("foodName");
double price = jsonObject.getDouble("price");
// JSONObject product=jsonObject.getJSONObject("product");
// String picture = product.getString("picture");
int sale = 1;
String shopName = "";
String detail = "";
boolean isShowSubBtn = true;
Product product = new Product(id, name, price, "", sale, shopName, detail, isShowSubBtn);
product.setSelctCount(jsonObject.getInt("num"));
selectedProducts.add(product);
}
String name = data.getString("userName");
String phone = data.getString("phone"); //从意图获取手机号
String tableId = data.getString("tableId"); //从意图获取用餐桌号
StringBuilder orderResult = new StringBuilder(); //新建订单结果信息
orderResult.append("\t\t\t\t\t\t\t订单信息如下\n\n");//添加文本内容
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
for (int i = 0; i < selectedProducts.size(); i++) { //遍历商品列表并往文本写入商品信息
Product product = selectedProducts.get(i);
if (product.getName().length() == 2) {
orderResult.append(product.getName() + "\t\t\t\t\t\t\t " + product.getSelectedCount() + " \t\t\t\t\t" + product.getPrice() * product.getSelectedCount() + "\n");
} else {
orderResult.append(product.getName() + "\t\t\t\t\t" + product.getSelectedCount() + "\t\t\t\t\t" + product.getPrice() * product.getSelectedCount() + "\n");
}
totalPrice += product.getPrice() * product.getSelectedCount(); //设置商品总价
}
orderResult.append("*************************");
orderResult.append("\n共计" + totalPrice + "元\n\n");
orderResult.append("\t\t\t\t\t\t\t您的信息如下\n");
orderResult.append("*************************\n");
orderResult.append("姓名:" + name + "\n");
orderResult.append("电话:" + phone + "\n");
orderResult.append("桌号:" + tableId + "\n");
//获取当前系统时间(记录下单时间)
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
String nowTime = simpleDateFormat.format(date);
orderResult.append("时间:" + nowTime + "\n");
//将订单结果信息设置到订单信息显示文字控件
return orderResult.toString();
}
private void orderDetail(final MyListener<JSONArray> literer) {
String postUrl = HttpUtil.HOST + "api/order/list";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("userId", ShareUtils.getInt(getApplicationContext(), "user_id", 0));
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
literer.onSuccess(res.getJSONArray("data"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
/**
*
*/
private void refreshfoods() {
new Thread(new Runnable() {
@Override
public void run() {
try {
//为了避免程序刷新太快先让线程睡眠2秒
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//从子线程切回到主线程从而可以更改UI
runOnUiThread(new Runnable() {
@Override
public void run() {
//向菜单中增加新菜
if (first == 0) {
Food WanZi = new Food("牛肉丸", "R.drawable.wanzi", "牛肉丸是潮汕美食啊!!!");
foodList.add(WanZi);
first = 1;
}
//通知适配器数据发生了变化用于RecycleView自动更新显示项
adapter.notifyDataSetChanged();
//刷新结束,将刷新进度条隐藏
swipeRefresh.setRefreshing(false);
//显示更新结果的弹框通知,告知用户更新情况
AlertDialog.Builder builder = new AlertDialog.Builder(OrderActivity.this);
builder.setMessage("菜单更新成功啦~")
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
}).start();
}
/**
* Food
*/
private void initFruits() {
foodList.clear();
String postUrl = HttpUtil.HOST + "api/food/list";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
JSONArray array = res.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject data = array.getJSONObject(i);
Food food = new Food(data.getString("name"), data.getString("imageId"), data.getString("description"));
foodList.add(food);
}
adapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
/**
* toolbar.xml
*
* @param menu
* @return
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.toolbar, menu);
return true;
}
/**
* Toolbat
*
* @param item
* @return
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//android.R.id.home是标题栏最左侧按键HomeAsUp的Id
case android.R.id.home:
//将滑动菜单展示出来GravityCompat.START参数与XML文件定义的保持一致
mDrawerLayout.openDrawer(GravityCompat.START);
break;
case R.id.backup:
Toast.makeText(this, "You click Backup", Toast.LENGTH_SHORT).show();
break;
case R.id.delete:
Toast.makeText(this, "You click Delete", Toast.LENGTH_SHORT).show();
break;
case R.id.setting:
Toast.makeText(this, "You click Setting", Toast.LENGTH_SHORT).show();
break;
default:
}
return true;
}
}

@ -0,0 +1,137 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import com.sbw.atrue.Order.Entity.Order;
import com.sbw.atrue.Order.Entity.Product;
import com.sbw.atrue.Order.Entity.ProductOrder;
import com.sbw.atrue.Order.R;
import org.litepal.crud.DataSupport;
import java.util.List;
/**
* FileName: ReadOrderActivity <br>
* Description: <br>
* Author: -13042299081 <br>
* Date: 2019/4/9 10:52
*/
public class ReadOrderActivity extends Activity {
private TextView tvResult; //订单信息显示文字控件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_readorder);
tvResult = (TextView) findViewById(R.id.tv_result);
//从数据库中读取订单信息
//readFromSqlite();
//暴力输出订单信息
readBaoLi();
}
/**
* LitePalSQlite
*/
private void readFromSqlite(){
//从SQLite数据库读取历史订单列表
List<Order> orders=DataSupport.findAll(Order.class);
//遍历订单列表并输出订单信息
for(Order order:orders){
StringBuilder orderResult = new StringBuilder(); //新建订单结果信息
orderResult.append("\t\t\t\t\t\t\t订单信息如下\n");//添加文本内容
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
double totalPrice = 0; //购买商品总价
for (int i = 0; i < order.getSelectedProducts().size(); i++) { //遍历商品列表并往文本写入商品信息
ProductOrder product = order.getSelectedProducts().get(i);
if(product.getFoodName().length()==2){
orderResult.append(product.getFoodName() + "\t\t\t\t\t\t\t " + product.getNum() + " \t\t\t\t\t" + product.getPrice() + "\n");
}else{
orderResult.append(product.getFoodName() + "\t\t\t\t\t" + product.getNum() + "\t\t\t\t\t" + product.getPrice()+ "\n");
}
totalPrice += product.getPrice(); //设置商品总价
}
orderResult.append("*************************");
orderResult.append("\n共计" + totalPrice + "元\n\n");
orderResult.append("\t\t\t\t\t\t\t您的信息如下\n");
orderResult.append("*************************\n");
orderResult.append("姓名:" + order.getUserName() + "\n");
orderResult.append("电话:" + order.getPhone() + "\n");
orderResult.append("桌号:" + order.getTableId()+ "\n");
orderResult.append("时间:"+ order.getTime()+ "\n");
//将订单结果信息设置到订单信息显示文字控件
tvResult.setText(orderResult);
}
}
/**
*
*/
private void readBaoLi(){
StringBuilder orderResult = new StringBuilder(); //新建订单结果信息
orderResult.append("\t\t\t\t\t\t\t订单1\n");//添加文本内容
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
orderResult.append("牛肉丸"+ "\t\t\t\t\t" + 2 + " \t\t\t\t\t" + 76 + "\n");
orderResult.append("嫩肉"+ "\t\t\t\t\t\t\t " + 2 + " \t\t\t\t\t" + 76 + "\n");
orderResult.append("五花趾"+ "\t\t\t\t\t" + 1 + " \t\t\t\t\t" + 38 + "\n");
orderResult.append("*************************");
orderResult.append("\n共计" + 152 + "元\n");
orderResult.append("姓名:" + "沈滨伟" + "\n");
orderResult.append("电话:" + "13042299081" + "\n");
orderResult.append("桌号:" + "10"+ "\n");
orderResult.append("时间:"+ "2019年4月10日 15:11:35"+ "\n");
orderResult.append("\n\n");
orderResult.append("\t\t\t\t\t\t\t订单2\n");
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
orderResult.append("雪花"+ "\t\t\t\t\t\t\t " + 2 + " \t\t\t\t\t" + 100 + "\n");
orderResult.append("吊龙"+ "\t\t\t\t\t\t\t " + 1 + " \t\t\t\t\t" + 40 + "\n");
orderResult.append("*************************");
orderResult.append("\n共计" + 140 + "元\n");
orderResult.append("姓名:" + "沈滨伟" + "\n");
orderResult.append("电话:" + "13042299081" + "\n");
orderResult.append("桌号:" + "10"+ "\n");
orderResult.append("时间:"+ "2019年4月11日 19:24:30"+ "\n");
orderResult.append("\n\n");
orderResult.append("\t\t\t\t\t\t\t订单3\n");
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
orderResult.append("胸口朥"+ "\t\t\t\t\t" + 2 + " \t\t\t\t\t" + 90 + "\n");
orderResult.append("嫩肉"+ "\t\t\t\t\t\t\t " + 2 + " \t\t\t\t\t" + 76 + "\n");
orderResult.append("五花趾"+ "\t\t\t\t\t" + 1 + " \t\t\t\t\t" + 38 + "\n");
orderResult.append("吊龙"+ "\t\t\t\t\t\t\t " + 2 + " \t\t\t\t\t" + 80 + "\n");
orderResult.append("*************************");
orderResult.append("\n共计" + 284 + "元\n");
orderResult.append("姓名:" + "沈滨伟" + "\n");
orderResult.append("电话:" + "13042299081" + "\n");
orderResult.append("桌号:" + "10"+ "\n");
orderResult.append("时间:"+ "2019年4月12日 08:15:45"+ "\n");
orderResult.append("\n\n");
orderResult.append("\t\t\t\t\t\t\t订单4\n");
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
orderResult.append("三花趾"+ "\t\t\t\t\t" + 2 + " \t\t\t\t\t" + 72 + "\n");
orderResult.append("胸口朥"+ "\t\t\t\t\t" + 2 + " \t\t\t\t\t" + 90 + "\n");
orderResult.append("嫩肉"+ "\t\t\t\t\t\t\t " + 2 + " \t\t\t\t\t" + 76 + "\n");
orderResult.append("五花趾"+ "\t\t\t\t\t" + 1 + " \t\t\t\t\t" + 38 + "\n");
orderResult.append("嫩肉"+ "\t\t\t\t\t\t\t " + 3 + " \t\t\t\t\t" + 120 + "\n");
orderResult.append("*************************");
orderResult.append("\n共计" + 399 + "元\n");
orderResult.append("姓名:" + "沈滨伟" + "\n");
orderResult.append("电话:" + "13042299081" + "\n");
orderResult.append("桌号:" + "10"+ "\n");
orderResult.append("时间:"+ "2019年4月15日 11:24:06"+ "\n");
//将订单结果信息设置到订单信息显示文字控件
tvResult.setText(getIntent().getStringExtra("content"));
}
}

@ -0,0 +1,186 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONException;
import org.json.JSONObject;
public class RegisterActivity extends Activity {
private EditText etUsername; //用户名输入框
private EditText etPassword; //密码输入框
private EditText etPassAgain; //第二次密码输入框
private TextView tvNameWrong; //用户名错误提示文字
private TextView tvPssWrong; //密码错误提示文字
private TextView tvPssNotMatch; //密码错误提示文字
private Button btnRegister; //注册按钮
private Button btnLogin; //登录按钮
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
initViews(); //初始化页面控件
initEvents(); //初始化控件事件
}
//初始化页面控件
private void initViews() {
etUsername = (EditText) findViewById(R.id.et_username);
etPassword = (EditText) findViewById(R.id.et_password);
etPassAgain = (EditText) findViewById(R.id.et_pass_again);
tvNameWrong = (TextView) findViewById(R.id.tv_name_wrong);
tvPssWrong = (TextView) findViewById(R.id.tv_pass_wrong);
tvPssNotMatch = (TextView) findViewById(R.id.tv_pass_not_match);
btnRegister = (Button) findViewById(R.id.btn_register);
btnLogin = (Button) findViewById(R.id.btn_login);
}
//初始化控件事件
private void initEvents() {
//给登陆按钮设置点击事件
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//跳转到登陆界面
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
RegisterActivity.this.finish(); //结束当前界面
}
});
//给注册按钮设置点击事件
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取用户名输入框中的内容
String username = etUsername.getText().toString();
//获取密码输入框中的内容
String password = etPassword.getText().toString();
//获取再次输入密码输入框中的内容
String passAgain = etPassAgain.getText().toString();
//判断用户名和密码是否正确
if (!TextUtils.isEmpty(username)
&& !TextUtils.isEmpty(password)
&& !TextUtils.isEmpty(passAgain)
&& password.equals(passAgain)) { //用户名和密码都不为空且两次密码相同
hideNameAndPassError(); //隐藏用户名和密码错误提示
tryToRegister(username, password); //尝试登陆
} else { //用户名或密码为空或两次密码不同
showNameOrPassError(username, password, passAgain); //显示用户名或密码错误文字提示
}
}
});
}
//隐藏用户名和密码错误提示
private void hideNameAndPassError() {
tvNameWrong.setVisibility(View.INVISIBLE); //隐藏用户名不能为空提示文字
tvPssWrong.setVisibility(View.INVISIBLE); //隐藏不能为空提示文字
tvPssNotMatch.setVisibility(View.INVISIBLE); //隐藏两次密码不一致提示文字
}
//尝试登陆
private void tryToRegister(final String username, final String password) {
String postUrl = HttpUtil.HOST + "api/user/register";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("username", username);
request.add("password", password);
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
JSONObject data = res.getJSONObject("data");
Toast.makeText(getApplicationContext(), "成功注册用户:" + username, Toast.LENGTH_SHORT).show();
//跳转到商品购买页面
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
finish();
} else {
Toast.makeText(getApplicationContext(), "用户名已存在", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
//获取数据库中该用户名对应的密码
String realPassword = ShareUtils.getString(this, username, "");
if ("".equals(realPassword)) { //数据库中没有该用户名的数据
} else { //该用户名已存在数据库中
//提示用户名已存在
}
}
/**
*
*
* @param username
* @param password
* @param passAgain
*/
private void showNameOrPassError(String username, String password, String passAgain) {
if (TextUtils.isEmpty(username)) { //用户名为空
tvNameWrong.setVisibility(View.VISIBLE); //显示用户名错误提示文字
} else { //用户名不为空
tvNameWrong.setVisibility(View.INVISIBLE); //用户名错误提示文字消失
}
if (TextUtils.isEmpty(password)) { //密码为空
tvPssWrong.setVisibility(View.VISIBLE); //显示密码错误提示文字
} else { //密码不为空
tvPssWrong.setVisibility(View.INVISIBLE); //密码错误提示文字消失
}
if (!password.equals(passAgain)) { //两次输入的密码不同
tvPssNotMatch.setVisibility(View.VISIBLE); //显示两次密码输入不一致提示
} else { //两次输入的密码相同
tvPssNotMatch.setVisibility(View.INVISIBLE); //两次密码输入不一致提示消失
}
}
}

@ -0,0 +1,103 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONException;
import org.json.JSONObject;
/**
* FileName: SettingActivity <br>
* Description: <br>
* Author: -13042299081 <br>
* Date: 2019/4/12 20:55
*/
public class SettingActivity extends Activity {
private EditText etname; //姓名输入框
private EditText etPhone; //手机号输入框
private EditText etMail; //邮箱输入框
private Button btnInputCompleted; //输入完成按钮
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.person_setting);
etname = (EditText) findViewById(R.id.et_name);
etPhone = (EditText) findViewById(R.id.et_phone);
etMail = (EditText) findViewById(R.id.et_mail);
btnInputCompleted = (Button) findViewById(R.id.btn_input_completed);
//登录时默认自动在本地保存了一份客户信息,将其读取出来并显示
etname.setText(ShareUtils.getString(this, "user_true_name", ""));
etPhone.setText(ShareUtils.getString(this, "user_true_phone", ""));
etMail.setText(ShareUtils.getString(this, "user_true_mail", ""));
btnInputCompleted.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String postUrl = HttpUtil.HOST + "api/user/updateUser";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("id", ShareUtils.getInt(getApplicationContext(), "user_id", 0));
request.add("nickname", etname.getText().toString());
request.add("phone", etPhone.getText().toString());
request.add("email", etMail.getText().toString());
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
//保存用户新设置的客户个人信息
ShareUtils.putString(SettingActivity.this, "user_true_name", etname.getText().toString());
ShareUtils.putString(SettingActivity.this, "user_true_phone", etPhone.getText().toString());
ShareUtils.putString(SettingActivity.this, "user_true_mail", etMail.getText().toString());
//登录成功,跳转到菜单展示的主页面
Intent intent = new Intent(SettingActivity.this, OrderActivity.class);
startActivity(intent);
finish();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
});
}
}

@ -0,0 +1,258 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.sbw.atrue.Order.Entity.Food;
import com.sbw.atrue.Order.Entity.Product;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.FoodFctory;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.ProductListAdapter;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ShoppingActivity extends Activity {
public static ShoppingActivity mInstance = null; //当前对象的实例本身
private ListView lvProduct; //商品展示列表控件
private TextView tvSelected; //已选择商品数量提示文字
private TextView tvTotal; //已选择商品总价提示文字
private Button btnTakeOrder; //下单按钮
private Button btnSortByNew; //根据新品排序
private Button btnSortBySale; //根据销量排序
private Button btnSortByPrice; //根据价格排序
private Button btnSortByAll; //根据综合情况排序
private List<Product> productsData = new ArrayList<Product>(); //所有的商品数据
private ArrayList<Product> selectedProducts = new ArrayList<Product>(); //被选择的的商品数据
private ProductListAdapter productListAdapter; //商品列表适配器
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shopping);
initViews(); //初始化页面控件
initDatas(); //初始化数据
initEvents(); //初始化控件事件
}
private void initDatas() {
productsData = new ArrayList<>();
String postUrl = HttpUtil.HOST + "api/food/productList";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
JSONArray array = res.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject data = array.getJSONObject(i);
Product product = new Product(data.getInt("id"),
data.getString("name"),
data.getDouble("price"),
data.getString("picture"),
data.getInt("sale"),
data.getString("shopName"),
data.getString("detail"), true);
productsData.add(product);
}
productListAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
//初始化页面控件
private void initViews() {
lvProduct = (ListView) findViewById(R.id.lv_product);
tvSelected = (TextView) findViewById(R.id.tv_selected);
tvTotal = (TextView) findViewById(R.id.tv_total);
btnTakeOrder = (Button) findViewById(R.id.btn_take_order);
btnSortByNew = (Button) findViewById(R.id.btn_sort_by_new);
btnSortByPrice = (Button) findViewById(R.id.btn_sort_by_price);
btnSortBySale = (Button) findViewById(R.id.btn_sort_by_sale);
btnSortByAll = (Button) findViewById(R.id.btn_sort_by_all);
}
//初始化控件事件
private void initEvents() {
mInstance = this; //设置实例等于当前对象本身
//将数据源放入适配器中
productListAdapter = new ProductListAdapter(this, productsData);
//给商品展示列表控件设置顶部分隔线
lvProduct.addHeaderView(new View(this));
//给商品展示列表控件设置适配器
lvProduct.setAdapter(productListAdapter);
//给下单按钮添加点击事件
btnTakeOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedProducts.size() != 0) { //已选择商品数据不为空
Intent intent = new Intent(getApplicationContext(), InputActivity.class); //新建意图
intent.putParcelableArrayListExtra("selectedProducts", selectedProducts); //设置已选择的商品数据
startActivity(intent); //启动信息输入界面
} else { //已选择商品数据为空
showDialog("购物车为空,请选择商品!");
}
}
});
//给按新品排序按钮设置点击事件
btnSortByNew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //点击事件
Collections.sort(productsData, new Comparator<Product>() { //对商品数据进行排序
@Override
public int compare(Product product1, Product product2) { //比较商品
//如果本商品被选择次数大于第二个商品
if (product1.getSelectedCount() > product2.getSelectedCount()) {
return 1; //返回正数代表本商品大于第二个商品
}
return -1; //返回负数代表本商品小于第二个商品
}
});
productListAdapter.notifyDataSetChanged(); //通知系统数据改变
}
});
//给按销量排序按钮设置点击事件
btnSortBySale.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //点击事件
Collections.sort(productsData, new Comparator<Product>() { //对商品数据进行排序
@Override
public int compare(Product product1, Product product2) { //比较商品
//如果本商品的销量小于第二个商品
if (product1.getSale() < product2.getSale()) {
return 1; //返回正数代表本商品大于第二个商品
}
return -1; //返回负数代表本商品小于第二个商品
}
});
productListAdapter.notifyDataSetChanged(); //通知系统数据改变
}
});
//给按价格排序按钮设置点击事件
btnSortByPrice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //点击事件
Collections.sort(productsData, new Comparator<Product>() { //对商品数据进行排序
@Override
public int compare(Product product1, Product product2) { //比较商品
//如果本商品的价格大于第二个商品
if (product1.getPrice() > product2.getPrice()) {
return 1; //返回正数代表本商品大于第二个商品
}
return -1; //返回负数代表本商品小于第二个商品
}
});
productListAdapter.notifyDataSetChanged(); //通知系统数据改变
}
});
//给按综合排序按钮设置点击事件
btnSortByAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //点击事件
Collections.sort(productsData, new Comparator<Product>() { //对商品数据进行排序
@Override
public int compare(Product product1, Product product2) { //比较商品
//如果本商品的价格大于第二个商品
if (product1.getId() > product2.getId()) {
return 1; //返回正数代表本商品大于第二个商品
}
return -1; //返回负数代表本商品小于第二个商品
}
});
productListAdapter.notifyDataSetChanged(); //通知系统数据改变
}
});
}
//设置被选择商品数量与价格
public void setSelectedCountAndPrice(int selectedCount, int totalPrice) {
tvSelected.setText(String.valueOf(selectedCount)); //在界面上设置已选择商品数量的信息
tvTotal.setText(String.valueOf(totalPrice)); //在界面上设置已选择商品总价的信息
if (selectedCount == 0 && totalPrice == 0) { //当被选择商品数量和总价都为0时
for (Product product : productsData) { //遍历商品列表
product.clearZero(); //将每一项商品的选择次数归零与不显示减去按钮
}
selectedProducts.clear(); //清空已选择商品列表
productListAdapter.notifyDataSetChanged(); //通知系统数据已改变
}
}
//设置被选择的商品数据
public void setSelectedProducts(ArrayList<Product> data) {
this.selectedProducts = data; //获取被选择商品数据
productListAdapter.setSelectedProducts(data); //设置被选择商品数据到商品适配器
}
/**
* 便
*
* @param msg
*/
private void showDialog(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
}

@ -0,0 +1,459 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.google.gson.Gson;
import com.sbw.atrue.Order.Entity.Order;
import com.sbw.atrue.Order.Entity.ProductOrder;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Entity.Product;
import com.sbw.atrue.Order.Util.HttpUtil;
import com.sbw.atrue.Order.Util.MyListener;
import com.sbw.atrue.Order.Util.ShareUtils;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.JsonObjectRequest;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.litepal.tablemanager.Connector;
public class SuccessActivity extends Activity {
private static final String TAG = SuccessActivity.class.getName();
private TextView tvResult; //订单信息显示文字控件
private Button btnContinueBuy; //加菜按钮
private Button btnPay; //结账按钮
private ArrayList<Product> selectedProducts = new ArrayList<Product>(); //被选择的的商品数据
private String nowTime;//订单提交时间
private double totalPrice = 0; //购买商品总价
private boolean ispay = false; //判断订单是否已被支付
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_success);
initViews(); //初始化页面控件
initDatas(); //初始化页面数据
initEvents(); //初始化控件事件
}
//初始化页面控件
private void initViews() {
tvResult = (TextView) findViewById(R.id.tv_result);
btnContinueBuy = (Button) findViewById(R.id.btn_continue_buy);
btnPay = (Button) findViewById(R.id.btn_pay);
}
/**
*
*/
private void initEvents() {
showDialog("您的订单提交成功!请您及时支付!");
//给加菜按钮设置点击事件
btnContinueBuy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ispay) {
//跳转到购物界面
startActivity(new Intent(getApplicationContext(), ShoppingActivity.class));
//结束当前界面
SuccessActivity.this.finish();
} else {
showDialog("您尚未支付当前订单!请结账后再加菜!");
}
}
});
//给结账按钮设置点击事件
btnPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//保存订单信息至SQLite数据库中可惜Litepal框架使用失败。
// transformData();
MyListener<JSONObject> stringMyListener = new MyListener<JSONObject>() {
@Override
public void onSuccess(JSONObject data) throws JSONException {
if (data.getInt("status") != 0) {
showDialog(data.getString("msg"));
} else {
int myMoney = ShareUtils.getInt(SuccessActivity.this, "money", 1);
if (totalPrice > myMoney) {
//当账户余额的钱不足以支付当前订单时
showDialogNoMoney();
} else {
myMoney -= totalPrice;
//更新账户余额
ShareUtils.putInt(SuccessActivity.this, "money", myMoney);
//将订单标记为“已结账”,并将结账按钮设置为不可见状态
ispay = true;
btnPay.setVisibility(View.INVISIBLE);
//结账成功后,客户选择返回主界面,还是继续加菜
showDialogFinish();
}
}
}
};
payOrder(getIntent().getStringExtra("orderId"), stringMyListener);
}
});
}
private void payOrder(String orderId, final MyListener<JSONObject> listener) {
String postUrl = HttpUtil.HOST + "api/order/pay";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("orderId", orderId);
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
Log.w(TAG, "onSucceed: " + res.getString("data"));
listener.onSuccess(res);
} else {
showDialog(res.getString("msg"));
}
} catch (Exception e) {
e.printStackTrace();
showDialog(e.getMessage());
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
/**
*
*/
private void initDatas() {
Intent otherIntent = getIntent(); //获取信息输入界面传来的意图
selectedProducts = otherIntent.getParcelableArrayListExtra("selectedProducts"); //从意图中获取被选择的的商品数据
String name = otherIntent.getStringExtra("name"); //从意图获取客户姓名
String phone = otherIntent.getStringExtra("phone"); //从意图获取手机号
String tableId = otherIntent.getStringExtra("table"); //从意图获取用餐桌号
StringBuilder orderResult = new StringBuilder(); //新建订单结果信息
orderResult.append("\t\t\t\t\t\t\t订单信息如下\n");//添加文本内容
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
for (int i = 0; i < selectedProducts.size(); i++) { //遍历商品列表并往文本写入商品信息
Product product = selectedProducts.get(i);
if (product.getName().length() == 2) {
orderResult.append(product.getName() + "\t\t\t\t\t\t\t " + product.getSelectedCount() + " \t\t\t\t\t" + product.getPrice() * product.getSelectedCount() + "\n");
} else {
orderResult.append(product.getName() + "\t\t\t\t\t" + product.getSelectedCount() + "\t\t\t\t\t" + product.getPrice() * product.getSelectedCount() + "\n");
}
totalPrice += product.getPrice() * product.getSelectedCount(); //设置商品总价
}
orderResult.append("*************************");
orderResult.append("\n共计" + totalPrice + "元\n\n");
orderResult.append("\t\t\t\t\t\t\t您的信息如下\n");
orderResult.append("*************************\n");
orderResult.append("姓名:" + name + "\n");
orderResult.append("电话:" + phone + "\n");
orderResult.append("桌号:" + tableId + "\n");
//获取当前系统时间(记录下单时间)
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
nowTime = simpleDateFormat.format(date);
orderResult.append("时间:" + nowTime + "\n");
//将订单结果信息设置到订单信息显示文字控件
tvResult.setText(orderResult);
}
/**
* 便
*/
private void transformData() {
Connector.getDatabase();//创建数据库
Intent otherIntent = getIntent(); //获取信息输入界面传来的意图
selectedProducts = otherIntent.getParcelableArrayListExtra("selectedProducts"); //从意图中获取被选择的的商品数据
String name = otherIntent.getStringExtra("name"); //从意图获取客户姓名
String phone = otherIntent.getStringExtra("phone"); //从意图获取手机号
String tableId = otherIntent.getStringExtra("table"); //从意图获取用餐桌号
List<ProductOrder> productOrders = new ArrayList<>();
ProductOrder productOrder = new ProductOrder();
for (int i = 0; i < selectedProducts.size(); i++) { //遍历商品列表并存入到productOrders列表中
Product product = selectedProducts.get(i);
productOrder.setFoodName(product.getName());
productOrder.setNum(product.getSelectedCount());
productOrder.setPrice(product.getPrice() * product.getSelectedCount());
productOrders.add(productOrder);
}
Order newOrder = new Order();
newOrder.setSelectedProducts(productOrders);
newOrder.setUserName(name);
newOrder.setPhone(phone);
newOrder.setTableId(tableId);
newOrder.setTime(nowTime);
String postUrl = HttpUtil.HOST + "api/user/login";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.setDefineRequestBodyForJson(new Gson().toJson(newOrder));
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
JSONObject data = res.getJSONObject("data");
//给用户的钱包余额设定金额
ShareUtils.putInt(getApplicationContext(), "money", data.getInt("money"));
ShareUtils.putInt(getApplicationContext(), "user_id", data.getInt("id"));
ShareUtils.putString(getApplicationContext(), "user_true_name", data.getString("nickname"));
ShareUtils.putString(getApplicationContext(), "user_true_phone", data.getString("phone"));
ShareUtils.putString(getApplicationContext(), "user_true_mail", data.getString("email"));
//登录成功,跳转到菜单展示的主页面
Intent intent = new Intent(getApplicationContext(), OrderActivity.class);
startActivity(intent);
finish();
} else {
showDialog(res.getString("msg"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
/**
* 便
*
* @param msg
*/
private void showDialog(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg)
.setCancelable(false)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
/**
*
*/
private void showDialogNoMoney() {
AlertDialog.Builder dialog = new AlertDialog.Builder(SuccessActivity.this);
dialog.setTitle("账户余额不足\n\n");
dialog.setMessage("请您到充值页面进行充值后再结账!");
dialog.setCancelable(false);
dialog.setPositiveButton("好的", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(getApplicationContext(), MyMoneyActivity.class));
}
});
dialog.setNegativeButton("不吃了", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(SuccessActivity.this, "您选择不吃了!", Toast.LENGTH_SHORT).show();
}
});
dialog.show();
}
/**
*
*/
private void showDialogFinish() {
AlertDialog.Builder dialog = new AlertDialog.Builder(SuccessActivity.this);
dialog.setTitle("订单支付成功!\n\n");
dialog.setMessage("您是否想继续加菜?");
dialog.setCancelable(false);
dialog.setPositiveButton("是的", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(SuccessActivity.this, "请继续点餐~", Toast.LENGTH_SHORT).show();
}
});
dialog.setNegativeButton("不用了", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(SuccessActivity.this, "感谢您的光临!祝您用餐愉快!", Toast.LENGTH_SHORT).show();
//跳转到购物界面
startActivity(new Intent(getApplicationContext(), OrderActivity.class));
SuccessActivity.this.finish(); //结束当前界面
}
});
dialog.show();
}
/**
*
*/
private void initDatas(String demo) {
tvResult.setText("ss\n\n\ndsss");
orderDetail(getIntent().getStringExtra("orderId"), new MyListener<JSONObject>() {
@Override
public void onSuccess(JSONObject data) throws JSONException {
selectedProducts = new ArrayList<>();
JSONArray array = data.getJSONArray("selectedProducts");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
int id = 0;
String name = jsonObject.getString("foodName");
double price = jsonObject.getDouble("price");
String picture = jsonObject.getJSONObject("product").getString("picture");
int sale = 1;
String shopName = "";
String detail = "";
boolean isShowSubBtn = true;
Product product = new Product(id, name, price, picture, sale, shopName, detail, isShowSubBtn);
product.setSelctCount(jsonObject.getInt("num"));
selectedProducts.add(product);
}
Log.w(TAG, "onSucceed: " + selectedProducts.size());
String name = data.getString("userName");
String phone = data.getString("phone"); //从意图获取手机号
String tableId = data.getString("tableId"); //从意图获取用餐桌号
StringBuilder orderResult = new StringBuilder(); //新建订单结果信息
orderResult.append("\t\t\t\t\t\t\t订单信息如下\n\n");//添加文本内容
orderResult.append("*************************\n");
orderResult.append("商品名\t\t\t数量\t\t\t\t价格\n");
for (int i = 0; i < SuccessActivity.this.selectedProducts.size(); i++) { //遍历商品列表并往文本写入商品信息
Product product = SuccessActivity.this.selectedProducts.get(i);
if (product.getName().length() == 2) {
orderResult.append(product.getName() + "\t\t\t\t\t\t\t " + product.getSelectedCount() + " \t\t\t\t\t" + product.getPrice() * product.getSelectedCount() + "\n");
} else {
orderResult.append(product.getName() + "\t\t\t\t\t" + product.getSelectedCount() + "\t\t\t\t\t" + product.getPrice() * product.getSelectedCount() + "\n");
}
totalPrice += product.getPrice() * product.getSelectedCount(); //设置商品总价
}
Log.w(TAG, "onSucceed: " + totalPrice);
orderResult.append("*************************");
orderResult.append("\n共计" + totalPrice + "元\n\n");
orderResult.append("\t\t\t\t\t\t\t您的信息如下\n");
orderResult.append("*************************\n");
orderResult.append("姓名:" + name + "\n");
orderResult.append("电话:" + phone + "\n");
orderResult.append("桌号:" + tableId + "\n");
//获取当前系统时间(记录下单时间)
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
nowTime = simpleDateFormat.format(date);
orderResult.append("时间:" + nowTime + "\n");
//将订单结果信息设置到订单信息显示文字控件
Log.w(TAG, "onSucceed: " + orderResult);
tvResult.setText(orderResult);
Log.w(TAG, "onSucceed: " + orderResult);
initEvents(); //初始化控件事件
}
});
}
private void orderDetail(String orderId, final MyListener<JSONObject> literer) {
String postUrl = HttpUtil.HOST + "api/order/orderDetail";
//1.创建一个队列
RequestQueue queue = NoHttp.newRequestQueue();
//2.创建消息请求 参数1:String字符串,传网址 参数2:请求方式
final Request<JSONObject> request = NoHttp.createJsonObjectRequest(postUrl, RequestMethod.POST);
//3.利用队列去添加消息请求
//使用request对象添加上传的对象添加键与值,post方式添加上传的数据
request.add("userId", ShareUtils.getInt(getApplicationContext(), "user_id", 0));
request.add("orderId", orderId);
queue.add(1, request, new OnResponseListener<JSONObject>() {
@Override
public void onStart(int what) {
}
@Override
public void onSucceed(int what, Response<JSONObject> response) {
JSONObject res = response.get();
try {
if (res.getInt("status") == 0) {
Log.w(TAG, "onSucceed: " + res.getJSONObject("data").toString());
literer.onSuccess(res.getJSONObject("data"));
} else {
showDialog(res.getString("msg"));
}
} catch (Exception e) {
e.printStackTrace();
showDialog(e.getMessage());
}
}
@Override
public void onFailed(int what, Response<JSONObject> response) {
}
@Override
public void onFinish(int what) {
}
});
}
}

@ -0,0 +1,37 @@
package com.sbw.atrue.Order.Entity;
import java.io.Serializable;
/**
* ClassName: Food <br >
* description: Intent <br>
* author: -13042299081 <br>
* Date: 2019/2/18 22:08
*/
public class Food implements Serializable {
//菜品名称
private String name;
/**
* R.drawable.mango
*/
private String imageId;
//菜品描述
private String description;
public Food(String name, String imageId,String description) {
this.name = name;
this.imageId = imageId;
this.description=description;
}
public String getName() {
return name;
}
public String getImageId() {
return imageId;
}
public String getDescription(){return description;}
}

@ -0,0 +1,41 @@
package com.sbw.atrue.Order.Entity;
import org.litepal.crud.DataSupport;
import java.util.HashMap;
//public类变量和方法可以跨包访问在全局作用。
//对实体类进行数据库操作之前一定要先让我们数据库知道哪些是我们的实体类可以对其进行操作故而需要让我们的实体类先继承DataSupport这个类
public class Nutrition extends DataSupport {
private String name;//营养成分这里需要图片吗 感觉可以做个分类出来 某几类的某几个
/**
* R.drawable.mango
*/
//做个排序 健康小助手只展示排名前几的 其余的用其他来代替?
private String imageId;
public final static int Unit_g = 100;//每100g
public int Heat; // 单位为千卡
public double protein; // 单位为克
public double fat; // 单位为克
public double carbohydrates; // 单位为克
public double Dietaryfiber; // 单位为克
public double Na; // 单位为毫克
public double Ca; // 单位为毫克
public double Fe; // 单位为毫克
public double Mg; // 单位为毫克
public double Mn; // 单位为毫克
public double Zn; // 单位为毫克
public double Cu; // 单位为毫克
public double K; // 单位为毫克
public double P; // 单位为毫克
public double thiamine; // 硫胺素 单位为毫克
public double riboflavin; // 核黄素 单位为毫克
public double nicotinic_acid; // 烟酸 单位为毫克
public double cholesterol; // 胆固醇 单位为毫克
public double VC; // 维生素C 单位为毫克
public double VE; // 维生素E 单位为毫克
public double VA; // 维生素A 单位为微克
public double Se; // 单位为微克
public double Carotene; // 胡罗卜素 单位为微克
public double Retinol_equivalent; // 视黄醇当量 单位为微克
}

@ -0,0 +1,87 @@
package com.sbw.atrue.Order.Entity;
import org.litepal.crud.DataSupport;
import java.util.ArrayList;
import java.util.List;
/**
* FileName: Order <br>
* Description: <br>
* Author: -13042299081 <br>
* Date: 2019/4/8 15:25
*/
public class Order extends DataSupport {
private int id; //订单ID
private List<ProductOrder> selectedProducts; //被选择的的商品数据
private double totalPrice;//该订单的总价
private String userName;//客户姓名
private String phone;//客户电话
private String tableId;//用餐桌号
private String time;//下单时间
private boolean ispay;//是否已结账
public int getId() {
return id;
}
public List<ProductOrder> getSelectedProducts() {
return selectedProducts;
}
public double getTotalPrice() {
return totalPrice;
}
public String getUserName() {
return userName;
}
public String getPhone() {
return phone;
}
public String getTableId() {
return tableId;
}
public String getTime() {
return time;
}
public boolean isIspay() {
return ispay;
}
public void setId(int id) {
this.id = id;
}
public void setSelectedProducts(List<ProductOrder> selectedProducts) {
this.selectedProducts = selectedProducts;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setTableId(String tableId) {
this.tableId = tableId;
}
public void setTime(String time) {
this.time = time;
}
public void setIspay(boolean ispay) {
this.ispay = ispay;
}
}

@ -0,0 +1,155 @@
package com.sbw.atrue.Order.Entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
//商品类
public class Product implements Parcelable {
private int id; //商品表示符
private String name; //商品名
private double price; //价格
private String picture; //商品图片
private int sale; //月销量
private String shopName; //店铺名称
private int level; //评级
private String detail; //产品描述
private int selectedCount = 0; //已选择该商品的数量
private boolean isShowSubBtn; //是否显示减去按钮
public Product(int id, String name, double price, String picture, int sale, String shopName, String detail, boolean isShowSubBtn) {
this.id = id;
this.name = name;
this.price = price;
this.picture = picture;
this.sale = sale;
this.shopName = shopName;
this.detail = detail;
this.isShowSubBtn = isShowSubBtn;
}
//获取该商品被选中的次数
public int getSelectedCount() {
return selectedCount;
}
//将商品被选中次数清零与设置不显示减去按钮
public void clearZero() {
selectedCount = 0;
isShowSubBtn = false;
}
//增加该商品被选中的次数
public void addSelectedCount() {
selectedCount++;
}
//减少该商品被选中的次数
public void subSelectedCount() {
if (selectedCount > 0) {
selectedCount--;
}
}
//获取该商品的id
public int getId() {
return id;
}
//获取该商品的名字
public String getName() {
return name;
}
//获取该商品的价格
public double getPrice() {
return price;
}
//获取该商品的图片
public String getPicture() {
return picture;
}
//获取该商品的月销量
public int getSale() {
return sale;
}
//获取该商品的店铺名
public String getShopName() {
return shopName;
}
//获取该商品的详情
public String getDetail() {
return detail;
}
//获取是否显示减去按钮
public boolean getIsShowSubBtn() {
return isShowSubBtn;
}
//设置是否显示减去按钮
public void setIsShowSubBtn(boolean isShowSubBtn) {
this.isShowSubBtn = isShowSubBtn;
}
@Override
public String toString() {
return "Product[ name=" + name + ",price=" + price + ",picture=" + picture
+ ",sale=" + sale + ",shopName=" + shopName + ",detail=" + detail + ",selectedCount=" + selectedCount + " ]";
}
//以下是实现Parcelable自动生成的内容
protected Product(Parcel in) {
id = in.readInt();
name = in.readString();
price = in.readDouble();
picture = in.readString();
sale = in.readInt();
shopName = in.readString();
detail = in.readString();
selectedCount = in.readInt();
isShowSubBtn = in.readByte() != 0;
}
public static final Creator<Product> CREATOR = new Creator<Product>() {
@Override
public Product createFromParcel(Parcel in) {
return new Product(in);
}
@Override
public Product[] newArray(int size) {
return new Product[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
dest.writeDouble(price);
dest.writeString(picture);
dest.writeInt(sale);
dest.writeString(shopName);
dest.writeString(detail);
dest.writeInt(selectedCount);
dest.writeByte((byte) (isShowSubBtn ? 1 : 0));
}
public void setSelctCount(int num) {
selectedCount = num;
}
}

@ -0,0 +1,58 @@
package com.sbw.atrue.Order.Entity;
import org.litepal.crud.DataSupport;
import java.util.List;
/**
* FileName: ProductOrder <br>
* Description: <br>
* Author: -13042299081 <br>
* Date: 2019/4/9 14:54
*/
public class ProductOrder extends DataSupport{
private int id; //订单ID
private List<Order> orders; //与Order表建立多对多关联关系
private String foodName;//菜名
private int num;//购买数量
private double price;//单项菜品总价
public int getId() {
return id;
}
public List<Order> getOrders() {
return orders;
}
public String getFoodName() {
return foodName;
}
public int getNum() {
return num;
}
public double getPrice() {
return price;
}
public void setId(int id) {
this.id = id;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
public void setFoodName(String foodName) {
this.foodName = foodName;
}
public void setNum(int num) {
this.num = num;
}
public void setPrice(double price) {
this.price = price;
}
}

@ -0,0 +1,107 @@
package com.sbw.atrue.Order.Util;
import android.content.Context;
import android.content.Intent;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.sbw.atrue.Order.Activity.FoodActivity;
import com.sbw.atrue.Order.Entity.Food;
import com.sbw.atrue.Order.R;
import java.util.List;
/**
* ClassName: FoodAdapter <br>
* description: RecycleView <br>
* author: -13042299081 <br>
* Date: 2019/2/18 21:03
*/
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.ViewHolder>{
private static final String TAG = "FoodAdapter";
private Context mContext;
private List<Food> mfoodList;
/**
* foodAdapter
*/
static class ViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
ImageView foodImage;
TextView foodName;
//构造函数
public ViewHolder(View view) {
super(view);
cardView = (CardView) view;
foodImage = (ImageView) view.findViewById(R.id.food_image);
foodName = (TextView) view.findViewById(R.id.food_name);
}
}
/**
* foodAdapter
* @param foodList
*/
public FoodAdapter(List<Food> foodList) {
mfoodList = foodList;
}
/**
* ViewHolder
* @param parent
* @param viewType
* @return ViewHolderonBindViewHolder
*/
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (mContext == null) {
mContext = parent.getContext();
}
//动态加载布局文件(菜品的简单展示布局,即图片+菜名并并把加载出来的布局传入到构造函数中从而创建ViewHolder实例
View view = LayoutInflater.from(mContext).inflate(R.layout.food_item, parent, false);
final ViewHolder holder = new ViewHolder(view);
//如果用户点击菜品卡片,则跳转到显示相应的菜品详情的活动中去
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = holder.getAdapterPosition();
Food food = mfoodList.get(position);
Intent intent = new Intent(mContext, FoodActivity.class);
//将用户点击的菜品的对象传递到下一个活动菜品详情展示FoodActivity
intent.putExtra("Food_Choose",food);
mContext.startActivity(intent);
}
});
return holder;
}
/**
* RecycleView+
* @param holder onCreateViewHolderViewHolder
* @param position
*/
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Food food = mfoodList.get(position);
holder.foodName.setText(food.getName());
//使用Glide加载图片不用担心像素太高导致内存溢出
Glide.with(mContext).load(food.getImageId()).into(holder.foodImage);
}
/**
*
* @return
*/
@Override
public int getItemCount() {
return mfoodList.size();
}
}

@ -0,0 +1,55 @@
package com.sbw.atrue.Order.Util;
import com.sbw.atrue.Order.Entity.Food;
import com.sbw.atrue.Order.Entity.Product;
import com.sbw.atrue.Order.R;
import java.util.ArrayList;
import java.util.List;
/**
* FileName: FoodFctory <br>
* Description: <br>
* Author: -13042299081 <br>
* Date: 2019/2/18 22:21
*/
public class FoodFctory {
// static public Food[] Beef={
// //备注文字如果想要有换行效果的话,直接上\n即可
// new Food("雪花",R.drawable.xuehua,"\t\t\t\t雪花是牛脖子上的凸起的一块肉是牛运动最为频繁的一块活肉也是牛身上最好吃的一块肉。一千斤的牛身上可能也就只有一两斤的雪花牛肉。因为在脖子上所以它还叫脖仁脖仁肥瘦相间拥有大理石般的纹路涮4-6秒后入口口感柔嫩多脂十分鲜甜脆爽。"),
// new Food("匙柄",R.drawable.chibing,"\t\t\t\t匙柄位于牛前腿上方部位是牛肉中最好的部位之一即牛夹层里脊肉内层。匙柄的脂肪含量少切面呈树叶状且纹理清晰口感甜嫩无渣。"),
// new Food("匙仁",R.drawable.chiren,"\t\t\t\t匙仁在西餐牛肉的分割部位叫做“眼肉”该处肉质柔嫩且多汁有雪花纹滋味无穷。眼肉属于高档肉经过精细切割后外观呈四方圆弧状肉质红白镶嵌有大理石花斑状纹理。由于臀部的运动较多眼肉肉质细嫩脂肪及水分含量较高吃起来的口感比较香甜多汁、不干涩。"),
// new Food("三花趾",R.drawable.sanhuazhi,"\t\t\t\t如果你在吃潮汕牛肉火锅的时候雪花脖仁没有了怎么办虽然有点遗憾但还有很多部位一样美味三花趾就是其中的一种。这块牛肉的位置在上肢就是牛前腿的腱子肉牛肉中有较粗的筋。"),
// new Food("五花趾",R.drawable.wuhuazhi,"\t\t\t\t五花趾中的筋要比三花趾中的筋还要多一些肉的纹理也要更加的清晰一些在口感上也要更加的爽口吃起来非常的脆。如果你喜欢吃脆弹一些的肉那么潮汕牛肉火锅中的五花趾就是你的不二之选。"),
// new Food("肥胼",R.drawable.feipin,"\t\t\t\t肥胼对应的部位是大家再熟悉不过的牛腩位置并且是经过精修的牛腩只留牛腩腹心及上面一层牛油这样切开来之后每一片就有明显的两层一层嫩肉再带着一层黄色的牛油。口感肥腻细嫩对牛脂香味情有独钟的值得一试。"),
// new Food("吊龙",R.drawable.diaolong,"\t\t\t\t吊龙的意思是牛脊吊龙伴则是腰脊肉的两个侧边而这里头还要再细分吊龙伴中的两个小吊龙即牛骨盆的夹缝中两条长长的肉样子有点像龙虾的两根大触须潮汕人叫它“伴仔”或“龙虾须”这几两重的肉须便是吊龙伴中最为登峰造极的美味其特点是鲜甜而弹牙。"),
// new Food("嫩肉",R.drawable.nengrou,"\t\t\t\t嫩肉是在牛屁股上的肉基本上没有油脂全是精肉在潮汕牛肉火锅中算是产量比较大的一种了。嫩肉在潮汕牛肉火锅中最大的特点就是甜度高一些。 烫煮时间8秒 。"),
// new Food("胸口朥",R.drawable.xiongkoulao,"\t\t\t\t胸口朥是牛前胸的脂肪部分不是每一头牛都有这么一部分肉只有大而肥的牛才能长出十分稀有只有在潮汕火锅才能看到它的身影。它看上去油得出奇入口却是清甜间微微泛着牛油的香味口感脆而爽口、带点韧劲与“肥腻”两字完全不沾边。 烫煮时间30秒-3分钟 。"),
// };
// static public List<Product> initDatas() {
// List<Product> productsData = new ArrayList<Product>();
// Product product = new Product(0, "雪花",50, R.drawable.xuehua, 220, "潮汕牛肉", "牛运动最为频繁的一块活肉!", false);
// productsData.add(product);
// product = new Product(1, "匙柄",40, R.drawable.chibing, 340,"潮汕牛肉", "纹理清晰~口感甜嫩无渣!", false);
// productsData.add(product);
// product = new Product(2,"匙仁",52, R.drawable.chiren, 572, "潮汕牛肉", "肉质柔嫩且多汁~滋味无穷!", false);
// productsData.add(product);
// product = new Product(3,"三花趾",38, R.drawable.sanhuazhi, 678, "潮汕牛肉", "牛前腿的腱子肉~", false);
// productsData.add(product);
// product = new Product(4, "五花趾",38, R.drawable.wuhuazhi, 441, "潮汕牛肉", "纹理清晰~肉质爽口!", false);
// productsData.add(product);
// product = new Product(5,"肥胼",42, R.drawable.feipin, 233, "潮汕牛肉", "口感肥腻细嫩,富有牛脂香味~", false);
// productsData.add(product);
// product = new Product(6, "吊龙",40, R.drawable.diaolong, 128, "潮汕牛肉", "鲜甜弹牙~登峰造极的美味!", false);
// productsData.add(product);
// product = new Product(7, "嫩肉",36, R.drawable.nengrou, 214, "潮汕牛肉", "精肉无油~味道甜美!", false);
// productsData.add(product);
// product = new Product(8, "胸口朥",45, R.drawable.xiongkoulao, 82, "潮汕牛肉", "清甜间+牛油的香味~脆而爽口!", false);
// productsData.add(product);
// product = new Product(9, "牛肉丸",38, R.drawable.wanzi, 520, "潮汕牛肉", "纯肉打造!!不可错过!", false);
// productsData.add(product);
// return productsData;
// }
}

@ -0,0 +1,7 @@
package com.sbw.atrue.Order.Util;
public class HttpUtil {
public static final String HOST = "http://coding-space.cn:9030/";
}

@ -0,0 +1,8 @@
package com.sbw.atrue.Order.Util;
import org.json.JSONException;
public interface MyListener<T> {
void onSuccess(T data) throws JSONException;
}

@ -0,0 +1,185 @@
package com.sbw.atrue.Order.Util;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import com.bumptech.glide.Glide;
import com.sbw.atrue.Order.Activity.ShoppingActivity;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Entity.Product;
//商品列表适配器
public class ProductListAdapter extends BaseAdapter {
private Context mContext; //页面布局加载器
private List<Product> productsData; //商品内容数据源
private ArrayList<Product> selectedProducts = new ArrayList<Product>(); //被选择的的商品数据
private int totalSelectedCount = 0; //当前选择商品总数
private int totalPrice = 0; //当前选择商品总价
public ProductListAdapter(Context context, List<Product> data) {
mContext = context;
productsData = data;
}
//返回适配器内子项的数量
@Override
public int getCount() {
return productsData.size();
}
//返回适配器内的某个子项
@Override
public Object getItem(int position) {
return productsData.get(position);
}
//返回适配器内的某个子项的id号
@Override
public long getItemId(int position) {
return position;
}
//每个子view生成都会调用的界面生成方法
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null; //声明控件暂存器
if (convertView == null) { //如果内容界面为空
viewHolder = new ViewHolder(); //新建控件暂存器
//加载内容界面
convertView = LayoutInflater.from(mContext).inflate(R.layout.product_listview_item, null);
//绑定控件
viewHolder.picture = (ImageView) convertView.findViewById(R.id.iv_product_picture);
viewHolder.name = (TextView) convertView.findViewById(R.id.tv_product_name);
viewHolder.price = (TextView) convertView.findViewById(R.id.tv_product_pirce);
viewHolder.sale = (TextView) convertView.findViewById(R.id.tv_sale_count);
viewHolder.shopName = (TextView) convertView.findViewById(R.id.tv_product_shop_name);
viewHolder.detail = (TextView) convertView.findViewById(R.id.tv_product_detail);
viewHolder.selectedCount = (TextView) convertView.findViewById(R.id.tv_selected_count);
viewHolder.addProduct = (ImageButton) convertView.findViewById(R.id.btn_add_product);
viewHolder.subProduct = (ImageButton) convertView.findViewById(R.id.btn_sub_product);
//将控件暂存器放到内容界面中
convertView.setTag(viewHolder);
} else { //内容界面不为空
viewHolder = (ViewHolder) convertView.getTag(); //从内容界面提取出控件暂存器
}
Product product = productsData.get(position); //获取当前位置的商品
initListItem(viewHolder, product); //初始化列表界面内容
initButtonEvent(viewHolder, product); //初始化按钮的点击事件
return convertView; //返回主界面
}
/**
*
*
* @param viewHolder
* @param product
*/
private void initListItem(final ViewHolder viewHolder, final Product product) {
// viewHolder.picture.setImageResource(product.getPicture()); //设置商品图片
Glide.with(mContext).load(product.getPicture()).into(viewHolder.picture);
viewHolder.name.setText(product.getName()); //设置商品名
viewHolder.price.setText(String.valueOf("¥" + product.getPrice())); //设置商品价格
viewHolder.sale.setText(String.valueOf("月售:" + product.getSale())); //设置商品月销售量
viewHolder.shopName.setText(product.getShopName()); //设置商家名称
viewHolder.detail.setText(product.getDetail()); //设置商品简介
}
/**
*
*
* @param viewHolder
* @param product
*/
private void initButtonEvent(final ViewHolder viewHolder, final Product product) {
//给添加商品按钮添加点击事件
viewHolder.addProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
totalSelectedCount++; //被选择商品总数加1
totalPrice += product.getPrice(); //被选择商品总价加上该商品的价格
product.addSelectedCount(); //商品本身的数量加1
if (!selectedProducts.contains(product)) { //如果被选择商品列表还没有该商品
selectedProducts.add(product); //将该商品加到被选择列表中
}
product.setIsShowSubBtn(true); //设置商品对应的减去按钮消失
//在被选择商品数标签上设置被选择商品数
viewHolder.selectedCount.setText(String.valueOf(product.getSelectedCount()));
//将被选择的商品总数和总价设置回购物界面
((ShoppingActivity) mContext).setSelectedCountAndPrice(totalSelectedCount, totalPrice);
//将被选择的商品列表设置回购物界面
((ShoppingActivity) mContext).setSelectedProducts(selectedProducts);
}
});
//给减去商品按钮添加点击事件
viewHolder.subProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (totalSelectedCount - 1 >= 0) { //当被选择总数减1不为0时
totalSelectedCount--; //被选择商品总数减1
totalPrice -= product.getPrice(); //被选择商品总价减去该商品的价格
product.subSelectedCount(); //商品本身的数量减1
if (product.getSelectedCount() == 0) { //如果被选择商品的数量为0
product.setIsShowSubBtn(false); //设置该商品对应的减去按钮消失
selectedProducts.remove(product); //从被选择商品列表中移除该商品
}
//在被选择商品数标签上设置被选择商品数
viewHolder.selectedCount.setText(String.valueOf(product.getSelectedCount()));
//将被选择的商品总数和总价设置回购物界面
((ShoppingActivity) mContext).setSelectedCountAndPrice(totalSelectedCount, totalPrice);
//将被选择的商品列表设置回购物界面
((ShoppingActivity) mContext).setSelectedProducts(selectedProducts);
}
}
});
//设置减去按钮的与被选择商品数量标签的可见性
setSubButtonAndSelectCount(viewHolder, product);
}
/**
*
*
* @param viewHolder
* @param product
*/
private void setSubButtonAndSelectCount(final ViewHolder viewHolder, Product product) {
boolean show = product.getIsShowSubBtn(); //从Map中获取是否需要展示减去按钮
viewHolder.subProduct.setVisibility(show ? View.VISIBLE : View.INVISIBLE); //设置减去商品按钮是否可见
viewHolder.selectedCount.setVisibility(show ? View.VISIBLE : View.INVISIBLE); //设置被选择商品数标签是否可见
if (show) { //需要展示减去按钮
//在被选择商品数标签上设置被选择商品数
viewHolder.selectedCount.setText(String.valueOf(product.getSelectedCount()));
}
}
//设置全部商品数据
public void setSelectedProducts(ArrayList<Product> selectedProducts) {
this.selectedProducts = selectedProducts; //设置被选择的商品
notifyDataSetChanged(); //通知系统数据改变
}
//控件暂存器
static class ViewHolder {
ImageView picture; //商品图片
TextView name; //商品名
TextView price; //商品价格
TextView sale; //月销量
TextView shopName; //商店名
TextView detail; //商品细节
TextView selectedCount; //选择商品的数量
ImageButton addProduct; //添加商品按钮
ImageButton subProduct; //减去商品按钮
}
}

@ -0,0 +1,50 @@
package com.sbw.atrue.Order.Util;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
/**
* SharedPreferences
*/
public class ShareUtils {
public static final String NAME = "config";
/**
*
* @param mContext
* @param key
* @param value
*/
public static void putString(Context mContext, String key, String value) {
getSP(mContext).edit().putString(key, value).commit();
}
public static void putInt(Context mContext, String key, int value) {
getSP(mContext).edit().putInt(key,value).commit();
}
/**
*
* @param mContext
* @param key
* @param defValue
*/
public static String getString(Context mContext, String key, String defValue) {
return getSP(mContext).getString(key, defValue);
}
public static int getInt(Context mContext, String key, int defValue) {
return getSP(mContext).getInt(key, defValue);
}
/**
* SharedPreferences
* @param mContext
* @return SharedPreferences
*/
private static SharedPreferences getSP(Context mContext) {
return mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
}
}

@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--圆角-->
<corners android:radius="30dp"/>
<!--中间颜色-->
<solid android:color="@android:color/white"/>
<!--边框/颜色-->
<stroke
android:width="2dp"
android:color="#ed7b7b"/>
</shape>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--圆角-->
<corners android:radius="30dp"/>
<!--中间颜色-->
<solid android:color="@android:color/white"/>
<!--边框/颜色-->
<stroke
android:width="2dp"
android:color="#82b2ff"/>
</shape>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#82b2ff" />
<corners android:radius="25dp" />
</shape>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#aee4da" />
<corners android:radius="10dp" />
</shape>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33b34f" />
<corners android:radius="20dp" />
<padding
android:right="6dp" />
</shape>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f9e939" />
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@drawable/bg_edittext_normal" />
<item android:state_focused="true"
android:drawable="@drawable/bg_edittext_focused" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save