마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

완전 초보입니다. 안드로이드 암호소스 관련

0 추천
public class Main extends Activity {
	EditText editText;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editText = (EditText)findViewById(R.id.editText1);

        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	Intent intent = new Intent(Main.this, Password.class);
            	intent.putExtra(Password.NEXT_ACTIVITY, "com.example.password.Profile");
                intent.putExtra(Password.PASSWORD, editText.getText().toString());
                intent.putExtra(Password.MODE, Password.MODE_INIT_PASSWORD);
                startActivity(intent);   
            }
		});
        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	Intent intent = new Intent(Main.this, Password.class);
            	intent.putExtra(Password.NEXT_ACTIVITY, "com.example.password.MainActivity");
                intent.putExtra(Password.PASSWORD, editText.getText().toString());
                intent.putExtra(Password.MODE, Password.MODE_CHECK_PASSWORD);
                startActivity(intent);   
            }
		});
    }
    
}

public class Password extends Activity {
	public static final String NEXT_ACTIVITY = "nextActivity";
	public static final String PASSWORD = "password";
	public static final String RESULT_PASSWORD = "resultPassword";
	public static final String MODE = "mode";
	
	public static final int MODE_CHANGE_PASSWORD = 0;
	public static final int MODE_INIT_PASSWORD = 1;
	public static final int MODE_CHECK_PASSWORD = 2;
	
	public static final int PHASE_INIT_PASSWORD = 0;
	public static final int PHASE_INPUT_PASSWORD = 1;
	public static final int PHASE_CONFIRM_PASSWORD = 2;
	
	private int currentMode = PHASE_CONFIRM_PASSWORD;
	private int initMode = PHASE_CONFIRM_PASSWORD;
	private String currentPassword;
	private int passwordLength = 9999;
	private Intent nextActivity;
	private EditText passwordForm, passwordConfirmForm;
	private String passwordString;
	private ViewFlipper passwordFlipper;
	private TranslateAnimation pushLeftIn, pushLeftOut, shakeAni;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.password);
        init();
        initAnimation();
    }
    
    private Runnable passwordRunnable = new Runnable(){
        @Override
        public void run() {
        	checkPassword();
        }
    };
     
    private void checkPassword(){  	
    	switch(currentMode){
    	case PHASE_INIT_PASSWORD:
    		if( passwordString.equals(passwordForm.getText().toString()) ){
    			goToNextPhase();
    		}else{
                passwordForm.startAnimation(shakeAni);
    		}
    		break;
    		
    	case PHASE_INPUT_PASSWORD:
    		goToNextPhase();
    		break;
    		
    	case PHASE_CONFIRM_PASSWORD:
    		EditText currentForm = passwordConfirmForm; 
    		if(initMode == PHASE_CONFIRM_PASSWORD) currentForm = passwordForm;
    		
    		if( currentPassword.equals(currentForm.getText().toString()) )
    			goToNextPhase();
    		else{
                passwordForm.startAnimation(shakeAni);
    		}
    	}
    	
    	passwordForm.setText("");
    	passwordConfirmForm.setText("");
    }
    
    private void goToNextPhase(){
    	switch(currentMode){
    	case PHASE_INIT_PASSWORD:
    		currentMode = PHASE_INPUT_PASSWORD;
    		break;
    		
    	case PHASE_INPUT_PASSWORD:
    		currentPassword = passwordForm.getText().toString();
    		currentMode = PHASE_CONFIRM_PASSWORD;
    	             
    		passwordFlipper.setInAnimation(pushLeftIn);
    		passwordFlipper.setOutAnimation(pushLeftOut);
    		passwordFlipper.showPrevious();
    		break;
    		
    	case PHASE_CONFIRM_PASSWORD:
    		finish();
    		nextActivity.putExtra(RESULT_PASSWORD, currentPassword);
        	startActivity(nextActivity);    		
        	break;
    	}
    }
    
    private void init(){
    	Intent intent = getIntent();
        String nextActivityClassString = intent.getStringExtra(NEXT_ACTIVITY);
        nextActivity = new Intent();
        nextActivity.setClassName(Password.this, nextActivityClassString);
        
        initMode = intent.getIntExtra(MODE, MODE_CHECK_PASSWORD);
        passwordString = intent.getStringExtra(PASSWORD);
        
        currentMode = initMode;
        currentPassword = passwordString;
        passwordLength = passwordString.length();
        
        passwordFlipper = (ViewFlipper)findViewById(R.id.password_flipper);
        passwordForm = (EditText)findViewById(R.id.password);       
        passwordForm.addTextChangedListener(new TextWatcher() {
        	public void  afterTextChanged (Editable s){
        	}
            public void  beforeTextChanged  (CharSequence s, int start, int count, int after){
            }
            public void  onTextChanged  (CharSequence s, int start, int before, int count) {
            	if(passwordForm.getText().toString().length() == passwordLength){
            		Handler passwordHandler = new Handler();
            		passwordHandler.postDelayed(passwordRunnable, 200);
        		}
            } 
        });
        
        passwordConfirmForm = (EditText)findViewById(R.id.password_confirm);       
        passwordConfirmForm.addTextChangedListener(new TextWatcher() {
        	public void  afterTextChanged (Editable s){
        	}
            public void  beforeTextChanged  (CharSequence s, int start, int count, int after){
            }
            public void  onTextChanged  (CharSequence s, int start, int before, int count) {
            	if(passwordConfirmForm.getText().toString().length() == passwordLength){
            		Handler passwordHandler = new Handler();
            		passwordHandler.postDelayed(passwordRunnable, 200);
        		}
            } 
        });
    }
    
    private void initAnimation(){
    	pushLeftIn = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 1.0f,   
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
    	pushLeftIn.setDuration(200);
    	pushLeftIn.setFillAfter(true);
    	
    	pushLeftOut = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,   
                TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
    	pushLeftOut.setDuration(200);
    	pushLeftOut.setFillAfter(true);
    	
    	shakeAni = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,   
                TranslateAnimation.RELATIVE_TO_SELF, 0.05f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
    	shakeAni.setDuration(300);
    	shakeAni.setInterpolator(new CycleInterpolator(2.0f));
    }
}

안드로이드 완전 초보자입니다.. 구글링하면서 찾은 소스인데요. 어플 암호잠금 소스인데 이 소스대로 사용하면 main에 edittext가 안뜨고 버튼을 눌러야만 뜨게하고 싶은데 소스를 어떻게 수정해야 할지 모르겠습니다... 도와주시면 감사하겠습니다 ㅠ main에서 edittext를 삭제면 오류가나서 프로그램이 정지되더라구요,,main버튼을눌렀을때

혀빙 (340 포인트) 님이 2017년 2월 10일 질문
완전 초보라면 일단 기본적인 뷰 컨트롤 예제부터 찾아보심이....
visible..gone...

1개의 답변

0 추천
에디트텍스트 속정중에 비지빌리티 곤(Gone) 하심대여
익명사용자 님이 2017년 2월 16일 답변
...