Android automatically logs on after remembering the password

Source: Internet
Author: User

Android automatically logs on after remembering the password

 

/**
*
* @ Author alex
* @ Version 5:25:45
*
*/
Public class LoginActivity extends Activity {
Private EditText name;
Private EditText pass;
Private CheckBox isRemenber;
Private CheckBox isLoginSelf;
Private Button longin;
Private ProgressDialog mDialog;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Name = (EditText) findViewById (R. id. et_name );
Pass = (EditText) findViewById (R. id. et_pass );
IsRemenber = (CheckBox) findViewById (R. id. isremenber );
IsLoginSelf = (CheckBox) findViewById (R. id. isloginself );
Longin = (Button) findViewById (R. id. longin );

Final SharedPreferences pre = getSharedPreferences (longinvalue, MODE_WORLD_WRITEABLE );
If (pre! = Null ){
// Remember the password
If (pre. getBoolean (isrmb, false) = true ){
Name. setText (pre. getString (name, null ));
Pass. setText (pre. getString (pass, null ));
IsRemenber. setChecked (true );
}
If (pre. getBoolean (islgs, false) = true ){
IsLoginSelf. setChecked (true );
CreatDialog ();
New Thread (){
Public void run (){
Try {


Thread. sleep (3000 );
If (mDialog. isShowing ()){
MDialog. dismiss ();
}
Intent intent2 = new Intent (LoginActivity. this, Show. class );
StartActivity (intent2 );
} Catch (Exception e ){
// TODO: handle exception
}
}
}. Start ();
}
}
IsRemenber. setOnCheckedChangeListener (new OnCheckedChangeListener (){

@ Override
Public void onCheckedChanged (CompoundButton buttonView, boolean isChecked ){
// TODO Auto-generated method stub
If (isRemenber. isChecked () = false ){
IsLoginSelf. setChecked (false );
}
}
});
IsLoginSelf. setOnCheckedChangeListener (new OnCheckedChangeListener (){

@ Override
Public void onCheckedChanged (CompoundButton buttonView, boolean isChecked ){
// TODO Auto-generated method stub
IsRemenber. setChecked (true );
}
});
Longin. setOnClickListener (new OnClickListener (){

@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
If (! Name. getText (). toString (). equals ()&&! Pass. getText (). toString (). equals ()){
If (isLoginSelf. isChecked ()){
Pre. edit (). putBoolean (isrmb, true). putBoolean (islgs, true). putString (name, name. getText (). toString ())
. PutString (pass, pass. getText (). toString (). commit ();
} Else {
If (isRemenber. isChecked ()){
Pre. edit (). putBoolean (isrmb, true). putBoolean (islgs, false). putString (name, name. getText (). toString ())
. PutString (pass, pass. getText (). toString (). commit ();
} Else {
Pre. edit (). putBoolean (isrmb, false). putBoolean (islgs, false). putString (name, name. getText (). toString ())
. PutString (pass, pass. getText (). toString (). commit ();
}
}
Intent intent = new Intent (LoginActivity. this, Show. class );
StartActivity (intent );
} Else {
Toast. makeText (getApplicationContext (), the password or account cannot be blank !, Toast. LENGTH_LONG). show ();
}


}
});
}
Private void creatDialog (){
MDialog = new ProgressDialog (this );
MDialog. setTitle (in verification );
MDialog. setMessage (logging in, please wait );
MDialog. setIndeterminate (true );
MDialog. setCancelable (true );
MDialog. show ();

}
}

Import android. app. Activity;
Import android. OS. Bundle;


Public class Show extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
SetContentView (R. layout. show );
}
}


Package = alex.sias.com
Android: versionCode = 1
Android: versionName = 1.0>









Android: icon = @ drawable/icon
Android: label = @ string/app_name
Android: theme = @ android: style/Theme. NoTitleBar. Fullscreen>
Android: name =. LoginActivity
Android: label = @ string/app_name>












 

Two layout files are used.


Android: orientation = vertical
Android: layout_width = fill_parent
Android: layout_height = fill_parent
Android: background = @ drawable/chat_bg_default
>
Android: layout_height = 50dp
Android: layout_width = fill_parent
Android: gravity = center
Android: textSize = 24sp
Android: text = logon page
Android: textColor = @ color/white
Android: background = @ drawable/song_index_item_bg/>
Android: id = @ + id/iv
Android: layout_height = 220dp
Android: layout_width = 230dp
Android: layout_marginTop = 110dp
Android: src = @ drawable/background
Android: layout_centerHorizontal = true
Android: scaleType = fitXY/>
Android: id = @ + id/TV _name
Android: layout_height = wrap_content
Android: layout_width = wrap_content
Android: textSize = 15sp
Android: layout_marginTop = 7dp
Android: text = Account:
Android: layout_alignLeft = @ + id/iv
Android: layout_alignTop = @ + id/iv
Android: layout_marginLeft = 7dp
Android: textColor = @ color/green/>
Android: id = @ + id/et_name
Android: layout_height = 25dp
Android: layout_width = 210dp
Android: layout_marginTop = 7dp
Android: layout_below = @ + id/TV _name
Android: background = @ drawable/shape
Android: layout_alignLeft = @ + id/TV _name/>
Android: id = @ + id/TV _pass
Android: layout_height = wrap_content
Android: layout_width = wrap_content
Android: textSize = 15sp
Android: text = password:
Android: layout_alignLeft = @ + id/TV _name
Android: layout_below = @ + id/et_name
Android: layout_marginTop = 7dp
Android: textColor = @ color/green/>
Android: id = @ + id/et_pass
Android: layout_height = 25dp
Android: layout_width = 210dp
Android: background = @ drawable/shape
Android: layout_marginTop = 7dp
Android: layout_below = @ + id/TV _pass
Android: layout_alignLeft = @ + id/TV _name/>
Android: id = @ + id/isremenber
Android: layout_height = wrap_content
Android: layout_width = wrap_content
Android: layout_alignLeft = @ + id/TV _name
Android: layout_marginTop = 10dp
Android: text = Remember password
Android: textSize = 11sp
Android: textColor = @ color/huise
Android: layout_below = @ + id/et_pass
Android: button = @ drawable/mycheckbox/>
Android: id = @ + id/isloginself
Android: layout_height = wrap_content
Android: layout_width = wrap_content
Android: layout_alignRight = @ + id/et_name
Android: layout_marginTop = 10dp
Android: text = Automatic Logon
Android: textSize = 11sp
Android: textColor = @ color/huise
Android: layout_below = @ + id/et_pass
Android: button = @ drawable/mycheckbox/>
Android: id = @ + id/longin
Android: layout_height = 25dp
Android: layout_width = 210dp
Android: layout_below = @ + id/isloginself
Android: layout_alignLeft = @ + id/et_pass
Android: layout_marginTop = 10dp
Android: text = Login
Android: gravity = center
Android: background = @ drawable/loginbtn/>

 


Xmlns: android = http://schemas.android.com/apk/res/android
Android: orientation = vertical
Android: layout_width = match_parent
Android: layout_height = match_parent
Android: background = @ color/white>
Android: layout_height = fill_parent
Android: layout_width = fill_parent
Android: text =!
Android: textSize = 40sp
Android: gravity = center/>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.