Extending SDLActivity (2.0.1/Android)

I’m trying to extend the SDLActivity, to avoid having to patch my "custom"
SDLActivity and build native glue for native methods every time I want to
update SDL.

My game uses RelativeLayout and needs access to SDLSurface for better "ads"
placement, so I had to override the onCreate method, and here i found the
problem:

[javac]
/home/gabry/no-backup/local/gabry/etw/android-project/src/org/ggsoft/etw/ETWGame.java:51:
org.libsdl.app.SDLSurface is not public in org.libsdl.app; cannot be
accessed from outside package
[javac] mSurface = new org.libsdl.app.SDLSurface(getApplication());

And also:

[javac]

/home/gabry/no-backup/local/gabry/etw/android-project/src/org/ggsoft/etw/ETWGame.java:72:
setId(int) in android.view.View is defined in an inaccessible class or
interface
[javac] mSurface.setId(1);
[javac] ^
[javac]
/home/gabry/no-backup/local/gabry/etw/android-project/src/org/ggsoft/etw/ETWGame.java:223:
getId() in android.view.View is defined in an inaccessible class or
interface
[javac] params.addRule(RelativeLayout.ABOVE,
mSurface.getId());

It seems that everything involving SDLSurface cannot be accessed since
SDLSurface is private, but I cannot make SDLSurface public otherwise I get
this error:

[javac]

/home/gabry/no-backup/local/gabry/etw/android-project/src/org/libsdl/app/SDLActivity.java:431:
class SDLSurface is public, should be declared in a file named
SDLSurface.java
[javac] public class SDLSurface extends SurfaceView implements
SurfaceHolder.Callback,

So I fear that if we want to have a “really” extendable SDLActivity we need
to *SPLIT *SDL in a few different files, SDLActivity.java, SDLSurface.java
and SDLMain.java otherwise the @Override in these classes cannot be used at
all…

Extending SDLSurface is not an option since it’s private, so it cannot be
done…

Please note that I’m not very used to JAVA development, maybe there is
something I’m doing wrong…–
Bye,
Gabry

I can only offer you take a look at what I’m using. This isn’t all my
code. Parts of it were posted earlier on this mailinglist.

Keep in mind to fill all the needed variables in there (like adUnitId
and base64PublicKey)
There are also some in-game-payitems defined there, too.

At least the requested layout stuff is in there. So you might find it
useful.

The important part is this one:

 @Override
 public void setContentView(View view) {
     layout = new RelativeLayout(this);
     view.setId(SDLViewID);
     layout.addView(view);
     super.setContentView(layout);
 }

Regards
Martin
-------------- next part --------------
A non-text attachment was scrubbed…
Name: MyGame.java
Type: text/x-java
Size: 8522 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20131024/b705ab2c/attachment.java

That did the trick, override setContentView is the way to go, thanks!

I think @Override should be removed from many methods in SDLActivity.java
because they are really NOT overridable.

For instance all the methods of SDLSurface and SDLMain (that since they are
private are not extendable) and the methods that need access to mSurface of
SDLActivity (for instance onCreate).On Thu, Oct 24, 2013 at 5:12 PM, Martin Gerhardy <martin.gerhardy at gmail.com>wrote:

I can only offer you take a look at what I’m using. This isn’t all my
code. Parts of it were posted earlier on this mailinglist.

Keep in mind to fill all the needed variables in there (like adUnitId and
base64PublicKey)
There are also some in-game-payitems defined there, too.

At least the requested layout stuff is in there. So you might find it
useful.

The important part is this one:

@Override
public void setContentView(View view) {
    layout = new RelativeLayout(this);
    view.setId(SDLViewID);
    layout.addView(view);
    super.setContentView(layout);
}

Regards
Martin


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Ing. Gabriele Greco, DARTS Engineering
Tel: +39-0100980150 Fax: +39-0100980184
s-mail: Piazza Della Vittoria 9/3 - 16121 GENOVA (ITALY)

That depends on your interpretation of @Override. It’s meant to tell the
compiler that a method overrides another one so more static checking can be
done. It’s not the same as “virtual” in C++, but rather more like the
converse. It doesn’t enable overrides; it indicates that one has been used.

Jonny DOn Fri, Oct 25, 2013 at 3:46 AM, Gabriele Greco <gabriele.greco at darts.it>wrote:

That did the trick, override setContentView is the way to go, thanks!

I think @Override should be removed from many methods in SDLActivity.java
because they are really NOT overridable.

For instance all the methods of SDLSurface and SDLMain (that since they
are private are not extendable) and the methods that need access to
mSurface of SDLActivity (for instance onCreate).

On Thu, Oct 24, 2013 at 5:12 PM, Martin Gerhardy < martin.gerhardy at gmail.com> wrote:

I can only offer you take a look at what I’m using. This isn’t all my
code. Parts of it were posted earlier on this mailinglist.

Keep in mind to fill all the needed variables in there (like adUnitId and
base64PublicKey)
There are also some in-game-payitems defined there, too.

At least the requested layout stuff is in there. So you might find it
useful.

The important part is this one:

@Override
public void setContentView(View view) {
    layout = new RelativeLayout(this);
    view.setId(SDLViewID);
    layout.addView(view);
    super.setContentView(layout);
}

Regards
Martin


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Ing. Gabriele Greco, DARTS Engineering
Tel: +39-0100980150 Fax: +39-0100980184
s-mail: Piazza Della Vittoria 9/3 - 16121 GENOVA (ITALY)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org