Choose other background.

Discussion in 'Help & Support' started by Vinicius, Apr 21, 2013.

  1. Vinicius In the know

    Member Since:
    Apr 16, 2013
    Message Count:
    25
    Likes Received:
    7
    Trophy Points:
    25
    Someone here already did the settings from the live wallpaper to set another background? Example choose another fund in the same screen live wallpaper.

    If someone already got would post the code? I'm trying to make here is this more difficult!

    Thank you!
  2. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
    First update the shared prefs xml file to add a list preference. Then extract that preference to a string in the OnSharedPreferenceChanged method of the main java file. Then using a loop statement change the background resource in the getWallpaperResource method. Like this -

    XML file:

    Code (text):
    <ListPreference
    android:defaultValue="@string/background"
    android:entries="@array/backgroundNames"
    android:entryValues="@array/backgroundValues" //values are Background 1, Background 2
    android:key="background_settings"
    android:summary="Change the background"
    android:title="Choose Background" />
    Main Java File:
    In the OnSharedPreference method-

    Code (text):
    selectedBackground = prefs.getString("background_settings",
    "Background 1");
    mBackground = getWallpaperResource();
    then in the getWallpaperResource() use a loop statement like:

    Code (text):
    if(selectedBackground.equals("Background1")) {
    bg = BitmapFactory.decodeResource(getResources(),
    R.drawable.backgroundimage);}





    bsmooth1 and Maximus like this.
  3. Vinicius In the know

    Member Since:
    Apr 16, 2013
    Message Count:
    25
    Likes Received:
    7
    Trophy Points:
    25
    Hello, James.

    Thanks for sharing this code! I'll test it here!

    Vlw!
  4. Vinicius In the know

    Member Since:
    Apr 16, 2013
    Message Count:
    25
    Likes Received:
    7
    Trophy Points:
    25
    Hi James.

    I tried to implement here, plus I'm not getting this giving error ..

    Could be made available for download an example of a project by choosing various background? Or at least the java files to the methods implemented ..

    Thank you for your help!
  5. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
    Ok can you tell me what error you get?
  6. Vinicius In the know

    Member Since:
    Apr 16, 2013
    Message Count:
    25
    Likes Received:
    7
    Trophy Points:
    25
    Hello James!

    James are various errors, like much possible if you put up here in the forum with a link to download an example ... I would be eternally grateful! So missing this for my live wallpaper stay good! I hope your help!

    Thank you for your attention and help here in the forum!
  7. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
    Maximus, Vinicius and davveis like this.
  8. Vinicius In the know

    Member Since:
    Apr 16, 2013
    Message Count:
    25
    Likes Received:
    7
    Trophy Points:
    25
    Perfect James!

    Wow, thanks a lot for example, and for helping me! You helped me a lot with this example! You here in the forum Live Wallpaper Creator are really cool!

    I greatly appreciate the help James! Success for you!

    Thank you, Thank you, Thank you = D.
    James Rebello likes this.
  9. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
    Absolutely no problem. Always happy to help :)
    davveis and Vinicius like this.
  10. davveis Keeps coming back

    Member Since:
    Mar 20, 2013
    Message Count:
    15
    Likes Received:
    7
    Trophy Points:
    10
    Does somebody know how to include this into the source code generated by LWC 2.6? The main class is guite different. I tried it, but I still have some errors wich I cant solve. :)
  11. NewKid Seasoned Vet

    Member Since:
    Apr 1, 2012
    Message Count:
    100
    Likes Received:
    20
    Trophy Points:
    100
    I would like to do that too but this code is hard, at least for me :(
  12. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
    Instead of using this from 2.1
    Code (text):
    if(selectedBackground.equals("Background1")) {
    bg = BitmapFactory.decodeResource(getResources(),
    R.drawable.backgroundimage);}
    try this in 2.6
    Code (text):

                if (selectedBackground.equals("Background 1")) {
     
                    res = R.drawable.wallpaper_hdpi;
     
                    if (sfHigh > sfMid) { // use mid resolution image
                        scaleFactor = sfMid;
                        res = R.drawable.wallpaper_mdpi;
                    }
     
                }
     
                else if (selectedBackground.equals("Background 2")) {
     
                    res = R.drawable.wallpaper2_hdpi;
     
                    if (sfHigh > sfMid) { // use mid resolution image
                        scaleFactor = sfMid;
                        res = R.drawable.wallpaper2_mdpi;
                    }
     
                }
     
                else {
     
                    res = R.drawable.wallpaper3_hdpi;
     
                    if (sfHigh > sfMid) { // use mid resolution image
                        scaleFactor = sfMid;
                        res = R.drawable.wallpaper3_mdpi;
                    }
     
                }
     
    EDIT: Also comment this code in init() method
    Code (text):
                if (background == null)
                background = getWallpaperResource();
    davveis likes this.
  13. davveis Keeps coming back

    Member Since:
    Mar 20, 2013
    Message Count:
    15
    Likes Received:
    7
    Trophy Points:
    10
    Thanks, it helped a lot. Also your Serene Rainfall Live Wallpaper is really beautifull - 5 stars. :)
  14. Vas Origin

    Member Since:
    Jan 4, 2012
    Message Count:
    770
    Likes Received:
    175
    Trophy Points:
    500
    Don't mind me. Moving this out of Archive.
  15. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
  16. ThemeStudio New Guy

    Member Since:
    Jun 25, 2013
    Message Count:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hello James,

    I followed the steps mentioned above however I am not sure what is to be done in the main Java file as I am quite new to eclipse, I am using LWC 2.6. I will be grateful if you could help me with the option to choose backgrounds.

    The link to the Demo Project is empty.

    Thanks
  17. James Rebello Active Member

    Member Since:
    Mar 28, 2013
    Message Count:
    70
    Likes Received:
    31
    Trophy Points:
    50
    You can check the link again. I have reuploaded it.The demo project is from LWC 2.1. Just follow the steps mentioned above for LWC 2.6
    Will try and create a demo project for 2.6
    Snow Fall likes this.
  18. ThemeStudio New Guy

    Member Since:
    Jun 25, 2013
    Message Count:
    3
    Likes Received:
    0
    Trophy Points:
    0
  19. Snow Fall Keeps coming back

    Member Since:
    Jun 23, 2013
    Message Count:
    16
    Likes Received:
    0
    Trophy Points:
    10
    Congrats
  20. Snow Fall Keeps coming back

    Member Since:
    Jun 23, 2013
    Message Count:
    16
    Likes Received:
    0
    Trophy Points:
    10
    Hello, James I've tried it on 2.6 but it giving error on XML, can you please help me for this?? Please.

Share This Page