Skip to content

Bump to SDL2 2.0.10 & extract .java from SDL2 tarball #1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ def name(self):
modname = self.__class__.__module__
return modname.split(".", 2)[-1]

def _copy_in_final_files(self):
if self.name == "sdl2":
# Get the paths for copying SDL2's java source code:
sdl2_recipe = Recipe.get_recipe("sdl2", self.ctx)
sdl2_build_dir = sdl2_recipe.get_jni_dir()
src_dir = join(sdl2_build_dir, "SDL", "android-project",
"app", "src", "main", "java",
"org", "libsdl", "app")
target_dir = join(self.dist_dir, 'src', 'main', 'java', 'org',
'libsdl', 'app')

# Do actual copying:
info('Copying in SDL2 .java files from: ' + str(src_dir))
if not os.path.exists(target_dir):
os.makedirs(target_dir)
copy_files(src_dir, target_dir, override=True)

def prepare_build_dir(self):
'''Ensure that a build dir exists for the recipe. This same single
dir will be used for building all different archs.'''
Expand All @@ -161,7 +178,12 @@ def prepare_build_dir(self):
def prepare_dist_dir(self, name):
ensure_dir(self.dist_dir)

def run_distribute(self):
def assemble_distribution(self):
''' Copies all the files into the distribution (this function is
overridden by the specific bootstrap classes to do this)
and add in the distribution info.
'''
self._copy_in_final_files()
self.distribution.save_info(self.dist_dir)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/bootstraps/empty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EmptyBootstrap(Bootstrap):

can_be_chosen_automatically = False

def run_distribute(self):
def assemble_distribution(self):
print('empty bootstrap has no distribute')
exit(1)

Expand Down
4 changes: 2 additions & 2 deletions pythonforandroid/bootstraps/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SDL2GradleBootstrap(Bootstrap):
set(Bootstrap.recipe_depends).union({'sdl2'})
)

def run_distribute(self):
def assemble_distribution(self):
info_main("# Creating Android project ({})".format(self.name))

arch = self.ctx.archs[0]
Expand Down Expand Up @@ -49,7 +49,7 @@ def run_distribute(self):

self.strip_libraries(arch)
self.fry_eggs(site_packages_dir)
super(SDL2GradleBootstrap, self).run_distribute()
super(SDL2GradleBootstrap, self).assemble_distribution()


bootstrap = SDL2GradleBootstrap()
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected void onPostExecute(String result) {
mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData;

PowerManager pm = (PowerManager) mActivity.getSystemService(Context.POWER_SERVICE);
if ( mActivity.mMetaData.getInt("wakelock") == 1 ) {
if (mActivity.mMetaData.getInt("wakelock") == 1) {
mActivity.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On");
mActivity.mWakeLock.acquire();
}
Expand Down Expand Up @@ -450,35 +450,32 @@ public void appConfirmedActive() {
public void considerLoadingScreenRemoval() {
if (loadingScreenRemovalTimer != null)
return;
runOnUiThread(new Runnable() {
public void run() {
if (((PythonActivity)PythonActivity.mSingleton).mAppConfirmedActive &&
loadingScreenRemovalTimer == null) {
// Remove loading screen but with a delay.
// (app can use p4a's android.loadingscreen module to
// do it quicker if it wants to)
// get a handler (call from main thread)
// this will run when timer elapses
TimerTask removalTask = new TimerTask() {
if (PythonActivity.mSingleton != null &&
mAppConfirmedActive &&
loadingScreenRemovalTimer == null) {
Log.v(TAG, "loading screen timer Runnable() launched.");
// Remove loading screen but with a delay.
// (app can use p4a's android.loadingscreen module to
// do it quicker if it wants to)
TimerTask removalTask = new TimerTask() {
@Override
public void run() {
// post a runnable to the handler
runOnUiThread(new Runnable() {
@Override
public void run() {
// post a runnable to the handler
runOnUiThread(new Runnable() {
@Override
public void run() {
PythonActivity activity =
((PythonActivity)PythonActivity.mSingleton);
if (activity != null)
activity.removeLoadingScreen();
}
});
Log.v(TAG, "loading screen timer Runnable() finished.");
PythonActivity activity =
((PythonActivity)PythonActivity.mSingleton);
if (activity != null)
activity.removeLoadingScreen();
}
};
loadingScreenRemovalTimer = new Timer();
loadingScreenRemovalTimer.schedule(removalTask, 5000);
});
}
}
});
};
loadingScreenRemovalTimer = new Timer();
loadingScreenRemovalTimer.schedule(removalTask, 5000);
}
}

public void removeLoadingScreen() {
Expand Down Expand Up @@ -589,14 +586,30 @@ protected void onResume() {
if (this.mWakeLock != null) {
this.mWakeLock.acquire();
}
Log.v(TAG, "onResume()");
Log.v(TAG, "onResume(), mSDLThread exists yet: " + (mSDLThread != null));
try {
super.onResume();
if (mSDLThread == null && !mIsResumedCalled) {
// Ok so SDL2's onStart() usually launches the native code.
// However, this may fail if native libs aren't loaded yet at that point
// (due ot our loading screen) so we may need to manually trigger this,
// otherwise code would only launch by leaving & re-entering the app:
Log.v(TAG, "Loading screen workaround: triggering native resume");
if (mSDLThread == null && mCurrentNativeState == NativeState.RESUMED) {
// Force a state change so SDL2 doesn't just ignore the resume:
mCurrentNativeState = NativeState.PAUSED;
}
resumeNativeThread(); // native resume to call native code
}
} catch (UnsatisfiedLinkError e) {
// Catch resume while still in loading screen failing to
// call native function (since it's not yet loaded)
Log.v(TAG, "failed to call native onResume() because libs " +
"aren't loaded yet. this is expected to happen");
}
considerLoadingScreenRemoval();
Log.v(TAG, "onResume() done in PythonActivity, " +
"mSDLThread exists yet: " + (mSDLThread != null));
}

@Override
Expand All @@ -606,6 +619,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
} catch (UnsatisfiedLinkError e) {
// Catch window focus while still in loading screen failing to
// call native function (since it's not yet loaded)
return; // no point in barging further
}
considerLoadingScreenRemoval();
}
Expand Down

This file was deleted.

Loading