2013년 9월 26일 목요일

visual svn - backup script

1. backup script
echo off  
echo BACKUP SVN TO D:\SVN_BACKUP\DUMP 
pushd c:\svn_data 
for /d %%i in (*) do echo dump %%i & svnadmin dump %%i > d:\svn_backup\dump\%%i_%date%.dump 
popd

c:\svn_data에 repository가 있는 거고, d:\SVN_BACKUP\DUMP 폴더로 백업하는 SCRIPT 입니다.

2. restore
svnadmin create xxx 
svnadmin load xxx<yyy.dump

2013년 9월 23일 월요일

android - TextWatcher

0. TextWatcher
 User input을 처리할 때 phone number를 어떻게 처리하면 좋을까?
예를 들어 01112345678을 입력으로 받았을 때 011-1234-5678 이렇게 보여주고 싶다면? 안드로이드에서 기본적으로 PhoneNumberFormattingTextWatcher class를 제공해 주고 있다.
아래 코드 처럼 간단하다
    
    etPhone.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
1. Customize TextWatcher
 price를 입력한다고 했을 때 쉼표를 넣어 주는 것을 고려해 보자. 이것은 android에서 제공하지 않기 때문에 아래와 같이 만들어 보았다.
    
public class PriceFormattingTextWatcher implements TextWatcher{
    /**
     * Indicates the change was caused by ourselves.
     */
    private boolean mSelfChange = false;

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        if (mSelfChange)
            return;
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (mSelfChange)
            return;
    }

    @Override
    public synchronized void afterTextChanged(Editable s) {
        if (mSelfChange) {
            // Ignore the change caused by s.replace().
            return;
        }
        
        String formatted = null;
        
        if(s.length() > 0){
            NumberFormat nf = NumberFormat.getInstance();
            String userInput= ""+s.toString().replaceAll("[^\\d]", "");
            formatted = String.valueOf(nf.format(Float.parseFloat(userInput)));
        }
        if (formatted != null) {
            mSelfChange = true;
            s.setFilters(new InputFilter[]{});
            s.replace(0, s.length(), formatted, 0, formatted.length());
            mSelfChange = false;
        }
    }
}

1,234 에서 2를 삭제했을 때 제일 먼저 beforeTextChanged()가 호출 되고 이때 값은 1,234이다. 이후 onTextChanged() 가 호출되고 이때 값은 1,34이다. 

2. 주의사항

public abstract void afterTextChanged (Editable s)

Added in API level 1
This method is called to notify you that, somewhere within s, the text has been changed. It is legitimate to make further changes to s from this callback, but be careful not to get yourself into an infinite loop, because any changes you make will cause this method to be called again recursively.
 사용자가 변경한 내용이 다시 callback 함수를 호출하여 무한 루프에 빠질 수 있으니 코드 작성에 주의해야 한다. 위 예제에서 mSelfChange 변수를 주목하자.

2013년 9월 5일 목요일

android - place fragments into the tabs (provided by action bar)

0. tab 속으로 fragment layout 넣기
  • http://developer.android.com/guide/topics/ui/actionbar.html#Tabs를 참고하면 action bar에 tabs을 추가하는 방법이 나와 있는데, 이대로 예제를 따라가다가 각 탭에 UI를 집어 넣어 보면 control들이 탭 속에 들어오는게 아니라 전체 activity 화면 위에 위치하게 된다.
1. How?
  • 문서의 예제인데 FragmentTransaction.add() 메소드를 호출할 때 layout에  android.R.id.content 를 넣어 줘서 그렇다. 이 부분을 fragment를 담을 layout으로 지정하면 tab 속에 fragment가 들어간다. 예를 들어 아래와 같이 activity layout xml파일에 추가한 R.id.fragment_container를 넣어주면 된다.
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_gravity="center">
    <LinearLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </LinearLayout>
</LinearLayout>