이너 클래스로 다이얼로그와 관련된 클래스를 만들었어요.

그래서 그 안에 AlertDialog를 만들었고요.

그런데 문제는 제가 메모 파일을 저장하고서 암호화를 하기 위해 키를 입력할 때,

 이너 클래스에 있는 입력 다이얼로그를 호출해야 하거든요.

그 부분을 어떻게 하면 좋은 지 알고 싶습니다.그에 대해 수행하는 소스 코드(Edit.java) 입니다.

 

그리고 패스워드 처리할 때, *모양이 나타나도록 해야하는데

xml 소스에서 패스워드 부분을 만들었지만 처리 소스에서는 어떻게 해야 하는지도 알고 싶습니다.

테스트를 위해서 제가 개발한 전체 소스까지 올립니다. 혹시나 테스트 하시다가 고쳐야 할 부분도

있다면 알려주세요.

 

(패스워드 ui)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical"
   android:padding="15dp">
 
   <EditText
    android:layout_width="200dip"
  android:layout_height="wrap_content"
  android:password="true"
  android:singleLine="true"
  android:hint="InputKey"
  android:id="@+id/trueyourKey"
  android:maxLength="16"
  android:layout_gravity="center"
  android:inputType="textPassword"
   >
 </EditText>
 
</LinearLayout>

 

(Edit.java)

package org.memo.pkg;

import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import org.kisa.*;

public class Edit extends Activity implements Variable{
 
 static{
  System.loadLibrary("KISACrypto");
 }
 
 //iv
 public static final byte[] iv = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
 //test key
 public static byte[] key = new byte[16];
 public static byte[] KeyCode;
 
 
 Button btn = null;
 boolean isOpenEdit = false;
 
 public void onCreate(Bundle savedInstanceState)
 {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit);

   
        final Intent intent = getIntent();
        isOpenEdit = intent.getBooleanExtra("isOpenEdit", false);

        if( isOpenEdit ){
         
         EditText etFileName = (EditText)findViewById(R.id.et_filename);
         EditText etMemo = (EditText)findViewById(R.id.et_edit);
         etFileName.setText(intent.getStringExtra("FILENAME"));
         etMemo.setText(intent.getStringExtra("FILECONTENT"));
         
        }
       
        ButtonProc(R.id.btn_save);
        ButtonProc(R.id.btn_menu);
        ButtonProc(R.id.btn_encrypt);
       

    }
    //버튼 처리하기
    public void ButtonProc(final int id)
    {
     btn = (Button)findViewById(id);
     btn.setOnClickListener(new OnClickListener()
     {
   @Override
   public void onClick(View v)
   {
       switch(id)
       {
       case R.id.btn_save:  
        SaveProc();
        break;
       case R.id.btn_encrypt:
        SaveEncrypt();
        break;
       case R.id.btn_menu:
//           finish();    
        Intent intent = new Intent(Edit.this, Memo.class);
        startActivity(intent);
        overridePendingTransition(R.anim.zoom_exit,R.anim.fade);
        break;
       }
   }
     });
    }
   
    //해시 처리 전 입력한 패스워드를 HIGHT의 키로 초기화
    public static byte[] initKey(byte[] pass)
    {
     for(int i=0;i<pass.length;i++)
     {
      key[i] = pass[i];
     }
     return key;
    }
   
    public void SaveEncrypt()
    {
     //입력 다이얼로그 호출
     EditText cet = (EditText)findViewById(R.id.et_filename);
     String enFileName = cet.getText().toString();
     encryption(enFileName);
     enFileName=enFileName+data.toString();
    }
   
    //저장 과정-일반 파일
    public void SaveProc()
    {
     EditText et = (EditText)findViewById(R.id.et_filename);
     String getFileName = et.getText().toString();
  if( getFileName.equals(""))
  {  
   Intent intent = new Intent(Edit.this, Message.class);
   intent.putExtra("MESSAGE", NO_NAME);
   startActivity(intent);
   overridePendingTransition(R.anim.zoom_exit,R.anim.fade);
  }
  else
  {
   int iFileLeng = fileList().length;   

   
   if( iFileLeng != 0 )
   {   
    boolean isAlreadyFile = false;
    String[] sFileList = fileList();   
    for( int i = 0 ; i < iFileLeng ; i++)
    {
     if( sFileList[i].equals(getFileName) )
     {  
      isAlreadyFile = true;
      break;
     }
    }
    
    if(isAlreadyFile)
    {     
     Intent intent = new Intent(Edit.this, Message.class);
     intent.putExtra("MESSAGE", ALREADY_FILE);
     startActivity(intent);
     overridePendingTransition(R.anim.zoom_exit,R.anim.fade);
    }
    else
    { 
     FileSave(getFileName);
    }
   }
   else
   {
    FileSave(getFileName);
   }
  }
    }
   
    //파일 저장,동시에 암호화 수행
    //입력 키와 파일 이름을 인자로 지정
    public void encryption(String sName)
    {
     byte[] plainText = new byte[128];
  byte[] cipherText = new byte[136];
  int outputTextLen = 0;
  
  HIGHT hight = new HIGHT();
  hight.init(HIGHT.ENC,key,iv);
     try{
      EditText et = (EditText)findViewById(R.id.et_edit);
      byte[] buffer = stringToByte(et.getText().toString());
      for(int i=0;i<buffer.length;i++)
      {
       plainText[i] = buffer[i];
      }
      outputTextLen = hight.process(plainText, plainText.length, cipherText, 0);
      hight.close(cipherText, outputTextLen);
      FileOutputStream fos = openFileOutput(sName,Context.MODE_PRIVATE);
      fos.write(cipherText);
      fos.flush();
      fos.close();  
     }
     catch(Exception e)
     {
      e.printStackTrace();
     }
    }
       
    //일반 파일
    public void FileSave(String sName)
    {
     try {
      EditText et = (EditText)findViewById(R.id.et_edit);
      byte[] buffer = stringToByte(et.getText().toString());    
   FileOutputStream fos = openFileOutput(sName, Context.MODE_PRIVATE);
   fos.write(buffer);
   fos.flush();
   fos.close();
  } catch (IOException e)
  {
   e.printStackTrace();
  }
  Intent intent = new Intent(Edit.this, Message.class);
  intent.putExtra("MESSAGE", SAVE_COMPLETE);
  startActivityForResult(intent, 0);
    }
   
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
  if( data.getAction().equals("ACTION_A")){
   finish();
  }
    }
 
   
    public byte[] stringToByte(String sBuffer)
    {
  byte[] bBuffer = new byte[sBuffer.length()];
  for(int i = 0 ; i < sBuffer.length() ; i ++)
   bBuffer[i]=(byte)sBuffer.charAt(i);
  return bBuffer;
 }
   
    class KeyDialog extends Activity
    {
     public void onCreate(Bundle savedInstanceState)
     {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.keydialog2);
     }
     
     public void keyInput()
     {
      
     }
     public void mOnClick(View v)
     {
      new AlertDialog.Builder(this)
      .setTitle("Notification")
      .setMessage("Input your Key")
      .setPositiveButton("OK", new DialogInterface.OnClickListener() {
    
    @Override
    public void onClick(DialogInterface dialog, int which)
    {
     EditText mUserText;
     mUserText = (EditText)findViewById(R.id.trueyourKey);
     KeyCode = stringToByte(mUserText.getText().toString());
     KeyManage.authenHashPass(KeyCode);
     
    }
   }).show();
     }
    }
}