Android如何实现机房座位预约系统
这篇文章主要介绍Android如何实现机房座位预约系统,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
成都创新互联是一家专业提供振安企业网站建设,专注与成都网站制作、做网站、H5响应式网站、小程序制作等业务。10年已为振安众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
具体内容如下
这周要去武汉开会,下周项目就得用上,所以,比较紧。加上导师不懂Android开发,只要开会就改需求,/(ㄒoㄒ)/~~反正他说先让学校用着,移动端和服务器的开发就给了两周时间。所以功能实现的比较简单,但代码做的比较容易扩展,都留了接口,后面更新起来也好做一些。通过这个工程,对Struts2的拦截器有了一些新体会。随着项目变大代码量变多,自然而然就会想起用一些设计模式了。不然代码根本没办法看。
整体是4个fragment,每个fragment里都有课程表的布局,课程可以从服务器传过来动态生成。其实很多都可以复用的布局,为了代码结构清晰,都分开写了。不然需要加控制器,调试起来心累。写的不好,还请大家多指教。做的还不完善,弄完以后再传上来。
Application里对数据进行持久化,这么做发现程序变得比较容易控制了。
Application
package com.example.myapplication; import android.app.Application; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class CustomApplication extends Application { public static final String serverAddress = "http://192.168.1.119"; // public static final String serverAddress = "http://10.187.86.63"; public static final String serverPort = "8080/Person_proj/upload"; // public static final String serverPort = "8000"; private static final String DEFAULT_NAME = ""; private static final String DEFAULT_ID = "-1"; private String name; private String id; private String room; private String myOrder="NULL"; private boolean isLogin = false; public boolean isLogin() { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); return sp.getBoolean("islogin", false); } /** * 0为 未登录 * 1为登录 */ public void setLogin(boolean isLogin) { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); Editor edit = sp.edit(); edit.putBoolean("islogin", isLogin); edit.commit(); } private int version; public int getVersion() { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); return sp.getInt("version",0); } public void setVersion(int version) { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); Editor edit = sp.edit(); edit.putInt("version",version); edit.commit(); } public String getMyOrder() { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); return sp.getString("order","NULL"); } public void setMyOrder(String myOrder) { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); Editor edit = sp.edit(); edit.putString("order",myOrder); edit.commit(); } @Override public void onCreate() { super.onCreate(); setName(DEFAULT_NAME); // 初始化全局变量 setId(DEFAULT_ID); } public void setName(String name) { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); Editor edit = sp.edit(); edit.putString("name", name); edit.commit(); } public String getName() { SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE); return sp.getString("name", "none"); } public String getId() { return id; } public void setId(String id) { this.id = id; } public void setRoom(String room) { this.room = room; } public String getRoom() { return room; } }
做注册时的逻辑判断,onClick事件里:
boolean cancel = false; View focusView = null; String id = builder.getUserId().trim(); String password = builder.getPassword().trim(); String passwordConfirm = builder.getPasswordConfirm().trim(); final String username = builder.getUsername().trim(); // Check for a valid password. if (TextUtils.isEmpty(password)) { cancel = true; focusView = builder.getStuPwdEditText(); } // Check for a valid password. if (TextUtils.isEmpty(passwordConfirm)) { cancel = true; focusView = builder.getStuPwdConfirmEditText(); } if (!password.equals(passwordConfirm)) { cancel = true; focusView = builder.getStuPwdEditText(); } // Check for a valid Id. if (TextUtils.isEmpty(id)) { cancel = true; focusView = builder.getStuIdEditText(); } // Check for a valid username. if (TextUtils.isEmpty(username)) { cancel = true; focusView = builder.getStuNameEditText(); } if(!MatchUtils.match(password)||!MatchUtils.match(passwordConfirm)){ cancel = true; focusView = builder.getStuPwdEditText(); ToastUtils.MyToast(getApplicationContext(), "密码只能为6位数字!"); } if (cancel) { ToastUtils.MyToast(getApplicationContext(), "输入有误,请从新输入!"); focusView.requestFocus(); } else { //...这里做的网络请求 // TODO signup 提交服务器Get请求 // 符合接口规范 final String url =app.serverAddress+":"+app.serverPort+"?"+"action=signin"+"&"+"username="+username+"&"+"oldpassword="+password; HttpUtils http = new HttpUtils(); http.send(HttpMethod.GET, url, new RequestCallBack() { @Override public void onSuccess(ResponseInfo responseInfo) { Log.i("tag", "============success============"+responseInfo.result); ToastUtils.MyToast(getApplicationContext(), responseInfo.result); if(responseInfo.result.equals("success")){ //注册成功,自动实现登录 app.setLogin(true); app.setName(username); //更新UI Message m = Message.obtain(); m.what=1; handler.sendMessage(m); ToastUtils.MyToast(getApplicationContext(), "注册成功,学号:"+username); }else{ ToastUtils.MyToast(getApplicationContext(), responseInfo.result); } dialog.dismiss(); } @Override public void onFailure(HttpException error, String msg) { ToastUtils.MyToast(getApplicationContext(), msg); dialog.dismiss(); } }); }
以上是“Android如何实现机房座位预约系统”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
网页标题:Android如何实现机房座位预约系统
文章网址:http://hbruida.cn/article/jegpes.html