From 2458c71cfda8444f76b661e0c0ff36fcd18d8e3e Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Tue, 29 Nov 2011 09:56:16 +0000 Subject: [PATCH] android example: Adds the forgotten Java source code git-svn-id: trunk@33850 - --- .gitattributes | 1 + .../src/com/pascal/lcltest/LCLActivity.java | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 examples/androidlcl/android/src/com/pascal/lcltest/LCLActivity.java diff --git a/.gitattributes b/.gitattributes index 3bca10c25a..f4bf0ac863 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3357,6 +3357,7 @@ examples/androidlcl/android/res/drawable-hdpi/icon.png -text svneol=unset#image/ examples/androidlcl/android/res/drawable-ldpi/icon.png -text svneol=unset#image/png examples/androidlcl/android/res/drawable-mdpi/icon.png -text svneol=unset#image/png examples/androidlcl/android/res/values/strings.xml svneol=native#text/plain +examples/androidlcl/android/src/com/pascal/lcltest/LCLActivity.java svneol=native#text/java examples/androidlcl/androidlcltest.lpi svneol=native#text/plain examples/androidlcl/androidlcltest.lpr svneol=native#text/pascal examples/androidlcl/mainform.lfm svneol=native#text/plain diff --git a/examples/androidlcl/android/src/com/pascal/lcltest/LCLActivity.java b/examples/androidlcl/android/src/com/pascal/lcltest/LCLActivity.java new file mode 100755 index 0000000000..42d0ede867 --- /dev/null +++ b/examples/androidlcl/android/src/com/pascal/lcltest/LCLActivity.java @@ -0,0 +1,80 @@ +package com.pascal.lcltest; + +import android.app.*; +import android.content.*; +import android.os.*; +import android.widget.*; +import android.util.*; +import android.graphics.*; +import android.view.*; + +public class LCLActivity extends Activity +{ + // Our drawing surface + private class LCLSurface extends SurfaceView + { + public LCLSurface(Context context) + { + super(context); + // Allows View.postInvalidate() to work + setWillNotDraw(false); + // We already double buffer, so no need for a second one + setWillNotCacheDrawing(true); + } + + @Override protected void onDraw(Canvas canvas) + { + int lWidth = getWidth(); + int lHeight = getHeight(); + + //Log.v("lclproject", "LCLSurface.onDraw width=" + Integer.toString(lWidth) + // + " height=" + Integer.toString(lHeight)); + + Bitmap lclbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888); + LCLDrawToBitmap(lWidth, lHeight, lclbitmap); + canvas.drawBitmap(lclbitmap, 0, 0, null); + } + + + @Override public boolean onTouchEvent (MotionEvent event) + { + int eventResult = LCLOnTouch(event.getX(), event.getY(), event.getAction()); + if ((eventResult | 1) != 0) postInvalidate(); + return true; + } + } + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + +// TextView tv = new TextView(this); +// tv.setText( Integer.toString(intFromJNI()) ); +// setContentView(tv); + LCLSurface lclsurface = new LCLSurface(this); + setContentView(lclsurface); + lclsurface.postInvalidate(); + } + + // JNI table of functions + public native int LCLDrawToBitmap(int width, int height, Bitmap bitmap); + public native int LCLOnTouch(float x, float y, int action); + + public long nativeCodeLoaded=0; + + static + { + try + { + Log.i("lclproject", "Trying to load liblclapp.so"); + System.loadLibrary("lclapp"); + } + catch(UnsatisfiedLinkError ule) + { + Log.e("lclproject", "WARNING: Could not load liblclapp.so"); + ule.printStackTrace(); + } + } +}