Skip to content

Commit

Permalink
Android work in progress changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioLiebisch committed Mar 20, 2018
1 parent 4cd36b7 commit ab63f22
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 300 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Expand Up @@ -125,11 +125,11 @@ if(SFML_OS_ANDROID)
# pass shared STL configuration (if any)
if (CMAKE_ANDROID_STL_TYPE MATCHES "_shared")
add_definitions("-DSTL_LIBRARY=${CMAKE_ANDROID_STL_TYPE}")
if(NOT CMAKE_ANDROID_STL_TYPE MATCHES "c\\+\\+_shared")
message("Android: Using ${CMAKE_ANDROID_STL_TYPE} as STL. Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
endif()
# if(NOT CMAKE_ANDROID_STL_TYPE MATCHES "c\\+\\+_shared")
# message("Android: Using ${CMAKE_ANDROID_STL_TYPE} as STL. Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
# endif()
else()
message(WARNING "Android: You're using a static STL (${CMAKE_ANDROID_STL_TYPE}). Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
# message(WARNING "Android: You're using a static STL (${CMAKE_ANDROID_STL_TYPE}). Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
endif()

# let the user switch ABIs
Expand Down
1 change: 1 addition & 0 deletions examples/android/.gitignore
Expand Up @@ -5,3 +5,4 @@ build
android.iml
app/build
app/.externalNativeBuild
app/src/main/obj
8 changes: 4 additions & 4 deletions examples/android/app/build.gradle
Expand Up @@ -4,14 +4,14 @@ android {
compileSdkVersion 27
defaultConfig {
applicationId "org.sfmldev.android"
minSdkVersion 19
targetSdkVersion 23
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
cppFlags "-std=c++14 -frtti -fexceptions"
// cppFlags "-std=c++14 -frtti -fexceptions"
}

}
Expand All @@ -28,7 +28,7 @@ android {
}
externalNativeBuild {
ndkBuild {
path "src/main/cpp/Android.mk"
path "src/main/jni/Android.mk"

}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/android/app/src/main/AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sfml"
package="org.sfmldev.android"
android:versionCode="1"
android:versionName="1.0" >

Expand All @@ -22,7 +22,7 @@
android:icon="@drawable/sfml_logo"
android:configChanges="keyboardHidden|orientation|screenSize">

<meta-data android:name="android.app.lib_name" android:value="sfml-activity" />
<meta-data android:name="android.app.lib_name" android:value="sfml-activity-d" />
<meta-data android:name="sfml.app.lib_name" android:value="sfml-example" />

<intent-filter>
Expand Down
20 changes: 0 additions & 20 deletions examples/android/app/src/main/cpp/Android.mk

This file was deleted.

5 changes: 0 additions & 5 deletions examples/android/app/src/main/cpp/Application.mk

This file was deleted.

20 changes: 20 additions & 0 deletions examples/android/app/src/main/jni/Android.mk
@@ -0,0 +1,20 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := sfml-example

LOCAL_SRC_FILES := main.cpp

LOCAL_SHARED_LIBRARIES := sfml-system-d
LOCAL_SHARED_LIBRARIES += sfml-window-d
LOCAL_SHARED_LIBRARIES += sfml-graphics-d
LOCAL_SHARED_LIBRARIES += sfml-audio-d
LOCAL_SHARED_LIBRARIES += sfml-network-d
LOCAL_SHARED_LIBRARIES += sfml-activity-d
LOCAL_SHARED_LIBRARIES += openal
LOCAL_WHOLE_STATIC_LIBRARIES := sfml-main-d

include $(BUILD_SHARED_LIBRARY)

$(call import-module,third_party/sfml)
8 changes: 8 additions & 0 deletions examples/android/app/src/main/jni/Application.mk
@@ -0,0 +1,8 @@
NDK_TOOLCHAIN_VERSION := 4.9
APP_PLATFORM := android-14
# APP_STL has to match CMAKE_ANDROID_STL_TYPE
APP_STL := c++_static
APP_ABI := armeabi-v7a
APP_MODULES := sfml-activity-d sfml-example
APP_OPTIM := debug
APP_CFLAG := -g -ggdb -O0
Expand Up @@ -76,40 +76,78 @@ int vibrate(sf::Time duration)
// ('vibrate()' in this example; undefine 'USE_JNI' above to disable it)
int main(int argc, char *argv[])
{
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "");
sf::VideoMode screen(sf::VideoMode::getDesktopMode());

sf::RenderWindow window(screen, "");
window.setFramerateLimit(30);

sf::Texture texture;
if(!texture.loadFromFile("image.png"))
return EXIT_FAILURE;

sf::Sprite image(texture);
image.setPosition(0, 0);
image.setPosition(screen.width / 2, screen.height / 2);
image.setOrigin(texture.getSize().x/2, texture.getSize().y/2);

sf::Music music;
sf::Font font;
if (!font.loadFromFile("sansation.ttf"))
return EXIT_FAILURE;

sf::Text text("Tap anywhere to move the logo.", font, 10);
text.setPosition(10, 10);

// Loading canary.wav fails for me for now; haven't had time to test why

/*sf::Music music;
if(!music.openFromFile("canary.wav"))
return EXIT_FAILURE;
music.play();
music.play();*/

sf::View view = window.getDefaultView();

sf::Color background = sf::Color::White;

// We shouldn't try drawing to the screen while in background
// so we'll have to track that. You can do minor background
// work, but keep battery life in mind.
bool active = true;

while (window.isOpen())
{
sf::Event event;

while (window.pollEvent(event))
while (active ? window.pollEvent(event) : window.waitEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::Escape)
window.close();
break;
case sf::Event::Resized:
view.setSize(event.size.width, event.size.height);
view.setCenter(event.size.width/2, event.size.height/2);
window.setView(view);
break;
case sf::Event::LostFocus:
background = sf::Color::Black;
break;
case sf::Event::GainedFocus:
background = sf::Color::White;
break;

// On Android MouseLeft/MouseEntered are (for now) triggered,
// whenever the app loses or gains focus.
case sf::Event::MouseLeft:
active = false;
break;
case sf::Event::MouseEntered:
active = true;
break;
case sf::Event::TouchBegan:
if (event.touch.finger == 0)
{
Expand All @@ -122,8 +160,15 @@ int main(int argc, char *argv[])
}
}

window.clear(sf::Color::White);
window.draw(image);
window.display();
if (active)
{
window.clear(background);
window.draw(image);
window.draw(text);
window.display();
}
else {
sf::sleep(sf::milliseconds(100));
}
}
}
Binary file removed examples/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 0 additions & 6 deletions examples/android/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

160 changes: 0 additions & 160 deletions examples/android/gradlew

This file was deleted.

0 comments on commit ab63f22

Please sign in to comment.