asdasd

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.TextView;
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 String server;   
    private CheckBox rememberMeCheckBox;
    private ViewFlipper flipper;
    
    private static final int viewId = R.layout.login;
	public static final String SERVER = "server";
	
	private SharedPreferences sharedPreferences;
	private TextView tvServerIP;   
       
    public int getViewId(){   
        return viewId;   
    }   
       
    void apply(){   
        etAccount = findViewById(R.id.loginAcc, EditText.class);   
        etPasswd = findViewById(R.id.loginPass, EditText.class);   
        tvServerIP = findViewById(R.id.serverIP, TextView.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);
        account = sharedPreferences.getString(ACCOUNT, "");
        passwd = sharedPreferences.getString(PASSWORD, "");
        server = sharedPreferences.getString(SERVER, "10.69.46.192:8088");
        etAccount.setText(account);
        etPasswd.setText(passwd);
        tvServerIP.setText(server);
        tvServerIP.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				activity.showDialog(TraceMe.SERVER_ADDR_UPDATE_DIALOG);
			}
		});
        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();   
            server = tvServerIP.getText().toString();
            verify();
        }
    }   
    
    public void onAuthenicateSuccess(){
    	if(rememberMeCheckBox.isChecked()){
    		SharedPreferences.Editor editor = sharedPreferences.edit();
    		editor.putString(ACCOUNT, account);
    		editor.putString(PASSWORD, passwd);
    		editor.putString(SERVER, server);
    		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());
    	loginInfoBundle.putString(SERVER, this.tvServerIP.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) {   
    }
}

相关推荐