master
李雨轩 3 years ago
parent 800de84f74
commit d693c2346f

@ -0,0 +1,22 @@
### liyuxuan_gitProject简介
- 软件工程课程设计项目——“航吃hang吃”。本项目旨在研究并设计一基于Android的解决餐食问题的系统系统能实现具有选择困难用户的选择菜品以及给出一些用餐健康的参考。
- 对于系统功能设计:主要包括功能框架和设计模块,其中功能框架主要包括登录模块、注册模块、菜品浏览模块、个人信息模块、选择菜品模块、评论模块和营养成分模块;功能模块涉及分为服务器和客户端,具体包括登录功能、注册功能、个人信息管理功能、菜品浏览功能、评论功能、选择菜品功能和计算营养成分功能。各模块之间互相依赖,形成一个完整的解决餐食问题的系统手机(平板)客户端与服务器的交互设计系统。
### 研究内容
- A、确立物理架构Android系统客户端通过无线网络访问后台Web服务器如果需要数据访问则访问后台数据库服务器
- B、确立技术选型Android客户端选用JAVA技术网络通信选用 协议而中间Web服务器采用端口监听响应客户请求。后台数据库使用Litepal来访问数据库Android客户端部分数据的存储则采用SQLite数据库
- C、进行系统规划和需求分析通过数据设计类图分析数据间的关系设计并创建一个合理可靠的数据库
- D、实现客户端功能设计基于Android开发平台前端客户端功能模块大概分为登录功能、注册功能、菜品浏览功能、更新用户信息功能、选择菜品功能和添加评论功能
- E、实现服务器端功能设计后端服务器主要功能操作后端数据库存储信息响应客户端发出的请求并给出回馈。
###
Author李雨轩小组全体成员
设备要求:安卓手机、模拟器或虚拟机
屏幕分辨率大于640X480(VGA)
系统要求Andriod 4.2 及以上
java 11.0.12 及以上
使用方法运行MyApplication.java
road(liyuxuan_gitProjectsrc/app/src/main/java/com/sbw/atrue/Order/Activity/MyApplication.java)
###

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

@ -19,11 +19,13 @@ android {
}
dependencies {
// implementation 'org.litepal.android:java:3.0.0'
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')
implementation files('libs\\litepal-2.0.0-src.jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-beta01'
@ -33,8 +35,9 @@ dependencies {
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 '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'
}

@ -1,56 +1,51 @@
<?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="航吃Hang吃"></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" />
<activity android:name=".Activity.horizonta_main"/>
</application>
<?xml version="1.0" encoding="utf-8"?>
<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="com.sbw.atrue.Order.Activity.MainActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<!-- 将登录活动设置为程序的主活动和启动项 -->
<activity
android:name=".Activity.LoginActivity"
android:exported="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<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="航吃Hang吃" />
<activity
android:name=".Activity.FoodActivity"
android:theme="@style/foodActivityTheme" /> <!-- 声明其他各项活动 -->
<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" />
<activity android:name=".Activity.horizonta_main" />
<activity android:name=".Activity.CommentActivity" />
<activity android:name=".Activity.TurnActivity" />
</application>
</manifest>

@ -0,0 +1,122 @@
package com.sbw.atrue.Order.Activity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.AdapterComment;
import com.sbw.atrue.Order.Entity.Comment;
import java.util.ArrayList;
import java.util.List;
public class CommentActivity extends Activity implements View.OnClickListener {
private ImageView comment;
private TextView hide_down;
private EditText comment_content;
private Button comment_send;
private LinearLayout rl_enroll;
private RelativeLayout rl_comment;
private ListView comment_list;
private AdapterComment adapterComment;
private List<Comment> data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
// 初始化评论列表
comment_list = (ListView) findViewById(R.id.comment_list);
// 初始化数据
data = new ArrayList<>();
// 初始化适配器
adapterComment = new AdapterComment(getApplicationContext(), data);
// 为评论列表设置适配器
comment_list.setAdapter(adapterComment);
comment = (ImageView) findViewById(R.id.comment);
hide_down = (TextView) findViewById(R.id.hide_down);
comment_content = (EditText) findViewById(R.id.comment_content);
comment_send = (Button) findViewById(R.id.comment_send);
rl_enroll = (LinearLayout) findViewById(R.id.rl_enroll);
rl_comment = (RelativeLayout) findViewById(R.id.rl_comment);
setListener();
}
/**
*
*/
public void setListener(){
comment.setOnClickListener(this);
hide_down.setOnClickListener(this);
comment_send.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.comment:
// 弹出输入法
InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
// 显示评论框
rl_enroll.setVisibility(View.GONE);
rl_comment.setVisibility(View.VISIBLE);
break;
case R.id.hide_down:
// 隐藏评论框
rl_enroll.setVisibility(View.VISIBLE);
rl_comment.setVisibility(View.GONE);
// 隐藏输入法,然后暂存当前输入框的内容,方便下次使用
InputMethodManager im = (InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(comment_content.getWindowToken(), 0);
break;
case R.id.comment_send:
sendComment();
break;
default:
break;
}
}
/**
*
*/
public void sendComment(){
if(comment_content.getText().toString().equals("")){
Toast.makeText(getApplicationContext(), "评论不能为空!", Toast.LENGTH_SHORT).show();
}else{
// 生成评论数据
Comment comment = new Comment();
comment.setName("评论者"+(data.size()+1)+"");
comment.setContent(comment_content.getText().toString());
adapterComment.addComment(comment);
// 发送完,清空输入框
comment_content.setText("");
Toast.makeText(getApplicationContext(), "评论成功!", Toast.LENGTH_SHORT).show();
}
}
}

@ -7,6 +7,8 @@ import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
@ -19,13 +21,16 @@ import com.sbw.atrue.Order.R;
* description: <br>
*/
public class FoodActivity extends AppCompatActivity {
// private Button btCommenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initEvents();
setContentView(R.layout.activity_food); // 这里连到界面
//获取各布局控件的实例
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
// btCommenter = (Button) findViewById(R.id.commerter);
ImageView foodImageView = (ImageView) findViewById(R.id.food_image_view);
TextView foodContentText = (TextView) findViewById(R.id.food_content_text);
@ -62,4 +67,19 @@ public class FoodActivity extends AppCompatActivity {
}
return super.onOptionsItemSelected(item);
}
private void initEvents() {
/* btCommenter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(FoodActivity.this, CommentActivity.class));
}
});*/
/* btCommenter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(FoodActivity.this, RegisterActivity.class));
}
});*/
}
}

