Compare commits
No commits in common. '772acb4157843c786fb4b029890a13e0b1931bb8' and '87a0cc3ea90a7e87e2d6b9ec7bb7bbeba6f228fe' have entirely different histories.
772acb4157
...
87a0cc3ea9
@ -1,33 +0,0 @@
|
|||||||
package net.micode.notes.tool;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import net.micode.notes.data.LoginData;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class CheckUtils {
|
|
||||||
public LoginData loginData = new LoginData();
|
|
||||||
|
|
||||||
public CheckUtils(Context context) throws IOException, ClassNotFoundException {
|
|
||||||
loginData.read(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
//验证
|
|
||||||
public boolean check(String account, String password){
|
|
||||||
HashMap<String,String> data = loginData.getLoginData();
|
|
||||||
Iterator<HashMap.Entry<String, String>> it = data.entrySet().iterator();
|
|
||||||
while(it.hasNext()){
|
|
||||||
Map.Entry<String,String> entry = it.next();
|
|
||||||
String account1 = entry.getKey();
|
|
||||||
String password1 = entry.getValue();
|
|
||||||
if(account1.equals(account) && password1.equals(password)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,135 +0,0 @@
|
|||||||
package net.micode.notes.ui;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import net.micode.notes.R;
|
|
||||||
import net.micode.notes.tool.CheckUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.zip.Inflater;
|
|
||||||
|
|
||||||
public class LoginActivity extends Activity {
|
|
||||||
String account;
|
|
||||||
String password;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
this.setContentView(R.layout.login);
|
|
||||||
|
|
||||||
//保存输入信息
|
|
||||||
EditText inputAccount = (EditText)findViewById(R.id.login_aacount);
|
|
||||||
EditText inputPassword = (EditText) findViewById(R.id.login_password);
|
|
||||||
|
|
||||||
inputAccount.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
account = s.toString();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
inputPassword.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
password = s.toString();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//登录按钮
|
|
||||||
Button loginButton = (Button) findViewById(R.id.login_accept);
|
|
||||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
CheckUtils checkUtils = null;
|
|
||||||
try {
|
|
||||||
checkUtils = new CheckUtils(LoginActivity.this);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(checkUtils.check(account,password)){
|
|
||||||
Intent intent = new Intent(LoginActivity.this,NoteEditActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Toast checkErrorToast = Toast.makeText(LoginActivity.this,R.string.check_error,Toast.LENGTH_SHORT);
|
|
||||||
checkErrorToast.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//注册按钮
|
|
||||||
Button registerButton = (Button) findViewById(R.id.login_register);
|
|
||||||
registerButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
//输入非空
|
|
||||||
if(account != null && password != null) {
|
|
||||||
CheckUtils checkUtils = null;
|
|
||||||
try {
|
|
||||||
checkUtils = new CheckUtils(LoginActivity.this);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
checkUtils.loginData.write(account,password,LoginActivity.this);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Toast registerOKToast = Toast.makeText(LoginActivity.this, R.string.register_ok, Toast.LENGTH_SHORT);
|
|
||||||
registerOKToast.show();
|
|
||||||
|
|
||||||
Intent intent = new Intent(LoginActivity.this, NoteEditActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
account = null;
|
|
||||||
password = null;
|
|
||||||
|
|
||||||
Toast toast = Toast.makeText(LoginActivity.this,R.string.input_error,Toast.LENGTH_SHORT);
|
|
||||||
toast.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue