美文网首页
登陆窗口

登陆窗口

作者: pengtuanyuan | 来源:发表于2016-10-12 23:06 被阅读0次

package com.example.pengtuanyuan.logindemo;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    private EditText input_name;
    private EditText input_password;
    private CheckBox checkBox1;
    private Button button1;
    private Context mContext;

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

        mContext = this;

        input_name = (EditText) findViewById(R.id.ed_input_name);
        input_password = (EditText) findViewById(R.id.ed_input_password);
        checkBox1 = (CheckBox) findViewById(R.id.checkbox1);
        button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(this);


        Map<String,String>map=UserInfoUtil.getUserInfo();
        if (map!=null){
            String username=map.get("username");
            String password=map.get("password");
            input_name.setText(username);
            input_password.setText(password);
        }
    }

    private void login(){
        String username=input_name.getText().toString().trim();
        String password=input_password.getText().toString().trim();

        boolean isChecked=checkBox1.isChecked();
        if(TextUtils.isEmpty(username)||TextUtils.isEmpty(password)){
            Toast.makeText(mContext,"Name and password cannot be empty",Toast.LENGTH_SHORT).show();
            return;
        }

        if (isChecked) {
            boolean result = UserInfoUtil.saveUserInfo(username, password);

            if (result) {
                Toast.makeText(mContext, "Name and password is saved", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "Name and password save failed", Toast.LENGTH_SHORT).show();
            }
        }else {
            Toast.makeText(mContext, "Name and password not need to save", Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button1:
                login();
                break;
            default:
                break;
        }
    }
}
-----------------------------------------------------

package com.example.pengtuanyuan.logindemo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class UserInfoUtil {
    public static boolean saveUserInfo(String username, String password) {

        try {

            String userinfo=username+"##"+password;
            String path="/data/data/com.example.pengtuanyuan.logindemo/";
            File file=new File(path,"userinfo.txt");
            FileOutputStream fileOutStream =new FileOutputStream(file);
            fileOutStream.write(userinfo.getBytes());
            fileOutStream.close();
            return true;


        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }

    public static Map<String,String>getUserInfo(){

        try {
            String path="/data/data/com.example.pengtuanyuan.logindemo/";
            File file=new File(path,"userinfo.txt");
            FileInputStream fileInputStream=new FileInputStream(file);
            BufferedReader bufferReader= new BufferedReader(new InputStreamReader(fileInputStream));
            String readLine=bufferReader.readLine();
            String[] split=readLine.split("##");
            HashMap<String,String> hashMap=new HashMap<String,String>();
            hashMap.put("username",split[0]);
            hashMap.put("password",split[1]);
            bufferReader.close();
            fileInputStream.close();
            return hashMap;



        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
-----------------------------------------------------------

相关文章

  • 登陆窗口

  • 2021-03-17

    1、需求描述(必填) 线上系统主要包含个人登陆窗口和企业登陆窗口。 个人登陆后需录入身份信息并进入答题页面,并开启...

  • python 用python写一个登陆窗口

    我玩一个新语言的时候都会拿这个语言写一个登陆窗口,可能是因为登陆窗口简单吧。。。

  • python3.5+selenium3.4自动化测试2_参数化

    这边继续讲一个简单得登陆窗口,一般登陆窗口保护用户名和密码,那测试登陆的时候必然会用到不同的用户名和密码,这个时候...

  • mysql报错

    2059 黑窗口登录 登陆Mysql后执行命令

  • javascript实现的窗口抖动代码实例

    javascript实现的窗口抖动代码实例:窗口抖动效果在很多地方都有应用,例如网易的登陆窗口就有这样的效果,当登...

  • Win10 远程桌面登陆闪退问题处理

    在远程阿里云服务器时,输入账号密码后,远程桌面卡住,一段时间后登陆窗口关闭,再次打开时,出现远程桌面登陆窗口闪退情...

  • 海康8700视频监控平台

    登陆界面: 登陆以后的首页 分组管理 录像回放 下载窗口 客流分析 人脸对比 热力分析 门禁控制 对讲 对讲通话 ...

  • windows下xshell登陆和mac电脑登录linux服务器

    登陆 备注:按照gif进行完美重现 设置字体和右键粘贴 尝试ftp传输 备注:这里还可以上传,左窗口拖向右窗口即为...

  • QT学习——笔记(二)

    实现多窗口对话 参照教程第二章 实现了窗口的关闭弹出和不关闭弹出image.png可以用来制作登陆界面和多窗口互动...

网友评论

      本文标题:登陆窗口

      本文链接:https://www.haomeiwen.com/subject/eyxwyttx.html