First drawer application
This commit is contained in:
commit
5d0e9987a7
18
AndroidManifest.xml
Normal file
18
AndroidManifest.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.ewolAbstraction"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:label="@string/app_name">
|
||||
<!--android:hasCode="false"-->
|
||||
<activity android:name=".EwolActivity"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_luncher_ewoltest">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="4" />
|
||||
</manifest>
|
21
Makefile
Normal file
21
Makefile
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
PROJECT_PATH=$(shell pwd)
|
||||
PROJECT_NDK=$(PROJECT_PATH)/../android/ndk-r7/
|
||||
PROJECT_SDK=$(PROJECT_PATH)/../android/sdk-r15/
|
||||
PROJECT_MODULE=$(PROJECT_PATH)/../
|
||||
EWOL_FOLDER=$(PROJECT_MODULE)ewol
|
||||
|
||||
all:
|
||||
cd $(PROJECT_NDK) ; NDK_PROJECT_PATH=$(PROJECT_PATH) NDK_MODULE_PATH=$(PROJECT_MODULE) ./ndk-build
|
||||
cp -rvf $(EWOL_FOLDER)/src .
|
||||
PATH=$(PROJECT_SDK)/tools/:$(PROJECT_SDK)/platform-tools/:$(PATH) ant -Dsdk.dir=$(PROJECT_SDK) debug
|
||||
rm -rf src
|
||||
|
||||
|
||||
install: all
|
||||
#$(PROJECT_SDK)/platform-tools/adb kill-server
|
||||
# install application
|
||||
sudo $(PROJECT_SDK)/platform-tools/adb install -r ./bin/EwolActivity-debug.apk
|
||||
|
||||
clean:
|
||||
rm -r bin libs gen obj
|
BIN
assets/Font/ebtfont/Monospace.bmp
Normal file
BIN
assets/Font/ebtfont/Monospace.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
129
assets/Font/ebtfont/Monospace.ebt
Normal file
129
assets/Font/ebtfont/Monospace.ebt
Normal file
@ -0,0 +1,129 @@
|
||||
name:Monospace
|
||||
source:Monospace.bmp
|
||||
#comment line ...
|
||||
# size 54 largeur 33 space between letter 12
|
||||
# unknow UTF8 code of the letter and start coordonate and size ==> 0x54 (33,45) (33,54)
|
||||
0x00 (99,453) (33,54) # Error : Unknow the UTF8 element ...
|
||||
# hexa UTF8 code of the letter and start coordonate and size ==> 0x54 (33,45) (33,54)
|
||||
# ABCDEFGHIJKLMN
|
||||
0x20 (0,7) (33,54) # space ...
|
||||
0x41 (33,7) (33,54) # A
|
||||
0x42 (66,7) (33,54) # B
|
||||
0x43 (99,7) (33,54) # C
|
||||
0x44 (132,7) (33,54) # D
|
||||
0x45 (165,7) (33,54) # E
|
||||
0x46 (198,7) (33,54) # F
|
||||
0x47 (231,7) (33,54) # G
|
||||
0x48 (264,7) (33,54) # H
|
||||
0x49 (297,7) (33,54) # I
|
||||
0x4A (330,7) (33,54) # J
|
||||
0x4B (363,7) (33,54) # K
|
||||
0x4C (396,7) (33,54) # L
|
||||
0x4D (429,7) (33,54) # M
|
||||
0x4E (462,7) (33,54) # N
|
||||
#OPQRSTUVWXYZabc
|
||||
0x4F (0,71) (33,54) # O
|
||||
0x50 (33,71) (33,54) # P
|
||||
0x51 (66,71) (33,54) # Q
|
||||
0x52 (99,71) (33,54) # R
|
||||
0x53 (132,71) (33,54) # S
|
||||
0x54 (165,71) (33,54) # T
|
||||
0x55 (198,71) (33,54) # U
|
||||
0x56 (231,71) (33,54) # V
|
||||
0x57 (264,71) (33,54) # W
|
||||
0x58 (297,71) (33,54) # X
|
||||
0x59 (330,71) (33,54) # Y
|
||||
0x5A (363,71) (33,54) # Z
|
||||
0x61 (396,71) (33,54) # a
|
||||
0x62 (429,71) (33,54) # b
|
||||
0x63 (462,71) (33,54) # c
|
||||
#defghijklmnopqr
|
||||
0x64 (0,135) (33,54) # d
|
||||
0x65 (33,135) (33,54) # e
|
||||
0x66 (66,135) (33,54) # f
|
||||
0x67 (99,135) (33,54) # g
|
||||
0x68 (132,135) (33,54) # h
|
||||
0x69 (165,135) (33,54) # i
|
||||
0x6A (198,135) (33,54) # j
|
||||
0x6B (231,135) (33,54) # k
|
||||
0x6C (264,135) (33,54) # l
|
||||
0x6D (297,135) (33,54) # m
|
||||
0x6E (330,135) (33,54) # n
|
||||
0x6F (363,135) (33,54) # o
|
||||
0x70 (396,135) (33,54) # p
|
||||
0x71 (429,135) (33,54) # q
|
||||
0x72 (462,135) (33,54) # r
|
||||
#stuvwxyz1234567
|
||||
0x73 (0,199) (33,54) # s
|
||||
0x74 (33,199) (33,54) # t
|
||||
0x75 (66,199) (33,54) # u
|
||||
0x76 (99,199) (33,54) # v
|
||||
0x77 (132,199) (33,54) # w
|
||||
0x78 (165,199) (33,54) # x
|
||||
0x79 (198,199) (33,54) # y
|
||||
0x7A (231,199) (33,54) # z
|
||||
0x31 (264,199) (33,54) # 1
|
||||
0x32 (297,199) (33,54) # 2
|
||||
0x33 (330,199) (33,54) # 3
|
||||
0x34 (363,199) (33,54) # 4
|
||||
0x35 (396,199) (33,54) # 5
|
||||
0x36 (429,199) (33,54) # 6
|
||||
0x37 (462,199) (33,54) # 7
|
||||
#890&é~"#'{([-|è
|
||||
0x38 (0,263) (33,54) # 8
|
||||
0x39 (33,263) (33,54) # 9
|
||||
0x30 (66,263) (33,54) # 0
|
||||
0x26 (99,263) (33,54) # &
|
||||
#0x (132,263) (33,54) # é
|
||||
0x7E (165,263) (33,54) # ~
|
||||
0x22 (198,263) (33,54) # "
|
||||
0x23 (231,263) (33,54) # #
|
||||
0x27 (264,263) (33,54) # '
|
||||
0x7B (297,263) (33,54) # {
|
||||
0x28 (330,263) (33,54) # (
|
||||
0x5B (363,263) (33,54) # [
|
||||
0x2D (396,263) (33,54) # -
|
||||
0x7C (429,263) (33,54) # |
|
||||
#0x (462,263) (33,54) # è
|
||||
#`_\ç^à@)]=}
|
||||
0x60 (0,335) (33,54) # `
|
||||
0x5F (33,335) (33,54) # _
|
||||
0x5C (66,335) (33,54) # \
|
||||
#0x (99,335) (33,54) # ç
|
||||
0x5E (132,335) (33,54) # ^
|
||||
#0x (165,335) (33,54) # à
|
||||
0x40 (198,335) (33,54) # @
|
||||
0x29 (231,335) (33,54) # )
|
||||
0x5D (264,335) (33,54) # ]
|
||||
0x3D (297,335) (33,54) # =
|
||||
0x7D (330,335) (33,54) # }
|
||||
#0x (363,335) (33,54) # o chap
|
||||
#0x (396,335) (33,54) # u chap
|
||||
#0x (429,335) (33,54) # e chap
|
||||
#0x (462,335) (33,54) # a chap
|
||||
#$£*µ%!§:/
|
||||
#0x (0,391) (33,54) # i chap
|
||||
#0x (33,391) (33,54) # o trema
|
||||
#0x (66,391) (33,54) # u trema
|
||||
#0x (99,391) (33,54) # e trema
|
||||
#0x (132,391) (33,54) # a trema
|
||||
0x24 (165,391) (33,54) # $
|
||||
#0x (198,391) (33,54) # £
|
||||
0x2A (231,391) (33,54) # *
|
||||
#0x (264,391) (33,54) # µ
|
||||
#0x (297,391) (33,54) # ù
|
||||
0x25 (330,391) (33,54) # %
|
||||
0x21 (363,391) (33,54) # !
|
||||
#0x (396,391) (33,54) # §
|
||||
0x3A (429,391) (33,54) # :
|
||||
0x2F (462,391) (33,54) # /
|
||||
#;.,?<>²!+
|
||||
0x3B (0,453) (33,54) # ;
|
||||
0x2E (33,453) (33,54) # .
|
||||
0x2C (66,453) (33,54) # ,
|
||||
0x3F (99,453) (33,54) # ?
|
||||
0x3C (132,453) (33,54) # <
|
||||
0x3E (165,453) (33,54) # >
|
||||
#0x (198,453) (33,54) # ²
|
||||
#0x21 (231,453) (33,54) # ! ==> doublon ...
|
||||
0x2B (264,453) (33,54) # +
|
BIN
assets/Font/freefont/FreeMono.ttf
Normal file
BIN
assets/Font/freefont/FreeMono.ttf
Normal file
Binary file not shown.
BIN
assets/Font/freefont/FreeMonoBold.ttf
Normal file
BIN
assets/Font/freefont/FreeMonoBold.ttf
Normal file
Binary file not shown.
BIN
assets/Font/freefont/FreeMonoBoldOblique.ttf
Normal file
BIN
assets/Font/freefont/FreeMonoBoldOblique.ttf
Normal file
Binary file not shown.
BIN
assets/Font/freefont/FreeMonoOblique.ttf
Normal file
BIN
assets/Font/freefont/FreeMonoOblique.ttf
Normal file
Binary file not shown.
85
build.xml
Normal file
85
build.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="EwolActivity" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<loadproperties srcFile="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
|
||||
<!-- extension targets. Uncomment the ones where you want to do custom work
|
||||
in between standard targets -->
|
||||
<!--
|
||||
<target name="-pre-build">
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
</target>
|
||||
|
||||
/* This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir} */
|
||||
<target name="-post-compile">
|
||||
</target>
|
||||
-->
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
30
jni/Android.mk
Normal file
30
jni/Android.mk
Normal file
@ -0,0 +1,30 @@
|
||||
# Copyright (C) 2010 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := ewolabstraction
|
||||
LOCAL_SRC_FILES := Main.cpp
|
||||
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
|
||||
LOCAL_STATIC_LIBRARIES := ewol
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := ewol
|
||||
LOCAL_JAVA_RESOURCE_DIRS := $(LOCAL_PATH)/../ewol
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
NDK_MODULE_PATH := $(LOCAL_PATH)/../../
|
||||
|
||||
$(call import-module,ewol/jni)
|
1
jni/Application.mk
Normal file
1
jni/Application.mk
Normal file
@ -0,0 +1 @@
|
||||
APP_PLATFORM := android-9
|
161
jni/Main.cpp
Normal file
161
jni/Main.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file Main.cpp
|
||||
* @brief main fonction
|
||||
* @author Edouard DUPIN
|
||||
* @date 13/10/2011
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/Font.h>
|
||||
#include <ewol/themeManager.h>
|
||||
#include <ewol/widget/Button.h>
|
||||
#include <ewol/widget/CheckBox.h>
|
||||
#include <ewol/widget/SizerHori.h>
|
||||
#include <ewol/widget/SizerVert.h>
|
||||
#include <ewol/widget/Test.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// need to run xcompmgr to have transparency
|
||||
|
||||
class Plop :public ewol::Windows
|
||||
{
|
||||
public:
|
||||
Plop(void)
|
||||
{
|
||||
// generate the display :
|
||||
ewol::SizerHori * mySizer = new ewol::SizerHori();
|
||||
SetSubWidget(mySizer);
|
||||
|
||||
ewol::Button * myButton = new ewol::Button("LB");
|
||||
mySizer->SubWidgetAdd(myButton);
|
||||
|
||||
ewol::SizerVert * mySizerVert = new ewol::SizerVert();
|
||||
mySizer->SubWidgetAdd(mySizerVert);
|
||||
|
||||
myButton = new ewol::Button("BT 3");
|
||||
myButton->SetExpendX(true);
|
||||
//myButton->SetExpendY(true);
|
||||
mySizerVert->SubWidgetAdd(myButton);
|
||||
|
||||
ewol::Test * myTest = new ewol::Test();
|
||||
mySizerVert->SubWidgetAdd(myTest);
|
||||
|
||||
ewol::CheckBox * myCheckBox = new ewol::CheckBox("mon label d'eK");
|
||||
mySizerVert->SubWidgetAdd(myCheckBox);
|
||||
myCheckBox = new ewol::CheckBox("Exemple 2");
|
||||
mySizerVert->SubWidgetAdd(myCheckBox);
|
||||
myCheckBox = new ewol::CheckBox("Exemple 3 et éà$");
|
||||
mySizerVert->SubWidgetAdd(myCheckBox);
|
||||
|
||||
myTest = new ewol::Test();
|
||||
myTest->SetExpendY(true);
|
||||
mySizerVert->SubWidgetAdd(myTest);
|
||||
myButton = new ewol::Button("4 4 BT");
|
||||
myButton->SetExpendY(true);
|
||||
mySizerVert->SubWidgetAdd(myButton);
|
||||
|
||||
myButton = new ewol::Button("Exemple 2");
|
||||
myButton->SetExpendX(true);
|
||||
mySizer->SubWidgetAdd(myButton);
|
||||
};
|
||||
|
||||
~Plop(void)
|
||||
{
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
static Plop * myWindowsExample = NULL;
|
||||
|
||||
/**
|
||||
* @brief main application function Initialisation
|
||||
*/
|
||||
void APP_Init(int argc, char *argv[])
|
||||
{
|
||||
ewol::ChangeSize(800, 600);
|
||||
/*
|
||||
if (true == ewol::AddFont("dataTest/TextMonospace.ebt", true, true, true) ) {
|
||||
//fontID = GetFontIdWithFileName("dataTest/TextMonospace.ebt");
|
||||
}
|
||||
*/
|
||||
ewol::SetFontFolder("Font");
|
||||
//ewol::SetDefaultFont("freefont/FreeMono", 14);
|
||||
//ewol::SetDefaultFont("ebtfont/Monospace", 14);
|
||||
ewol::SetDefaultFont("ebtfont/Monospace", 33);
|
||||
//ewol::theme::LoadDefault("dataTest/exemple.eol");
|
||||
/*
|
||||
etk::File fileTmp("exemple.eol", etk::FILE_TYPE_DATA);
|
||||
ewol::theme::LoadDefault(fileTmp);
|
||||
*/
|
||||
/*
|
||||
etk::File tmpFile("/data/data/com.example.EwolActivity.app/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile = ("/data/data/com.example.EwolActivity/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile=("/data/com.example.EwolActivity.app/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile=("/data/com.example.EwolActivity/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile=("/data/data/com.example.ewolactivity.app/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile=("/data/data/com.example.ewolactivity/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile=("/data/com.example.ewolactivity.app/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
tmpFile=("/data/com.example.ewolactivity/assets/theme/exemple.eol");
|
||||
if (tmpFile.Exist() ) {
|
||||
EWOL_WARNING("file existed : " << tmpFile);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
myWindowsExample = new Plop();
|
||||
|
||||
|
||||
// create the specific windows
|
||||
ewol::DisplayWindows(myWindowsExample);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief main application function Un-Initialisation
|
||||
*/
|
||||
void APP_UnInit(void)
|
||||
{
|
||||
delete(myWindowsExample);
|
||||
}
|
307
jni/main.c
Normal file
307
jni/main.c
Normal file
@ -0,0 +1,307 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
//BEGIN_INCLUDE(all)
|
||||
#include <jni.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES/gl.h>
|
||||
|
||||
#include <android/sensor.h>
|
||||
#include <android/log.h>
|
||||
#include <android_native_app_glue.h>
|
||||
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
|
||||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* Our saved state data.
|
||||
*/
|
||||
struct saved_state {
|
||||
float angle;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shared state for our app.
|
||||
*/
|
||||
struct engine {
|
||||
struct android_app* app;
|
||||
|
||||
ASensorManager* sensorManager;
|
||||
const ASensor* accelerometerSensor;
|
||||
ASensorEventQueue* sensorEventQueue;
|
||||
|
||||
int animating;
|
||||
EGLDisplay display;
|
||||
EGLSurface surface;
|
||||
EGLContext context;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
struct saved_state state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize an EGL context for the current display.
|
||||
*/
|
||||
static int engine_init_display(struct engine* engine) {
|
||||
// initialize OpenGL ES and EGL
|
||||
|
||||
/*
|
||||
* Here specify the attributes of the desired configuration.
|
||||
* Below, we select an EGLConfig with at least 8 bits per color
|
||||
* component compatible with on-screen windows
|
||||
*/
|
||||
const EGLint attribs[] = {
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_NONE
|
||||
};
|
||||
EGLint w, h, dummy, format;
|
||||
EGLint numConfigs;
|
||||
EGLConfig config;
|
||||
EGLSurface surface;
|
||||
EGLContext context;
|
||||
|
||||
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
|
||||
eglInitialize(display, 0, 0);
|
||||
|
||||
/* Here, the application chooses the configuration it desires. In this
|
||||
* sample, we have a very simplified selection process, where we pick
|
||||
* the first EGLConfig that matches our criteria */
|
||||
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
|
||||
|
||||
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
|
||||
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
|
||||
* As soon as we picked a EGLConfig, we can safely reconfigure the
|
||||
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
|
||||
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
|
||||
|
||||
ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
|
||||
|
||||
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
|
||||
context = eglCreateContext(display, config, NULL, NULL);
|
||||
|
||||
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
|
||||
LOGW("Unable to eglMakeCurrent");
|
||||
return -1;
|
||||
}
|
||||
|
||||
eglQuerySurface(display, surface, EGL_WIDTH, &w);
|
||||
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
|
||||
|
||||
engine->display = display;
|
||||
engine->context = context;
|
||||
engine->surface = surface;
|
||||
engine->width = w;
|
||||
engine->height = h;
|
||||
engine->state.angle = 0;
|
||||
|
||||
// Initialize GL state.
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just the current frame in the display.
|
||||
*/
|
||||
static void engine_draw_frame(struct engine* engine) {
|
||||
if (engine->display == NULL) {
|
||||
// No display.
|
||||
return;
|
||||
}
|
||||
|
||||
// Just fill the screen with a color.
|
||||
glClearColor(((float)engine->state.x)/engine->width, engine->state.angle,
|
||||
((float)engine->state.y)/engine->height, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
eglSwapBuffers(engine->display, engine->surface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down the EGL context currently associated with the display.
|
||||
*/
|
||||
static void engine_term_display(struct engine* engine) {
|
||||
if (engine->display != EGL_NO_DISPLAY) {
|
||||
eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
if (engine->context != EGL_NO_CONTEXT) {
|
||||
eglDestroyContext(engine->display, engine->context);
|
||||
}
|
||||
if (engine->surface != EGL_NO_SURFACE) {
|
||||
eglDestroySurface(engine->display, engine->surface);
|
||||
}
|
||||
eglTerminate(engine->display);
|
||||
}
|
||||
engine->animating = 0;
|
||||
engine->display = EGL_NO_DISPLAY;
|
||||
engine->context = EGL_NO_CONTEXT;
|
||||
engine->surface = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next input event.
|
||||
*/
|
||||
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
|
||||
struct engine* engine = (struct engine*)app->userData;
|
||||
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
|
||||
engine->animating = 1;
|
||||
engine->state.x = AMotionEvent_getX(event, 0);
|
||||
engine->state.y = AMotionEvent_getY(event, 0);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next main command.
|
||||
*/
|
||||
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
struct engine* engine = (struct engine*)app->userData;
|
||||
switch (cmd) {
|
||||
case APP_CMD_SAVE_STATE:
|
||||
// The system has asked us to save our current state. Do so.
|
||||
engine->app->savedState = malloc(sizeof(struct saved_state));
|
||||
*((struct saved_state*)engine->app->savedState) = engine->state;
|
||||
engine->app->savedStateSize = sizeof(struct saved_state);
|
||||
break;
|
||||
case APP_CMD_INIT_WINDOW:
|
||||
// The window is being shown, get it ready.
|
||||
if (engine->app->window != NULL) {
|
||||
engine_init_display(engine);
|
||||
engine_draw_frame(engine);
|
||||
}
|
||||
break;
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
// The window is being hidden or closed, clean it up.
|
||||
engine_term_display(engine);
|
||||
break;
|
||||
case APP_CMD_GAINED_FOCUS:
|
||||
// When our app gains focus, we start monitoring the accelerometer.
|
||||
if (engine->accelerometerSensor != NULL) {
|
||||
ASensorEventQueue_enableSensor(engine->sensorEventQueue,
|
||||
engine->accelerometerSensor);
|
||||
// We'd like to get 60 events per second (in us).
|
||||
ASensorEventQueue_setEventRate(engine->sensorEventQueue,
|
||||
engine->accelerometerSensor, (1000L/60)*1000);
|
||||
}
|
||||
break;
|
||||
case APP_CMD_LOST_FOCUS:
|
||||
// When our app loses focus, we stop monitoring the accelerometer.
|
||||
// This is to avoid consuming battery while not being used.
|
||||
if (engine->accelerometerSensor != NULL) {
|
||||
ASensorEventQueue_disableSensor(engine->sensorEventQueue,
|
||||
engine->accelerometerSensor);
|
||||
}
|
||||
// Also stop animating.
|
||||
engine->animating = 0;
|
||||
engine_draw_frame(engine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the main entry point of a native application that is using
|
||||
* android_native_app_glue. It runs in its own thread, with its own
|
||||
* event loop for receiving input events and doing other things.
|
||||
*/
|
||||
void android_main(struct android_app* state) {
|
||||
struct engine engine;
|
||||
|
||||
// Make sure glue isn't stripped.
|
||||
app_dummy();
|
||||
|
||||
memset(&engine, 0, sizeof(engine));
|
||||
state->userData = &engine;
|
||||
state->onAppCmd = engine_handle_cmd;
|
||||
state->onInputEvent = engine_handle_input;
|
||||
engine.app = state;
|
||||
|
||||
// Prepare to monitor accelerometer
|
||||
engine.sensorManager = ASensorManager_getInstance();
|
||||
engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
|
||||
ASENSOR_TYPE_ACCELEROMETER);
|
||||
engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
|
||||
state->looper, LOOPER_ID_USER, NULL, NULL);
|
||||
|
||||
if (state->savedState != NULL) {
|
||||
// We are starting with a previous saved state; restore from it.
|
||||
engine.state = *(struct saved_state*)state->savedState;
|
||||
}
|
||||
|
||||
// loop waiting for stuff to do.
|
||||
|
||||
while (1) {
|
||||
// Read all pending events.
|
||||
int ident;
|
||||
int events;
|
||||
struct android_poll_source* source;
|
||||
|
||||
// If not animating, we will block forever waiting for events.
|
||||
// If animating, we loop until all events are read, then continue
|
||||
// to draw the next frame of animation.
|
||||
while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
|
||||
(void**)&source)) >= 0) {
|
||||
|
||||
// Process this event.
|
||||
if (source != NULL) {
|
||||
source->process(state, source);
|
||||
}
|
||||
|
||||
// If a sensor has data, process it now.
|
||||
if (ident == LOOPER_ID_USER) {
|
||||
if (engine.accelerometerSensor != NULL) {
|
||||
ASensorEvent event;
|
||||
while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
|
||||
&event, 1) > 0) {
|
||||
LOGI("accelerometer: x=%f y=%f z=%f",
|
||||
event.acceleration.x, event.acceleration.y,
|
||||
event.acceleration.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we are exiting.
|
||||
if (state->destroyRequested != 0) {
|
||||
engine_term_display(&engine);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (engine.animating) {
|
||||
// Done with events; draw next animation frame.
|
||||
engine.state.angle += .01f;
|
||||
if (engine.state.angle > 1) {
|
||||
engine.state.angle = 0;
|
||||
}
|
||||
|
||||
// Drawing is throttled to the screen update rate, so there
|
||||
// is no need to do timing here.
|
||||
engine_draw_frame(&engine);
|
||||
}
|
||||
}
|
||||
}
|
||||
//END_INCLUDE(all)
|
BIN
res/drawable/ic_luncher_ewoltest.png
Normal file
BIN
res/drawable/ic_luncher_ewoltest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
13
res/layout/main.xml
Normal file
13
res/layout/main.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World, EwolActivity"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
4
res/values/strings.xml
Normal file
4
res/values/strings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Ewol Test Application</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user