날짜를 String 값으로 받아서 Date 형식으로 변환했을때 exception 이 발생하지 않으면 정상 발생하면 비정상
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
sdf.setLenient(false); //정확한 해석을 위해
try{
//형식 맞음
}catch(Exception e){
//형식 틀림
}
2011년 6월 29일 수요일
2011년 6월 24일 금요일
Android - Custom Font 적용
폰트파일위치 - assets/fonts
소스
Typefact tf = Typeface.createFromAsset(getAssets(), "fonts/폰트파일명");
TextView tv = (Textview) findViewById(R.id.CustomFont);
tv.setTypeface(tf);
이렇게 해주면 해당 폰트가 적용이 된다~
소스
Typefact tf = Typeface.createFromAsset(getAssets(), "fonts/폰트파일명");
TextView tv = (Textview) findViewById(R.id.CustomFont);
tv.setTypeface(tf);
이렇게 해주면 해당 폰트가 적용이 된다~
라벨:
안드로이드,
폰트,
android,
custom font
2011년 6월 20일 월요일
Android - Activity에서 Service 호출하기
상황
어느 Activity 에서 특정 이벤트를 발생 시켰을때 자신이 생성한 Service를 호출 하고 싶은경우
예) 위젯 설정 Activity에서 위젯의 바탕화면 이나, 폰트 등을 설정하였을경우 이게 바로 위젯으로 적용되었으면 하는 경우
Activity와 Service와 호출 하기 위해 aidl 이란걸 사용한다.
1. aidl 정의 (jh/project/widget/digital/biorhythm/IBiorhythmClockService.aidl)
package jh.project.widget.digital.biorhythm;
interface IBiorhythmClockService {
void updateWidgetIF();
}
어느 Activity 에서 특정 이벤트를 발생 시켰을때 자신이 생성한 Service를 호출 하고 싶은경우
예) 위젯 설정 Activity에서 위젯의 바탕화면 이나, 폰트 등을 설정하였을경우 이게 바로 위젯으로 적용되었으면 하는 경우
Activity와 Service와 호출 하기 위해 aidl 이란걸 사용한다.
1. aidl 정의 (jh/project/widget/digital/biorhythm/IBiorhythmClockService.aidl)
package jh.project.widget.digital.biorhythm;
interface IBiorhythmClockService {
void updateWidgetIF();
}
2. Service에서 aidl Interface 구현, onBind 구현
package jh.project.widget.digital.biorhythm;
public class BiorhythmClockService extends Service{
...
...
...
public class BiorhythmClockServiceImple extends IBiorhythmClockService.Stub {
@Override
public void updateWidgetIF() throws RemoteException {
readAgain = true;
updateWidget();
}
}
public IBinder onBind(Intent intent) {
return new BiorhythmClockServiceImple();
}
private void updateWidget() {
//Do Something
}
...
...
...
}
3. Activity에서 해당 Interface 호출
package jh.project.widget.digital.biorhythm;
public class Configuration extends{
//Interface, ServiceConnection 정의
private IBiorhythmClockService biorhythmClockService = null;
private ServiceConnection biorhythmClockConn = new ServiceConnection() {
public void onServiceDisconnected(ComponentName p_name) {
biorhythmClockService = null;
}
public void onServiceConnected(ComponentName name, IBinder service) {
biorhythmClockService = IBiorhythmClockService.Stub.asInterface(service);
//callService();
}
};
//binding 시작
protected void onStart() {
super.onStart();
bindService(new Intent(IBiorhythmClockService.class.getName()), biorhythmClockConn, Context.BIND_AUTO_CREATE);
}
//binding 종료
protected void onStop() {
super.onStop();
unbindService(biorhythmClockConn);
}
//Interface 함수 호출하는 함수
private void callService() {
try {
biorhythmClockService.updateWidgetIF();
} catch(RemoteException e) {
Toast toast = Toast.makeText(this, "ERROR - " + e.getMessage(), Toast.LENGTH_SHORT);
toast.show();
}
}
// 뭔가 이벤트가 발생하면 위에서 만든 함수를 실행해서 Service에 함수를 호출한다.
//(Configuration.onClick() -> Configuration.callService() -> IBiorhythmClockService.updateWidgetIF() -> BiorhythmClockService.updateWidget() 순으로 실행된다.)
public void onClick(View v) {
...
...
...
callService();
...
...
...
}
}
※ 알고있는것을 말, 글로 표현한다는건 엄청 어려운일.
혹시 추가 코멘트나, 잘못된 정보 지적등 댓글 받습니다.
2011년 6월 14일 화요일
Android - 어느 Widget에서 Configuration (Activity)를 호출하였나?
위젯을 생성할때 설정 화면(activity) 로 넘어가서 필요 한 데이터들을 설정한 다음에 위젯을 생성하는 경우가 있다.
manifast에
<activity android:name=".Configuration" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
그리고 앱 위젯 프로바이더에
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dip"
android:minHeight="146dip"
android:initialLayout="@layout/biorhythm_clock_widget"
android:configure="jh.project.widget.digital.biorhythm.Configuration"/>
이렇게 설정 해주면 된다.
하지만 다양한 종류의 위젯에서 하나의 설정 화면을 호출하는경우, 필요에 따라서 어느 앱 위젯 프로바이더에서 설정 화면을 호출하였는가가 중요할 때도 있다.
이런 경우에는
설정 화면(activity)의 onCreate(Bundle savedInstanceState) 함수 안에
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
String className = manager.getAppWidgetInfo(widgetId).provider.getClassName();
}
해주면 어느 프로바이더를 통해서 해당 activity가 호출 되었는지 알 수 있다.
manifast에
<activity android:name=".Configuration" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
그리고 앱 위젯 프로바이더에
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dip"
android:minHeight="146dip"
android:initialLayout="@layout/biorhythm_clock_widget"
android:configure="jh.project.widget.digital.biorhythm.Configuration"/>
이렇게 설정 해주면 된다.
하지만 다양한 종류의 위젯에서 하나의 설정 화면을 호출하는경우, 필요에 따라서 어느 앱 위젯 프로바이더에서 설정 화면을 호출하였는가가 중요할 때도 있다.
이런 경우에는
설정 화면(activity)의 onCreate(Bundle savedInstanceState) 함수 안에
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
String className = manager.getAppWidgetInfo(widgetId).provider.getClassName();
}
해주면 어느 프로바이더를 통해서 해당 activity가 호출 되었는지 알 수 있다.
2011년 6월 8일 수요일
Java - 1000 단위마다 콤마(,) 삽입하는 펑션
public static String insertComma(String arg){
int j = 0;
String rtnValue = new String();
for (int i = arg.length() - 1 ; i >= 0; i--){
j++;
rtnValue = arg.charAt(i) + rtnValue;
if(i > 0){
if(j == 3){
rtnValue = "," + rtnValue;
j = 0;
}
}
}
return rtnValue;
}
int j = 0;
String rtnValue = new String();
for (int i = arg.length() - 1 ; i >= 0; i--){
j++;
rtnValue = arg.charAt(i) + rtnValue;
if(i > 0){
if(j == 3){
rtnValue = "," + rtnValue;
j = 0;
}
}
}
return rtnValue;
}
2011년 6월 7일 화요일
SQLite - Date, Time Functions
Functions
date( timestring, modifier, modifier, ...)
time( timestring, modifier, modifier, ...)
datetime( timestring, modifier, modifier, ...)
julianday( timestring, modifier, modifier, ...)
strftime( format, timestring, modifier, modifier, ...)
timestring
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDD.DDDD
modifier
NNN days
NNN hours
NNN minutes
NNN.NNNN seconds
NNN months (see #551 and [1163] )
NNN years (see #551 and [1163] )
start of month
start of year
start of week (withdrawn -- will not be implemented)
start of day
weekday N (see #551 and [1163] )
unixepoch
localtime
utc
현재의 날짜를 알고 싶으면
select date('now');
현재 기준 20일 후의 날짜를 알고 싶으면
select date('now', '20 days');
date( timestring, modifier, modifier, ...)
time( timestring, modifier, modifier, ...)
datetime( timestring, modifier, modifier, ...)
julianday( timestring, modifier, modifier, ...)
strftime( format, timestring, modifier, modifier, ...)
timestring
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDD.DDDD
modifier
NNN days
NNN hours
NNN minutes
NNN.NNNN seconds
NNN months (see #551 and [1163] )
NNN years (see #551 and [1163] )
start of month
start of year
start of week (withdrawn -- will not be implemented)
start of day
weekday N (see #551 and [1163] )
unixepoch
localtime
utc
현재의 날짜를 알고 싶으면
select date('now');
현재 기준 20일 후의 날짜를 알고 싶으면
select date('now', '20 days');
현재 기준 20일 이전의 날짜를 알고 싶으면
select date('now', '-20 days');
이렇게 조회를 하면 'YYYY-MM-DD' 형태로 조회가 된다.
특정한 양식으로 조회 결과를 얻는다던가, 아니면 일자, 월, 년도만 따로 조회를 하고 싶다면, strftime을 사용하면 된다.
strftime 함수의 format 파라미터에 아래 파라 미터들을 조합해서 원하는 형태로 날짜, 시간을 조회 할 수 있다.
%d day of month
%f ** fractional seconds SS.SSS
%H hour 00-24
%j day of year 001-366
%J ** Julian day number
%m month 01-12
%M minute 00-59
%s seconds since 1970-01-01
%S seconds 00-59
%w day of week 0-6 sunday==0
%W week of year 00-53
%Y year 0000-9999
%% %
현재 일시를 'YYYY/MM/DD HH24:MI' 형태로 조회하고 싶다면
select strftime('%Y/%m/%d %H:%M', 'now');
피드 구독하기:
글 (Atom)