@ -36,6 +36,7 @@ public class LoginActivity extends AppCompatActivity {
private EditText passwordEdit;
private Button btnlogin;
private Button btnRegister;
// private Button btCommenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -51,6 +52,7 @@ public class LoginActivity extends AppCompatActivity {
passwordEdit = (EditText) findViewById(R.id.password);
btnlogin = (Button) findViewById(R.id.login);
btnRegister = (Button) findViewById(R.id.register);
// btCommenter = (Button) findViewById(R.id.commerter);
}
//初始化控件事件
@ -81,6 +83,14 @@ public class LoginActivity extends AppCompatActivity {
LoginActivity.this.finish(); //结束当前界面
}
});
// btCommenter.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// //跳转到注册界面
// startActivity(new Intent(LoginActivity.this, CommentActivity.class));
// }
// });
}
/**

@ -1,515 +0,0 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static android.Manifest.permission.READ_CONTACTS;
/**
* A login screen that offers login via name/password.
* /
*/
public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> {
/**
* Id to identity READ_CONTACTS permission request.
* IDREAD_CONTACTS
*/
private static final int REQUEST_READ_CONTACTS = 0;
/**
* A dummy authentication store containing known user names and passwords.
*
* TODO: remove after connecting to a real authentication system.
*
*/
private static final String[] DUMMY_CREDENTIALS = new String[]{
"foo@example.com:hello", "bar@example.com:world",
//DUMMY_CREDENTTALS用于模拟已存在的账户冒号前为账户冒号后为密码
};
/**
* Keep track of the login task to ensure we can cancel it if requested.
*
*/
private UserLoginTask mAuthTask = null;
// UI references.
private AutoCompleteTextView mUserNameView;
private EditText mPasswordView;
private View mProgressView;
private View mLoginFormView;
private SharedPreferences preferences;
private SharedPreferences.Editor editor;
//记住密码
private CheckBox rememberPass;
//自动登录
private CheckBox autoLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= 21) {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
// Set up the login form. 设置登录表单
rememberPass = (CheckBox) findViewById(R.id.remember_pass);
autoLogin = (CheckBox) findViewById(R.id.auto_login);
//账号输入
mUserNameView = (AutoCompleteTextView) findViewById(R.id.UserName);
populateAutoComplete();
//密码输入
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});
//记住密码
boolean isRemember = preferences.getBoolean("remember_password",false);
boolean isAutoLogin = preferences.getBoolean("auto_Login",false);
if(isRemember ) {
//将账户和密码都设置到文本框中
String account = preferences.getString("UserName", "");
String password = preferences.getString("password", "");
mUserNameView.setText(account);
mPasswordView.setText(password);
rememberPass.setChecked(true);
//自动登录
if (isAutoLogin) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(intent);
Toast.makeText(getApplicationContext(), "自动登录", Toast.LENGTH_SHORT).show();
}
}
//登录按钮
Button mUserNameSignInButton = (Button) findViewById(R.id.UserName_sign_in_button);
mUserNameSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
//注册按钮
Button register = (Button) findViewById(R.id.register);
register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this,registerActivity.class);
startActivity(intent);
}
});
//方法最后两个mLoginFormView和mProgressView是用于获取显示的View
//在登陆的时候可以进行登陆窗口goneProgressBar visible的操作。
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
}
//先是通过mayRequestContacts判断是否继续执行若通过判断则初始化Loaders通过Loaders后台异步读取用户的账户信息。
private void populateAutoComplete() {
if (!mayRequestContacts()) {
return;
}
getLoaderManager().initLoader(0, null, this);
}
//这个方法是用于请求用户以获取读取账户的权限主要是为了适配6.0新的权限机制
private boolean mayRequestContacts() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
return true;
}
if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
Snackbar.make(mUserNameView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onClick(View v) {
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
}
});
} else {
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
}
return false;
}
/**
* Callback received when a permissions request has been completed.
*
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == REQUEST_READ_CONTACTS) {
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
populateAutoComplete();
}
}
}
/**
* Attempts to sign in or register the account specified by the login form.
*
* If there are form errors (invalid UserName, missing fields, etc.), the
*
* errors are presented and no actual login attempt is made.
*
*/
private void attemptLogin() {
if (mAuthTask != null) {
return;
}
// Reset errors.重置错误。
mUserNameView.setError(null);
mPasswordView.setError(null);
// Store values at the time of the login attempt.在登录尝试时存储值。
String UserName = mUserNameView.getText().toString();
String password = mPasswordView.getText().toString();
editor = preferences.edit();
if(autoLogin.isChecked()){
editor.putBoolean("auto_Login",true);
}
if (rememberPass.isChecked()) {
editor.putBoolean("remember_password", true);
editor.putString("UserName", UserName);
editor.putString("password", password);
} else {
editor.clear();
}
editor.apply();
boolean cancel = false;
View focusView = null;
// Check for a valid password, if the user entered one.如果用户输入密码,请检查有效的密码。
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordView.setError(getString(R.string.error_invalid_password));
focusView = mPasswordView;
cancel = true;
}
// Check
if (TextUtils.isEmpty(UserName)) {
mUserNameView.setError(getString(R.string.error_field_required));
focusView = mUserNameView;
cancel = true;
} else if (!isUserNameValid(UserName)) {
mUserNameView.setError(getString(R.string.error_invalid_UserName));
focusView = mUserNameView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
//有一个错误;不要尝试登录并首先关注
// form field with an error.
//表单字段有错误。
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
//显示进度微调,并启动后台任务
// perform the user login attempt.
//执行用户登录尝试。
showProgress(true);
mAuthTask = new UserLoginTask(UserName, password);
mAuthTask.execute((Void) null);
}
}
private boolean isUserNameValid(String UserName) {
//TODO: Replace this with your own logic 用你自己的逻辑代替这个
return UserName.contains("@");
}
private boolean isPasswordValid(String password) {
//TODO: Replace this with your own logic 用你自己的逻辑代替这个
return password.length() > 4;
}
/**
* Shows the progress UI and hides the login form.
* UI
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show) {
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
// for very easy animations. If available, use these APIs to fade-in
// the progress spinner.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
mLoginFormView.animate().setDuration(shortAnimTime).alpha(
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
}
});
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
mProgressView.animate().setDuration(shortAnimTime).alpha(
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
}
});
} else {
// The ViewPropertyAnimator APIs are not available, so simply show
// and hide the relevant UI components.
//ViewPropertyAnimator API不可用因此只需显示和隐藏相关的UI组件。
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
}
}
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new CursorLoader(this,
// Retrieve data rows for the device user's 'profile' contact.
//检索设备用户的“个人资料”联系人的数据行。
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
ContactsContract.Contacts.Data.MIMETYPE +
" = ?", new String[]{ContactsContract.CommonDataKinds.UserName
.CONTENT_ITEM_TYPE},
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
List<String> UserNames = new ArrayList<>();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
UserNames.add(cursor.getString(ProfileQuery.ADDRESS));
cursor.moveToNext();
}
addUserNamesToAutoComplete(UserNames);
}
@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
}
private void addUserNamesToAutoComplete(List<String> UserNameAddressCollection) {
//Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
//创建适配器以告诉AutoCompleteTextView在其下拉列表中显示什么。
ArrayAdapter<String> adapter =
new ArrayAdapter<>(LoginActivity.this,
android.R.layout.simple_dropdown_item_1line, UserNameAddressCollection);
mUserNameView.setAdapter(adapter);
}
private interface ProfileQuery {
String[] PROJECTION = {
ContactsContract.CommonDataKinds.UserName.ADDRESS,
ContactsContract.CommonDataKinds.UserName.IS_PRIMARY,
};
int ADDRESS = 0;
int IS_PRIMARY = 1;
}
/**
* Represents an asynchronous login/registration task used to authenticate
* the user.
* /
*/
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
private final String mUserName;
private final String mPassword;
UserLoginTask(String UserName, String password) {
mUserName = UserName;
mPassword = password;
}
@Override
protected Boolean doInBackground(Void... params) {
// TODO: attempt authentication against a network service.
//尝试对网络服务进行身份验证。
try {
LoginRequest(mUserName,mPassword);
// Simulate network access.模拟网络访问。
Thread.sleep(3000);
} catch (InterruptedException e) {
return false;
}
for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mUserName)) {
// Account exists, return true if the password matches.
//帐户存在如果密码匹配则返回true。
return pieces[1].equals(mPassword);
}
}
// TODO: register the new account here.
//在此注册新帐户。
return true;
}
@Override
protected void onPostExecute(final Boolean success) {
mAuthTask = null;
showProgress(false);
if (success) {
/*
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
finish();
*/
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
}
@Override
protected void onCancelled() {
mAuthTask = null;
showProgress(false);
}
}
public void LoginRequest(final String account, final String password) {
//请求地址
String url = "http://8.130.38.15:8080/Whoere/LoginServlet?account="+account+"&password="+password;
String tag = "Login";
//取得请求队列
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
//防止重复请求所以先取消tag标识的请求队列
requestQueue.cancelAll(tag);
//创建StringRequest定义字符串请求的请求方式为POST(省略第一个参数会默认为GET方式)
final StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
//@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
String result = jsonObject.getString("Result");
if (result.equals("success")) {
//做自己的登录成功操作,如页面跳转
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
Toast.makeText(LoginActivity.this,"欢迎!",Toast.LENGTH_LONG).show();
} else {
if (result.equals("failed"))
Toast.makeText(LoginActivity.this,"账户或密码错误!",Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
//做自己的请求异常操作如Toast提示“无网络连接”等
Log.e("TAG", e.getMessage(), e);
}
}
}, new Response.ErrorListener() {
//@Override
public void onErrorResponse(VolleyError error) {
//做自己的响应错误操作如Toast提示“请稍后重试”等
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("Account", account);
params.put("Password", password);
return params;
}
};
//设置Tag标签
request.setTag(tag);
//将请求添加到队列中
requestQueue.add(request);
}
}

@ -0,0 +1,16 @@
package com.sbw.atrue.Order.Activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.sbw.atrue.Order.R;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}

@ -109,7 +109,6 @@ public class OrderActivity extends AppCompatActivity {
startActivity(intent);
}
});
break;
case R.id.nav_money:
//跳转到钱包界面
@ -386,11 +385,17 @@ public class OrderActivity extends AppCompatActivity {
case R.id.backup:
Toast.makeText(this, "You click Backup", Toast.LENGTH_SHORT).show();
break;
case R.id.delete:
/* 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;*/
case R.id.comment:
startActivity(new Intent(OrderActivity.this, CommentActivity.class));
break;
case R.id.turntable:
startActivity(new Intent(OrderActivity.this, TurnActivity.class));
break;
default:
}

@ -9,6 +9,8 @@ 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 org.litepal.crud.DataSupport;
import java.util.List;
@ -38,7 +40,7 @@ public class ReadOrderActivity extends Activity {
*/
private void readFromSqlite(){
//从SQLite数据库读取历史订单列表
List<Order> orders=DataSupport.findAll(Order.class);
List<Order> orders= DataSupport.findAll(Order.class);
//遍历订单列表并输出订单信息
for(Order order:orders){
StringBuilder orderResult = new StringBuilder(); //新建订单结果信息

@ -0,0 +1,43 @@
package com.sbw.atrue.Order.Activity;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.sbw.atrue.Order.R;
import com.sbw.atrue.Order.Util.LuckyView;
//import com.showly.luckyactivity.view.LuckyView;
public class TurnActivity extends AppCompatActivity {
private LuckyView luckyView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_turnable);
initView();
initData();
initListener();
}
private void initView() {
luckyView = findViewById(R.id.lucky_view);
}
private void initData() {
}
private void initListener() {
luckyView.setLuckAnimationEndListener(new LuckyView.OnLuckAnimationEndListener() {
@Override
public void onLuckAnimationEnd(int pos, String msg) {
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}
});
}
}

@ -14,22 +14,26 @@ import com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum;
import com.sbw.atrue.Order.R;
public class horizonta_main extends AppCompatActivity {
private CustomHorizontalProgresNoNum horizontalProgress01;//水平不带进度
private CustomHorizontalProgresWithNum horizontalProgress1,horizontalProgress2,horizontalProgress3;//水平带进度
private Timer timer,timer2,timer3;
// private CustomHorizontalProgresWithNum horizontalProgress01;//水平不带进度
private CustomHorizontalProgresWithNum horizontalProgress01, horizontalProgress1,horizontalProgress2,horizontalProgress3;//水平带进度
private Timer timer;
private Timer timer1;
private Timer timer2;
private Timer timer3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
setContentView(R.layout.horizontalprogres);
horizontalProgress01 = (CustomHorizontalProgresNoNum) findViewById(R.id.horizontalProgress01);
horizontalProgress01 = (CustomHorizontalProgresWithNum) findViewById(R.id.horizontalProgress01);
horizontalProgress1 = (CustomHorizontalProgresWithNum) findViewById(R.id.horizontalProgress1);
horizontalProgress2 = (CustomHorizontalProgresWithNum) findViewById(R.id.horizontalProgress2);
horizontalProgress3 = (CustomHorizontalProgresWithNum) findViewById(R.id.horizontalProgress3);
horizontalProgress01.setProgress(0);
horizontalProgress01.setMax(100);
horizontalProgress1.setProgress(0);
horizontalProgress1.setMax(100);
@ -39,18 +43,43 @@ public class horizonta_main extends AppCompatActivity {
horizontalProgress3.setProgress(0);
horizontalProgress3.setMax(200);
/*
Timer timer1 = new Timer();
timer1.schedule(new TimerTask() {
@Override
public void run() {
//实时更新进度
if (horizontalProgress1.getProgress() >= 10) {//指定时间取消
timer.cancel();
}
horizontalProgress1.setProgress(horizontalProgress1.getProgress()+1);
}
}, 50, 50);
*/
timer1 = new Timer();
final Timer finalTimer = timer1;
timer1.schedule(new TimerTask() {
@Override
public void run() {
//实时更新进度
if (horizontalProgress1.getProgress() >= 12) {//指定时间取消
finalTimer.cancel();
}
horizontalProgress1.setProgress(horizontalProgress1.getProgress()+1);
}
}, 50, 50);
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//实时更新进度
if (horizontalProgress1.getProgress() >= 100) {//指定时间取消
if (horizontalProgress1.getProgress() >= 25) {//指定时间取消
timer.cancel();
}
horizontalProgress1.setProgress(horizontalProgress1.getProgress()+1);
horizontalProgress01.setProgress(horizontalProgress01.getProgress()+1);
}
}, 50, 50);
@ -59,13 +88,13 @@ public class horizonta_main extends AppCompatActivity {
@Override
public void run() {
//实时更新进度
if (horizontalProgress2.getProgress() >= 100) {//指定时间取消
if (horizontalProgress2.getProgress() >= 15) {//指定时间取消
timer2.cancel();
}
horizontalProgress2.setProgress(horizontalProgress2.getProgress()+1);
}
}, 40, 40);
}, 50, 50);
timer3 = new Timer();
@ -73,7 +102,7 @@ public class horizonta_main extends AppCompatActivity {
@Override
public void run() {
//实时更新进度
if (horizontalProgress3.getProgress() >= horizontalProgress3.getMax()) {//指定时间取消
if (horizontalProgress3.getProgress() >= 57) {//指定时间取消
timer3.cancel();
}
horizontalProgress3.setProgress(horizontalProgress3.getProgress()+1);
@ -81,6 +110,4 @@ public class horizonta_main extends AppCompatActivity {
}
}, 50, 50);
}
}

