Skip to content

Commit

Permalink
hzuapps#2 提交实验2代码 惠大宿舍缴电费app
Browse files Browse the repository at this point in the history
  • Loading branch information
wzq-55552 committed Mar 12, 2019
1 parent 7e18d27 commit 37760ed
Show file tree
Hide file tree
Showing 15 changed files with 1,215 additions and 0 deletions.
25 changes: 25 additions & 0 deletions students/soft1714080902133/lab2/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.hzuapps.androidlabs.soft1714080902133">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1714080902133PerfectInformationActivity"></activity>
<activity android:name=".Soft1714080902133HomeActivity" />
<activity android:name=".Soft1714080902133UserActivity" />
<activity android:name=".Soft1714080902133ForgetPasswordActivity" />
<activity android:name=".Soft1714080902133RegisterActivity" />
<activity android:name=".Soft1714080902133LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.hzuapps.androidlabs.soft1714080902133;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

//惠大宿舍缴电费app 没想到实验2只需建立activity就好,讲课前我就打了好多
//登录页面,点击忘记密码,跳转过来,实现修改密码,后期加更多
public class Soft1714080902133ForgetPasswordActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902133_forgetpasswordactivity);

Toolbar toolbar = (Toolbar)findViewById(R.id.forget_password_toolbar);
setSupportActionBar(toolbar);//获得ToolBar实例
ActionBar actionBar = getSupportActionBar();
if (actionBar!=null){
actionBar.setDisplayHomeAsUpEnabled(true);//菜单,默认图片返回图片
}
}



@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home://点击了返回,结束该活动,返回上一个活动
Intent intent = new Intent(Soft1714080902133ForgetPasswordActivity.this, Soft1714080902133LoginActivity.class);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.hzuapps.androidlabs.soft1714080902133;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


//惠大宿舍缴电费app
//主页,查询,缴费,充值
//只实现了一个点击事件,以后实验补充
public class Soft1714080902133HomeActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902133_homeactivity);
Button b1 = findViewById(R.id.home_button4);
//点击事件
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//意图实现跳转Activity
Intent intent = new Intent(Soft1714080902133HomeActivity.this, Soft1714080902133UserActivity.class);
startActivity(intent);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package edu.hzuapps.androidlabs.soft1714080902133;


import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

//惠大宿舍缴电费app
/**
*手机号/学号为账号,登陆界面,还有登陆后的界面,登陆前界面
* 大体改了我以前做过的
* 后端服务器数据库后期加进去,暂时实现点击跳转到主页面,不判断用户是否在数据库
*/
public class Soft1714080902133LoginActivity extends AppCompatActivity{

// 登陆按钮
Button loginbutton;
// 显示账号和密码
EditText number,password;

// 创建等待框
private ProgressDialog dialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902133_loginactivity);

//界面标题bar
Toolbar toolbar = (Toolbar) findViewById(R.id.login_toolbar);
setSupportActionBar(toolbar);//获得ToolBar实例
ActionBar actionBar = getSupportActionBar();
if (actionBar!=null){
actionBar.setDisplayHomeAsUpEnabled(true);//菜单,默认图片返回图片
}

// 获取控件
number = findViewById(R.id.number);
password = findViewById(R.id.password);
loginbutton = findViewById(R.id.login_button);

// 设置按钮监听器,实现点击
loginbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isUserNameAndPwdValid()&&number.getText().toString().equals("1714080902133")
&&password.getText().toString().equals("123456")){
Intent intent = new Intent(Soft1714080902133LoginActivity.this,Soft1714080902133HomeActivity.class);
startActivity(intent);//登录成功
}
}
});
}


//跳转注册页面
public void user_register(View view) {
Intent intent = new Intent(Soft1714080902133LoginActivity.this, Soft1714080902133RegisterActivity.class);
startActivity(intent);
finish();
}

//跳转忘记密码页面
public void forget_password(View view) {
Intent intent = new Intent(Soft1714080902133LoginActivity.this, Soft1714080902133ForgetPasswordActivity.class);
startActivity(intent);
finish();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home://点击了返回,结束该活动,返回上一个活动
Intent intent = new Intent(Soft1714080902133LoginActivity.this, Soft1714080902133HomeActivity.class);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}

//判断用户名和密码是否有效
public boolean isUserNameAndPwdValid() {// 用户名和密码不得为空
if (number.getText().toString().equals("")||!(number.getText().toString().length()==11
||number.getText().toString().length()==13)){
Toast.makeText(this,"手机号/学号格式错误!" ,
Toast.LENGTH_SHORT).show();
return false;
} else if (password.getText().toString().equals("")) {
Toast.makeText(this, "密码不能为空!",
Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package edu.hzuapps.androidlabs.soft1714080902133;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import edu.hzuapps.androidlabs.Soft1714080902133.javabean.Soft1714080902133User;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static android.provider.ContactsContract.CommonDataKinds.Website.URL;

//惠大宿舍缴电费app
//注册后完善用户信息
public class Soft1714080902133PerfectInformationActivity extends AppCompatActivity {

private Soft1714080902133User user = new Soft1714080902133User();

// 显示位置声明
private TextView perfectNumber;
private TextView perfectNickname;
private TextView perfectSex;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902133_perfectinformationactivity);

Toolbar toolbar = findViewById(R.id.perfect_information_toolbar);
setSupportActionBar(toolbar);//获得ToolBar实例
ActionBar actionBar = getSupportActionBar();
if (actionBar!=null){
actionBar.setDisplayHomeAsUpEnabled(true);//菜单,默认图片返回图片
}

Intent intent = getIntent();
String telephone = intent.getStringExtra("telephone");
String password = intent.getStringExtra("password");
user.setTelephone(telephone);
user.setPassword(password);

// 显示位置id
perfectNumber = findViewById(R.id.perfect_number_show);
perfectNickname = findViewById(R.id.perfect_nickname_show);
perfectSex = findViewById(R.id.perfect_sex_show);
}


// 根据结果修改显示
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
String number = null;
if (data != null) {
number = data.getStringExtra("number");
}
perfectNumber.setText(number);
user.setNumber(number);
}
break;
case 1:
if (resultCode == RESULT_OK) {
String nickname = null;
if (data != null) {
nickname = data.getStringExtra("nickname");
}
perfectNickname.setText(nickname);
user.setNickname(nickname);
}
case 2:
if (resultCode == RESULT_OK) {
String sex = null;
if (data != null) {
sex = data.getStringExtra("sex");
}
perfectSex.setText(sex);
user.setSex(sex);
}
default:
}
}

//提交 添加信息给User
public void submit(View view) {
register();
Intent intent = new Intent(Soft1714080902133PerfectInformationActivity.this,Soft1714080902133HomeActivity.class);
startActivity(intent);
}

private void register() {
new Thread(new Runnable() {
@Override
public void run() {
try {
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new FormBody.Builder()
.add("number", user.getNumber())
.add("telephone", user.getTelephone())
.add("nickname", user.getNickname())
.add("sex", user.getSex())
.add("password", user.getPassword())
.build();
Request request = new Request.Builder()
.url(URL)
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
String data = null;
if (response.body() != null) {
data = response.body().string();
}
showResult(data);
} catch (Exception e) {
e.printStackTrace();
}

}
}).start();
}

//显示结果UI操作
private void showResult(final String data) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (data.equals("true")) {
Toast.makeText(Soft1714080902133PerfectInformationActivity.this, "注册成功,将会在一秒后跳转首页",
Toast.LENGTH_LONG).show();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent intent = new Intent(Soft1714080902133PerfectInformationActivity.this, Soft1714080902133User.class);
startActivity(intent);
finish();
} else {
Toast.makeText(Soft1714080902133PerfectInformationActivity.this,"此学号已被注册,如有问题请联系客服",
Toast.LENGTH_SHORT).show();
}
}
});
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home://点击了返回,结束该活动,返回上一个活动
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 37760ed

Please sign in to comment.