}
+JNIEXPORT void JNICALL
+Java_org_navitproject_navit_NavitSensors_SensorCallback( JNIEnv* env, jobject thiz, int id, int sensor, float x, float y, float z)
+{
+ dbg(1,"enter %p %p %f %f %f\n",thiz, (void *)id,x,y,z);
+ callback_call_4((struct callback *)id, sensor, &x, &y, &z);
+}
+
+
--- /dev/null
+/*
+ * Copyright (C) 2009 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.
+ */
+package org.navitproject.navit;
+
+import android.app.Activity;
+import android.widget.TextView;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.Message;
+import android.os.Handler;
+import android.content.Context;
+import android.util.Log;
+import android.hardware.Camera;
+import android.hardware.Camera.Parameters;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.PixelFormat;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import java.io.IOException;
+
+
+
+
+public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
+ SurfaceHolder mHolder;
+ static Camera mCamera = Camera.open();
+
+
+
+ NavitCamera(Context context)
+ {
+ super(context);
+ mHolder = getHolder();
+ mHolder.addCallback(this);
+ mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
+ Log.e("NavitCamera","Creator");
+
+
+ }
+
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ // The Surface has been created, acquire the camera and tell it where
+ // to draw.
+ try {
+ mCamera.setPreviewDisplay(holder);
+ } catch (IOException exception) {
+ mCamera.release();
+ mCamera = null;
+ // TODO: add more exception handling logic here
+ }
+ Log.e("NavitCamera","surfaceCreated");
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ // Surface will be destroyed when we return, so stop the preview.
+ // Because the CameraDevice object is not a shared resource, it's very
+ // important to release it when the activity is paused.
+ mCamera.stopPreview();
+ mCamera = null;
+ Log.e("NavitCamera","surfaceDestroyed");
+ }
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ // Now that the size is known, set up the camera parameters and begin
+ // the preview.
+ Log.e("NavitCamera","surfaceChanged "+w+"x"+h);
+ Camera.Parameters parameters = mCamera.getParameters();
+ parameters.setPreviewSize(w, h);
+ mCamera.setParameters(parameters);
+ mCamera.startPreview();
+ }
+
+}
+
import android.os.Bundle;
import android.os.Debug;
import android.view.*;
+import android.view.Window;
import android.util.Log;
+import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.lang.String;
+import android.app.Activity;
+import android.content.Context;
+import android.hardware.Camera;
+import android.os.Bundle;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.Window;
+import java.io.IOException;
+
public class NavitGraphics {
private NavitGraphics parent_graphics;
int overlay_disabled;
float trackball_x,trackball_y;
View view;
- public NavitGraphics(Activity activity, NavitGraphics parent, int x, int y, int w, int h, int alpha, int wraparound) {
+ RelativeLayout relativelayout;
+ public NavitGraphics(Activity activity, NavitGraphics parent, int x, int y, int w, int h, int alpha, int wraparound, int camera) {
if (parent == null) {
view=new View(activity) {
@Override protected void onDraw(Canvas canvas)
};
view.setFocusable(true);
view.setFocusableInTouchMode(true);
- activity.setContentView(view);
+ if (camera != 0) {
+ activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ relativelayout=new RelativeLayout(activity);
+ NavitCamera camera=new NavitCamera(activity);
+ relativelayout.addView(camera);
+ relativelayout.addView(view);
+ activity.setContentView(relativelayout);
+ } else {
+ activity.setContentView(view);
+ }
view.requestFocus();
} else {
draw_bitmap=Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
}
protected void draw_mode(int mode)
{
- if (mode == 1 && parent_graphics == null)
+ if (mode == 2 && parent_graphics == null)
view.invalidate();
- if (mode == 0 && parent_graphics != null)
+ if (mode == 1 || (mode == 0 && parent_graphics != null))
draw_bitmap.eraseColor(0);
}
--- /dev/null
+/*
+ * Copyright (C) 2009 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.
+ */
+package org.navitproject.navit;
+
+import android.app.Activity;
+import android.widget.TextView;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.Message;
+import android.os.Handler;
+import android.content.Context;
+import android.util.Log;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorManager;
+import android.hardware.SensorListener;
+import android.hardware.SensorEventListener;
+
+
+
+public class NavitSensors implements SensorEventListener {
+ private SensorManager mSensorManager;
+ private int callbackid;
+ public native void SensorCallback(int id, int sensor, float x, float y, float z);
+
+
+ NavitSensors(Context context, int cbid)
+ {
+ mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
+ mSensorManager.registerListener((SensorEventListener)this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
+ callbackid=cbid;
+ }
+
+ public void
+ onAccuracyChanged(Sensor sensor, int accuracy)
+ {
+ }
+
+ public void
+ onSensorChanged(SensorEvent sev)
+ {
+ // Log.e("NavitSensor","Type:" + sev.sensor.getType() + " X:" + sev.values[0] + " Y:"+sev.values[1]+" Z:"+sev.values[2]);
+ SensorCallback(callbackid, sev.sensor.getType(), sev.values[0], sev.values[1], sev.values[2]);
+ }
+}
+
struct mapset;
enum draw_mode_num {
- draw_mode_begin, draw_mode_end, draw_mode_cursor, draw_mode_end_lazy
+ draw_mode_begin, draw_mode_begin_clear, draw_mode_end, draw_mode_cursor, draw_mode_end_lazy
};
struct graphics_priv;
ret->gra=gr;
ret->Paint=(*jnienv)->NewObject(jnienv, gr->PaintClass, gr->Paint_init);
dbg(1,"result=%p\n",ret->Paint);
- if (ret->Paint)
+ if (ret->Paint) {
(*jnienv)->NewGlobalRef(jnienv, ret->Paint);
+ (*jnienv)->DeleteLocalRef(jnienv, ret->Paint);
+ }
return ret;
}
dbg(1,"result=%p\n",ret->Bitmap);
if (ret->Bitmap) {
(*jnienv)->NewGlobalRef(jnienv, ret->Bitmap);
+ (*jnienv)->DeleteLocalRef(jnienv, ret->Bitmap);
*w=(*jnienv)->CallIntMethod(jnienv, ret->Bitmap, gra->Bitmap_getWidth);
*h=(*jnienv)->CallIntMethod(jnienv, ret->Bitmap, gra->Bitmap_getHeight);
dbg(1,"w=%d h=%d for %s\n",*w,*h,path);
if (!find_class_global("org/navitproject/navit/NavitGraphics", &ret->NavitGraphicsClass))
return 0;
dbg(0,"at 3\n");
- cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIII)V");
+ cid = (*jnienv)->GetMethodID(jnienv, ret->NavitGraphicsClass, "<init>", "(Landroid/app/Activity;Lorg/navitproject/navit/NavitGraphics;IIIIIII)V");
if (cid == NULL) {
dbg(0,"no method found\n");
return 0; /* exception thrown */
}
dbg(0,"at 4 android_activity=%p\n",android_activity);
- ret->NavitGraphics=(*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity, parent ? parent->NavitGraphics : NULL, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, alpha, wraparound);
+ ret->NavitGraphics=(*jnienv)->NewObject(jnienv, ret->NavitGraphicsClass, cid, android_activity, parent ? parent->NavitGraphics : NULL, pnt ? pnt->x:0 , pnt ? pnt->y:0, w, h, alpha, wraparound, 0);
dbg(0,"result=%p\n",ret->NavitGraphics);
if (ret->NavitGraphics)
(*jnienv)->NewGlobalRef(jnienv, ret->NavitGraphics);