@ -0,0 +1,33 @@
package com.sbw.atrue.Order.Entity;
public class Comment {
String name; //评论者
String content; //评论内容
public Comment(){
}
public Comment(String name, String content){
this.name = name;
this.content = content;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,8 @@
package com.sbw.atrue.Order.Entity;
import org.litepal.LitePalApplication;
public class Custom extends LitePalApplication {
}

@ -0,0 +1,81 @@
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.TextView;
import com.sbw.atrue.Order.Util.AdapterComment;
import com.sbw.atrue.Order.Entity.Comment;
import com.sbw.atrue.Order.R;
import java.util.List;
/**
* Created by yyp on 2016/8/10.
*/
public class AdapterComment extends BaseAdapter {
Context context;
List<Comment> data;
public AdapterComment(Context c, List<Comment> data){
this.context = c;
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int i) {
return data.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
ViewHolder holder;
// 重用convertView
if(convertView == null){
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.item_comment, null);
holder.comment_name = (TextView) convertView.findViewById(R.id.comment_name);
holder.comment_content = (TextView) convertView.findViewById(R.id.comment_content);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
// 适配数据
holder.comment_name.setText(data.get(i).getName());
holder.comment_content.setText(data.get(i).getContent());
return convertView;
}
/**
* ,
* @param comment
*/
public void addComment(Comment comment){
data.add(comment);
notifyDataSetChanged();
}
/**
* 便GC
*/
public static class ViewHolder{
TextView comment_name;
TextView comment_content;
}
}

@ -1,56 +0,0 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 设置响应内容类型
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
try (PrintWriter out = response.getWriter()) {
//获得请求中传来的用户名和密码
String account = request.getParameter("account").trim();
String password = request.getParameter("password").trim();
//密码验证结果
Boolean verifyResult = verifyLogin(account, password);
Map<String, String> params = new HashMap<>();
JSONObject jsonObject = new JSONObject();
if (verifyResult) {
params.put("Result", "success");
} else {
params.put("Result", "failed");
}
jsonObject.put("params", params);
out.write(jsonObject.toString());
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
//验证用户名密码是否正确
private Boolean verifyLogin(String userName, String password) {
User user = UserDAO.queryUser(userName);
//账户密码验证
return null != user && password.equals(user.getPassword());
}
}

@ -0,0 +1,309 @@
package com.sbw.atrue.Order.Util;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
//import com.showly.luckyactivity.R;
import com.sbw.atrue.Order.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class LuckyView extends View {
private Paint mPaint;
private float mStrokeWidth = 5;
private int mRepeatCount = 5; // 转的圈数
private int mRectSize; // 矩形的宽和高(矩形为正方形)
private boolean mShouldStartFlag;
private boolean mShouldStartNextTurn = true; // 标记是否应该开启下一轮抽奖
private int mStartLuckPosition = 0; // 开始抽奖的位置
private int mCurrentPosition = -1; // 当前转圈所在的位置
private OnLuckAnimationEndListener mLuckAnimationEndListener;
/**
* mLuckNum
*/
private int mLuckNum = 3; // 默认最终中奖位置
private List<RectF> mRectFs; // 存储矩形的集合
private int[] mItemColor = {Color.parseColor("#ffefd6"), Color.parseColor("#ffefd6")}; // 矩形的颜色
private String[] mPrizeDescription = {"南一食堂", "南二食堂", "南三食堂", "北二食堂", "再来一次", "北三食堂", "中餐厅", "北一食堂", "开始"};
private int[] mLuckyPrizes = {R.drawable.nan1, R.drawable.nan2, R.drawable.nan3, R.drawable
.bei2, R.drawable.again, R.drawable.bei3, R.drawable.zhong, R.drawable.bei1 ,R
.drawable.begin};
private List<String> lettersBeans;
private float left;
private float top;
private Bitmap[] bitmaps;
private String[] luckyName;
private String[] id;
private int selectPos;
public LuckyView(Context context) {
this(context, null);
}
public LuckyView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public LuckyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // 抗锯齿
mPaint.setStyle(Paint.Style.FILL);
// mPaint.setStyle(Paint.Style.STROKE); // 设置样式为描边
mPaint.setStrokeWidth(mStrokeWidth); // 设置描边的宽度
mRectFs = new ArrayList<>();
}
public void setLuckAnimationEndListener(OnLuckAnimationEndListener luckAnimationEndListener) {
mLuckAnimationEndListener = luckAnimationEndListener;
}
public int getLuckNum() {
return mLuckNum;
}
public void setLuckNum(int luckNum) {
mLuckNum = luckNum;
}
public int[] getLuckyPrizes() {
return mLuckyPrizes;
}
public void setLuckyPrizes(int[] luckyPrizes) {
mLuckyPrizes = luckyPrizes;
}
public void setData(List<String> lettersBeans) {
this.lettersBeans = lettersBeans;
invalidate();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mRectSize = (Math.min(w, h)) / 3; // 矩形的宽高
mRectFs.clear(); // 当控件大小改变的时候清空数据
initNineRect();
}
/**
* 9
*/
private void initNineRect() {
final float width = getWidth();
// 加载前三个矩形
for (int i = 0; i < 3; i++) {
float left = i * mRectSize + 5;
float right = (i + 1) * mRectSize;
float top = 5;
float bottom = mRectSize;
RectF rectF = new RectF(left, top, right, bottom);
mRectFs.add(rectF);
}
// 加载第 4 个矩形
mRectFs.add(new RectF(width - mRectSize + 5, mRectSize + 5, width, 2 * mRectSize));
// 加载第 5~7 个矩形
for (int j = 3; j > 0; j--) {
float left = width - (4 - j) * mRectSize + 5;
float right = width - (3 - j) * mRectSize;
float top = 2 * mRectSize + 5;
float bottom = 3 * mRectSize;
RectF rectF = new RectF(left, top, right, bottom);
mRectFs.add(rectF);
}
// 加载第 8 个矩形
mRectFs.add(new RectF(5, mRectSize + 5, mRectSize, 2 * mRectSize));
// 加载中心第 9 个矩形
mRectFs.add(new RectF(mRectSize + 5, mRectSize + 5, 2 * mRectSize, 2 * mRectSize));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawNineRect(canvas);
drawNineBitmaps(canvas); // 填充奖品图片
drawNineText(canvas); // 填充奖品文字
}
/**
*
* leftThe position of the left side of the bitmap being drawn
* topThe position of the top side of the bitmap being drawn
*/
private void drawNineBitmaps(final Canvas canvas) {
for (int i = 0; i < mRectFs.size(); i++) {
RectF rectF = mRectFs.get(i);
// 将图片设置在每个矩形中央
left = rectF.left + mRectSize / 4;
top = rectF.top + mRectSize / 4;
canvas.drawBitmap(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), mLuckyPrizes[i]), mRectSize / 2, mRectSize / 2, false), left, top, null);
}
}
/**
*
* xhe x-coordinate of the origin of the text being drawn
* yThe y-coordinate of the baseline of the text being drawn
*/
private void drawNineText(Canvas canvas) {
for (int i = 0; i < mRectFs.size(); i++) {
RectF rectF = mRectFs.get(i);
float x = rectF.left + mRectSize / 4; // 将文字设置在每个矩形中央
float y = rectF.top + mRectSize - 20;
mPaint.setColor(Color.parseColor("#5e5448"));
mPaint.setStyle(Paint.Style.FILL);
mPaint.setTextSize(30); // unit px
if (i == mRectFs.size() - 1) {
canvas.drawText("", x, y, mPaint);
} else {
canvas.drawText(mPrizeDescription[i], x, y, mPaint);
}
}
}
/**
*
*/
private void drawNineRect(Canvas canvas) {
for (int x = 0; x < mRectFs.size(); x++) {
RectF rectF = mRectFs.get(x);
if (x == 8) {
mPaint.setColor(Color.WHITE);
} else {
if (mCurrentPosition == x) {
mPaint.setColor(Color.parseColor("#edcea9"));
} else {
mPaint.setColor(mItemColor[x % 2]); // 标记当前转盘经过的位置
}
}
canvas.drawRect(rectF, mPaint);
}
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mShouldStartFlag = mRectFs.get(8).contains(event.getX(), event.getY());
return true;
}
if (event.getAction() == MotionEvent.ACTION_UP) {
if (mShouldStartFlag) {
if (mRectFs.get(8).contains(event.getX(), event.getY())) {
// mLuckAnimationEndListener.onClickLuck();
startAnim(); // 判断只有手指落下和抬起都在中间的矩形内时才开始执行动画抽奖
}
mShouldStartFlag = false;
}
}
return super.onTouchEvent(event);
}
private void startAnim() {
if (!mShouldStartNextTurn) {
return;
}
Random random = new Random();
setLuckNum(random.nextInt(8)); // 生成 [0,8) 的随机整数
ValueAnimator animator = ValueAnimator.ofInt(mStartLuckPosition, mRepeatCount * 8 + mLuckNum)
.setDuration(5000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final int position = (int) animation.getAnimatedValue();
setCurrentPosition(position % 8);
mShouldStartNextTurn = false;
}
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mShouldStartNextTurn = true;
mStartLuckPosition = mLuckNum;
//最终选中的位置
if (mLuckAnimationEndListener != null) {
mLuckAnimationEndListener.onLuckAnimationEnd(mCurrentPosition,
mPrizeDescription[mCurrentPosition]);
}
}
});
animator.start();
}
private void setCurrentPosition(int position) {
mCurrentPosition = position;
invalidate(); // 强制刷新,在 UI 线程回调 onDraw()
}
public void setBitmap(Bitmap[] bitmaps1, String[] name, String[] strings) {
bitmaps = bitmaps1;
luckyName = name;
id = strings;
invalidate();
}
/**
* id
*
* @param datas
*/
public void setSelectId(int datas) {
String selectId = datas + "";
if (id != null && id.length != 0) {
for (int i = 0; i < id.length; i++) {
if (id[i].equals(selectId)) {
selectPos = i;
}
}
}
startAnim();
}
/**
*
*/
public interface OnLuckAnimationEndListener {
void onLuckAnimationEnd(int pos, String msg);
}
}

