Remembering the implementation of password and automatic login interface (v)

Source: Internet
Author: User

You can't get around the weather, but you can change your mood. You can't change your looks, but you can master yourself. You can't foresee tomorrow, but you can cherish today.


This content: Remember the password and automatic login interface implementation


Example



here is the Res/layout/activity_login.xml layout file: (Login interface )

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:background=" @drawable/L Ogin "> <imagebutton android:id=" @+id/img_btn "android:layout_width=" Wrap_content "android:l     ayout_height= "Wrap_content" android:layout_alignparentright= "true" android:background= "@drawable/quit"/> <textview android:id= "@+id/tv_zh" android:layout_width= "Wrap_content" android:layout_height= "3        5DP "android:layout_marginleft=" 15DP "android:layout_margintop=" 12DP "android:gravity=" Bottom " android:text= "Account:" android:textcolor= "#000000" android:textsize= "20sp"/> <edittext Android : id= "@+id/et_zh" android:layout_width= "match_parent" android:layout_height= "40DP" Android:layout_belo w= "@+id/tv_zh" Android:layout_marginleft= "15DP" android:layout_marginright= "12DP"/> <textview android:id= "@+id/tv_pws"        Android:layout_width= "Wrap_content" android:layout_height= "35DP" android:layout_below= "@+id/et_zh" android:layout_marginleft= "15DP" android:layout_margintop= "12DP" android:gravity= "Bottom" Android:tex t= "Password:" android:textcolor= "#000000" android:textsize= "20sp"/> <edittext android:id= "@+id/et _PWS "android:layout_width=" match_parent "android:layout_height=" 40DP "android:layout_below=" @+id/tv_ PWS "android:layout_marginleft=" 15DP "android:layout_marginright=" 12DP "/> <checkbox Android : id= "@+id/cb_pws" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:la yout_below= "@+id/et_pws" android:layout_marginleft= "15DP" android:text= "Remember Password" android:textcolor= "#000 "/> <checkbOx android:id= "@+id/cb_auto" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_below= "@+id/cb_pws" android:layout_marginleft= "15DP" android:text= "Auto Login" Andro Id:textcolor= "#000000"/> <button android:id= "@+id/btn_login" android:layout_width= "80DP" an        droid:layout_height= "40DP" android:layout_alignparentright= "true" android:layout_aligntop= "@+id/cb_auto" android:layout_below= "@+id/et_pws" android:layout_marginright= "10DP" android:gravity= "center" and roid:text= "Login" android:textcolor= "#000000" android:textsize= "20SP"/></relativelayout>

here is the Res/layout/activity_logo.xml layout file: (Login buffer Interface)

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:background=" @drawable/L Ogin "android:orientation=" vertical "> <relativelayout android:layout_width=" match_parent "Andro id:layout_height= "Wrap_content" android:layout_weight= "3" > <progressbar android:id= "@+id/p Gbar "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android:la Yout_centerinparent= "true"/> <textview android:id= "@+id/tv1" android:layout_width= "Wra P_content "android:layout_height=" wrap_content "android:layout_below=" @+id/pgbar "Android : Layout_centerhorizontal= "True" android:text= "logging in ..." android:textcolor= "#000000" Androi D:textsize= "20sp"/> </relativelayout> <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:layout_weight= "1" android:gravity= "center" > <button android:id= "@+id/btn_b            Ack "android:layout_width=" 70DP "android:layout_height=" 35DP "android:text=" Cancel " Android:textcolor= "#000000" android:textsize= "15sp"/> </LinearLayout></LinearLayout>

here is the Res/layout/activity_welcome.xml layout file: ( Welcome Screen )

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android: background= "@drawable/bg"    android:orientation= "vertical" >    <textview        android:layout_width= " Match_parent "        android:layout_height=" wrap_content "        android:layout_margintop=" 20DP "        android:gravity = "Center"        android:text= "login successfully, enter user interface"        android:textcolor= "#ff00ff"        android:textsize= "25sp"/> </LinearLayout>

here is the Loginactivity.java interface file: (To register)

< Span style= "Color:rgb (51,51,51); font-family:arial; font-size:18px; Line-height:26px ">

