1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2008 Navit Team
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
package com.zoffcc.applications.zanavi;
|
21 |
|
22 |
import android.app.Activity;
|
23 |
import android.content.Context;
|
24 |
import android.graphics.*;
|
25 |
import android.os.Bundle;
|
26 |
import android.os.Debug;
|
27 |
import android.view.*;
|
28 |
import android.view.Window;
|
29 |
import android.util.Log;
|
30 |
import android.widget.RelativeLayout;
|
31 |
import java.util.ArrayList;
|
32 |
import java.lang.String;
|
33 |
import android.app.Activity;
|
34 |
import android.content.Context;
|
35 |
import android.hardware.Camera;
|
36 |
import android.os.Bundle;
|
37 |
import android.opengl.GLSurfaceView;
|
38 |
import android.view.SurfaceHolder;
|
39 |
import android.view.SurfaceView;
|
40 |
import android.view.Window;
|
41 |
import java.io.IOException;
|
42 |
|
43 |
import javax.microedition.khronos.egl.EGLConfig;
|
44 |
import javax.microedition.khronos.opengles.GL10;
|
45 |
import android.opengl.GLU;
|
46 |
import java.nio.ByteBuffer;
|
47 |
import java.nio.FloatBuffer;
|
48 |
import java.nio.ByteOrder;
|
49 |
|
50 |
|
51 |
|
52 |
class ClearRenderer implements GLSurfaceView.Renderer {
|
53 |
public FloatBuffer flb[];
|
54 |
public int flb_len;
|
55 |
boolean busy;
|
56 |
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
57 |
// Do nothing special.
|
58 |
}
|
59 |
|
60 |
public void onSurfaceChanged(GL10 gl, int w, int h) {
|
61 |
gl.glViewport(0, 0, w, h);
|
62 |
}
|
63 |
protected static FloatBuffer makeFloatBuffer(float[] arr) {
|
64 |
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4);
|
65 |
bb.order(ByteOrder.nativeOrder());
|
66 |
FloatBuffer fb = bb.asFloatBuffer();
|
67 |
fb.put(arr);
|
68 |
fb.position(0);
|
69 |
return fb;
|
70 |
}
|
71 |
|
72 |
|
73 |
|
74 |
public void onDrawFrame(GL10 gl) {
|
75 |
if (busy) {
|
76 |
return;
|
77 |
}
|
78 |
float[] square = new float[] { -0.25f, -0.25f, 0.0f,
|
79 |
0.25f, -0.25f, 0.0f,
|
80 |
-0.25f, 0.25f, 0.0f,
|
81 |
0.25f, 0.25f, 0.0f };
|
82 |
|
83 |
gl.glClearColor(1.0f, 1.0f, 0.2f, 0.0f);
|
84 |
gl.glMatrixMode(GL10.GL_PROJECTION);
|
85 |
gl.glLoadIdentity();
|
86 |
//GLU.gluOrtho2D(gl, 0.0f,1.3f,0.0f,1.0f);
|
87 |
GLU.gluOrtho2D(gl, 0.0f,320.0f,480.0f,0.0f);
|
88 |
|
89 |
|
90 |
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
|
91 |
gl.glShadeModel(GL10.GL_SMOOTH);
|
92 |
|
93 |
gl.glMatrixMode(GL10.GL_MODELVIEW);
|
94 |
gl.glLoadIdentity();
|
95 |
|
96 |
|
97 |
gl.glColor4f(0.25f, 0.25f, 0.75f, 1.0f);
|
98 |
//gl.glTranslatef(0f, 1f, 0.0f);
|
99 |
//gl.glScalef(1.0f/320, -1.0f/480, 0.001f);
|
100 |
//gl.glRotatef(0, 0, 1, 0);
|
101 |
|
102 |
|
103 |
Log.e("navit", "flb_len "+flb_len);
|
104 |
for (int i = 0 ; i < flb_len ; i++) {
|
105 |
if (flb[i] != null) {
|
106 |
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, flb[i]);
|
107 |
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
|
108 |
gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, flb[i].capacity()/3);
|
109 |
}
|
110 |
}
|
111 |
// FloatBuffer buf=makeFloatBuffer(square);
|
112 |
// gl.glVertexPointer(3, GL10.GL_FLOAT, 0, buf);
|
113 |
// gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
|
114 |
// Log.e("navit", "capacity "+buf.capacity());
|
115 |
// gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, buf.capacity()/3);
|
116 |
}
|
117 |
}
|
118 |
|
119 |
public class NavitGraphics2 {
|
120 |
private NavitGraphics2 parent_graphics;
|
121 |
private ArrayList overlays=new ArrayList();
|
122 |
int bitmap_w;
|
123 |
int bitmap_h;
|
124 |
int pos_x;
|
125 |
int pos_y;
|
126 |
int pos_wraparound;
|
127 |
int overlay_disabled;
|
128 |
float trackball_x,trackball_y;
|
129 |
GLSurfaceView view;
|
130 |
FloatBuffer[] flb;
|
131 |
|
132 |
RelativeLayout relativelayout;
|
133 |
NavitCamera camera;
|
134 |
Activity activity;
|
135 |
ClearRenderer renderer;
|
136 |
|
137 |
public void
|
138 |
SetCamera(int use_camera)
|
139 |
{
|
140 |
if (use_camera != 0 && camera == null) {
|
141 |
// activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
142 |
camera=new NavitCamera(activity);
|
143 |
relativelayout.addView(camera);
|
144 |
relativelayout.bringChildToFront(view);
|
145 |
}
|
146 |
}
|
147 |
public NavitGraphics2(Activity activity, NavitGraphics2 parent, int x, int y, int w, int h, int alpha, int wraparound, int use_camera) {
|
148 |
if (parent == null) {
|
149 |
this.activity=activity;
|
150 |
flb=new FloatBuffer[10000];
|
151 |
view=new GLSurfaceView(activity) {
|
152 |
@Override protected void onDraw(Canvas canvas)
|
153 |
{
|
154 |
super.onDraw(canvas);
|
155 |
canvas.drawBitmap(draw_bitmap, pos_x, pos_y, null);
|
156 |
if (overlay_disabled == 0) {
|
157 |
Object overlays_array[];
|
158 |
overlays_array=overlays.toArray();
|
159 |
for (Object overlay : overlays_array) {
|
160 |
NavitGraphics2 overlay_graphics=(NavitGraphics2)overlay;
|
161 |
if (overlay_graphics.overlay_disabled == 0) {
|
162 |
int x=overlay_graphics.pos_x;
|
163 |
int y=overlay_graphics.pos_y;
|
164 |
if (overlay_graphics.pos_wraparound != 0 && x < 0)
|
165 |
x+=bitmap_w;
|
166 |
if (overlay_graphics.pos_wraparound != 0 && y < 0)
|
167 |
y+=bitmap_h;
|
168 |
canvas.drawBitmap(overlay_graphics.draw_bitmap, x, y, null);
|
169 |
}
|
170 |
}
|
171 |
}
|
172 |
}
|
173 |
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
174 |
{
|
175 |
super.onSizeChanged(w, h, oldw, oldh);
|
176 |
draw_bitmap=Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
177 |
draw_canvas=new Canvas(draw_bitmap);
|
178 |
bitmap_w=w;
|
179 |
bitmap_h=h;
|
180 |
SizeChangedCallback(SizeChangedCallbackID, w, h);
|
181 |
}
|
182 |
@Override public boolean onTouchEvent(MotionEvent event)
|
183 |
{
|
184 |
super.onTouchEvent(event);
|
185 |
int action = event.getAction();
|
186 |
int x=(int)event.getX();
|
187 |
int y=(int)event.getY();
|
188 |
if (action == MotionEvent.ACTION_DOWN) {
|
189 |
// Log.e("NavitGraphics", "onTouch down");
|
190 |
ButtonCallback(ButtonCallbackID, 1, 1, x, y);
|
191 |
}
|
192 |
if (action == MotionEvent.ACTION_UP) {
|
193 |
// Log.e("NavitGraphics", "onTouch up");
|
194 |
ButtonCallback(ButtonCallbackID, 0, 1, x, y);
|
195 |
// if (++count == 3)
|
196 |
// Debug.stopMethodTracing();
|
197 |
}
|
198 |
if (action == MotionEvent.ACTION_MOVE) {
|
199 |
// Log.e("NavitGraphics", "onTouch move");
|
200 |
MotionCallback(MotionCallbackID, x, y);
|
201 |
}
|
202 |
return true;
|
203 |
}
|
204 |
@Override public boolean onKeyDown(int keyCode, KeyEvent event)
|
205 |
{
|
206 |
int i;
|
207 |
String s=null;
|
208 |
boolean handled=true;
|
209 |
i=event.getUnicodeChar();
|
210 |
Log.e("NavitGraphics","onKeyDown "+keyCode+" "+i);
|
211 |
// Log.e("NavitGraphics","Unicode "+event.getUnicodeChar());
|
212 |
if (i == 0) {
|
213 |
if (keyCode == android.view.KeyEvent.KEYCODE_DEL) {
|
214 |
s=java.lang.String.valueOf((char)8);
|
215 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_MENU) {
|
216 |
s=java.lang.String.valueOf((char)1);
|
217 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_SEARCH) {
|
218 |
s=java.lang.String.valueOf((char)19);
|
219 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_BACK) {
|
220 |
s=java.lang.String.valueOf((char)27);
|
221 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_CALL) {
|
222 |
s=java.lang.String.valueOf((char)3);
|
223 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP) {
|
224 |
s=java.lang.String.valueOf((char)21);
|
225 |
handled=false;
|
226 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN) {
|
227 |
s=java.lang.String.valueOf((char)4);
|
228 |
handled=false;
|
229 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_CENTER) {
|
230 |
s=java.lang.String.valueOf((char)13);
|
231 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_DOWN) {
|
232 |
s=java.lang.String.valueOf((char)16);
|
233 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_LEFT) {
|
234 |
s=java.lang.String.valueOf((char)2);
|
235 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_RIGHT) {
|
236 |
s=java.lang.String.valueOf((char)6);
|
237 |
} else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_UP) {
|
238 |
s=java.lang.String.valueOf((char)14);
|
239 |
}
|
240 |
} else if (i == 10) {
|
241 |
s=java.lang.String.valueOf((char)13);
|
242 |
} else {
|
243 |
s=java.lang.String.valueOf((char)i);
|
244 |
}
|
245 |
if (s != null) {
|
246 |
KeypressCallback(KeypressCallbackID, s);
|
247 |
}
|
248 |
return handled;
|
249 |
}
|
250 |
@Override public boolean onKeyUp(int keyCode, KeyEvent event)
|
251 |
{
|
252 |
Log.e("NavitGraphics","onKeyUp "+keyCode);
|
253 |
return true;
|
254 |
}
|
255 |
@Override public boolean onTrackballEvent(MotionEvent event)
|
256 |
{
|
257 |
Log.e("NavitGraphics","onTrackball "+event.getAction() + " " +event.getX()+" "+event.getY());
|
258 |
String s=null;
|
259 |
if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
|
260 |
s=java.lang.String.valueOf((char)13);
|
261 |
}
|
262 |
if (event.getAction() == android.view.MotionEvent.ACTION_MOVE) {
|
263 |
trackball_x+=event.getX();
|
264 |
trackball_y+=event.getY();
|
265 |
Log.e("NavitGraphics","trackball "+trackball_x+" "+trackball_y);
|
266 |
if (trackball_x <= -1) {
|
267 |
s=java.lang.String.valueOf((char)2);
|
268 |
trackball_x+=1;
|
269 |
}
|
270 |
if (trackball_x >= 1) {
|
271 |
s=java.lang.String.valueOf((char)6);
|
272 |
trackball_x-=1;
|
273 |
}
|
274 |
if (trackball_y <= -1) {
|
275 |
s=java.lang.String.valueOf((char)16);
|
276 |
trackball_y+=1;
|
277 |
}
|
278 |
if (trackball_y >= 1) {
|
279 |
s=java.lang.String.valueOf((char)14);
|
280 |
trackball_y-=1;
|
281 |
}
|
282 |
}
|
283 |
if (s != null) {
|
284 |
KeypressCallback(KeypressCallbackID, s);
|
285 |
}
|
286 |
return true;
|
287 |
}
|
288 |
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
|
289 |
{
|
290 |
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
291 |
Log.e("NavitGraphics","FocusChange "+gainFocus);
|
292 |
}
|
293 |
};
|
294 |
view.setFocusable(true);
|
295 |
view.setFocusableInTouchMode(true);
|
296 |
renderer=new ClearRenderer();
|
297 |
renderer.flb=new FloatBuffer[1000];
|
298 |
renderer.flb_len=0;
|
299 |
view.setRenderer(renderer);
|
300 |
view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
301 |
relativelayout=new RelativeLayout(activity);
|
302 |
if (use_camera != 0) {
|
303 |
SetCamera(use_camera);
|
304 |
}
|
305 |
relativelayout.addView(view);
|
306 |
activity.setContentView(relativelayout);
|
307 |
view.requestFocus();
|
308 |
} else {
|
309 |
draw_bitmap=Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
310 |
bitmap_w=w;
|
311 |
bitmap_h=h;
|
312 |
pos_x=x;
|
313 |
pos_y=y;
|
314 |
pos_wraparound=wraparound;
|
315 |
draw_canvas=new Canvas(draw_bitmap);
|
316 |
parent.overlays.add(this);
|
317 |
}
|
318 |
parent_graphics=parent;
|
319 |
}
|
320 |
public native void SizeChangedCallback(int id, int x, int y);
|
321 |
public native void ButtonCallback(int id, int pressed, int button, int x, int y);
|
322 |
public native void MotionCallback(int id, int x, int y);
|
323 |
public native void KeypressCallback(int id, String s);
|
324 |
private Canvas draw_canvas;
|
325 |
private Bitmap draw_bitmap;
|
326 |
private int SizeChangedCallbackID,ButtonCallbackID,MotionCallbackID,KeypressCallbackID;
|
327 |
// private int count;
|
328 |
|
329 |
public void setSizeChangedCallback(int id)
|
330 |
{
|
331 |
SizeChangedCallbackID=id;
|
332 |
}
|
333 |
public void setButtonCallback(int id)
|
334 |
{
|
335 |
ButtonCallbackID=id;
|
336 |
}
|
337 |
public void setMotionCallback(int id)
|
338 |
{
|
339 |
MotionCallbackID=id;
|
340 |
}
|
341 |
public void setKeypressCallback(int id)
|
342 |
{
|
343 |
KeypressCallbackID=id;
|
344 |
}
|
345 |
|
346 |
protected void draw_polyline(Paint paint,int c[])
|
347 |
{
|
348 |
}
|
349 |
|
350 |
protected void draw_polygon(Paint paint,int c[])
|
351 |
{
|
352 |
//float[] square = new float[] { -0.25f, -0.25f, 0.0f,
|
353 |
// 0.25f, -0.25f, 0.0f,
|
354 |
// -0.25f, 0.25f, 0.0f,
|
355 |
// 0.25f, 0.25f, 0.0f };
|
356 |
int len=c.length/2;
|
357 |
float[] square = new float[3*len];
|
358 |
for (int i = 0 ; i < len ; i++) {
|
359 |
square[i*3]=c[i*2];
|
360 |
square[i*3+1]=c[i*2+1];
|
361 |
square[i*3+2]=0;
|
362 |
}
|
363 |
// if (renderer.flb_len < 100) {
|
364 |
// renderer.flb[renderer.flb_len++]=ClearRenderer.makeFloatBuffer(square);
|
365 |
// }
|
366 |
if (renderer!=null && renderer.flb_len < 1000) {
|
367 |
renderer.flb[renderer.flb_len++]=ClearRenderer.makeFloatBuffer(square);
|
368 |
//renderer.flb_len=1;
|
369 |
}
|
370 |
|
371 |
}
|
372 |
protected void draw_rectangle(Paint paint,int x, int y, int w, int h)
|
373 |
{
|
374 |
}
|
375 |
protected void draw_circle(Paint paint,int x, int y, int r)
|
376 |
{
|
377 |
}
|
378 |
protected void draw_text(Paint paint,int x, int y, String text, int size, int dx, int dy)
|
379 |
{
|
380 |
}
|
381 |
protected void draw_image(Paint paint, int x, int y, Bitmap bitmap)
|
382 |
{
|
383 |
}
|
384 |
protected void draw_mode(int mode)
|
385 |
{
|
386 |
Log.e("navit", "draw_mode "+mode);
|
387 |
if (mode == 2 && parent_graphics == null) {
|
388 |
view.draw(draw_canvas);
|
389 |
view.invalidate();
|
390 |
view.requestRender();
|
391 |
}
|
392 |
if (mode == 1 || (mode == 0 && parent_graphics != null)) {
|
393 |
if (renderer!=null) {
|
394 |
renderer.flb_len=0;
|
395 |
}
|
396 |
draw_bitmap.eraseColor(0);
|
397 |
}
|
398 |
if (mode == 0 && renderer != null) {
|
399 |
renderer.flb_len=0;
|
400 |
}
|
401 |
}
|
402 |
protected void draw_drag(int x, int y)
|
403 |
{
|
404 |
pos_x=x;
|
405 |
pos_y=y;
|
406 |
}
|
407 |
protected void overlay_disable(int disable)
|
408 |
{
|
409 |
overlay_disabled=disable;
|
410 |
}
|
411 |
protected void overlay_resize(int x, int y, int w, int h, int alpha, int wraparond)
|
412 |
{
|
413 |
pos_x=x;
|
414 |
pos_y=y;
|
415 |
}
|
416 |
}
|