parent
7889a9e970
commit
d1f1936b09
Binary file not shown.
@ -0,0 +1,200 @@
|
||||
package com.example.logistics.ui;
|
||||
|
||||
import com.example.logistics.R;
|
||||
import com.example.logistics.manager.goodManager;
|
||||
import com.example.logistics.manager.operationManager;
|
||||
import com.example.logistics.manager.userManager;
|
||||
import com.example.logistics.entity.User;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
public class LoginActivity extends Activity {
|
||||
|
||||
private int islogin = 0;
|
||||
private Button loginButton;
|
||||
private Button signUpButton;
|
||||
private Button forgetButton;
|
||||
private Button phonenumButton;
|
||||
private AlertDialog alert;
|
||||
private Button changeButton;
|
||||
private EditText fphonenum;
|
||||
private EditText fpassword;
|
||||
int flag = 0; //flag = 0 是用户名登录;=1是手机号
|
||||
|
||||
// 调用Actvity
|
||||
private String TAG = "LoginActivity";
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
loginButton = (Button) this.findViewById(R.id.LoginButton);
|
||||
signUpButton = (Button) this.findViewById(R.id.SignUpButton);
|
||||
forgetButton = (Button) this.findViewById(R.id.forget);
|
||||
phonenumButton = (Button) this.findViewById(R.id.phonenum);
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
|
||||
|
||||
View view2 = View.inflate(LoginActivity.this, R.layout.forget, null);
|
||||
|
||||
builder.setTitle("取件").setView(view2);
|
||||
|
||||
alert = builder.create();
|
||||
|
||||
changeButton = (Button) view2.findViewById(R.id.change);
|
||||
fphonenum = (EditText) view2.findViewById(R.id.fphonenum);
|
||||
fpassword = (EditText) view2.findViewById(R.id.fpassword);
|
||||
|
||||
loginButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
login(v);
|
||||
Log.d(TAG, "login");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
signUpButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(LoginActivity.this, SignUpActivity.class);
|
||||
Log.d(TAG, "signup");
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
forgetButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
alert.show();
|
||||
changeButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.d(TAG, "change password");
|
||||
change(view);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
|
||||
phonenumButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
userName.setHint("请输入手机号");
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void change(View view){
|
||||
String phoneunm = fphonenum.getText().toString().trim();
|
||||
String password = fpassword.getText().toString().trim();
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
userManager userManager = new userManager();
|
||||
|
||||
int msg = userManager.change(phoneunm, password);
|
||||
|
||||
Log.d(TAG, "change");
|
||||
if(msg != 1){
|
||||
Log.d(TAG, "pickup,failed");
|
||||
hand2.sendEmptyMessage(msg);
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "change,success");
|
||||
|
||||
hand2.sendEmptyMessage(msg);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public void login(View view){
|
||||
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
|
||||
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run(){
|
||||
userManager userManager = new userManager();
|
||||
int msg = 0;
|
||||
if(flag == 0){
|
||||
msg = userManager.login(userName.getText().toString().trim(), passWord.getText().toString().trim());
|
||||
}else if(flag == 1){
|
||||
msg = userManager.loginByPhone(userName.getText().toString().trim(), passWord.getText().toString().trim());
|
||||
|
||||
}
|
||||
Log.e("MAin", "msg");
|
||||
hand1.sendEmptyMessage(msg);
|
||||
if(msg == 1){
|
||||
User owner = userManager.findUser(userName.getText().toString().trim());
|
||||
Intent intent = new Intent(LoginActivity.this, MenuActivity.class);
|
||||
if(flag == 1){
|
||||
intent.putExtra("user", userName.getText().toString().trim());
|
||||
}else{
|
||||
intent.putExtra("user", owner.getPhoneNum());
|
||||
}
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
final Handler hand1 = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg){
|
||||
if(msg.what == 0){
|
||||
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT).show();
|
||||
}else if(msg.what == 1){
|
||||
Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
|
||||
islogin = 1;
|
||||
}else if(msg.what == 2){
|
||||
Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_SHORT).show();
|
||||
}else if(msg.what == 3){
|
||||
Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
@SuppressLint("HandlerLeak")
|
||||
final Handler hand2 = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if(msg.what == 0){
|
||||
Toast.makeText(LoginActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
|
||||
}else if(msg.what == 1) {
|
||||
Toast.makeText(LoginActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.example.logistics.ui;
|
||||
|
||||
import com.example.logistics.R;
|
||||
import com.example.logistics.manager.userManager;
|
||||
import com.example.logistics.entity.User;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private int islogin = 0;
|
||||
// 调用Actvity
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Button loginButton = (Button) this.findViewById(R.id.LoginButton);
|
||||
Button signUpButton = (Button) this.findViewById(R.id.SignUpButton);
|
||||
|
||||
loginButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
login(v);
|
||||
}
|
||||
}
|
||||
);
|
||||
signUpButton.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, SignUpActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void login(View view){
|
||||
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
|
||||
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run(){
|
||||
userManager userManager = new userManager();
|
||||
int msg = userManager.login(userName.getText().toString().trim(), passWord.getText().toString().trim());
|
||||
Log.e("MAin", "msg");
|
||||
hand1.sendEmptyMessage(msg);
|
||||
if(msg == 1){
|
||||
User owner = userManager.findUser(userName.getText().toString().trim());
|
||||
Intent intent = new Intent(MainActivity.this, MenuActivity.class);
|
||||
intent.putExtra("user", owner.getPhoneNum());
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
final Handler hand1 = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg){
|
||||
if(msg.what == 0){
|
||||
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT).show();
|
||||
}else if(msg.what == 1){
|
||||
Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
|
||||
islogin = 1;
|
||||
}else if(msg.what == 2){
|
||||
Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_SHORT).show();
|
||||
}else if(msg.what == 3){
|
||||
Toast.makeText(getApplicationContext(), "账号不存在", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<EditText
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fphonenum"
|
||||
android:hint="请输入注册时手机号"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<EditText
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fpassword"
|
||||
android:hint="请输入新密码"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="修改"
|
||||
android:id="@+id/change"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue