2011. 3. 16. 17:39
...

... class Notactivity
{
  ..
  private Context mContext = null;
  ..
  public Notactivity(Context context)
    {
     this.mContext = context;
    }
  ..
  //액티비티에서 실행되는 것 앞에다 mContext. 을 붙여줌
}
Posted by newkie
2011. 3. 14. 17:42

..extends Activity
{

  ..

  private ProgressDialog mProgressDialog = null;

  ..onCreate(..)
  {

    ..
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog = ProgressDialog.show(ctx,"로딩", "로딩중.", true);
    //로딩화면 띄운 동안 할것
    runOnUiThread(returnRes);

  }

  ..

  private Runnable returnRes = new Runnable()
 {
  @Override
  public void run()
  {
   mProgressDialog.dismiss();
  }
 };

Posted by newkie
2011. 3. 14. 13:07

핸들러로

new Thread(new Runnable()
      {
       @Override
       public void run()
       {
        Message msg = handler.obtainMessage();
           handler.sendMessage(msg);
       }
      }).start();


final Handler handler = new Handler() {
     public void handleMessage(Message msg) {
//실행할 부분
     }
    };
Posted by newkie
2011. 3. 11. 16:46

     new Thread(new Runnable()
     {
      @Override
      public void run()
      {
       Send();
      }
     }).start();

'자바' 카테고리의 다른 글

돈에 ,찍기나 전화번호에 -찍는 등의 정규식.  (0) 2011.04.21
JSON 배열 만들고 파싱하기  (2) 2011.04.12
배열정렬 Comparator  (1) 2011.03.31
암호화/복호화  (0) 2011.03.11
Posted by newkie
2011. 3. 11. 14:21


package com.newkie;

import java.security.SecureRandom;

import javax.crypto.Cipher; 
import javax.crypto.KeyGenerator; 
import javax.crypto.SecretKey; 
import javax.crypto.spec.SecretKeySpec;

public class AESCrypto
{
 private static AESCrypto instance = null;
 public static AESCrypto getInstance()
 {
  if(instance == null)
  {
   instance = new AESCrypto();
  }
  return instance;
 }
 
 public String encrypt(String masterPassword, String clearText)
 throws Exception
 {
  byte[] rawKey = getRawKey(masterPassword.getBytes());
  byte[] result = encrypt(rawKey, clearText.getBytes());
  return toHex(result);
 }
 
 public String decrypt(String masterPassword, String encrypted)
 throws Exception
 {
  byte[] rawKey = getRawKey(masterPassword.getBytes());
  byte[] enc = toByte(encrypted);
  byte[] result = decrypt(rawKey, enc);
  return new String(result);
 }

 private byte[] getRawKey(byte[] seed)
 throws Exception
 {
  KeyGenerator kgen = KeyGenerator.getInstance("AES");
  SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
  sr.setSeed(seed);
     kgen.init(128, sr);
     SecretKey skey = kgen.generateKey();
     return skey.getEncoded();
 }
 
 private byte[] encrypt(byte[] raw, byte[] clear)
 throws Exception
 {
     SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
  Cipher cipher = Cipher.getInstance("AES");
     cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
     byte[] encrypted = cipher.doFinal(clear);
  return encrypted;
 }

 private byte[] decrypt(byte[] raw, byte[] encrypted)
 throws Exception
 {
     SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
  Cipher cipher = Cipher.getInstance("AES");
     cipher.init(Cipher.DECRYPT_MODE, skeySpec);
     byte[] decrypted = cipher.doFinal(encrypted);
  return decrypted;
 }
 
 public byte[] toByte(String hexString)
 {
  int len = hexString.length()/2;
  byte[] result = new byte[len];
  for (int i = 0; i < len; i++)
  {
   result[i] = Integer.valueOf(hexString.substring(2*i, 2*i+2), 16)
     .byteValue();
  }
  return result;
 }

 public String toHex(byte[] buf)
 {
  if (buf == null || buf.length == 0)
  {
   return "";
  }
  StringBuffer result = new StringBuffer(2*buf.length);
  
  for (int i = 0; i < buf.length; i++)
  {
   appendHex(result, buf[i]);
  }
  return result.toString();
 }
 
 private final static String HEX = "0123456789ABCDEF";
 private void appendHex(StringBuffer sb, byte b)
 {
  sb.append(HEX.charAt((b>>4)&0x0f)).append(HEX.charAt(b&0x0f));
 }
}





AESCrypto ae = new AESCrypto.getInstance();
ae.encrypt(newkie,pw);//암호화

ae.decrypt(newkie,pw);//복호화

'자바' 카테고리의 다른 글

돈에 ,찍기나 전화번호에 -찍는 등의 정규식.  (0) 2011.04.21
JSON 배열 만들고 파싱하기  (2) 2011.04.12
배열정렬 Comparator  (1) 2011.03.31
간단한 쓰레드 예제  (0) 2011.03.11
Posted by newkie
2011. 3. 11. 11:23

public class Mainactivity extends Activity
{
 private SharedPreferences pref = null;
 SharedPreferences.Editor editor;
 
    @Override
 public void onCreate(Bundle savedInstanceState)
 {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
       
        pref = getSharedPreferences("com.newkie",Activity.MODE_PRIVATE);
editor = pref.edit();
//각종작업
editor.commit();

 }
}

pref 는 불러올때 editor는 데이터관리

'안드로이드' 카테고리의 다른 글

로딩화면 띄우기  (0) 2011.03.14
쓰레드 내에서 뷰터치 실행  (0) 2011.03.14
어플 완전히 죽이기  (0) 2011.03.10
다이얼로그 타이틀바 없애기  (0) 2011.03.09
intent 여러액티비티 한방에 끄기  (0) 2011.03.08
Posted by newkie
2011. 3. 10. 18:16

android.os.Process.killProcess(android.os.Process.myPid());

System.Exit(0);도 되긴 되는데 쓰지 말라는듯
Posted by newkie
2011. 3. 9. 16:22

super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.cancelcall);

컨텐트뷰 전에 지정

super.onCreate(savedInstanceState);
setContentView(R.layout.cancelcall);

requestWindowFeature(Window.FEATURE_NO_TITLE);

이렇게 했다가 Exception이 계속 떠서 빡쳐서 적어둠
Posted by newkie
2011. 3. 8. 17:42
A.java
onCreate{
...
Intent intent = new Intent(ctx, B.class);
startActivityForResult(intent, 0);
...
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
super.onActivityResult(requestCode, resultCode, intent);
 
switch(requestCode)
{
case 0:
if(resultCode == RESULT_OK)
{
intent = getIntent();//반복할때
setResult(RESULT_OK,intent);//반복할때
finish();
}
}
}

B.java

Intent intent = getIntent();
setResult(RESULT_OK,intent);
finish();


B에서 위 코드가 실행되면 B와 A가 동시에 꺼짐

반복해서 여러 액티비티가 동시에 꺼지는것도 가능
Posted by newkie
2011. 3. 7. 11:25
보내는쪽
Intent intent = new Intent(ctx, 전달클래스.class);
intent.putExtra("파라미터","전달값");
startActivity(intent);

받는쪽
Intent intent = getIntent();
String s = intent.getStringExtra("파라미터");
Posted by newkie