登录模板

XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#f6f6f6">
    <RelativeLayout
        android:id="@+id/log_back_lian"
        android:layout_width="60dp"
        android:layout_height="49dp">
        <ImageView
            android:id="@+id/mimie_log_back"
            android:layout_centerVertical="true"
            android:layout_width="17dp"
            android:layout_height="10dp"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="10dp"
            android:src="@mipmap/juxing" />
    </RelativeLayout>

        <ImageView
            android:layout_gravity="center_horizontal"
            android:layout_width="85dp"
            android:layout_height="85dp"
            android:src="@mipmap/logo" />

    <RelativeLayout
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#FFFFFF">

        <EditText
            android:id="@+id/mime_log_phone"
            android:textSize="14sp"
            android:textColorHint="#c9c9c9"
            android:inputType="phone"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null"
            android:gravity="center"
            android:hint="请输入手机号" />
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"/>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="#FFFFFFFF">

        <EditText
            android:id="@+id/mime_log_password"
            android:textSize="14sp"
            android:textColorHint="#c9c9c9"
            android:inputType="textPassword"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null"
            android:gravity="center"
            android:hint="请输入密码" />
    </RelativeLayout>

    <TextView
        android:id="@+id/mime_login"
        android:textSize="15sp"
        android:layout_marginTop="25dp"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:background="@drawable/log_background"
        android:text="立即登录"
        android:textColor="@color/textcolor"
        android:layout_width="330dp"
        android:layout_height="38dp" />

    <RelativeLayout
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="13sp"
            android:id="@+id/log_forgetpassword"
            android:layout_marginLeft="17dp"
            android:textColor="#ff4c4c"
            android:text="忘记密码"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:textSize="13sp"
            android:id="@+id/log_registeruser"
            android:layout_marginRight="17dp"
            android:layout_alignParentRight="true"
            android:textColor="#ff4c4c"
            android:text="注册用户"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RelativeLayout>
</LinearLayout>
activity文件


public class LogActivity extends BaseActivity implements View.OnClickListener {

    private TextView txtforgetpass;
    private TextView txtregistuser;
    private TextView mime_login;
    private EditText mime_log_phone;
    private EditText mime_log_password;
    private RequestQueue requestQueue;
    private String phoneNum;
    private String passw;
    private String soleId;
    private JSONObject result;
    private ProgressDialog progressDialog;
    private RelativeLayout log_back_lian;
    private SharedPreferences sp;
    private SharedPreferences.Editor edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_log);
        progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("正在登录...");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

        sp = getSharedPreferences("config", MODE_PRIVATE);
        edit = sp.edit();

        requestQueue = VolleyUtils.getQueue(getApplicationContext());
        txtforgetpass = (TextView) findViewById(R.id.log_forgetpassword);
        txtforgetpass.setOnClickListener(this);
        txtregistuser = (TextView) findViewById(R.id.log_registeruser);
        txtregistuser.setOnClickListener(this);
        mime_log_phone = (EditText) findViewById(R.id.mime_log_phone);
        mime_log_password = (EditText) findViewById(R.id.mime_log_password);
        mime_login = (TextView) findViewById(R.id.mime_login);
        mime_login.setOnClickListener(this);

        findViewById(R.id.mimie_log_back).setOnClickListener(this);
        log_back_lian = (RelativeLayout) findViewById(R.id.log_back_lian);
        log_back_lian.setOnClickListener(this);

    }

    
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            //忘记密码
            case R.id.log_forgetpassword:
                final Intent intent = new Intent(this, ForgetPassActivity.class);
                startActivity(intent);
                break;
            //用户注册
            case R.id.log_registeruser:
                Intent intent2 = new Intent(this, RegisterActivity.class);
                startActivity(intent2);
                break;
            //用户登录
            case R.id.mime_login:
                phoneNum = mime_log_phone.getText().toString().trim();
                String passWor = mime_log_password.getText().toString().trim();
                soleId = App.getSoleId(this);
                if (soleId != null) {
                    if (phoneNum.equals("")) {
                        Toast.makeText(this, "请输入手机号码", Toast.LENGTH_SHORT).show() ;
                    } else if (passWor.equals("")) {
                        Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
                    } else {
                        progressDialog.show();
                        final String pass = passWor + "easyLink0826";
                        String md5Value = MD5Util.getMd5Value(pass);
                        passw = MD5Util.getMd5Value(md5Value);
                        StringRequest stringRegister = new StringRequest(StringRequest.Method.POST, URL, new Response.Listener<String>() {
                            @Override
                            public void onResponse(String s) {
                                try {
                                    JSONObject jsonObject = new JSONObject(s);
                                    boolean success = jsonObject.getBoolean("success");
                                    String msg = jsonObject.getString("message");
                                    String errorCode = jsonObject.getString("errorCode");

                                    if ("0".equals(errorCode)) {
                                        Toast.makeText(LogActivity.this, msg, Toast.LENGTH_SHORT).show();
                                        progressDialog.cancel();
                                        App.isTrue = true;
                                        App.flag = true;
                                        result = jsonObject.getJSONObject("result");
                                        writeConfig(result);
                                        Intent intent1 = new Intent();
                                        intent1.putExtra("nickname", result.getString("nickname"));
                                        intent1.putExtra("sex", result.getString("sex"));
                                        intent1.putExtra("head", result.getString("head"));
                                        setResult(88, intent1);
                                        finish();
                                    }  else {
                                        Toast.makeText(LogActivity.this, msg, Toast.LENGTH_SHORT).show();
                                        progressDialog.cancel();
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError volleyError) {
                                progressDialog.cancel();
                            }
                        }) {
                            @Override
                            protected Map<String, String> getParams() throws AuthFailureError {
                                MyLog.d("ttt","参数username"+phoneNum+"pass"+passw+"soleid"+soleId);
                                Map<String, String> map = new HashMap();
                                map.put("username", phoneNum);
                                map.put("password", passw);
                                map.put("soleId", soleId);

                                return map;
                            }
                        };
                        requestQueue.add(stringRegister);
                    }

                } else {
                    progressDialog.cancel();
                    Toast.makeText(LogActivity.this, "设备号码不存在,请查看手机设备编号", Toast.LENGTH_SHORT).show();
                }

                break;
            case R.id.mimie_log_back:
            case R.id.log_back_lian:
                finish();
                break;
        }
    }
   
    public void writeConfig(Login login) {
        SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString("id", login.getId());       
        edit.commit();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值