public class Loginactivity extends Activity{private EditText username,password;private CheckBox rem_pw,auto_login; Private Button btn_login;private ImageButton btnquit;private sharedpreferences sp;private String Usernamevalue, passwordvalue;protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); This.requestwindowfeature (window.feature_no_title);//Remove title Setcontentview (r.layout.activity_login); InitView (); InitData ();} private void Initview () {//Get Instance Object Username= (EditText) Findviewbyid (R.id.et_zh);p assword= (EditText) Findviewbyid ( R.ID.ET_PWS); rem_pw= (checkbox) Findviewbyid (R.ID.CB_PWS); auto_login= (checkbox) Findviewbyid (R.id.cb_auto); btn_ Login= (Button) Findviewbyid (R.id.btn_login); btnquit= (ImageButton) Findviewbyid (R.ID.IMG_BTN); sp= This.getsharedpreferences ("UserInfo", context.mode_world_readable);} private void InitData () {///determines the state of the Remember password multi-box if (Sp.getboolean ("Ischeck", False)) {//Set default is the record password status rem_pw.setchecked (true); Username.settext (sp.getstring ("user_name", ""));p Assword.SetText (sp.getstring ("PASSWORD", ""));//determine automatic login multi-box status if (Sp.getboolean ("Auto_ischech", False)) {//set default is auto login status Auto_ Login.setchecked (TRUE); Jump Interface Intent Intent=new Intent (loginactivity.this,logoactivity.class); LoginActivity.this.startActivity (intent);}} Login Listener Event Now defaults to User name: Jin Password: 1230btn_login.setonclicklistener (new Onclicklistener () {public void OnClick (View arg0) { Usernamevalue=username.gettext (). ToString ();p asswordvalue=password.gettext (). ToString (); if ( Usernamevalue.equals ("Jin") &&passwordvalue.equals ("1230")) {//toast.maketext (loginactivity.this, "Login succeeded", Toast.length_short). Show ();//Login Success and remember Password box is selected to save user information if (rem_pw.ischecked ()) {//Remember user name, Password editor editor=sp.edit (); Editor.putstring ("user_name", Usernamevalue); Editor.putstring ("PASSWORD", Passwordvalue); Editor.commit ();} Jump Interface Intent Intent = new Intent (Loginactivity.this,logoactivity.class); LoginActivity.this.startActivity (intent);//finish ();} Else{toast.maketext (loginactivity.this, "User name or password is wrong, please log in again", Toast.length_long). Show ();}}); /Monitor RememberPassword Multi Box button event Rem_pw.setoncheckedchangelistener (new Oncheckedchangelistener () {public void oncheckedchanged ( Compoundbutton Buttonview,boolean isChecked) {if (rem_pw.ischecked ()) {Toast.maketext (loginactivity.this, "Remember Password is selected", Toast.length_long). Show (); Sp.edit (). Putboolean ("Ischeck", true). commit (); Else{toast.maketext (loginactivity.this, "Remember Password not selected", Toast.length_long). Show (); Sp.edit (). Putboolean ("Ischeck", False). commit ();}}); /Listen for auto-login multi-box event Auto_login.setoncheckedchangelistener (new Oncheckedchangelistener () {public void oncheckedchanged ( Compoundbutton arg0, Boolean arg1) {if (auto_login.ischecked ()) {Toast.maketext (loginactivity.this, "Automatic Logon is selected", Toast.length_long). Show (); Sp.edit (). Putboolean ("Auto_ischeck", true). commit (); Else{toast.maketext (Loginactivity.this, "Automatic logon is not selected", Toast.length_long). Show (); Sp.edit (). Putboolean ("Auto_ischeck ", false). commit ();}}); /Delete event (Exit program) Btnquit.setonclicklistener (new Onclicklistener () {public void OnClick (View arg0) {finish ();}});}}

here is the Logoactivity.java interface file: (To register)

public class Logoactivity extends Activity implements Runnable{private ProgressBar progressbar;private Button Backbutton ;p rotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); This.requestwindowfeature ( Window.feature_no_title); Setcontentview (R.layout.activity_logo);p rogressbar= (ProgressBar) Findviewbyid ( R.id.pgbar) backbutton= (Button) Findviewbyid (r.id.btn_back);p Rogressbar.setmax (3000);//Start a deferred thread          new Thread ( This). Start ();  Backbutton.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {finish ();}}); public void Run () {try {thread.sleep (2000);//Delay Two seconds Time   startactivity (new Intent (This,welcomeactivity.class));} catch (Exception e) {e.printstacktrace ();}}}

here is the Welcomeactivity.java interface file:

public class Welcomeactivity extends activity{protected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_welcome);}}


Take your time and enjoy it to the original code, passing, study, please leave a message, the top of the Bai ~ ~

Remembering the implementation of password and automatic login interface (v)

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.