Skip to content

Commit

Permalink
attempt to fix android touch bug
Browse files Browse the repository at this point in the history
now required API >= 19
  • Loading branch information
White Dragon committed Apr 4, 2018
1 parent df70874 commit 85383d0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
8 changes: 4 additions & 4 deletions engine/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.openbor.engine"
android:versionCode="1"
android:versionName="1.4.2"
android:versionName="1.4.3"
android:installLocation="preferExternal">

<!-- Android 4.0.1 -->
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16" />
<!-- Android 4.4.2 -->
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
Expand All @@ -24,7 +24,7 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="org.libsdl.app.SDLActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape"
>
<intent-filter>
Expand Down
42 changes: 33 additions & 9 deletions engine/android/jni/openbor/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ extern int videoMode;

SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture *texture = NULL;
SDL_Texture *texture = NULL;
SDL_Texture *texture_base = NULL;

//For Android - Textures and a surface for the buttons
SDL_Texture *buttons = NULL;
Expand Down Expand Up @@ -355,7 +356,12 @@ int video_set_mode(s_videomodes videomodes)
// 8-bit color should be transparently converted to 32-bit
assert(videomodes.pixel == 2 || videomodes.pixel == 4);

//destroy all
//destroy all
if(texture_base)
{
SDL_DestroyTexture(texture_base);
texture_base = NULL;
}
if(texture)
{
SDL_DestroyTexture(texture);
Expand Down Expand Up @@ -397,6 +403,20 @@ int video_set_mode(s_videomodes videomodes)

textureWidth = videomodes.hRes;
textureHeight = videomodes.vRes;

if(!texture_base)
{
SDL_Surface *tmp_surface = SDL_CreateRGBSurface(0, 800, 480, 32, 0, 0, 0, 0);
SDL_FillRect(tmp_surface, NULL, SDL_MapRGB(tmp_surface->format, 0, 0, 0));
SDL_SetSurfaceBlendMode(tmp_surface, SDL_BLENDMODE_NONE);
if(!tmp_surface || !(texture_base = SDL_CreateTextureFromSurface(renderer, tmp_surface)))
{
printf("error: %s\n", SDL_GetError());
return 0;
}
SDL_FreeSurface(tmp_surface);
tmp_surface = NULL;
}

if(!(texture = SDL_CreateTexture(renderer, pixelformats[videomodes.pixel-1], SDL_TEXTUREACCESS_STREAMING, textureWidth, textureHeight)))
{
Expand All @@ -408,14 +428,14 @@ int video_set_mode(s_videomodes videomodes)

if(!buttons)
{
SDL_Surface *bscreen = pngToSurface(buttonpng);
if(!bscreen || !(buttons = SDL_CreateTextureFromSurface(renderer, bscreen)))
SDL_Surface *btn_screen = pngToSurface(buttonpng);
if(!btn_screen || !(buttons = SDL_CreateTextureFromSurface(renderer, btn_screen)))
{
printf("error: %s\n", SDL_GetError());
return 0;
}
SDL_FreeSurface(bscreen);
bscreen = NULL;
SDL_FreeSurface(btn_screen);
btn_screen = NULL;
}

SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
Expand All @@ -434,6 +454,13 @@ void blit()
int hide_touch;
extern int hide_t;

SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);

SDL_RenderSetLogicalSize(renderer, 0, 0);
SDL_SetTextureBlendMode(texture_base, SDL_BLENDMODE_NONE);
SDL_RenderCopy(renderer, texture_base, NULL, NULL);

if(stretch)
{
SDL_RenderSetLogicalSize(renderer, 0, 0);
Expand All @@ -442,9 +469,6 @@ void blit()
{
SDL_RenderSetLogicalSize(renderer, textureWidth, textureHeight);
}

SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);

if(brightness > 0)
Expand Down
2 changes: 1 addition & 1 deletion engine/android/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-16
target=android-19
43 changes: 38 additions & 5 deletions engine/android/src/org/libsdl/app/SDLActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public enum NativeState {
protected static boolean mScreenKeyboardShown;
protected static ViewGroup mLayout;
protected static SDLClipboardHandler mClipboardHandler;
protected static WakeLock wakeLock;
protected static WakeLock wakeLock;
protected static View decorView;


// This is what SDL runs in. It invokes SDL_main(), eventually
Expand Down Expand Up @@ -227,8 +228,24 @@ public void onClick(DialogInterface dialog,int id) {
mLayout.addView(mSurface);

setContentView(mLayout);
setWindowStyle(false);
CopyPak("BOR");
setWindowStyle(false);

CopyPak("BOR");

//White Dragon: hide navigation bar programmatically
SDLActivity.decorView = getWindow().getDecorView();
hideSystemUI();

SDLActivity.decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
hideSystemUI();
}
}
});


//CRxTRDude - Added FLAG_KEEP_SCREEN_ON to prevent screen timeout.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Expand All @@ -250,7 +267,21 @@ public void onClick(DialogInterface dialog,int id) {
}*/
}

public static native void setRootDir(String dir);
public static native void setRootDir(String dir);

private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}


private void CopyPak(String pakName)
{
Expand Down Expand Up @@ -333,7 +364,9 @@ public void onWindowFocusChanged(boolean hasFocus) {

SDLActivity.mHasFocus = hasFocus;
if (hasFocus) {
mNextNativeState = NativeState.RESUMED;
mNextNativeState = NativeState.RESUMED;

hideSystemUI();
} else {
mNextNativeState = NativeState.PAUSED;
}
Expand Down

0 comments on commit 85383d0

Please sign in to comment.