2010년 12월 25일 토요일
2010년 12월 2일 목요일
bada에서 md5 hash 구하기
const char* DhrUtils::GetMd5N(const char* str)
{
Md5Hash md5;
ByteBuffer* byteText = new ByteBuffer();
byteText->Construct(strlen(str) + 1);
byteText->SetArray((byte*)str, 0, strlen(str));
byteText->SetByte(strlen(str), '\0');
byteText->Flip();
AppLog("position %d, limit %d, capacity %d", byteText->GetPosition(), byteText->GetLimit(), byteText->GetCapacity());
ByteBuffer* byteMd5Text = md5.GetHashN(*byteText);
const byte* pActualOutput = byteMd5Text->GetPointer();
String id;
id.Format(33, L"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
pActualOutput[0], pActualOutput[1], pActualOutput[2], pActualOutput[3],
pActualOutput[4], pActualOutput[5], pActualOutput[6], pActualOutput[7],
pActualOutput[8], pActualOutput[9], pActualOutput[10], pActualOutput[11],
pActualOutput[12], pActualOutput[13], pActualOutput[14], pActualOutput[15]);
char* ret = new char[33];
memset(ret, '\0', 33);
AppLog("MD5: %ls", id.GetPointer());
snprintf(ret, 33, "%ls", id.GetPointer());
delete byteMd5Text;
delete byteText;
return ret;
}
Android에서 Home 으로 보내기
Intent intent = new Intent();
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Android에서 sd카드 마운트 상태 확인하기
public static boolean isSdMounted() {
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}
Android에서 sqlite 버전 구하기
public static String getSqliteVersion() {
Cursor cursor = SQLiteDatabase.openOrCreateDatabase(":memory:", null).rawQuery("select sqlite_version() AS sqlite_version", null);
String sqliteVersion = "";
while(cursor.moveToNext()){
sqliteVersion += cursor.getString(0);
}
cursor.close();
return sqliteVersion;
}
Cursor cursor = SQLiteDatabase.openOrCreateDatabase(":memory:", null).rawQuery("select sqlite_version() AS sqlite_version", null);
String sqliteVersion = "";
while(cursor.moveToNext()){
sqliteVersion += cursor.getString(0);
}
cursor.close();
return sqliteVersion;
}
Android에서 deviceId 구하기
public static String getDeviceId(Context context) {
TelephonyManager telManager = (TelephonyManager)context.getSystemService(
Context.TELEPHONY_SERVICE);
return telManager.getDeviceId();
}
필요 Permission
android.permission.READ_PHONE_STATE
TelephonyManager telManager = (TelephonyManager)context.getSystemService(
Context.TELEPHONY_SERVICE);
return telManager.getDeviceId();
}
필요 Permission
android.permission.READ_PHONE_STATE
Android에서 md5 hash 구하기
public static String getMd5(String s) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(s.getBytes());
BigInteger number = new BigInteger(1, messageDigest);
String md5 = number.toString(16);
while (md5.length() < 32)
md5 = "0" + md5;
return md5;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(s.getBytes());
BigInteger number = new BigInteger(1, messageDigest);
String md5 = number.toString(16);
while (md5.length() < 32)
md5 = "0" + md5;
return md5;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
2010년 9월 17일 금요일
MySQL 유저 추가
insert user(host, user, password, ssl_cipher, x509_issuer, x509_subject)
values('localhost', '아이디', password('패스워드'), '', '', '');
flush privileges;
values('localhost', '아이디', password('패스워드'), '', '', '');
flush privileges;
2010년 8월 18일 수요일
Android에서 HttpPost 속도 개선
Android에서 HttpClient, HttpGet, HttpPost 클래스를 통해서
HTTP 통신을 하게 되는데...
기본 설정으로 하면 HttpGet은 속도가 빠른 반면에
HttpPost는 2~3초가 걸린다.
이것을 해결하기 위해서는 HTTP 버전을 1.1로 지정해야 한다.
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient httpclient = new DefaultHttpClient(params);
출처 : http://stackoverflow.com/questions/3046424/http-post-requests-using-httpclient-take-2-seconds-why
HTTP 통신을 하게 되는데...
기본 설정으로 하면 HttpGet은 속도가 빠른 반면에
HttpPost는 2~3초가 걸린다.
이것을 해결하기 위해서는 HTTP 버전을 1.1로 지정해야 한다.
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient httpclient = new DefaultHttpClient(params);
출처 : http://stackoverflow.com/questions/3046424/http-post-requests-using-httpclient-take-2-seconds-why
2010년 8월 5일 목요일
Android에서 MS 형식의 Dialog 만들기
안드로이드에서는 AlertDialog라는 다이얼로그를 제공하는데..
PositiveButton, NegativeButton, NeutralButton 이렇게
세 가지의 버튼을 지원한다.
아무래도 용어도 생소할뿐더러
MS 형식에 익숙해져 있어서 새롭게 만들어보았다.
만들면서도 괜히하는 것은 아닌가라는 생각이 들지만..
이렇게 하면서 배우는 것도 있을테니까..
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
1. 우선 버튼의 종류와 그 버튼을 클릭했을 때의 리턴값을 정의한다.
종류는 OK, OKCANCEL, YESNO, YESNOCANCEL, 임의의 버튼1개, 임의의 버튼2개, 임의의 버튼3개
이렇게 정했다.
public final static int OK = 1; // button type, return type
public final static int CANCEL = 2; // return type
public final static int YES = 3; // return type
public final static int NO = 4; // return type
public final static int OKCANCEL = 5; // button type
public final static int YESNO = 6; // button type
public final static int YESNOCANCEL = 7; // button type
public final static int ONE_BUTTON = 8; // button type
public final static int TWO_BUTTON = 9; // button type
public final static int THREE_BUTTON = 10; // button type
public final static int BUTTON1 = 11; // return type;
public final static int BUTTON2 = 12; // return type;
public final static int BUTTON3 = 13; // return type;
2. 다이얼로그의 아이콘을 표시하기 위해 상수를 지정한다.
여기서는 INFO와 ALERT 두 가지를 지정했다
(왜냐면 구글에서 이 두가지의 아이콘만 제공한다)
public final static int INFO = 1;
public final static int ALERT = 2;
3. 클릭 이벤트를 처리할 리스너를 만든다
protected OnClickListener mOnClickListener;
4. setButtonText 메소드를 통해서 임의의 버튼의 텍스를 지정한다.(전체소스 참조)
5. show 메소드를 통해서 실제로 다이얼로그를 표시한다.
show 메소드의 파라미터는 타이틀, 메시지, 버튼타입, 아이콘 타입인데..
오버라이드를 해서 타이틀과 메시지만 입력했을 경우는
INFO 아이콘에 확인 버튼 하나만 나오도록 했다.
그리고 다이얼로그 종류에 따라서 버튼을 클릭했을 때
해당하는 버튼값이 리턴되도록 지정한다.
## 주의할 점은 안드로이드는 MS의 다이얼로그와 달리 Modal 형식이 아니어서
사용자가 버튼을 클릭할 때까지 기다려주지 않는다.
그래서 클릭 이벤트를 만들고 클릭했을 때에
다음 동작을 처리해야 한다.
예)
SimpleDialog dialog = new SimpleDialog(context);
dialog.show("제목", "메시지 내용");
dialog.setOnClickListener( new SimpleDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// 처리할 내용 구현
}
});
-- 전체소스 --
public class SimpleDialog {
public final static int OK = 1; // button type, return type
public final static int CANCEL = 2; // return type
public final static int YES = 3; // return type
public final static int NO = 4; // return type
public final static int OKCANCEL = 5; // button type
public final static int YESNO = 6; // button type
public final static int YESNOCANCEL = 7; // button type
public final static int ONE_BUTTON = 8; // button type
public final static int TWO_BUTTON = 9; // button type
public final static int THREE_BUTTON = 10; // button type
public final static int BUTTON1 = 11; // return type;
public final static int BUTTON2 = 12; // return type;
public final static int BUTTON3 = 13; // return type;
public final static int INFO = 1;
public final static int ALERT = 2;
protected OnClickListener mOnClickListener;
private Context mContext;
private int mResult = -1;
private String mButton1Text = "";
private String mButton2Text = "";
private String mButton3Text = "";
public SimpleDialog(Context context) {
// TODO Auto-generated constructor stub
mContext = context;
}
public void setButtonText(int button, int caption) {
String strCaption = mContext.getResources().getString(caption);
setButtonText(button, strCaption);
}
public void setButtonText(int button, String caption) {
switch (button) {
case 1:
case BUTTON1:
mButton1Text = caption;
break;
case 2:
case BUTTON2:
mButton2Text = caption;
break;
case 3:
case BUTTON3:
mButton3Text = caption;
break;
}
}
public int getResult() {
return mResult;
}
public int show(int title, int msg) {
String strTitle = mContext.getResources().getString(title);
String strMsg = mContext.getResources().getString(msg);
return show(strTitle, strMsg, OK, INFO);
}
public int show(int title, String msg) {
String strTitle = mContext.getResources().getString(title);
return show(strTitle, msg, OK, INFO);
}
public int show(String title, int msg) {
String strMsg = mContext.getResources().getString(msg);
return show(title, strMsg, OK, INFO);
}
public int show(String title, String msg) {
return show(title, msg, OK, INFO);
}
public int show(int title, int msg, int buttonType, int iconType) {
String strTitle = mContext.getResources().getString(title);
String strMsg = mContext.getResources().getString(msg);
return show(strTitle, strMsg, buttonType, iconType);
}
public int show(int title, String msg, int buttonType, int iconType) {
String strTitle = mContext.getResources().getString(title);
return show(strTitle, msg, buttonType, iconType);
}
public int show(String title, int msg, int buttonType, int iconType) {
String strMsg = mContext.getResources().getString(msg);
return show(title, strMsg, buttonType, iconType);
}
public int show(String title, String msg, int buttonType, int iconType) {
Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(msg).setCancelable(false);
if (buttonType == OK || buttonType == OKCANCEL) {
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = OK;
performClick(dialog, OK);
}
});
}
if (buttonType == OKCANCEL) {
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = CANCEL;
performClick(dialog, CANCEL);
}
});
}
if (buttonType == YESNO || buttonType == YESNOCANCEL) {
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = YES;
performClick(dialog, YES);
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = NO;
performClick(dialog, NO);
}
});
}
if (buttonType == YESNOCANCEL) {
builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = CANCEL;
performClick(dialog, CANCEL);
}
});
}
if (buttonType == ONE_BUTTON || buttonType == TWO_BUTTON || buttonType == THREE_BUTTON) {
builder.setPositiveButton(mButton1Text, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = BUTTON1;
performClick(dialog, BUTTON1);
}
});
}
if (buttonType == TWO_BUTTON || buttonType == THREE_BUTTON) {
builder.setNegativeButton(mButton2Text, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = BUTTON2;
performClick(dialog, BUTTON2);
}
});
}
if (buttonType == THREE_BUTTON) {
builder.setNeutralButton(mButton3Text, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = BUTTON3;
performClick(dialog, BUTTON3);
}
});
}
AlertDialog alert = builder.create();
alert.setTitle(title);
if (iconType == INFO)
alert.setIcon(R.drawable.ic_dialog_info);
else if (iconType == ALERT)
alert.setIcon(R.drawable.ic_dialog_alert);
alert.show();
return mResult;
}
public static interface OnClickListener {
public abstract void onClick(android.content.DialogInterface dialog, int which);
}
public void setOnClickListener(OnClickListener l) {
mOnClickListener = l;
}
public boolean performClick(DialogInterface dialog, int id) {
if (mOnClickListener != null) {
mOnClickListener.onClick(dialog, id);
return true;
}
return false;
}
}
PositiveButton, NegativeButton, NeutralButton 이렇게
세 가지의 버튼을 지원한다.
아무래도 용어도 생소할뿐더러
MS 형식에 익숙해져 있어서 새롭게 만들어보았다.
만들면서도 괜히하는 것은 아닌가라는 생각이 들지만..
이렇게 하면서 배우는 것도 있을테니까..
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
1. 우선 버튼의 종류와 그 버튼을 클릭했을 때의 리턴값을 정의한다.
종류는 OK, OKCANCEL, YESNO, YESNOCANCEL, 임의의 버튼1개, 임의의 버튼2개, 임의의 버튼3개
이렇게 정했다.
public final static int OK = 1; // button type, return type
public final static int CANCEL = 2; // return type
public final static int YES = 3; // return type
public final static int NO = 4; // return type
public final static int OKCANCEL = 5; // button type
public final static int YESNO = 6; // button type
public final static int YESNOCANCEL = 7; // button type
public final static int ONE_BUTTON = 8; // button type
public final static int TWO_BUTTON = 9; // button type
public final static int THREE_BUTTON = 10; // button type
public final static int BUTTON1 = 11; // return type;
public final static int BUTTON2 = 12; // return type;
public final static int BUTTON3 = 13; // return type;
2. 다이얼로그의 아이콘을 표시하기 위해 상수를 지정한다.
여기서는 INFO와 ALERT 두 가지를 지정했다
(왜냐면 구글에서 이 두가지의 아이콘만 제공한다)
public final static int INFO = 1;
public final static int ALERT = 2;
3. 클릭 이벤트를 처리할 리스너를 만든다
protected OnClickListener mOnClickListener;
4. setButtonText 메소드를 통해서 임의의 버튼의 텍스를 지정한다.(전체소스 참조)
5. show 메소드를 통해서 실제로 다이얼로그를 표시한다.
show 메소드의 파라미터는 타이틀, 메시지, 버튼타입, 아이콘 타입인데..
오버라이드를 해서 타이틀과 메시지만 입력했을 경우는
INFO 아이콘에 확인 버튼 하나만 나오도록 했다.
그리고 다이얼로그 종류에 따라서 버튼을 클릭했을 때
해당하는 버튼값이 리턴되도록 지정한다.
## 주의할 점은 안드로이드는 MS의 다이얼로그와 달리 Modal 형식이 아니어서
사용자가 버튼을 클릭할 때까지 기다려주지 않는다.
그래서 클릭 이벤트를 만들고 클릭했을 때에
다음 동작을 처리해야 한다.
예)
SimpleDialog dialog = new SimpleDialog(context);
dialog.show("제목", "메시지 내용");
dialog.setOnClickListener( new SimpleDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// 처리할 내용 구현
}
});
-- 전체소스 --
public class SimpleDialog {
public final static int OK = 1; // button type, return type
public final static int CANCEL = 2; // return type
public final static int YES = 3; // return type
public final static int NO = 4; // return type
public final static int OKCANCEL = 5; // button type
public final static int YESNO = 6; // button type
public final static int YESNOCANCEL = 7; // button type
public final static int ONE_BUTTON = 8; // button type
public final static int TWO_BUTTON = 9; // button type
public final static int THREE_BUTTON = 10; // button type
public final static int BUTTON1 = 11; // return type;
public final static int BUTTON2 = 12; // return type;
public final static int BUTTON3 = 13; // return type;
public final static int INFO = 1;
public final static int ALERT = 2;
protected OnClickListener mOnClickListener;
private Context mContext;
private int mResult = -1;
private String mButton1Text = "";
private String mButton2Text = "";
private String mButton3Text = "";
public SimpleDialog(Context context) {
// TODO Auto-generated constructor stub
mContext = context;
}
public void setButtonText(int button, int caption) {
String strCaption = mContext.getResources().getString(caption);
setButtonText(button, strCaption);
}
public void setButtonText(int button, String caption) {
switch (button) {
case 1:
case BUTTON1:
mButton1Text = caption;
break;
case 2:
case BUTTON2:
mButton2Text = caption;
break;
case 3:
case BUTTON3:
mButton3Text = caption;
break;
}
}
public int getResult() {
return mResult;
}
public int show(int title, int msg) {
String strTitle = mContext.getResources().getString(title);
String strMsg = mContext.getResources().getString(msg);
return show(strTitle, strMsg, OK, INFO);
}
public int show(int title, String msg) {
String strTitle = mContext.getResources().getString(title);
return show(strTitle, msg, OK, INFO);
}
public int show(String title, int msg) {
String strMsg = mContext.getResources().getString(msg);
return show(title, strMsg, OK, INFO);
}
public int show(String title, String msg) {
return show(title, msg, OK, INFO);
}
public int show(int title, int msg, int buttonType, int iconType) {
String strTitle = mContext.getResources().getString(title);
String strMsg = mContext.getResources().getString(msg);
return show(strTitle, strMsg, buttonType, iconType);
}
public int show(int title, String msg, int buttonType, int iconType) {
String strTitle = mContext.getResources().getString(title);
return show(strTitle, msg, buttonType, iconType);
}
public int show(String title, int msg, int buttonType, int iconType) {
String strMsg = mContext.getResources().getString(msg);
return show(title, strMsg, buttonType, iconType);
}
public int show(String title, String msg, int buttonType, int iconType) {
Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(msg).setCancelable(false);
if (buttonType == OK || buttonType == OKCANCEL) {
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = OK;
performClick(dialog, OK);
}
});
}
if (buttonType == OKCANCEL) {
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = CANCEL;
performClick(dialog, CANCEL);
}
});
}
if (buttonType == YESNO || buttonType == YESNOCANCEL) {
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = YES;
performClick(dialog, YES);
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = NO;
performClick(dialog, NO);
}
});
}
if (buttonType == YESNOCANCEL) {
builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = CANCEL;
performClick(dialog, CANCEL);
}
});
}
if (buttonType == ONE_BUTTON || buttonType == TWO_BUTTON || buttonType == THREE_BUTTON) {
builder.setPositiveButton(mButton1Text, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = BUTTON1;
performClick(dialog, BUTTON1);
}
});
}
if (buttonType == TWO_BUTTON || buttonType == THREE_BUTTON) {
builder.setNegativeButton(mButton2Text, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = BUTTON2;
performClick(dialog, BUTTON2);
}
});
}
if (buttonType == THREE_BUTTON) {
builder.setNeutralButton(mButton3Text, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
mResult = BUTTON3;
performClick(dialog, BUTTON3);
}
});
}
AlertDialog alert = builder.create();
alert.setTitle(title);
if (iconType == INFO)
alert.setIcon(R.drawable.ic_dialog_info);
else if (iconType == ALERT)
alert.setIcon(R.drawable.ic_dialog_alert);
alert.show();
return mResult;
}
public static interface OnClickListener {
public abstract void onClick(android.content.DialogInterface dialog, int which);
}
public void setOnClickListener(OnClickListener l) {
mOnClickListener = l;
}
public boolean performClick(DialogInterface dialog, int id) {
if (mOnClickListener != null) {
mOnClickListener.onClick(dialog, id);
return true;
}
return false;
}
}
2010년 8월 2일 월요일
Android 모바일 웹을 위한 Meta 태그
모바일 웹의 레이아웃을 위한 Meta 태그
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densityDpi=device-dpi" />
width : 화면 가로 사이트 (device-width로 폰의 크기로 지정)
initial-scale : 초기의 확대 비율
maximum-scale : 최대 확대 비율
user-scalable : 사용자가 Zoom기능 사용 제어(no일 경우 Zoom기능이 disable)
target-densityDpi : DPI를 지정(device-dpi를 지정하면 폰의 DPI가 설정됨)
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densityDpi=device-dpi" />
width : 화면 가로 사이트 (device-width로 폰의 크기로 지정)
initial-scale : 초기의 확대 비율
maximum-scale : 최대 확대 비율
user-scalable : 사용자가 Zoom기능 사용 제어(no일 경우 Zoom기능이 disable)
target-densityDpi : DPI를 지정(device-dpi를 지정하면 폰의 DPI가 설정됨)
2010년 7월 26일 월요일
Android에서 Timer 사용하기
스플래쉬 화면은 잠깐 표시되고
다음 화면으로 넘어가기 때문에
이것을 타이머를 사용해서 구현했다.
private Timer mTimer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod(); // 지정된 시간에 실행할 메소드
}
}, 5000); // 밀리세컨드 단위로 딜레이될 시간
}
private void TimerMethod(){
Intent intent = new Intent(DhrActivity.this, LoginActivity.class);
startActivity(intent);
mTimer.cancel(); // 타이머를 취소하지 않으면 계속 실행이 된다.
finish(); // finish를 하지 않으면 뒤로가기 버튼을 누를 때 스플래쉬 화면으로 간다.
}
다음 화면으로 넘어가기 때문에
이것을 타이머를 사용해서 구현했다.
private Timer mTimer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod(); // 지정된 시간에 실행할 메소드
}
}, 5000); // 밀리세컨드 단위로 딜레이될 시간
}
private void TimerMethod(){
Intent intent = new Intent(DhrActivity.this, LoginActivity.class);
startActivity(intent);
mTimer.cancel(); // 타이머를 취소하지 않으면 계속 실행이 된다.
finish(); // finish를 하지 않으면 뒤로가기 버튼을 누를 때 스플래쉬 화면으로 간다.
}
JavaScript에서 Target 지정하기
_top : top.location='주소';
_self : self.location.href='주소';
_parent : _parent.window.location='주소';
프레임을 사용했을 경우(프레임 파일에서)
document.frames['프레임명'].location='주소';
document.frames[숫자].location='주소';
프레임의 자식(프레임에 지정된 파일)에서는 parent를 붙인다.
parent.document.frames['프레임명'].location='주소';
parent.document.frames[숫자].location='주소';
_self : self.location.href='주소';
_parent : _parent.window.location='주소';
프레임을 사용했을 경우(프레임 파일에서)
document.frames['프레임명'].location='주소';
document.frames[숫자].location='주소';
프레임의 자식(프레임에 지정된 파일)에서는 parent를 붙인다.
parent.document.frames['프레임명'].location='주소';
parent.document.frames[숫자].location='주소';
2010년 7월 25일 일요일
JAVA에서 문자열을 숫자, 영문자, 한글로 구분하기
Pattern클래스는 첫 번째 파라미터인 패턴과
두 번째 파라미터인 문자열을 비교해
두 번째 문자열이 첫 번째 패턴과 일치하는 지를 알려준다.
숫자 한글자 : [0-9]
영소문자 한글자 : [a-z]
영대문자 한글자 : [A-Z]
유니코드 한글 한 글자 : [가-힣]
한글자가 아닌 문자열일 경우 *를 붙여준다.
숫자 : [0-9]*
영소문자 : [a-z]*
영대문자 : [A-Z]*
유니코드 한글 : [가-힣]*
자주 쓰이는 형식에 대해서 다음과 같은 축약형이 있다.
\d 하나의 숫자 : [0-9]
\D 하나의 숫자가 아닌 문자 : [^0-9]
\s 하나의 공백 문자 : [ \t\n\x0B\f\r]
\S 하나의 공백 문자 이외의 문자 :[^\s]
\w 하나의 영숫자 : [a-zA-Z_0-9]
\W 하나의 영숫자 이외의 문자 :[^\w]
또한 POSIX 형식의 분류가 있다.
\p{Lower} 하나의 소문자 알파벳 문자: [a-z]
\p{Upper} 하나의 대문자 알파벳 문자: [A-Z]
\p{ASCII} 모든 ASCII: [\x00-\x7f]
\p{Alpha} 하나의 알파벳 문자: [\p{Lower}\p{Upper}]
\p{Digit} 하나의 십진 숫자: [0-9]
\p{Alnum} 하나의 영숫자 문자: [\p{Alpha}\p{Digit}]
\p{Punct} 구두점: !”#$%&’()*,-./:;<=>?@[\]^_`{|}
\p{Graph} 하나의 눈에 보이는 문자7: [\p{Alnum}\p{Punct}]
\p{Print} 하나의 프린트 가능한 문자: [\p{Graph}]
\p{Blank} 하나의 스페이스(space)나 탭(tab): [ \t]
\p{Cntrl} 하나의 제어 문자: [\x00-\x1F\x7F]
\p{XDigit} 하나의 16진수 숫자: [0-9a-fA-F]
\p{Space} 하나의 공백문자: [\t\n\x0B\f\r]
주의 사항: \는 이스케이프 문자이기 때문에 \\ 이렇게 표시해야 한다.
자바에서의 실용예
num 이 숫자인지 확인
boolean a = Pattern.matches("\\p{Digit}*", num);
boolean b = Pattern.matches("[0-9]*", num);
boolean c = Pattern.matches("[\\d]*", num);
두 번째 파라미터인 문자열을 비교해
두 번째 문자열이 첫 번째 패턴과 일치하는 지를 알려준다.
숫자 한글자 : [0-9]
영소문자 한글자 : [a-z]
영대문자 한글자 : [A-Z]
유니코드 한글 한 글자 : [가-힣]
한글자가 아닌 문자열일 경우 *를 붙여준다.
숫자 : [0-9]*
영소문자 : [a-z]*
영대문자 : [A-Z]*
유니코드 한글 : [가-힣]*
자주 쓰이는 형식에 대해서 다음과 같은 축약형이 있다.
\d 하나의 숫자 : [0-9]
\D 하나의 숫자가 아닌 문자 : [^0-9]
\s 하나의 공백 문자 : [ \t\n\x0B\f\r]
\S 하나의 공백 문자 이외의 문자 :[^\s]
\w 하나의 영숫자 : [a-zA-Z_0-9]
\W 하나의 영숫자 이외의 문자 :[^\w]
또한 POSIX 형식의 분류가 있다.
\p{Lower} 하나의 소문자 알파벳 문자: [a-z]
\p{Upper} 하나의 대문자 알파벳 문자: [A-Z]
\p{ASCII} 모든 ASCII: [\x00-\x7f]
\p{Alpha} 하나의 알파벳 문자: [\p{Lower}\p{Upper}]
\p{Digit} 하나의 십진 숫자: [0-9]
\p{Alnum} 하나의 영숫자 문자: [\p{Alpha}\p{Digit}]
\p{Punct} 구두점: !”#$%&’()*,-./:;<=>?@[\]^_`{|}
\p{Graph} 하나의 눈에 보이는 문자7: [\p{Alnum}\p{Punct}]
\p{Print} 하나의 프린트 가능한 문자: [\p{Graph}]
\p{Blank} 하나의 스페이스(space)나 탭(tab): [ \t]
\p{Cntrl} 하나의 제어 문자: [\x00-\x1F\x7F]
\p{XDigit} 하나의 16진수 숫자: [0-9a-fA-F]
\p{Space} 하나의 공백문자: [\t\n\x0B\f\r]
주의 사항: \는 이스케이프 문자이기 때문에 \\ 이렇게 표시해야 한다.
자바에서의 실용예
num 이 숫자인지 확인
boolean a = Pattern.matches("\\p{Digit}*", num);
boolean b = Pattern.matches("[0-9]*", num);
boolean c = Pattern.matches("[\\d]*", num);
Android에서 POST로 파라미터 보내기
// url로 HttpPost객체를 생성한다.
httpPost = new HttpPost(url);
// NameValuePair로 보내고자 하는 파라미터를 추가한다.
Listparams = new ArrayList ();
params.add(new BasicNameValuePair("uid", uid));
params.add(new BasicNameValuePair("ukey", ukey));
UrlEncodedFormEntity entity = null;
try {
// 원하는 인코딩으로 entity 객체를 생성한다.
enity= new UrlEncodedFormEntity(params, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// HttpPost 객체에 entity를 설정한다.
httpPost.setEntity(entity);
2010년 7월 24일 토요일
FRAMESET 만들기
<html>
<head>
</head>
<frameset rows="200, *" frameborder="0">
<frame src="head_top.php" name="top" scrolling="no" noresize/>
<frame src="head_body.php" name="body" noresize/>
</frameset>
</html>
주의할 점은 일반 HTML문서와 같이 <body>를 넣으면 frame이 표시되지 않는다.
PHP에서 Redirect
<? header("Location: URL"); exit; ?>
헤더가 이미 전송되었을 경우에는 아래의 방법으로 한다.
헤더가 전송되었는지 확인하는 함수 headers_sent()
echo "<meta http-equiv='refresh' content='0;url=URL'>";
헤더가 이미 전송되었을 경우에는 아래의 방법으로 한다.
헤더가 전송되었는지 확인하는 함수 headers_sent()
echo "<meta http-equiv='refresh' content='0;url=URL'>";
2010년 7월 21일 수요일
MySQL에서 스크립트 파일 실행하기
mysql 프롬프트에서..
mysql> source 파일명
linux 프롬프트에서..
[xxxx]$ mysql -u 아이디 -p 비밀번호 데이터베이스명 < 파일명
mysql> source 파일명
linux 프롬프트에서..
[xxxx]$ mysql -u 아이디 -p 비밀번호 데이터베이스명 < 파일명
피드 구독하기:
글 (Atom)