package com.example.alimjan.hello_world;

 /**
* Created by alimjan on 7/4/2017.
*/ import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener; public class class_3_6 extends AppCompatActivity implements OnClickListener { private RadioGroup rg_login;
private RadioButton rb_password;
private RadioButton rb_verifycode;
private EditText et_phone;
private TextView tv_password;
private EditText et_password;
private Button btn_forget;
private CheckBox ck_remember;
private Button btn_login; private int mRequestCode = 0;
private int mType = 0;
private boolean bRemember = false;
private String mPassword = "111111";
private String mVerifyCode; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.code_3_6);
rg_login = (RadioGroup) findViewById(R.id.rg_login);
rb_password = (RadioButton) findViewById(R.id.rb_password);
rb_verifycode = (RadioButton) findViewById(R.id.rb_verifycode);
et_phone = (EditText) findViewById(R.id.et_phone);
tv_password = (TextView) findViewById(R.id.tv_password);
et_password = (EditText) findViewById(R.id.et_password);
btn_forget = (Button) findViewById(R.id.btn_forget);
ck_remember = (CheckBox) findViewById(R.id.ck_remember);
btn_login = (Button) findViewById(R.id.btn_login); rg_login.setOnCheckedChangeListener(new RadioListener());
ck_remember.setOnCheckedChangeListener(new CheckListener());
et_phone.addTextChangedListener(new HideTextWatcher(et_phone));
et_password.addTextChangedListener(new HideTextWatcher(et_password));
btn_forget.setOnClickListener(this);
btn_login.setOnClickListener(this); ArrayAdapter<String> typeAdapter = new ArrayAdapter<String>(this,
R.layout.item_select, typeArray);
typeAdapter.setDropDownViewResource(R.layout.item_dropdown);
Spinner sp_type = (Spinner) findViewById(R.id.sp_type);
sp_type.setPrompt("请选择用户类型");
sp_type.setAdapter(typeAdapter);
sp_type.setSelection(mType);
sp_type.setOnItemSelectedListener(new TypeSelectedListener());
} private class RadioListener implements RadioGroup.OnCheckedChangeListener {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.rb_password) {
tv_password.setText("登录密码:");
et_password.setHint("请输入密码");
btn_forget.setText("忘记密码");
ck_remember.setVisibility(View.VISIBLE);
} else if (checkedId == R.id.rb_verifycode) {
tv_password.setText(" 验证码:");
et_password.setHint("请输入验证码");
btn_forget.setText("获取验证码");
ck_remember.setVisibility(View.INVISIBLE);
}
}
} private String[] typeArray = {"个人用户", "公司用户"};
class TypeSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
mType = arg2;
} public void onNothingSelected(AdapterView<?> arg0) {
}
} private class CheckListener implements CompoundButton.OnCheckedChangeListener {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.getId() == R.id.ck_remember) {
bRemember = isChecked;
}
}
} private class HideTextWatcher implements TextWatcher {
private EditText mView;
private int mMaxLength;
private CharSequence mStr; public HideTextWatcher(EditText v) {
super();
mView = v;
mMaxLength = ViewUtil.getMaxLength(v);
} @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mStr = s;
} @Override
public void afterTextChanged(Editable s) {
if (mStr == null || mStr.length() == 0)
return;
if ((mStr.length() == 11 && mMaxLength == 11) ||
(mStr.length() == 6 && mMaxLength == 6)) {
ViewUtil.hideOneInputMethod(class_3_6.this, mView);
}
}
} @Override
public void onClick(View v) {
String phone = et_phone.getText().toString();
if (v.getId() == R.id.btn_forget) {
if (phone==null || phone.length()<11) {
Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
return;
}
if (rb_password.isChecked() == true) {
Intent intent = new Intent(this, class_3_6_1.class);
intent.putExtra("phone", phone);
startActivityForResult(intent, mRequestCode);
} else if (rb_verifycode.isChecked() == true) {
mVerifyCode = String.format("%06d", (int)(Math.random()*1000000%1000000));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请记住验证码");
builder.setMessage("手机号"+phone+",本次验证码是"+mVerifyCode+",请输入验证码");
builder.setPositiveButton("好的", null);
AlertDialog alert = builder.create();
alert.show();
}
} else if (v.getId() == R.id.btn_login) {
if (phone==null || phone.length()<11) {
Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
return;
}
if (rb_password.isChecked() == true) {
if (et_password.getText().toString().equals(mPassword) != true) {
Toast.makeText(this, "请输入正确的密码", Toast.LENGTH_SHORT).show();
return;
} else {
loginSuccess();
}
} else if (rb_verifycode.isChecked() == true) {
if (et_password.getText().toString().equals(mVerifyCode) != true) {
Toast.makeText(this, "请输入正确的验证码", Toast.LENGTH_SHORT).show();
return;
} else {
loginSuccess();
}
}
}
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == mRequestCode && data!=null) {
//用户密码已改为新密码
mPassword = data.getStringExtra("new_password");
}
} //从修改密码页面返回登录页面,要清空密码的输入框
@Override
protected void onRestart() {
et_password.setText("");
super.onRestart();
} private void loginSuccess() {
String desc = String.format("您的手机号码是%s,类型是%s。恭喜你通过登录验证,点击“确定”按钮返回上个页面",
et_phone.getText().toString(), typeArray[mType]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("登录成功");
builder.setMessage(desc);
builder.setPositiveButton("确定返回", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton("我再看看", null);
AlertDialog alert = builder.create();
alert.show();
} public static void startHome(Context mContext) {
Intent intent = new Intent(mContext, class_3_6.class);
mContext.startActivity(intent);
} }
 package com.example.alimjan.hello_world;

 /**
* Created by alimjan on 7/4/2017.
*/ import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast; public class class_3_6_1 extends AppCompatActivity implements OnClickListener { private EditText et_password_first;
private EditText et_password_second;
private EditText et_verifycode;
private String mVerifyCode;
private String mPhone; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.code_3_6_1);
et_password_first = (EditText) findViewById(R.id.et_password_first);
et_password_second = (EditText) findViewById(R.id.et_password_second);
et_verifycode = (EditText) findViewById(R.id.et_verifycode);
findViewById(R.id.btn_verifycode).setOnClickListener(this);
findViewById(R.id.btn_confirm).setOnClickListener(this);
mPhone = getIntent().getStringExtra("phone");
} @Override
public void onClick(View v) {
if (v.getId() == R.id.btn_verifycode) {
if (mPhone==null || mPhone.length()<11) {
Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
return;
}
mVerifyCode = String.format("%06d", (int) (Math.random() * 1000000 % 1000000));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请记住验证码");
builder.setMessage("手机号"+mPhone+",本次验证码是"+mVerifyCode+",请输入验证码");
builder.setPositiveButton("好的", null);
AlertDialog alert = builder.create();
alert.show();
} else if (v.getId() == R.id.btn_confirm) {
String password_first = et_password_first.getText().toString();
String password_second = et_password_second.getText().toString();
if (password_first==null || password_first.length()<6 ||
password_second==null || password_second.length()<6) {
Toast.makeText(this, "请输入正确的新密码", Toast.LENGTH_SHORT).show();
return;
}
if (password_first.equals(password_second) != true) {
Toast.makeText(this, "两次输入的新密码不一致", Toast.LENGTH_SHORT).show();
return;
}
if (et_verifycode.getText().toString().equals(mVerifyCode) != true) {
Toast.makeText(this, "请输入正确的验证码", Toast.LENGTH_SHORT).show();
return;
} else {
Toast.makeText(this, "密码修改成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("new_password", password_first);
setResult(Activity.RESULT_OK, intent);
finish();
}
}
} }
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="5dp" > <RadioGroup
android:id="@+id/rg_login"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" > <RadioButton
android:id="@+id/rb_password"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:checked="true"
android:gravity="left|center"
android:text="密码登录"
android:textColor="@color/black"
android:textSize="17sp" /> <RadioButton
android:id="@+id/rb_verifycode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:checked="false"
android:gravity="left|center"
android:text="验证码登录"
android:textColor="@color/black"
android:textSize="17sp" />
</RadioGroup> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/tv_type"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="  我是:"
android:textColor="@color/black"
android:textSize="17sp" /> <Spinner
android:id="@+id/sp_type"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/tv_type"
android:gravity="left|center"
android:spinnerMode="dialog" />
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/tv_phone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="手机号码:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/tv_phone"
android:background="@drawable/editext_selector"
android:gravity="left|center"
android:hint="请输入手机号码"
android:inputType="number"
android:maxLength="11"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:textCursorDrawable="@drawable/text_cursor"
android:textSize="17sp" />
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/tv_password"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="登录密码:"
android:textColor="@color/black"
android:textSize="17sp" /> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/tv_password" > <EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/editext_selector"
android:gravity="left|center"
android:hint="请输入密码"
android:inputType="numberPassword"
android:maxLength="6"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:textCursorDrawable="@drawable/text_cursor"
android:textSize="17sp" /> <Button
android:id="@+id/btn_forget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="center"
android:text="忘记密码"
android:textColor="@color/black"
android:textSize="17sp" />
</FrameLayout>
</RelativeLayout> <CheckBox
android:id="@+id/ck_remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_selector"
android:checked="false"
android:padding="10dp"
android:text="记住密码"
android:textColor="@color/black"
android:textSize="17sp" /> <Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"
android:textColor="@color/black"
android:textSize="22sp" /> </LinearLayout>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="5dp" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/tv_password_first"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="输入新密码:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_password_first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/tv_password_first"
android:background="@drawable/editext_selector"
android:gravity="left|center"
android:hint="请输入新密码"
android:inputType="numberPassword"
android:maxLength="11"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:textCursorDrawable="@drawable/text_cursor"
android:textSize="17sp" />
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/tv_password_second"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="确认新密码:"
android:textColor="@color/black"
android:textSize="17sp" /> <EditText
android:id="@+id/et_password_second"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/tv_password_second"
android:background="@drawable/editext_selector"
android:gravity="left|center"
android:hint="请再次输入新密码"
android:inputType="numberPassword"
android:maxLength="11"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:textCursorDrawable="@drawable/text_cursor"
android:textSize="17sp" />
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" > <TextView
android:id="@+id/tv_verifycode"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="  验证码:"
android:textColor="@color/black"
android:textSize="17sp" /> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/tv_verifycode" > <EditText
android:id="@+id/et_verifycode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/editext_selector"
android:gravity="left|center"
android:hint="请输入验证码"
android:inputType="numberPassword"
android:maxLength="6"
android:textColor="@color/black"
android:textColorHint="@color/grey"
android:textCursorDrawable="@drawable/text_cursor"
android:textSize="17sp" /> <Button
android:id="@+id/btn_verifycode"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="center"
android:text="获取验证码"
android:textColor="@color/black"
android:textSize="17sp" />
</FrameLayout>
</RelativeLayout> <Button
android:id="@+id/btn_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="确定"
android:textColor="@color/black"
android:textSize="22sp" /> </LinearLayout>

