먼저 설정창에 쓰일 layout 파일을 만든다.

option.xml
 

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="et_name"
android:title="이름"
/>
<CheckBoxPreference
android:key="cb_draw"
android:title="Drawing?"
android:summary="이미지 보기"
android:defaultValue="true"
/>
<PreferenceCategory
android:title="카테고리">
<PreferenceScreen
android:key="fluit"
android:title="과일">
<CheckBoxPreference
android:key="fluit_01"
android:title="사과"/>
<CheckBoxPreference
android:key="fluit_02"
android:title="배"/>
<CheckBoxPreference
android:key="fluit_03"
android:title="포도"/>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>

레이아웃은 PrefenceScreen으로 해야하며 위 코드는 EditText, CheckBox, Category가 들어있다.
기본적으로 key, title, summary의 값을 지닌다. 



LiveWallPaPer_Canvas.java
package pe.berabue.livewallpaper;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;

public class LiveWallPaPer_Canvas extends PreferenceActivity implements OnPreferenceClickListener, OnPreferenceChangeListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.option);
        
        EditTextPreference editName = (EditTextPreference)findPreference("et_name");
        CheckBoxPreference checkDraw = (CheckBoxPreference)findPreference("cb_draw");
        editName.setOnPreferenceChangeListener(this);
        checkDraw.setOnPreferenceClickListener(this);
        
        // fluit category
        CheckBoxPreference checkFluit_01 = (CheckBoxPreference)findPreference("fluit_01");
        checkFluit_01.setOnPreferenceClickListener(this);
    }

	@Override
	public boolean onPreferenceClick(Preference preference) {
		if ( preference.getKey().equals("cb_draw")) {
			boolean isDraw = preference.getSharedPreferences().getBoolean("cb_draw", false);
			Log.v(null,"Click CheckPreference : "+isDraw);
			
			WallPaPer_Canvas.isDraw = isDraw;
		}
		if ( preference.getKey().equals("fluit_01") ) {
			Log.v(null,"Click fluit_01");
		}
		return false;
	}

	@Override
	public boolean onPreferenceChange(Preference preference, Object newValue) {
		if ( preference.getKey().equals("et_name") ) {
			preference.setSummary((CharSequence) newValue);
			Log.v(null,""+newValue);
		}
		return false;
	}
}
PreferenceActivity를 상속받는다.
addPreferencesFromResource(R.layout.option);
 먼저 작성해둔 option.xml 을 불러들인다.
xml파일에서 작성해둔 key값으로 리스너를 등록시킨다.

WallPaPer_Canvas.java 의 그림을 그려주는 부분에 isDraw를 추가시켜 놓았는데 Drawing?이 체크되면 이미지를 보이고 체크가 해제되면 이미지를 보여주지 않도록 바꾸어 놓았다.

WallPaPer_Canvas.jaca -> DrawFrame();
if (canvas != null) {
	if ( isDraw )
		canvas.drawBitmap(imgIcon, 0, 0, null);
}
 



ex.xml
 

<?xml version="1.0" encoding="UTF-8"?> <wallpaper xmlns:android="http://schemas.android.com/apk/res/android" android:thumbnail="@drawable/icon" android:description="@string/test" android:settingsActivity="pe.berabue.livewallpaper.LiveWallPaPer_Canvas"/>

ex.xml 파일내의 settingsActivity 옵션에 "패키지명.액티비티명"을 입력 시키면 완성 ~



+ Recent posts