Search code examples
androidpreferenceslive-wallpaperrenderscript

Android LWP, How to refresh RenderScript objects after Setting Preferences Changes?


I have developed Android LWP using RenderScript. Now I want to add Setting Page and I use Preferences to save the option values.

EG. Initial objects quantity is 10. Then user can change the objects quantity to 20.

I cannot update/refresh/reset/recall the RenderScript to regenerate with the new Setting. How to do it?

I have managed up to onSharedPreferenceChanged, but how to call it in order to regenerate the LWP with the new Setting just after user click?

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//How to force the renderscript to update here
}    

In fact, what I need to know is "How to refresh/clear any drawn object on renderscript?" Because when setting has been changed, I need to redraw the objects again....

The best things I have managed to go so far is to set the quantity of the objects on the listener like this

private class SPListener implements SharedPreferences.OnSharedPreferenceChangeListener {

@Override
public void onSharedPreferenceChanged(
        SharedPreferences sharedPreferences, String key) {
    // TODO Auto-generated method stub

    OBJ_COUNT = Integer.parseInt(Utility.getNoOfObjects(mContext));

    mScript.set_gObjectsCount(OBJ_COUNT);           
    mScript.invoke_updateObjects();


}

}

But I got "double" drawn objects. I need to clear existing objects first before I set with new quantity of objects.

EG. Initial objects quantity is 10. Then user can change the objects quantity to 5.

What I got is still 10 objects....with 5 objects are drawn twice/duplicated on top of it. So 5 objects have darker color due this overlay drawn.


Solution

  • Finally managed to fix it...Nothing wrong on the technique. The location to update is also correct on onSharedPreferenceChanged. But I manage to redraw everything perfectly now.