Android 开发笔记___登陆app的更多相关文章

  1. Android 开发笔记___基本适配器的使用__BaseAdapter

    之前用到过ArryAdapter适用于纯文本的列表数据,SimpleAdapter适用于带图标的列表数据,但在实际应用中常常有更复杂的列表,比如同一项中存在多个控件,这时候用前面的两个会比较复杂,而且 ...

  2. Android 开发笔记___时间选择器---timePicker

    像datepicker一样,也有timepicker. 同样有timepickerdialog 所用到的方法还是一样,监听时间选择器的变化. package com.example.alimjan.h ...

  3. Android 开发笔记___实战项目:购物车

    购物车的应用很广泛,电商app基本上都有它的身影.由于它用到了多种存储方式,通过项目对数据的存储有更高层次的了解. 1.设计思路 首先看看购物车的外观.第一次进入时里面是空的,去购物页面加入购物车以后 ...

  4. Android 开发笔记___存储方式__共享参数__sharedprefences

    Android 的数据存储方式有四种,这次是[共享参数__sharedprefences] 听起来挺别扭的,平时看到的app里面,当用户删除了一些软件以后下次安装,发现原来的设置还在,这种情况就是把一 ...

  5. Android 开发笔记___复选框__checkbox

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  6. Android 开发笔记___初级控件之实战__计算器

    功能简单,实现并不难,对于初学者可以总和了解初级控件的基本使用. 用到的知识点如下: 线性布局 LinearLayout:整体界面是从上往下的,因此需要垂直方向的linearlayout:下面每行四个 ...

  7. Android 开发笔记___图像按钮__imageButton

    IMAGEBUTTON 其实派生自image view,而不是派生自button.,image view拥有的属性和方法,image button 统统拥有,只是imagebutton有个默认的按钮外 ...

  8. Android 开发笔记___滚动视图__scroll view

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  9. Android 开发笔记___图像视图__简单截屏

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

