Java processing code (gestures, sdk version = 7).

This commit is contained in:
vng 2011-06-18 00:16:39 +03:00 committed by Alex Zolotarev
parent 0eaff04fee
commit 0ff2d58ff3
6 changed files with 208 additions and 7 deletions

View file

@ -3,7 +3,7 @@
package="com.mapswithme.maps"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MWMActivity"

View file

@ -8,4 +8,4 @@
# project structure.
# Project target.
target=android-4
target=android-7

View file

@ -4,12 +4,15 @@
#include <assert.h>
#define LOG(...) __android_log_print(ANDROID_LOG_INFO, "main_native", __VA_ARGS__)
#define LOG(...) __android_log_print(ANDROID_LOG_INFO, "mapswithme", __VA_ARGS__)
namespace jni_help
{
// Some examples of sig:
// "()V" - void function returning void;
// "(Ljava/lang/String;)V" - String function returning void;
jmethodID GetJavaMethodID(JNIEnv * env, jobject obj,
char const * fn, char const * sig)
char const * fn, char const * sig)
{
jclass cls = env->GetObjectClass(obj);
jmethodID mid = env->GetMethodID(cls, fn, sig);
@ -39,6 +42,7 @@ namespace jni_help
extern "C"
{
/* Some dummy functions.
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_MWMActivity_stringsJNI(JNIEnv * env, jobject thiz, jstring s)
{
@ -65,4 +69,22 @@ extern "C"
LOG("Leave callbackFromJNI");
}
*/
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MainGLView_nativeInit(JNIEnv * env, jobject thiz)
{
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_GesturesProcessor_nativeMove(JNIEnv * env, jobject thiz,
jint mode, jdouble x, jdouble y)
{
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_GesturesProcessor_nativeZoom(JNIEnv * env, jobject thiz,
jint mode, jdouble x1, jdouble y1, jdouble x2, jdouble y2)
{
}
}

View file

@ -0,0 +1,84 @@
package com.mapswithme.maps;
import android.graphics.PointF;
import android.view.MotionEvent;
public class GesturesProcessor
{
private final int NONE = 0;
private final int MOVE = 1;
private final int ZOOM = 2;
// Do not modify this constant values (or take into account native code, please).
private final int START = 0;
private final int PROCESS = 1;
private final int END = 2;
private PointF m_pt1;
private PointF m_pt2;
private int m_mode;
private void getPointsMove(MotionEvent e)
{
m_pt1.set(e.getX(), e.getY());
}
private void getPointsZoom(MotionEvent e)
{
m_pt1.set(e.getX(0), e.getY(0));
m_pt2.set(e.getX(1), e.getY(1));
}
public GesturesProcessor()
{
m_pt1 = new PointF();
m_pt2 = new PointF();
m_mode = NONE;
}
public void onTouchEvent(MotionEvent e)
{
switch (e.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
getPointsMove(e);
m_mode = MOVE;
nativeMove(START, m_pt1.x, m_pt1.y);
break;
case MotionEvent.ACTION_POINTER_DOWN:
getPointsZoom(e);
nativeZoom(START, m_pt1.x, m_pt1.y, m_pt2.x, m_pt2.y);
break;
case MotionEvent.ACTION_UP:
getPointsMove(e);
nativeMove(END, m_pt1.x, m_pt1.y);
m_mode = NONE;
break;
case MotionEvent.ACTION_POINTER_UP:
getPointsZoom(e);
nativeZoom(END, m_pt1.x, m_pt1.y, m_pt2.x, m_pt2.y);
m_mode = NONE;
break;
case MotionEvent.ACTION_MOVE:
if (m_mode == MOVE)
{
getPointsMove(e);
nativeMove(PROCESS, m_pt1.x, m_pt1.y);
}
else if (m_mode == ZOOM)
{
getPointsZoom(e);
nativeZoom(PROCESS, m_pt1.x, m_pt1.y, m_pt2.x, m_pt2.y);
}
break;
}
}
private native void nativeMove(int mode, double x, double y);
private native void nativeZoom(int mode, double x1, double y1, double x2, double y2);
}

View file

@ -1,15 +1,41 @@
package com.mapswithme.maps;
import com.mapswithme.maps.MainGLView;
import android.app.Activity;
import android.os.Bundle;
public class MWMActivity extends Activity
{
/** Called when the activity is first created. */
private MainGLView m_view;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
m_view = new MainGLView(getApplication());
setContentView(m_view);
}
@Override
protected void onPause()
{
super.onPause();
m_view.onPause();
}
@Override
protected void onResume()
{
super.onResume();
m_view.onResume();
}
static
{
System.loadLibrary("mapswithme");
}
}

View file

@ -0,0 +1,69 @@
package com.mapswithme.maps;
import com.mapswithme.maps.GesturesProcessor;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;
public class MainGLView extends GLSurfaceView
{
private static String TAG = "MainGLView";
GesturesProcessor m_gestures;
public MainGLView(Context context)
{
super(context);
init();
}
private void init()
{
m_gestures = new GesturesProcessor();
// Do native initialization with OpenGL.
nativeInit();
setRenderer(new Renderer());
// When renderMode is RENDERMODE_WHEN_DIRTY, the renderer only rendered
// when the surface is created, or when requestRender() is called.
setRenderMode(RENDERMODE_WHEN_DIRTY);
}
private static class Renderer implements GLSurfaceView.Renderer
{
@Override
public void onDrawFrame(GL10 gl)
{
Log.i(TAG, "Renderer::onDrawFrame");
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
Log.i(TAG, "Renderer::onSurfaceChanged");
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
Log.i(TAG, "Renderer::onSurfaceCreated");
}
}
@Override
public boolean onTouchEvent(MotionEvent e)
{
m_gestures.onTouchEvent(e);
return true; // if handled
}
private native void nativeInit();
}