Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7043549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:18:11+00:00 2026-05-28T02:18:11+00:00

EDIT: I’ll try and make it clearer sorry for the confusion. I have two

  • 0

EDIT: I’ll try and make it clearer sorry for the confusion.
I have two livewallpapers one is called the Past one is called the Future, what I want to do is put both into one livewallpaper (sort of a two for one deal) but let the user decide which one they want to load.
How I had it set up for one (let’s say the Past) I had the onDraw method running in a class called the Past (it did not impliment anything) just past the onDraw and put the whole livewallpaper togeather.
In the livewallpaper engine I had this.

 public class ThePastActivity extends WallpaperService {
@Override
public Engine onCreateEngine() {
    return new ThePastActivityEngine();
}


class ThePastActivityEngine extends Engine {

    private Past _past;

    public ThePastActivityEngine() {
        this._past = new Past();
        this._past.initialize(getBaseContext(), getSurfaceHolder());
    }


    @Override
    public void onVisibilityChanged(boolean visible) {
        if(visible){
            this._past.render();
        }
    }

    @Override
    public void onSurfaceChanged(SurfaceHolder holder, int format,
            int width, int height) {        
        super.onSurfaceChanged(holder, format, width, height);          
    }


    @Override
    public void onSurfaceCreated(SurfaceHolder holder) {            
        super.onSurfaceCreated(holder);
        this._past.start();
    }

    @Override
    public void onSurfaceDestroyed(SurfaceHolder holder) {          
        super.onSurfaceDestroyed(holder);
        this._past.stop();
    }

    @Override
    public void onOffsetsChanged(float xOffset, float yOffset,float xStep, float yStep, int xPixels, int yPixels) {
     this._past.drawXOff = Math.round((this._blimp.theBackgroundImage.getWidth() - initFrameParamsWidth()) * -xOffset);
     this._past.drawYOff = Math.round((this._blimp.theBackgroundImage.getHeight() - initFrameParams()) * -yOffset);

        this._past.render();

 }

}

Now I have two instead of one. The new one is called Future so now I have it like so:

   public class ThePastActivity extends WallpaperService {

    public static final String SHARED_PREFS_NAME = "livewallpapersettings";
public static final String PREFERENCE_BACK = "livewallpaper_back";         

@Override
public Engine onCreateEngine() {
    return new ThePastActivityEngine();
}


class ThePastActivityEngine extends Engine implements SharedPreferences.OnSharedPreferenceChangeListener{
    private SharedPreferences prefs;
            private String whichEra;
    private Past _past;
            private Future _future;

            //make a new name  ChooseEra and let it become either Past or Future
            private ChooseEra _chooseEra;

    public ThePastActivityEngine() {
        this._chooseEra = new ChooseEra();
        this._past.initialize(getBaseContext(), getSurfaceHolder());
                    prefs = TheSteampunkCityActivity.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
        prefs.registerOnSharedPreferenceChangeListener(this);
        onSharedPreferenceChanged(prefs, null);
    }

            public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {

        whichEra=(prefs.getString(PREFERENCE_BACK, "past"));
        // from here I want to get either the "past" or "future" 
                    // make the ChooseEra to be either Past or Future
                   // and use that for this livewallpaper engine instead
    }


    @Override
    public void onVisibilityChanged(boolean visible) {
        if(visible){
            this._chooseEra.render();
        }
    }

    @Override
    public void onSurfaceChanged(SurfaceHolder holder, int format,
            int width, int height) {        
        super.onSurfaceChanged(holder, format, width, height);          
    }


    @Override
    public void onSurfaceCreated(SurfaceHolder holder) {            
        super.onSurfaceCreated(holder);
        this._past.start();
    }

    @Override
    public void onSurfaceDestroyed(SurfaceHolder holder) {          
        super.onSurfaceDestroyed(holder);
        this._chooseEra.stop();
    }

    @Override
    public void onOffsetsChanged(float xOffset, float yOffset,float xStep, float yStep, int xPixels, int yPixels) {
     this._chooseEra.drawXOff = Math.round((this._chooseEra.theBackgroundImage.getWidth() - initFrameParamsWidth()) * -xOffset);
     this._chooseEra.drawYOff = Math.round((this._chooseEra.theBackgroundImage.getHeight() - initFrameParams()) * -yOffset);

        this._chooseEra.render();

 }

}

So chooseEra has to become either Future or Past so it reads one of the two classes only and passes the arguments along through the engine.
The issue I am having is making ChooseEra to become either Past or Future. Normally using a method is easy to do but this is the first time I am trying to make it change the class name so when I put

private ChooseEra _chooseEra; 

it makes no sense at all, I tried ChooseEra = Past and ChooseEra = Future in an if else statement comparing the prefs of “past” and “future” but no luck.
Again any help is greatly appreciated.
Sam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:18:12+00:00Added an answer on May 28, 2026 at 2:18 am

    Your having typing issues. If you want to return the implementation to use (either Future or Past) then they need a shared interface or base class that you can use. I’ll pick the name to be Era. Define all of your variables of that shared type and it will work. For example:

    public Era readTheEra(SharedPreferences prefs) {
        String whichEra = prefs.getString(PREFERENCE_BACK, "past");
        Era era = whichEra.equals("past") ? new Past() : new Future();
        return era;
    }
    

    Notice Era is marked as the return type of the method (you had void which won’t work). Also notice I simply passed the SharedPreferences to the method, and encapsulated the code to extract the preference value in the method. That way you aren’t writing to instance variables (that you don’t need), then reading in other methods. Just pass the information to the method, and don’t save the intermediate steps. The only thing you need is the Era reference to use. The value of the preference isn’t needed after you instantiate the correct class.

    You’ll need to mark the two concrete implementations as implementing the Era Interface:

    public interface Era {
       // put methods here you need both implementations to 
       // have so you can work from Era interface and not the 
       // individual concrete clases.
    }
    
    public class Past implements Era {
        ...
    }
    
    public class Future implements Era {
        ...
    }
    
    public class Engine {
       private Era era;
    
       ...
       private Era readTheEra(SharedPreferences prefs) {
          String whichEra = prefs.getString(PREFERENCE_BACK, "past");
          Era era = whichEra.equals("past") ? new Past() : new Future();
          return era;
       }
    }
    

    I picked to use Interfaces because your question isn’t clear enough to know if you need classes or can use simply Interfaces. But all of the same thing applies if you need to use some class like Activity or whatever. Subclass Activty with an abstract base class, and Past and Future should subclass the abstract base class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
EDIT (4/3/2017): Sorry, I was a noob back then. I'm trying to make a
EDIT heres the github page if people want to have a look https://github.com/brandongrossutti/EventStore I
Edit: Translated I have a RSS-feed that i want to parse. It's a podcast
Edit: The below question was answered by this . I have a new updated
EDIT: Changed as I have a different issue with the same code 2nd Edit:
EDIT After staring at this for 2 days, I do see one issue. I
EDIT: I have reworded the title question slightly, and adjusted the text to respond
[Edit: see below for final code] I have the following code and I'm trying
[Edit: don't try to understand the whole thing and don't waste your time to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.