`
ggyyleo
  • 浏览: 49659 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

assaas

阅读更多
package com.jleo;   
  
import android.app.Activity;   
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;   
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.Button;   
import android.widget.CheckBox;
import android.widget.EditText;   
import android.widget.ViewFlipper;
  
public class LoginAction extends Action{   
    public static final String COM_JLEO_LOGIN_INFO = "com.jleo.loginInfo";
    public static final String PASSWORD = "password";
    public static final String ACCOUNT = "account";
	private EditText etAccount;   
    private EditText etPasswd;   
    private Button loginButton;   
    private String account;   
    private String passwd;   
    private CheckBox rememberMeCheckBox;
    private ViewFlipper flipper;
    
    private static final int viewId = R.layout.login;
	private SharedPreferences sharedPreferences;   
       
    public int getViewId(){   
        return viewId;   
    }   
       
    void apply(){   
        etAccount = findViewById(R.id.loginAcc, EditText.class);   
        etPasswd = findViewById(R.id.loginPass, EditText.class);   
        rememberMeCheckBox = findViewById(R.id.cbRememberMe, CheckBox.class);
        flipper = findViewById(R.id.flipper, ViewFlipper.class);
        flipper.setLayoutAnimation(new LayoutAnimationController(AnimationUtils.loadAnimation(activity,
        		R.anim.fadein)));
        flipper.setOutAnimation(AnimationUtils.loadAnimation(activity,
        		android.R.anim.fade_out));
        
        sharedPreferences = getSharedPreferences(TraceMe.PREFERENCE_NAME);
        String account = sharedPreferences.getString(ACCOUNT, "");
        String passwd = sharedPreferences.getString(PASSWORD, "");
        etAccount.setText(account);
        etPasswd.setText(passwd);
        
        loginButton = findViewById(R.id.login, Button.class);   
           
        loginButton.setOnClickListener(new LoginButtonOnClickListener());   
        flipper.startLayoutAnimation();
        //flipper.getInAnimation().startNow();
    }   
       
    private class LoginButtonOnClickListener implements OnClickListener{
        public void onClick(View v) {   
            account = etAccount.getText().toString();   
            passwd = etPasswd.getText().toString();   
            verify();
        } 
    }   
    
    public void onAuthenicateSuccess(){
    	if(rememberMeCheckBox.isChecked()){
    		SharedPreferences.Editor editor = sharedPreferences.edit();
    		editor.putString(ACCOUNT, account);
    		editor.putString(PASSWORD, passwd);
    		editor.commit();
    	}
    	activity.finish();
    	activity.overridePendingTransition(R.anim.fade, R.anim.hold);
    	Intent intent = new Intent("android.intent.action.DISP_FIX");
    	Bundle loginInfoBundle = new Bundle();
    	loginInfoBundle.putString(ACCOUNT, this.etAccount.getText().toString());
    	loginInfoBundle.putString(PASSWORD, this.etPasswd.getText().toString());
    	intent.putExtra(COM_JLEO_LOGIN_INFO, loginInfoBundle);
    	activity.startActivity(intent);
    }
    
    public void onAuthenicateFail(){
    	alert(R.string.login_fail); 
    }
  
    private void verify() { 
    	activity.showDialog(TraceMe.DIALOG_PROGRESS_BAR);
    	new Thread(new Authenicator(this)).start();
    }   
  
    @Override  
    public void unapply(Activity activity) {   
    	flipper.startAnimation(flipper.getOutAnimation());
    }
}  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics