-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The initialization for Android is much like the same one for iOS. However, some method implementations are not done yet for Android such as the NativeView::SetBounds() method. The OpenGL view is implemented as Java class and can be instantiated by the View class through JNI. To setup the moui environment for Android. The activity on the Java side must call a native method to initializes the Application class. Signed-off-by: Olli Wang <[email protected]>
- Loading branch information
Showing
18 changed files
with
511 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ollix.moui" | ||
android:versionCode="1" | ||
android:versionName="1.0"> | ||
|
||
<uses-sdk android:minSdkVersion="8" /> | ||
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2014 Ollix | ||
# | ||
# 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. | ||
{ | ||
'includes': [ | ||
'../../moui/common.gypi', | ||
], | ||
'targets': [ | ||
{ | ||
'target_name': 'libmoui-jni', | ||
'type': 'shared_library', | ||
'sources': [ | ||
'renderer.cc', | ||
], | ||
'dependencies': [ '../../moui/moui.gyp:libmoui' ], | ||
'export_dependent_settings': [ '../../moui/moui.gyp:libmoui' ], | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2014 Ollix. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
// --- | ||
// Author: [email protected] (Olli Wang) | ||
|
||
#include "jni.h" | ||
#include "moui/moui.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
JNIEXPORT void JNICALL Java_com_ollix_moui_OpenGLRenderer_drawFrame | ||
(JNIEnv* env, jobject obj, jlong moui_view_pointer) { | ||
moui::View* view = (moui::View*)moui_view_pointer; | ||
view->Render(); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system edit | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
# | ||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): | ||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt | ||
|
||
android.library=true | ||
# Project target. | ||
target=android-19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2014 Ollix. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
// --- | ||
// Author: [email protected] (Olli Wang) | ||
|
||
package com.ollix.moui; | ||
|
||
import android.opengl.GLES20; | ||
import android.opengl.GLSurfaceView; | ||
import javax.microedition.khronos.egl.EGLConfig; | ||
import javax.microedition.khronos.opengles.GL10; | ||
|
||
public class OpenGLRenderer implements GLSurfaceView.Renderer { | ||
|
||
private long mMouiViewPointer; | ||
private native void drawFrame(long mouiViewPointer); | ||
|
||
public OpenGLRenderer(long mouiViewPointer) { | ||
mMouiViewPointer = mouiViewPointer; | ||
} | ||
|
||
@Override | ||
public void onDrawFrame(GL10 unused) { | ||
drawFrame(mMouiViewPointer); | ||
} | ||
|
||
@Override | ||
public void onSurfaceCreated(GL10 unused, EGLConfig config) {} | ||
|
||
@Override | ||
public void onSurfaceChanged(GL10 unused, int width, int height) { | ||
GLES20.glViewport(0, 0, width, height); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2014 Ollix. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
// --- | ||
// Author: [email protected] (Olli Wang) | ||
|
||
package com.ollix.moui; | ||
|
||
import com.ollix.moui.OpenGLRenderer; | ||
import android.content.Context; | ||
import android.graphics.PixelFormat; | ||
import android.opengl.GLSurfaceView; | ||
|
||
public class OpenGLView extends GLSurfaceView { | ||
public OpenGLView(Context context, long mouiViewPointer) { | ||
super(context); | ||
|
||
setEGLContextClientVersion(2); // adopts OpenGL ES 2.0 context | ||
setZOrderOnTop(true); | ||
setEGLConfigChooser(8, 8, 8, 8, 16, 0); | ||
getHolder().setFormat(PixelFormat.TRANSLUCENT); | ||
|
||
setRenderer(new OpenGLRenderer(mouiViewPointer)); | ||
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2014 Ollix. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
// --- | ||
// Author: [email protected] (Olli Wang) | ||
|
||
#include "moui/core/application.h" | ||
|
||
#include "jni.h" | ||
|
||
namespace { | ||
|
||
JavaVM* java_vm = nullptr; | ||
jobject main_activity = nullptr; | ||
moui::Application* shared_application = nullptr; | ||
|
||
} // namespace | ||
|
||
namespace moui { | ||
|
||
Application* Application::SharedApplication() { | ||
if (shared_application == nullptr) | ||
shared_application = new Application(); | ||
return shared_application; | ||
} | ||
|
||
Application::Application() { | ||
} | ||
|
||
Application::~Application() { | ||
} | ||
|
||
void Application::Init(JNIEnv* env, jobject activity) { | ||
if (main_activity != nullptr) | ||
env->DeleteGlobalRef(main_activity); | ||
main_activity = reinterpret_cast<jobject>(env->NewGlobalRef(activity)); | ||
env->GetJavaVM(&java_vm); | ||
} | ||
|
||
JNIEnv* Application::GetJNIEnv() const { | ||
JNIEnv* env; | ||
java_vm->GetEnv((void **)&env, JNI_VERSION_1_6); | ||
return env; | ||
} | ||
|
||
jobject Application::GetMainActivity() const { | ||
return main_activity; | ||
} | ||
|
||
} // namespace moui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2014 Ollix. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
// --- | ||
// Author: [email protected] (Olli Wang) | ||
|
||
#ifndef MOUI_CORE_ANDROID_APPLICATION_H_ | ||
#define MOUI_CORE_ANDROID_APPLICATION_H_ | ||
|
||
#include "jni.h" | ||
#include "moui/base.h" | ||
|
||
namespace moui { | ||
|
||
class Application { | ||
public: | ||
static Application* SharedApplication(); | ||
|
||
Application(); | ||
~Application(); | ||
|
||
void Init(JNIEnv* env, jobject activity); | ||
|
||
JNIEnv* GetJNIEnv() const; | ||
|
||
jobject GetMainActivity() const; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(Application); | ||
}; | ||
|
||
} // namespace moui | ||
|
||
#endif // MOUI_CORE_ANDROID_APPLICATION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2014 Ollix. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
// --- | ||
// Author: [email protected] (Olli Wang) | ||
|
||
#ifndef MOUI_CORE_APPLICATION_H_ | ||
#define MOUI_CORE_APPLICATION_H_ | ||
|
||
#if MOUI_ANDROID | ||
#include "moui/core/android/application.h" | ||
#endif | ||
|
||
#endif // MOUI_CORE_APPLICATION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.