zakaria bouhanna zakaria bouhanna - 1 month ago 8
Android Question

How to make checkboxes work in a live wallpaper Android app?

I have three check boxes in my live wallpaper's settings that I need to figure out how to make them work, I want for example checkbox1 to execute code1, checkbox2 to execute code 2 and the last checkbox to execute code3:

code1:

private void incrementCounter() {


if (mImagesArrayIndex >= mImagesArray.length-10) {
mImagesArrayIndex = mImagesArray.length-10;}
if (mImagesArrayIndex <10) {
mImagesArrayIndex = 10;


code2:

private void incrementCounter() {


if (mImagesArrayIndex >= mImagesArray.length-20) {
mImagesArrayIndex = 0;}
if (mImagesArrayIndex <0) {
mImagesArrayIndex = mImagesArray.length-20;

}

}


code3:

mImagesArrayIndex++;


code3 (goes into code1 and code2), codes1,2,3 are all in CustomWallpaper.java That's all, I have already set my settings layout and it looks like this:

settings screen

Answer

solution:

public void run() {

            SharedPreferences myPref = PreferenceManager.getDefaultSharedPreferences( CustomWallpaper.this);
            try {
                while (true) {
                    drawFrame();

                    if (myPref.getBoolean("lwp_o_scroll_lock_key",true)) 
                    incrementCounter1();
                    else 
                        incrementCounter2();
                    if (myPref.getBoolean("lwp_auto_animation_key",true))
                        mImagesArrayIndex++;
                    else
                        //
                //  if (myPref.getBoolean("lwp_auto_animation_key",true))
                        //incrementCounter2();

                    Thread.sleep(SeekBarPreference.mCurrentValue);
                }
            } catch (Exception e) {
                //
            }
        }