Android blog garden client (7) login function
This is just a simple login function. operations that can be performed after successful logon have not yet been implemented. The principle of logon is to obtain Cookies and store data in the database. Using HttpClient to simulate logon has already been written in another blog, so I will not go into details here. The code is very simple: SplashActivity: Copy code 1 if (Personal. isLogin (this) {2 Config. FLAG_LOGIN = true; 3} 4 5 final Intent intent; 6 if (Config. FLAG_LOGIN) {7 intent = new Intent (SplashActivity. this, MainActivity. class); 8} else {9 intent = new Intent (SplashActivity. this, LoginActivity. class); 10} copy the code LoginActivity copy code 1 private void setListener () {2 OnClickListener listener = new OnClickListener () {3 4 @ Override 5 public void onClick (View v) {6 7 if (v. getId () = buttonLogin. getId () {8 userName = editTextUserName. getText (). toString (); 9 password = editTextPassword. getText (). toString (); 10 loginUrl = Config. LOGIN_RUL; 11 if (userName. trim (). equals ("") {12 13} else if (userName. trim (). equals ("") {14 15} else {16 login (); 17} 18} else if (v. getId () = buttonVisitor. getId () {19 Intent intent = New Intent (LoginActivity. this, 20 MainActivity. class); 21 startActivity (intent); 22 LoginActivity. this. finish (); 23} 24 25} 26}; 27 28 buttonLogin. setOnClickListener (listener); 29 buttonVisitor. setOnClickListener (listener); 30} 31 32 private void login () {33 LoginDialog dialog = new LoginDialog (this); 34 ProgressCallBack callBack = new ProgressCallBack () {35 36 @ Override37 public void action () {38 cookie = Personal. Login (userName, password, loginUrl); 39 if (cookie! = Null) {40 DBUtils. addCookie (LoginActivity. this, userName, cookie); 41 Intent intent = new Intent (LoginActivity. this, 42 MainActivity. class); 43 startActivity (intent); 44 LoginActivity. this. finish (); 45 Config. FLAG_LOGIN = true; 46} 47} 48}; 49 50 dialog. showProgressDialog ("login", "logging... ", callBack); 51 52}