@ -1,51 +0,0 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
public class RegisterServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 设置响应内容类型
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
try (PrintWriter out = response.getWriter()) {
//获得请求中传来的用户名和密码
String account = request.getParameter("account").trim();
String password = request.getParameter("password").trim();
Map<String, String> params = new HashMap<>();
JSONObject jsonObject = new JSONObject();
if(isExist(account)){
params.put("Result", "账号已存在");
}else{
UserDAO.Register(account, password);
params.put("Result", "注册成功");
}
jsonObject.put("结果", params);
out.write(jsonObject.toString());
}
}
//判断用户是否存在
private Boolean isExist(String account) {
User user = UserDAO.queryUser(account);
if(user.getAccount().isEmpty()){
return false;
}else{
return true;
}
}
}

@ -1,79 +0,0 @@
private int socket_port=9999;
private boolean ifListen =true;
/**
*
*/
private Thread socketThread = new Thread() {
public void run() {
while (true) {
try {
if (serverSocket == null && ifListen) {
serverSocket = new ServerSocket(socket_port);
// serverSocket.setSoTimeout(60*1000);
} else if (serverSocket != null) {
socket = serverSocket.accept();
if (socket != null) {
DataInputStream in = new DataInputStream(new BufferedInputStream(socket
.getInputStream()));
try {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = in.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
byte[] data = outStream.toByteArray();
dataString = new String(data, "utf-8");
AppLog.Log(dataString);
} catch (Exception e) {
AppLog.Log(AppLog.LogType.ERROR, "DataService read: " + e);
destorySocket();
}
}
}
} catch (IOException e1) {
AppLog.Log(AppLog.LogType.ERROR, "DataService accept: " + e1);
destorySocket(); }
try {
Thread.sleep(Config.KEEP_ALIVE_RESPONSE_TIMEOUT);
} catch (InterruptedException e) {
AppLog.Log(e.toString());
}
}
}
};
public void startListen() {
ifListen = true;
if (!ifSocketThreadStart) {
ifSocketThreadStart = true;
socketThread.start();
}
}
public void stopListen() {
ifListen = false;
destorySocket();
}
private void destorySocket() {
AppLog.Log("destorySocket");
try {
if (serverSocket != null && !serverSocket.isClosed()) {
serverSocket.close();
}
} catch (IOException e) {
AppLog.Log(e.toString());
} finally {
serverSocket = null;
}
try {
if (socket != null && !socket.isClosed()) {
socket.close();
}
} catch (IOException e) {
AppLog.Log(e.toString());
} finally {
socket = null;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 966 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey">
<ListView
android:id="@+id/comment_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="50dp" />
<LinearLayout
android:id="@+id/rl_enroll"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="@color/white">
<ImageView
android:id="@+id/comment"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/comment"
android:layout_weight="1"
android:layout_gravity="center" />
<ImageView
android:id="@+id/chat"
android:layout_width="23dp"
android:layout_height="23dp"
android:src="@drawable/chat"
android:layout_weight="1"
android:layout_gravity="center"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/rl_comment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:visibility="gone"
android:layout_alignParentBottom="true">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey" />
<TextView
android:id="@+id/hide_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hide_down"
android:textSize="13sp"
android:textColor="@color/txtgrey"
android:drawableBottom="@drawable/hide_dowm"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/grey"
android:layout_toRightOf="@id/hide_down"
android:layout_marginLeft="10dp"/>
<EditText
android:id="@+id/comment_content"
android:hint="@string/comment_content"
android:textSize="15sp"
android:singleLine="true"
android:layout_width="240dp"
android:layout_height="match_parent"
android:background="@null"
android:layout_toRightOf="@id/hide_down"
android:layout_marginLeft="20dp"/>
<Button
android:id="@+id/comment_send"
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_margin="5dp"
android:text="@string/send"
android:textSize="13sp"
android:textColor="@color/white"
android:background="@color/mainColor"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="15dp"/>
</RelativeLayout>
</RelativeLayout>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
tools:context="com.sbw.atrue.Order.Activity.TurnActivity">
<com.sbw.atrue.Order.Util.LuckyView
android:id="@+id/lucky_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
tools:ignore="MissingClass" />
</RelativeLayout>

@ -19,7 +19,7 @@
android:textColor="#36513e"
android:layout_marginTop="20dp"
></TextView>
<com.sbw.atrue.Order.Activity.CustomHorizontalProgresNoNum
<com.sbw.atrue.Order.Activity.CustomHorizontalProgresWithNum
android:layout_marginTop="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/comment_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/mainColor"
android:textSize="15sp"
android:layout_marginLeft="15dp"
android:layout_marginRight="3dp"/>
<TextView
android:id="@+id/comment_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:textSize="15sp" />
</LinearLayout>

@ -18,7 +18,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="1425553230@qq.com"
android:text="hangchi@cauc.edu.cn"
android:textColor="#FFF"
android:textSize="14sp" />
@ -27,7 +27,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/person_email"
android:text="True"
android:text="航吃"
android:textColor="#FFF"
android:textSize="14sp" />

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

@ -10,7 +10,7 @@
<item
android:id="@+id/nav_money"
android:icon="@drawable/nav_task"
android:title="钱包" />
android:title="消费额度" />
<item
android:id="@+id/nav_setting"

@ -11,14 +11,24 @@
android:icon="@drawable/ic_backup"
android:title="Backup"
app:showAsAction="never"/>
<item
<!-- <item
android:id="@+id/delete"
android:icon="@drawable/ic_delete"
android:title="Delete"
app:showAsAction="never"/>
<item
app:showAsAction="never"/>-->
<!-- <item
android:id="@+id/setting"
android:icon="@drawable/ic_settings"
android:title="Setting"
app:showAsAction="never" />-->
<item
android:id="@+id/comment"
android:icon="@drawable/ic_settings"
android:title="Comment"
app:showAsAction="never" />
<item
android:id="@+id/turntable"
android:icon="@drawable/ic_settings"
android:title="TurnTable"
app:showAsAction="never" />
</menu>

@ -3,4 +3,164 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#ff4054</color>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="mainColor">#4dc445</color>
<!-- <color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#000000</color>-->
<color name="txtgrey">#7c7b7b</color>
<color name="greywhite">#aeacac</color>
<color name="white">#FFFFFF</color><!--白色 -->
<color name="ivory">#FFFFF0</color><!--象牙色 -->
<color name="lightyellow">#FFFFE0</color><!--亮黄色 -->
<color name="yellow">#FFFF00</color><!--黄色 -->
<color name="snow">#FFFAFA</color><!--雪白色 -->
<color name="floralwhite">#FFFAF0</color><!--花白色 -->
<color name="lemonchiffon">#FFFACD</color><!--柠檬绸色 -->
<color name="cornsilk">#FFF8DC</color><!--米绸色 -->
<color name="seashell">#FFF5EE</color><!--海贝色 -->
<color name="lavenderblush">#FFF0F5</color><!--淡紫红 -->
<color name="papayawhip">#FFEFD5</color><!--番木色 -->
<color name="blanchedalmond">#FFEBCD</color><!--白杏色 -->
<color name="mistyrose">#FFE4E1</color><!--浅玫瑰色 -->
<color name="bisque">#FFE4C4</color><!--桔黄色 -->
<color name="moccasin">#FFE4B5</color><!--鹿皮色 -->
<color name="navajowhite">#FFDEAD</color><!--纳瓦白 -->
<color name="peachpuff">#FFDAB9</color><!--桃色 -->
<color name="gold">#FFD700</color><!--金色 -->
<color name="pink">#FFC0CB</color><!--粉红色 -->
<color name="lightpink">#FFB6C1</color><!--亮粉红色 -->
<color name="orange">#FFA500</color><!--橙色 -->
<color name="lightsalmon">#FFA07A</color><!--亮肉色 -->
<color name="darkorange">#FF8C00</color><!--暗桔黄色 -->
<color name="coral">#FF7F50</color><!--珊瑚色 -->
<color name="hotpink">#FF69B4</color><!--热粉红色 -->
<color name="tomato">#FF6347</color><!--西红柿色 -->
<color name="orangered">#FF4500</color><!--红橙色 -->
<color name="deeppink">#FF1493</color><!--深粉红色 -->
<color name="fuchsia">#FF00FF</color><!--紫红色 -->
<color name="magenta">#FF00FF</color><!--红紫色-->
<color name="red">#FF0000</color><!--红色 -->
<color name="oldlace">#FDF5E6</color><!--老花色 -->
<color name="lightgoldenrodyellow">#FAFAD2</color><!--亮金黄色 -->
<color name="linen">#FAF0E6</color><!--亚麻色 -->
<color name="antiquewhite">#FAEBD7</color><!--古董白 -->
<color name="salmon">#FA8072</color><!--鲜肉色 -->
<color name="ghostwhite">#F8F8FF</color><!--幽灵白 -->
<color name="mintcream">#F5FFFA</color><!--薄荷色 -->
<color name="whitesmoke">#F5F5F5</color><!--烟白色 -->
<color name="beige">#F5F5DC</color><!--米色 -->
<color name="wheat">#F5DEB3</color><!--浅黄色 -->
<color name="sandybrown">#F4A460</color><!--沙褐色 -->
<color name="azure">#F0FFFF</color><!--天蓝色 -->
<color name="honeydew">#F0FFF0</color><!--蜜色 -->
<color name="aliceblue">#F0F8FF</color><!--艾利斯兰 -->
<color name="khaki">#F0E68C</color><!--黄褐色 -->
<color name="lightcoral">#F08080</color><!--亮珊瑚色 -->
<color name="palegoldenrod">#EEE8AA</color><!--苍麒麟色 -->
<color name="violet">#EE82EE</color><!--紫罗兰色 -->
<color name="darksalmon">#E9967A</color><!--暗肉色 -->
<color name="lavender">#E6E6FA</color><!--淡紫色 -->
<color name="lightcyan">#E0FFFF</color><!--亮青色 -->
<color name="burlywood">#DEB887</color><!--实木色 -->
<color name="plum">#DDA0DD</color><!--洋李色 -->
<color name="gainsboro">#DCDCDC</color><!--淡灰色 -->
<color name="crimson">#DC143C</color><!--暗深红色 -->
<color name="palevioletred">#DB7093</color><!--苍紫罗兰色-->
<color name="goldenrod">#DAA520</color><!--金麒麟色 -->
<color name="orchid">#DA70D6</color><!--淡紫色 -->
<color name="thistle">#D8BFD8</color><!--蓟色 -->
<color name="lightgray">#D3D3D3</color><!--亮灰色 -->
<color name="lightgrey">#D3D3D3</color><!--亮灰色 -->
<color name="tan">#D2B48C</color><!--茶色 -->
<color name="chocolate">#D2691E</color><!--巧可力色 -->
<color name="peru">#CD853F</color><!--秘鲁色 -->
<color name="indianred">#CD5C5C</color><!--印第安红 -->
<color name="mediumvioletred">#C71585</color><!--中紫罗兰色 -->
<color name="silver">#C0C0C0</color><!--银色 -->
<color name="darkkhaki">#BDB76B</color><!--暗黄褐色 -->
<color name="rosybrown">#BC8F8F</color><!--褐玫瑰红 -->
<color name="mediumorchid">#BA55D3</color><!--中粉紫色 -->
<color name="darkgoldenrod">#B8860B</color><!--暗金黄色 -->
<color name="firebrick">#B22222</color><!--火砖色 -->
<color name="powderblue">#B0E0E6</color><!--粉蓝色 -->
<color name="lightsteelblue">#B0C4DE</color><!--亮钢兰色-->
<color name="paleturquoise">#AFEEEE</color><!--苍宝石绿 -->
<color name="greenyellow">#ADFF2F</color><!--黄绿色 -->
<color name="lightblue">#ADD8E6</color><!--亮蓝色 -->
<color name="darkgray">#A9A9A9</color><!--暗灰色 -->
<color name="darkgrey">#A9A9A9</color><!--暗灰色 -->
<color name="brown">#A52A2A</color><!--褐色 -->
<color name="sienna">#A0522D</color><!--赭色 -->
<color name="darkorchid">#9932CC</color><!--暗紫色 -->
<color name="palegreen">#98FB98</color><!--苍绿色 -->
<color name="darkviolet">#9400D3</color><!--暗紫罗兰色 -->
<color name="mediumpurple">#9370DB</color><!--中紫色 -->
<color name="lightgreen">#90EE90</color><!--亮绿色 -->
<color name="darkseagreen">#8FBC8F</color><!--暗海兰色 -->
<color name="saddlebrown">#8B4513</color><!--重褐色 -->
<color name="darkmagenta">#8B008B</color><!--暗洋红 -->
<color name="darkred">#8B0000</color><!--暗红色 -->
<color name="blueviolet">#8A2BE2</color><!--紫罗兰蓝色 -->
<color name="lightskyblue">#87CEFA</color><!--亮天蓝色 -->
<color name="skyblue">#87CEEB</color><!--天蓝色 -->
<color name="gray">#808080</color><!--灰色 -->
<color name="grey">#808080</color><!--灰色 -->
<color name="olive">#808000</color><!--橄榄色 -->
<color name="purple">#800080</color><!--紫色 -->
<color name="maroon">#800000</color><!--粟色 -->
<color name="aquamarine">#7FFFD4</color><!--碧绿色 -->
<color name="chartreuse">#7FFF00</color><!--黄绿色 -->
<color name="lawngreen">#7CFC00</color><!--草绿色 -->
<color name="mediumslateblue">#7B68EE</color><!--中暗蓝色-->
<color name="lightslategray">#778899</color><!--亮蓝灰 -->
<color name="lightslategrey">#778899</color><!--亮蓝灰 -->
<color name="slategray">#708090</color><!--灰石色 -->
<color name="slategrey">#708090</color><!--灰石色 -->
<color name="olivedrab">#6B8E23</color><!--深绿褐色 -->
<color name="slateblue">#6A5ACD</color><!--石蓝色 -->
<color name="dimgray">#696969</color><!--暗灰色 -->
<color name="dimgrey">#696969</color><!--暗灰色 -->
<color name="mediumaquamarine">#66CDAA</color><!--中绿色-->
<color name="cornflowerblue">#6495ED</color><!--菊兰色 -->
<color name="cadetblue">#5F9EA0</color><!--军兰色 -->
<color name="darkolivegreen">#556B2F</color><!--暗橄榄绿 -->
<color name="indigo">#4B0082</color><!--靛青色 -->
<color name="mediumturquoise">#48D1CC</color><!--中绿宝石-->
<color name="darkslateblue">#483D8B</color><!--暗灰蓝色 -->
<color name="steelblue">#4682B4</color><!--钢兰色 -->
<color name="royalblue">#4169E1</color><!--皇家蓝 -->
<color name="turquoise">#40E0D0</color><!--青绿色 -->
<color name="mediumseagreen">#3CB371</color><!--中海蓝 -->
<color name="limegreen">#32CD32</color><!--橙绿色 -->
<color name="darkslategray">#2F4F4F</color><!--暗瓦灰色 -->
<color name="darkslategrey">#2F4F4F</color><!--暗瓦灰色 -->
<color name="seagreen">#2E8B57</color><!--海绿色 -->
<color name="forestgreen">#228B22</color><!--森林绿 -->
<color name="lightseagreen">#20B2AA</color><!--亮海蓝色 -->
<color name="dodgerblue">#1E90FF</color><!--闪兰色 -->
<color name="midnightblue">#191970</color><!--中灰兰色 -->
<color name="aqua">#00FFFF</color><!--浅绿色 -->
<color name="cyan">#00FFFF</color><!--青色 -->
<color name="springgreen">#00FF7F</color><!--春绿色 -->
<color name="lime">#00FF00</color><!--酸橙色 -->
<color name="mediumspringgreen">#00FA9A</color><!--中春绿色 -->
<color name="darkturquoise">#00CED1</color><!--暗宝石绿 -->
<color name="deepskyblue">#00BFFF</color><!--深天蓝色 -->
<color name="darkcyan">#008B8B</color><!--暗青色 -->
<color name="teal">#008080</color><!--水鸭色 -->
<color name="green">#008000</color><!--绿色 -->
<color name="darkgreen">#006400</color><!--暗绿色 -->
<color name="blue">#0000FF</color><!--蓝色 -->
<color name="mediumblue">#0000CD</color><!--中兰色 -->
<color name="darkblue">#00008B</color><!--暗蓝色 -->
<color name="navy">#000080</color><!--海军色 -->
<color name="black">#000000</color><!--黑色 -->
</resources>

@ -1,4 +1,7 @@
<resources>
<string name="app_name">航吃Hang吃</string>
<string name="随即转盘">吃货大赏</string>
<string name="hide_down">隐藏</string>
<string name="comment_content">输入评论内容</string>
<string name="send">发送</string>
</resources>

@ -1,11 +0,0 @@
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipartAsset">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/D:/Program%20Files%20(x86)/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/communication/ic_message_black_24dp.xml" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="outputName" value="ic_message_black_24dp" />
<entry key="sourceFile" value="C:\Users\ACER" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>

@ -1,116 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</component>

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="delegatedBuild" value="false" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
</GradleProjectSettings>
</option>
</component>
</project>

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

@ -1,17 +0,0 @@
### 简介
- 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")

@ -1,38 +0,0 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.sbw.atrue.Order"
minSdkVersion 16
targetSdkVersion 28
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(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
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 'com.yanzhenjie.nohttp:nohttp:1.1.4'
implementation 'com.google.code.gson:gson:2.8.6'
implementation files('libs/mysql-connector-java-5.1.38.jar')
}

@ -1,21 +0,0 @@
# 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

@ -1 +0,0 @@
[{"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":{}}]

@ -1,26 +0,0 @@
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());
}
}

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sbw.atrue.Order">
<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">
<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>

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<litepal>
<dbname value="order" ></dbname>
<version value="8" ></version>
<list>
<mapping class="com.sbw.atrue.Order.Entity.ProductOrder"></mapping>
<mapping class="com.sbw.atrue.Order.Entity.Order"></mapping>
</list>
</litepal>