随机推荐

  1. 第4章 同步控制 Synchronization ----同步机制的摘要

    同步机制摘要Critical Section Critical section(临界区)用来实现"排他性占有".适用范围是单一进程的各线程之间.它是:  一个局部性对象,不是一个核 ...

  2. AES加解密算法Qt实现

    [声明] (1) 本文源码 在一位未署名网友源码基础上,利用Qt编程,实现了AES加解密算法,并添加了文件加解密功能.在此表示感谢!该源码仅供学习交流,请勿用于商业目的. (2) 图片及描述 除图1外 ...

  3. [转]HDFS HA 部署安装

    1. HDFS 2.0 基本概念 相比于 Hadoop 1.0,Hadoop 2.0 中的 HDFS 增加了两个重大特性,HA 和 Federaion.HA 即为 High Availability, ...

  4. JSP入门 el表达式

    我们已经知道el是jsp-2.0规范的一部分,tomcat-5.x版本以上都已经能够支持jsp-2.0规范,但在更低版本的tomcat和webphere,weblogic中还是无法使用这一便捷方式. ...

  5. TeamFlowy——结合Teambition与Workflowy提高生产力

    Teambition是一个跨平台的团队协作和项目管理工具,相当于国外的Trello.使用Teambition可以像使用白板与便签纸一样来管理项目进度,如下图所示. Teambition虽然便于管理项目 ...

  6. Django进阶篇【1】

    注:本篇是Django进阶篇章,适合人群:有Django基础,关于Django基础篇,将在下一章节中补充! 首先我们一起了解下Django整个请求生命周期: Django 请求流程,生命周期: 路由部 ...

  7. 用MXNet实现mnist的生成对抗网络(GAN)

    用MXNet实现mnist的生成对抗网络(GAN) 生成式对抗网络(Generative Adversarial Network,简称GAN)由一个生成网络与一个判别网络组成.生成网络从潜在空间(la ...

  8. Java面向对象 网络编程 上

     Java面向对象 网络编程 上 知识概要:                     (1)网络模型 (2)网络通讯要素 (3)UDP TCP 概念 (4)Socket (5)UDP TCP 传输 ...

  9. JavaScript设计模式--简单工厂模式

    一,介绍 工厂模式创建对象(视为工厂里的产品)时无需指定创建对象的具体类. 工厂模式定义一个用于创建对象的接口,这个接口由子类决定实例化哪一个类.该模式使一个类的实例化延迟到了子类.而子类可以重写接口 ...

  10. 小程序1_app.json配置

    1 window配置: window属性主要用于设置小程序的状态栏,导航条,标题,窗口背景色 直接在app.json里配置即可 2 tabBar底部导航 一般程序都会有底部导航栏,这个同样只要在app ...