Below is an example of how one might implement what you want to do where 4 different themes are available to choose from.
Step 1: Create an activity and give it the ProntoScript name, "
Resources". This activity will be used to store your background images.
Step 2: Create a page under the activity and give it the ProntoScript name, "
Images". Each of your background images will be placed on this page.
Step 3: Place 4 panels on the page inserting the appropriate background image to each, then giving each ProntoScript names. In this example they'll be named, "
bkgd_1", "
bkgd_2","
bkgd_3", and "
bkgd_4".
Now perform
Steps 4-6 shown below for each of the activities in which you'd like custom backgrounds used per the selected theme.
Step 4: Place the below ProntoScript at the activity level.
function doPageStart() {
doSetBkgd();
}
//
function doSetBkgd() {
if(System.getGlobal ("Theme")=="1") {
widget("Background").setImage(CF.widget("bkgd_1","Images","Resources").getImage(0),0); return;
}
if(System.getGlobal ("Theme")=="2") {
widget("Background").setImage(CF.widget("bkgd_2","Images","Resources").getImage(0),0); return;
}
if(System.getGlobal ("Theme")=="3") {
widget("Background").setImage(CF.widget("bkgd_3","Images","Resources").getImage(0),0); return;
}
if(System.getGlobal ("Theme")=="4") {
widget("Background").setImage(CF.widget("bkgd_4","Images","Resources").getImage(0),0); return;
}
else { System.setGlobal ("Theme","1");
widget("Background").setImage(CF.widget("bkgd_1","Images","Resources").getImage(0),0);
}
}The function
doPageStart() will be executed at the page level which in turn is executing the function
doSetBkgd(). The function
doSetBkgd() is responsible for populating the appropriate background image based on the theme which was selected. If a theme wasn't selected "Theme 1" will be used by default.
Step 5: Place the below ProntoScript on each page within the activity.
doPageStart();Step 6: Place a panel on each page within the activity to be used for your background image. Give the panel the ProntoScript name, "
Background".
Step 7: Last thing needed is a place within your activity where you're able to select what theme to be used. In this example lets say this is being done from your Home page. So on the Home page create 4 buttons, one labeled for each theme, then add the below ProntoScript to each.
ProntoScript to be placed on the button labeled, "Theme 1":
System.setGlobal ("Theme","1");ProntoScript to be placed on the button labeled, "Theme 2":
System.setGlobal ("Theme","2");ProntoScript to be placed on the button labeled, "Theme 3":
System.setGlobal ("Theme","3");ProntoScript to be placed on the button labeled, "Theme 4":
System.setGlobal ("Theme","4");Now if you wanted your Home page to use a themed background image as well just make sure to implement
Steps 4-6 shown above for the Home activity also. You'd also want to update the buttons on your Home page used to select each theme per the below as to ensure that when selecting a given theme the background image on the Home page updates on the fly.
ProntoScript to be placed on the button labeled, "Theme 1":
System.setGlobal ("Theme","1");
doPageStart();ProntoScript to be placed on the button labeled, "Theme 2":
System.setGlobal ("Theme","2");
doPageStart();ProntoScript to be placed on the button labeled, "Theme 3":
System.setGlobal ("Theme","3");
doPageStart();ProntoScript to be placed on the button labeled, "Theme 4":
System.setGlobal ("Theme","4");
doPageStart();Note above that the system global is first set, then the
doStartPage() function is executed which in turn results in the background image on the home page being updated accordingly based on the selected theme.
Added note...
Per my example, note that I've defined the given functions at the activity level instead of on each page. This prevents one from having to update the given function if needed on each individual page for a given activity. Furthermore, the function
doPageStart() is intended to run any needed ProntoScript when a given page is displayed. This is why I did not suggest executing the function
doSetBkgd() on each page directly. The function
doPageStart() is executed from each page instead. If at any point additional ProntoScript needs to be run when a given page is displayed you simply update the
doPageStart() function at the activity level rather than having to update the ProntoScript on each page individually.
(An example XCF can be downloaded here.)
Last edited by Lowpro on November 21, 2011 17:12.