@ -1,62 +0,0 @@
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.41.175";
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 = "lyx123";
// 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();
}
}

@ -1,68 +0,0 @@
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);
}
}

@ -1,160 +0,0 @@
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();
}
}

@ -1,164 +0,0 @@
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) {
}
});
}
/**
* 便
*
* @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();
}
}

@ -1,21 +0,0 @@
package com.sbw.atrue.Order.Activity;
import com.yanzhenjie.nohttp.InitializationConfig;
import com.yanzhenjie.nohttp.NoHttp;
import org.litepal.LitePalApplication;
public class MyApplication extends LitePalApplication {
@Override
public void onCreate() {
super.onCreate();
InitializationConfig config = InitializationConfig.newBuilder(this)
.connectionTimeout(30 * 1000)
.readTimeout(30 * 1000)
.retry(10)
.build();
NoHttp.initialize(config);
Connection.mymysql();
}
}

@ -1,104 +0,0 @@
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) {
}
});
}
});
}
}

@ -1,398 +0,0 @@
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;
}
}

@ -1,137 +0,0 @@
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"));
}
}

@ -1,186 +0,0 @@
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); //两次密码输入不一致提示消失
}
}
}

@ -1,103 +0,0 @@
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) {
}
});
}
});
}
}

@ -1,258 +0,0 @@
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();
}
}

@ -1,459 +0,0 @@
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) {
}
});
}
}

@ -1,37 +0,0 @@
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;}
}

@ -1,87 +0,0 @@
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;
}
}

@ -1,152 +0,0 @@
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 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;
}
}

@ -1,58 +0,0 @@
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;
}
}

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

Loading…
Cancel
Save