Skip to content

Instantly share code, notes, and snippets.

@vasilakisfil
Created March 31, 2012 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasilakisfil/2261941 to your computer and use it in GitHub Desktop.
Save vasilakisfil/2261941 to your computer and use it in GitHub Desktop.
Java code ( the testing app)
# build file written to describe the C and C++ source files to the Android NDK
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := debugTest
LOCAL_CXXFLAGS := -W
LOCAL_SRC_FILES := debug_test.cpp
#This definition is needed by wiselib
LOCAL_C_INCLUDES := /home/vasilakis/Development/wiselib/wiselib.testing/ \
/home/vasilakis/Development/wiselib/wiselib.stable/
#This definition is also needed by wiselib
LOCAL_SRC_FILES += ../../../../wiselib.testing/external_interface/android/jni_essentials.cpp
include $(BUILD_SHARED_LIBRARY)
/***************************************************************************
** This file is part of the generic algorithm library Wiselib. **
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
** **
** The Wiselib is free software: you can redistribute it and/or modify **
** it under the terms of the GNU Lesser General Public License as **
** published by the Free Software Foundation, either version 3 of the **
** License, or (at your option) any later version. **
** **
** The Wiselib is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU Lesser General Public License for more details. **
** **
** You should have received a copy of the GNU Lesser General Public **
** License along with the Wiselib. **
** If not, see <http://www.gnu.org/licenses/>. **
***************************************************************************/
#include <jni.h>
#include "cbox_androidWiselib_debugConc_NativeConnection.h"
#include "external_interface/android/android_os_model.h"
using namespace std;
using namespace wiselib;
typedef AndroidOsModel Os;
Os::Debug DebugInstance;
JniEssentials jni;
// function that tests the debug concept
void test_debug(void)
{
// AndrDebug testDebug;
DebugInstance.debug("This message was sent by andr%did NDK (C++)\n", 0);
}
/*
* Class: cbox_androidWiselib_debugConc_NativeConnection
* Method: debugConceptJNI
* Signature: (Ljava/lang/Object;)Ljava/lang/String;
*/
// second parameter is not used since it holds object pointer of
// NativeConnection class and not Main's class pointer
JNIEXPORT jstring
JNICALL
Java_cbox_androidWiselib_debugConc_NativeConnection_debugConceptJNI
(JNIEnv * environment, jobject native_connection_class_object,
jobject main_class_object)
{
// setting the global java environment variables
jni.set_java_environment(environment);
jni.set_java_object(main_class_object);
// testing the debug feature
test_debug();
return environment->NewStringUTF(jni.jni_custom_error().c_str());
}
diff --git a/apps/android_apps/testDebugAndroid/.classpath b/apps/android_apps/testDebugAndroid/.classpath
new file mode 100644
index 0000000..d3bb07b
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
diff --git a/apps/android_apps/testDebugAndroid/.project b/apps/android_apps/testDebugAndroid/.project
new file mode 100644
index 0000000..75c0e83
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>debugConcept</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/apps/android_apps/testDebugAndroid/AndroidManifest.xml b/apps/android_apps/testDebugAndroid/AndroidManifest.xml
new file mode 100644
index 0000000..60198e6
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/AndroidManifest.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="cbox.androidWiselib.debugConc"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="8" />
+
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".Main"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+</manifest>
\ No newline at end of file
diff --git a/apps/android_apps/testDebugAndroid/Makefile b/apps/android_apps/testDebugAndroid/Makefile
new file mode 100644
index 0000000..ee43438
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/Makefile
@@ -0,0 +1,17 @@
+# ----------------------------------------
+# Environment variable WISELIB_PATH needed
+# ----------------------------------------
+
+# all: shawn
+# all: scw_msb
+# all: contiki_msb
+# all: contiki_sky
+# all: contiki_micaz
+# all: isense
+# all: tinyos-tossim
+# all: tinyos-micaz
+all: android
+
+export PROJECT_PATH=/home/vasilakis/Development/wiselib/apps/android_apps/testDebugAndroid
+
+include ../../generic_apps/Makefile
diff --git a/apps/android_apps/testDebugAndroid/jni/Android.mk b/apps/android_apps/testDebugAndroid/jni/Android.mk
new file mode 100644
index 0000000..2364802
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/jni/Android.mk
@@ -0,0 +1,13 @@
+# build file written to describe the C and C++ source files to the Android NDK
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := debugTest
+LOCAL_CXXFLAGS := -W
+LOCAL_SRC_FILES := debug_test.cpp
+#This definition is needed by wiselib
+LOCAL_C_INCLUDES := /home/vasilakis/Development/wiselib/wiselib.testing/ \
+/home/vasilakis/Development/wiselib/wiselib.stable/
+#This definition is also needed by wiselib
+LOCAL_SRC_FILES += ../../../../wiselib.testing/external_interface/android/jni_essentials.cpp
+include $(BUILD_SHARED_LIBRARY)
diff --git a/apps/android_apps/testDebugAndroid/jni/Application.mk b/apps/android_apps/testDebugAndroid/jni/Application.mk
new file mode 100644
index 0000000..caf3b26
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/jni/Application.mk
@@ -0,0 +1 @@
+APP_STL := stlport_static
diff --git a/apps/android_apps/testDebugAndroid/jni/cbox_androidWiselib_debugConc_NativeConnection.h b/apps/android_apps/testDebugAndroid/jni/cbox_androidWiselib_debugConc_NativeConnection.h
new file mode 100644
index 0000000..5bf5e17
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/jni/cbox_androidWiselib_debugConc_NativeConnection.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ ** This file is part of the generic algorithm library Wiselib. **
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
+ ** **
+ ** The Wiselib is free software: you can redistribute it and/or modify **
+ ** it under the terms of the GNU Lesser General Public License as **
+ ** published by the Free Software Foundation, either version 3 of the **
+ ** License, or (at your option) any later version. **
+ ** **
+ ** The Wiselib is distributed in the hope that it will be useful, **
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
+ ** GNU Lesser General Public License for more details. **
+ ** **
+ ** You should have received a copy of the GNU Lesser General Public **
+ ** License along with the Wiselib. **
+ ** If not, see <http://www.gnu.org/licenses/>. **
+ ***************************************************************************/
+
+/*
+ DO NOT EDIT THIS FILE - it is machine generated
+ */
+#include <jni.h>
+/*
+ Header for class cbox_androidWiselib_debugConc_NativeConnection
+ */
+
+#ifndef _Included_cbox_androidWiselib_debugConc_NativeConnection
+#define _Included_cbox_androidWiselib_debugConc_NativeConnection
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ /*
+ * Class: cbox_androidWiselib_debugConc_NativeConnection
+ * Method: debugConceptJNI
+ * Signature: (Ljava/lang/Object;)Ljava/lang/String;
+ */
+ JNIEXPORT jstring JNICALL
+ Java_cbox_androidWiselib_debugConc_NativeConnection_debugConceptJNI
+ (JNIEnv *, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/apps/android_apps/testDebugAndroid/jni/debug_test.cpp b/apps/android_apps/testDebugAndroid/jni/debug_test.cpp
new file mode 100644
index 0000000..49e1a66
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/jni/debug_test.cpp
@@ -0,0 +1,57 @@
+/***************************************************************************
+ ** This file is part of the generic algorithm library Wiselib. **
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
+ ** **
+ ** The Wiselib is free software: you can redistribute it and/or modify **
+ ** it under the terms of the GNU Lesser General Public License as **
+ ** published by the Free Software Foundation, either version 3 of the **
+ ** License, or (at your option) any later version. **
+ ** **
+ ** The Wiselib is distributed in the hope that it will be useful, **
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
+ ** GNU Lesser General Public License for more details. **
+ ** **
+ ** You should have received a copy of the GNU Lesser General Public **
+ ** License along with the Wiselib. **
+ ** If not, see <http://www.gnu.org/licenses/>. **
+ ***************************************************************************/
+
+#include <jni.h>
+#include "cbox_androidWiselib_debugConc_NativeConnection.h"
+#include "external_interface/android/android_os_model.h"
+
+using namespace std;
+using namespace wiselib;
+
+typedef AndroidOsModel Os;
+Os::Debug DebugInstance;
+JniEssentials jni;
+
+// function that tests the debug concept
+void test_debug(void)
+{
+ // AndrDebug testDebug;
+ DebugInstance.debug("This message was sent by andr%did NDK (C++)\n", 0);
+}
+
+/*
+ * Class: cbox_androidWiselib_debugConc_NativeConnection
+ * Method: debugConceptJNI
+ * Signature: (Ljava/lang/Object;)Ljava/lang/String;
+ */
+// second parameter is not used since it holds object pointer of
+// NativeConnection class and not Main's class pointer
+JNIEXPORT jstring
+ JNICALL
+ Java_cbox_androidWiselib_debugConc_NativeConnection_debugConceptJNI
+ (JNIEnv * environment, jobject native_connection_class_object,
+ jobject main_class_object)
+{
+ // setting the global java environment variables
+ jni.set_java_environment(environment);
+ jni.set_java_object(main_class_object);
+ // testing the debug feature
+ test_debug();
+ return environment->NewStringUTF(jni.jni_custom_error().c_str());
+}
diff --git a/apps/android_apps/testDebugAndroid/proguard-project.txt b/apps/android_apps/testDebugAndroid/proguard-project.txt
new file mode 100644
index 0000000..f2fe155
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/apps/android_apps/testDebugAndroid/proguard.cfg b/apps/android_apps/testDebugAndroid/proguard.cfg
new file mode 100644
index 0000000..12dd039
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/proguard.cfg
@@ -0,0 +1,36 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembernames class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembernames class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
diff --git a/apps/android_apps/testDebugAndroid/project.properties b/apps/android_apps/testDebugAndroid/project.properties
new file mode 100644
index 0000000..0840b4a
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/project.properties
@@ -0,0 +1,14 @@
+# 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
+
+# Project target.
+target=android-15
diff --git a/apps/android_apps/testDebugAndroid/res/drawable-hdpi/icon.png b/apps/android_apps/testDebugAndroid/res/drawable-hdpi/icon.png
new file mode 100644
index 0000000..8074c4c
Binary files /dev/null and b/apps/android_apps/testDebugAndroid/res/drawable-hdpi/icon.png differ
diff --git a/apps/android_apps/testDebugAndroid/res/drawable-ldpi/icon.png b/apps/android_apps/testDebugAndroid/res/drawable-ldpi/icon.png
new file mode 100644
index 0000000..1095584
Binary files /dev/null and b/apps/android_apps/testDebugAndroid/res/drawable-ldpi/icon.png differ
diff --git a/apps/android_apps/testDebugAndroid/res/drawable-mdpi/icon.png b/apps/android_apps/testDebugAndroid/res/drawable-mdpi/icon.png
new file mode 100644
index 0000000..a07c69f
Binary files /dev/null and b/apps/android_apps/testDebugAndroid/res/drawable-mdpi/icon.png differ
diff --git a/apps/android_apps/testDebugAndroid/res/layout/main.xml b/apps/android_apps/testDebugAndroid/res/layout/main.xml
new file mode 100644
index 0000000..33d9149
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/res/layout/main.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+ <TextView android:id="@+id/DefaultText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/hello" />
+ <Button android:id="@+id/ShowTime"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="50dip"
+ android:layout_gravity="right"
+ android:text="Test concepts"/>
+ <TextView android:id="@+id/RetrievedText"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+</TableLayout>
diff --git a/apps/android_apps/testDebugAndroid/res/menu/menu.xml b/apps/android_apps/testDebugAndroid/res/menu/menu.xml
new file mode 100644
index 0000000..9be546c
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/res/menu/menu.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/exit"
+ android:title="Exit" />
+</menu>
+
\ No newline at end of file
diff --git a/apps/android_apps/testDebugAndroid/res/values/strings.xml b/apps/android_apps/testDebugAndroid/res/values/strings.xml
new file mode 100644
index 0000000..86768bb
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">This app tests the debug concept in Android.</string>
+ <string name="app_name">debugConcept</string>
+</resources>
diff --git a/apps/android_apps/testDebugAndroid/src/cbox/androidWiselib/debugConc/Main.java b/apps/android_apps/testDebugAndroid/src/cbox/androidWiselib/debugConc/Main.java
new file mode 100644
index 0000000..4028ae3
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/src/cbox/androidWiselib/debugConc/Main.java
@@ -0,0 +1,124 @@
+/***************************************************************************
+ ** This file is part of the generic algorithm library Wiselib. **
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
+ ** **
+ ** The Wiselib is free software: you can redistribute it and/or modify **
+ ** it under the terms of the GNU Lesser General Public License as **
+ ** published by the Free Software Foundation, either version 3 of the **
+ ** License, or (at your option) any later version. **
+ ** **
+ ** The Wiselib is distributed in the hope that it will be useful, **
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
+ ** GNU Lesser General Public License for more details. **
+ ** **
+ ** You should have received a copy of the GNU Lesser General Public **
+ ** License along with the Wiselib. **
+ ** If not, see <http://www.gnu.org/licenses/>. **
+ ***************************************************************************/
+
+/*This class tests the debug concept of wiselib in the android environment.
+ * Method public void testNative(String s) has to be included in every object that needs
+ * the debug feature enabled.
+ */
+
+package cbox.androidWiselib.debugConc;
+
+import java.lang.Object;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.os.Bundle;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class Main extends Activity {
+ // loading the class that handles native methods
+ NativeConnection NativeConnection_ = new NativeConnection();
+ // global variables
+ Menu menu_;
+ Button main_button_; // when pressed calls the native methods
+ TextView default_text_; // the default text which never changes
+ TextView retrieved_text_; // the dynamic text which is retrieved by C++
+ Object object_instance_ = this; // variable that holds the object instance
+ // to pass it in native code
+
+ /* Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // sets the layout according to res/layout/main.xml file
+ setContentView(R.layout.main);
+ // retrieving the values from menu.xml layout
+ main_button_ = (Button) findViewById(R.id.ShowTime);
+ default_text_ = (TextView) findViewById(R.id.DefaultText);
+ retrieved_text_ = (TextView) findViewById(R.id.RetrievedText);
+ // registering an event listener
+ main_button_.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ // calling a native method that tests the debug concept
+ // passing an object argument is mandatory since the native
+ // class
+ // is declared in different class
+ String jni_return_error;
+ jni_return_error = NativeConnection_
+ .debugConceptJNI(object_instance_);
+ if (jni_return_error.compareTo("OK") != 0) {
+ debugFromNative("JNI returned an error: "
+ + jni_return_error);
+ }
+ }
+ });
+ }
+
+ /** this method that created a menu according to res/menu/menu.xml file */
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ this.menu_ = menu;
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.menu, menu);
+ return true;
+ }
+
+ /* this method handles the user input on menu */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle item selection
+ switch (item.getItemId()) {
+ case R.id.exit: // exit the application
+ exitApp();
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+ /* This method kills the application */
+ public void exitApp() {
+ finish();
+ }
+
+ /**
+ * Simple method that is called through JNI from native method testDebug()
+ */
+ public void debugFromNative(String s) {
+ // prepare the alert box
+ AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
+ // set the message to display
+ alertbox.setMessage(s);
+ // add a neutral button to the alert box and assign a click listener
+ alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
+ // click listener on the alert box
+ public void onClick(DialogInterface arg0, int arg1) {
+ // the button was clicked
+ }
+ });
+ // show it
+ alertbox.show();
+ }
+}
diff --git a/apps/android_apps/testDebugAndroid/src/cbox/androidWiselib/debugConc/NativeConnection.java b/apps/android_apps/testDebugAndroid/src/cbox/androidWiselib/debugConc/NativeConnection.java
new file mode 100644
index 0000000..50037d1
--- /dev/null
+++ b/apps/android_apps/testDebugAndroid/src/cbox/androidWiselib/debugConc/NativeConnection.java
@@ -0,0 +1,38 @@
+/***************************************************************************
+ ** This file is part of the generic algorithm library Wiselib. **
+ ** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
+ ** **
+ ** The Wiselib is free software: you can redistribute it and/or modify **
+ ** it under the terms of the GNU Lesser General Public License as **
+ ** published by the Free Software Foundation, either version 3 of the **
+ ** License, or (at your option) any later version. **
+ ** **
+ ** The Wiselib is distributed in the hope that it will be useful, **
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
+ ** GNU Lesser General Public License for more details. **
+ ** **
+ ** You should have received a copy of the GNU Lesser General Public **
+ ** License along with the Wiselib. **
+ ** If not, see <http://www.gnu.org/licenses/>. **
+ ***************************************************************************/
+
+/* This class handles the connection between android code and
+ * native code. Using a static System.loadLibrary("foo"); the
+ * class loads the library libfoo.so in the .apk.
+ */
+package cbox.androidWiselib.debugConc;
+
+public class NativeConnection {
+ /**
+ * Calls the native(C++) method using JNI
+ *
+ * @return Returns a string containing a hello world message
+ */
+ public native String debugConceptJNI(Object c);
+
+ // This method loads as soon as the instance of the class is created
+ static {
+ System.loadLibrary("debugTest");
+ }
+}
/***************************************************************************
** This file is part of the generic algorithm library Wiselib. **
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
** **
** The Wiselib is free software: you can redistribute it and/or modify **
** it under the terms of the GNU Lesser General Public License as **
** published by the Free Software Foundation, either version 3 of the **
** License, or (at your option) any later version. **
** **
** The Wiselib is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU Lesser General Public License for more details. **
** **
** You should have received a copy of the GNU Lesser General Public **
** License along with the Wiselib. **
** If not, see <http://www.gnu.org/licenses/>. **
***************************************************************************/
/*This class tests the debug concept of wiselib in the android environment.
* Method public void testNative(String s) has to be included in every object that needs
* the debug feature enabled.
*/
package cbox.androidWiselib.debugConc;
import java.lang.Object;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity {
// loading the class that handles native methods
NativeConnection NativeConnection_ = new NativeConnection();
// global variables
Menu menu_;
Button main_button_; // when pressed calls the native methods
TextView default_text_; // the default text which never changes
TextView retrieved_text_; // the dynamic text which is retrieved by C++
Object object_instance_ = this; // variable that holds the object instance
// to pass it in native code
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// sets the layout according to res/layout/main.xml file
setContentView(R.layout.main);
// retrieving the values from menu.xml layout
main_button_ = (Button) findViewById(R.id.ShowTime);
default_text_ = (TextView) findViewById(R.id.DefaultText);
retrieved_text_ = (TextView) findViewById(R.id.RetrievedText);
// registering an event listener
main_button_.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// calling a native method that tests the debug concept
// passing an object argument is mandatory since the native
// class
// is declared in different class
String jni_return_error;
jni_return_error = NativeConnection_
.debugConceptJNI(object_instance_);
if (jni_return_error.compareTo("OK") != 0) {
debugFromNative("JNI returned an error: "
+ jni_return_error);
}
}
});
}
/** this method that created a menu according to res/menu/menu.xml file */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu_ = menu;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
/* this method handles the user input on menu */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.exit: // exit the application
exitApp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* This method kills the application */
public void exitApp() {
finish();
}
/**
* Simple method that is called through JNI from native method testDebug()
*/
public void debugFromNative(String s) {
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage(s);
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
}
});
// show it
alertbox.show();
}
}
/***************************************************************************
** This file is part of the generic algorithm library Wiselib. **
** Copyright (C) 2008,2012 by the Wisebed (www.wisebed.eu) project. **
** **
** The Wiselib is free software: you can redistribute it and/or modify **
** it under the terms of the GNU Lesser General Public License as **
** published by the Free Software Foundation, either version 3 of the **
** License, or (at your option) any later version. **
** **
** The Wiselib is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU Lesser General Public License for more details. **
** **
** You should have received a copy of the GNU Lesser General Public **
** License along with the Wiselib. **
** If not, see <http://www.gnu.org/licenses/>. **
***************************************************************************/
/* This class handles the connection between android code and
* native code. Using a static System.loadLibrary("foo"); the
* class loads the library libfoo.so in the .apk.
*/
package cbox.androidWiselib.debugConc;
public class NativeConnection {
/**
* Calls the native(C++) method using JNI
*
* @return Returns a string containing a hello world message
*/
public native String debugConceptJNI(Object c);
// This method loads as soon as the instance of the class is created
static {
System.loadLibrary("debugTest");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment