SDL: Android TV support, preliminary for now.

This commit is contained in:
Sergii Pylypenko
2015-12-07 22:24:46 +02:00
parent bca631718c
commit fb7e7ae217
14 changed files with 45 additions and 20 deletions

3
.gitignore vendored
View File

@@ -6,7 +6,7 @@ project/libs
project/assets
project/obj
project/src
project/res/values*
project/res/values*/strings.xml
project/AndroidManifest.xml
project/jni/Settings.mk
project/jni/application/*/libapplication*.so
@@ -17,3 +17,4 @@ project/proguard-project.txt
project/proguard-local.cfg
project/themes/converter
project/jni/android-support
project/res/drawable/banner.png

View File

@@ -909,7 +909,7 @@ cat project/jni/SettingsTemplate.mk | \
project/jni/Settings.mk
echo Patching strings.xml
rm -rf project/res/values*
rm -rf project/res/values*/strings.xml
cd $JAVA_SRC_PATH/translations
for F in */strings.xml; do
mkdir -p ../../res/`dirname $F`
@@ -994,6 +994,13 @@ rm -rf project/bin/res
rm -rf project/jni/android-support
ln -s "`which ndk-build | sed 's@/ndk-build@@'`/sources/android/support" project/jni/android-support
rm -rf project/res/drawable/banner.png
if [ -e project/jni/application/src/banner.png ]; then
ln -s ../../jni/application/src/banner.png project/res/drawable/banner.png
else
ln -s ../../themes/tv-banner-placeholder.png project/res/drawable/banner.png
fi
if uname -s | grep -i "darwin" > /dev/null ; then
find project/src -name "*.killme.tmp" -delete
fi

View File

@@ -9,6 +9,8 @@
android:icon="@drawable/icon"
android:debuggable="true"
android:allowBackup="true"
android:banner="@drawable/banner"
android:isGame="true"
>
<activity android:name=".MainActivity"
android:label="@string/app_name"
@@ -22,6 +24,7 @@
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" /> <!-- Samsung's multiwindow -->
<action android:name="com.sec.android.airview.HOVER" /> <!-- Stupid Samsung requires their own intent for finger-hover events -->
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> <!-- Android TV requires this -->
</intent-filter>
</activity>
<!-- ==ADMOB== --> <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection"/>
@@ -55,6 +58,9 @@
<!-- <uses-permission android:name="android.permission.VIBRATE"></uses-permission> --> <!-- Vibrator not supported yet by SDL -->
<uses-feature android:name="android.hardware.touchscreen" android:required="false" /> <!-- Allow TV boxes -->
<uses-feature android:name="android.software.leanback" android:required="false" /> <!-- Android TV requires this -->
<uses-feature android:name="android.hardware.microphone" android:required="false" /> <!-- Android TV requires this -->
<uses-feature android:name="android.hardware.gamepad" android:required="false"/> <!-- Android TV requires this -->
<!-- ==SCREEN-SIZE-SMALL== --> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" />
<!-- ==SCREEN-SIZE-NORMAL== --> <supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" />
<!-- ==SCREEN-SIZE-LARGE== --> <supports-screens android:smallScreens="false" android:normalScreens="false" android:largeScreens="true" android:xlargeScreens="true" />

View File

@@ -92,6 +92,7 @@ import android.inputmethodservice.Keyboard;
import android.app.Notification;
import android.app.PendingIntent;
import java.util.TreeSet;
import android.app.UiModeManager;
public class MainActivity extends Activity
{
@@ -349,7 +350,13 @@ public class MainActivity extends Activity
setContentView(_videoLayout);
mGLView = new DemoGLSurfaceView(this);
SetLayerType.get().setLayerType(mGLView);
_videoLayout.addView(mGLView);
FrameLayout.LayoutParams margin = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
// Add TV screen borders, if needed
margin.setMargins( getResources().getDimensionPixelOffset(R.dimen.screen_border_horizontal),
getResources().getDimensionPixelOffset(R.dimen.screen_border_vertical),
getResources().getDimensionPixelOffset(R.dimen.screen_border_horizontal),
getResources().getDimensionPixelOffset(R.dimen.screen_border_vertical));
_videoLayout.addView(mGLView, margin);
mGLView.setFocusableInTouchMode(true);
mGLView.setFocusable(true);
mGLView.requestFocus();
@@ -1444,7 +1451,8 @@ public class MainActivity extends Activity
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return Globals.OuyaEmulation;
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) || Globals.OuyaEmulation;
}
public boolean isCurrentOrientationHorizontal()

View File

@@ -202,8 +202,6 @@ class Settings
}
Log.i("SDL", "libSDL: Settings.Load(): enter");
nativeInitKeymap();
if( p.isRunningOnOUYA() )
nativeSetKeymapKey(KeyEvent.KEYCODE_MENU, nativeGetKeymapKey(KeyEvent.KEYCODE_BACK)); // Ouya does not have Back key, only Menu, so remap Back keycode to Menu
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
{
int sdlKey = nativeGetKeymapKey(i);
@@ -635,7 +633,11 @@ class Settings
nativeSetEnv( "ANDROID_PACKAGE_PATH", p.getPackageCodePath() );
Log.d("SDL", "libSDL: Is running on OUYA: " + p.isRunningOnOUYA());
if( p.isRunningOnOUYA() )
{
nativeSetEnv( "OUYA", "1" );
nativeSetEnv( "TV", "1" );
nativeSetEnv( "ANDROID_TV", "1" );
}
if (p.getIntent().getStringExtra(RestartMainActivity.SDL_RESTART_PARAMS) != null)
nativeSetEnv( RestartMainActivity.SDL_RESTART_PARAMS, p.getIntent().getStringExtra(RestartMainActivity.SDL_RESTART_PARAMS) );
try {

View File

@@ -616,6 +616,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
int mLastPendingResize = 0;
public void onWindowResize(final int w, final int h)
{
if (context.isRunningOnOUYA())
return; // TV screen is never resized, and this event will mess up TV borders
Log.d("SDL", "libSDL: DemoRenderer.onWindowResize(): " + w + "x" + h);
mLastPendingResize ++;
final int resizeThreadIndex = mLastPendingResize;
@@ -990,6 +992,8 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
@Override
public boolean onTouchEvent(final MotionEvent event)
{
if (getX() != 0)
event.offsetLocation(-getX(), -getY());
DifferentTouchInput.touchInput.process(event);
if( DemoRenderer.mRatelimitTouchEvents )
{

View File

@@ -658,7 +658,7 @@ int main(int argc, char* argv[])
int mx, my;
int b = SDL_GetMouseState(&mx, &my);
//__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Mouse buttons: %d", b);
//__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Mouse: %04d %04d buttons %d", mx, my, b);
int cursorIdx = 0;
if( b & SDL_BUTTON_LMASK )
cursorIdx |= 1;

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -420,17 +420,6 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
window.w = width;
window.h = height;
if( getenv("OUYA") )
{
// Leave 10% at the borders blank, because all TVs have crazy thick edges and not enough pixels
// Also this is enforced by Ouya guidelines, so there's not much choice.
window.x += window.w / 10;
window.y += window.h / 10;
window.w -= window.w / 5;
window.h -= window.h / 5;
SDL_ANDROID_ForceClearScreenRectAmount = 4;
}
SDL_ANDROID_ForceClearScreenRect[0].x = 0;
SDL_ANDROID_ForceClearScreenRect[0].y = 0;
SDL_ANDROID_ForceClearScreenRect[0].w = window.x;

View File

@@ -0,0 +1,4 @@
<resources>
<dimen name="screen_border_horizontal">48dp</dimen>
<dimen name="screen_border_vertical">27dp</dimen>
</resources>

View File

@@ -0,0 +1,4 @@
<resources>
<dimen name="screen_border_horizontal">0dp</dimen>
<dimen name="screen_border_vertical">0dp</dimen>
</resources>

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB