Changeset 14046
- Timestamp:
- 11/28/12 17:35:23 (12 years ago)
- Location:
- issm/trunk-jpl/src/android/ISSM
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/android/ISSM
- Property svn:ignore
-
old new 1 Makefile.in2 Makefile 1 gen 2 .settings 3 3 libs 4 4 obj 5 Makefile 6 Makefile.in
-
- Property svn:ignore
-
issm/trunk-jpl/src/android/ISSM/.classpath
r13890 r14046 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <classpath> 3 <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> 4 <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> 3 5 <classpathentry kind="src" path="src"/> 4 6 <classpathentry kind="src" path="gen"/> 5 <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>6 <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>7 7 <classpathentry kind="output" path="bin/classes"/> 8 8 </classpath> -
issm/trunk-jpl/src/android/ISSM/AndroidManifest.xml
r13998 r14046 7 7 android:minSdkVersion="10" 8 8 android:targetSdkVersion="15" /> 9 9 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 10 10 <application 11 11 android:icon="@drawable/ic_launcher" … … 16 16 <intent-filter> 17 17 <action android:name="android.intent.action.MAIN" /> 18 19 <category android:name="android.intent.category.LAUNCHER" /> 18 <category android:name="android.intent.category.LAUNCHER" /> 20 19 </intent-filter> 21 20 </activity> -
issm/trunk-jpl/src/android/ISSM/bin
- Property svn:ignore
-
old new 1 ISSM.apk1 *ISSM.apk 2 2 resources.ap_ 3 3 res
-
- Property svn:ignore
-
issm/trunk-jpl/src/android/ISSM/bin/AndroidManifest.xml
r13891 r14046 5 5 6 6 <uses-sdk 7 android:minSdkVersion="1 5"7 android:minSdkVersion="10" 8 8 android:targetSdkVersion="15" /> 9 9 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 10 10 <application 11 11 android:icon="@drawable/ic_launcher" 12 12 android:label="@string/app_name" 13 13 android:theme="@style/AppTheme" > 14 <activity 14 <activity android:name=".MapSelection" 15 android:label="@string/title_activity_issm" > 16 <intent-filter> 17 <action android:name="android.intent.action.MAIN" /> 18 <category android:name="android.intent.category.LAUNCHER" /> 19 </intent-filter> 20 </activity> 21 <activity 15 22 android:name=".ISSM" 16 23 android:label="@string/title_activity_issm" > 17 <intent-filter>18 <action android:name="android.intent.action.MAIN" />19 20 <category android:name="android.intent.category.LAUNCHER" />21 </intent-filter>22 24 </activity> 23 25 </application> -
issm/trunk-jpl/src/android/ISSM/jni/Android.mk
r13931 r14046 11 11 LOCAL_PATH := $(my_LOCAL_PATH) 12 12 LOCAL_ALLOW_UNDEFINED_SYMBOLS := true 13 LOCAL_CFLAGS := -Wno-psabi 13 LOCAL_CFLAGS := -Wno-psabi -DHAVE_CONFIG_H 14 14 LOCAL_LDLIBS := -llog -ldl 15 15 LOCAL_MODULE := IssmJni -
issm/trunk-jpl/src/android/ISSM/jni/Main.cpp
r13997 r14046 1 1 #include <jni.h> 2 2 #include "../../../c/android/fac.h" 3 #include "../../../c/issm.h" 3 4 #include <cstddef> 5 #include <stdio.h> 4 6 /////////////////////////////////////////////////////////////////////////////////////////// 5 7 namespace com_example_issm 6 8 { 7 9 fac* f; 10 //FemModel *fm; 8 11 //------------------------------------------------------------------------------------ 9 void initilizeObject(JNIEnv *env, jclass clazz)12 jint initilize(JNIEnv *env, jclass clazz, jstring file) 10 13 { 14 const char *nativefile = env->GetStringUTFChars(file,0); 15 11 16 f = new fac(); 17 18 //call Model constructor passing in infile as File Descriptor parameter. 19 // fm = new FemModel(nativefile); 20 21 env->ReleaseStringUTFChars(file, nativefile); //must realease the char* 22 //jint size = (jint) fm->bufferSize(); 23 //return size; 24 25 return 0; //return 0 for now. 12 26 } 13 27 //------------------------------------------------------------------------------------ 14 28 //fill out the first two slots, extract the same way in java using get(int position) 15 void fillBuffer(JNIEnv *env, jclass clazz, jobject buf)29 void solve(JNIEnv *env, jclass clazz , jint alpha, jobject buf) 16 30 { 17 jdouble *bBuf = (jdouble *)env->GetDirectBufferAddress(buf); 18 bBuf[1] = 10.67; 19 bBuf[2] = 100.0; 31 jdouble *dBuf = (jdouble *)env->GetDirectBufferAddress(buf); 32 33 //pass bBuff to fem model to allocate data 34 // fm -> solve(dBuf, alpha); 35 20 36 } 21 37 //------------------------------------------------------------------------------------ … … 31 47 { 32 48 {"fac" , "(J)J" , (void *) factorial}, 33 {" initialize" , "()V" , (void *) initilizeObject},34 {"processBuffer", "( Ljava/nio/DoubleBuffer;)V", (void *) fillBuffer}49 {"createISSMModel" ,"(Ljava/lang/String;)I" , (void *) initilize}, 50 {"processBuffer", "(ILjava/nio/DoubleBuffer;)V", (void *) solve} 35 51 }; 36 52 } … … 55 71 else return -1; 56 72 } 57 58 // Get jclass with env->FindClass.59 // Register methods with env->RegisterNatives.60 73 } 61 74 /////////////////////////////////////////////////////////////////////////////////////////// -
issm/trunk-jpl/src/android/ISSM/jni/issmlib/Android.mk
r14000 r14046 3 3 LOCAL_MODULE := libISSMCore 4 4 LOCAL_SRC_FILES := libISSMCore.a 5 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include6 5 include $(PREBUILT_STATIC_LIBRARY) 7 8 9 #include $(CLEAR_VARS)10 #LOCAL_MODULE := libTestBuffer11 #LOCAL_SRC_FILES := libTestBuffer.a12 #LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include13 #include $(PREBUILT_STATIC_LIBRARY) -
issm/trunk-jpl/src/android/ISSM/src/com/example/issm/ISSM.java
r13996 r14046 26 26 private IssmJni issmNative; 27 27 private String mapName; 28 private String textinFile;29 private String actualinput;28 private String issmFolder; 29 private int size; 30 30 @Override 31 31 //------------------------------------------------------------------------------------------------ … … 37 37 { 38 38 mapName = map.getString("map"); 39 issmFolder = map.getString("pathToFile"); 39 40 } 40 41 } … … 44 45 Button button = (Button) super.findViewById(R.id.button1); 45 46 button.setOnClickListener(this); 46 this.readFile(mapName);47 47 48 48 //load up the ISSM library and create double buffer in java … … 50 50 issmNative = new IssmJni(); 51 51 buff = ByteBuffer.allocateDirect(15*8).order(ByteOrder.nativeOrder()).asDoubleBuffer(); 52 this.createModel( "Model");52 this.createModel(); 53 53 } 54 54 //------------------------------------------------------------------------------------------------ 55 public void createModel( String Model)55 public void createModel() 56 56 { 57 issmNative.initialize(); 58 } 59 //------------------------------------------------------------------------------------------------ 60 public void readFile(String mapName) 61 { 62 AssetManager am = getAssets(); 63 String mapNameFile = "Map/"+mapName+".txt"; 64 try { 65 InputStream is = am.open(mapNameFile); 66 int size = is.available(); 67 byte[]buffer = new byte[size]; 68 is.read(buffer); 69 is.close(); 70 71 textinFile = new String(buffer); 72 73 //testing on actual file 74 InputStream is1 = am.open("Map/test102.petsc"); 75 int size1 = is1.available(); 76 byte[]buffer1 = new byte[size1]; 77 is1.read(buffer1); 78 System.out.println(buffer1); 79 is1.close(); 80 actualinput = new String(buffer1); 81 } catch (IOException e) { 82 // TODO Auto-generated catch block 83 e.printStackTrace(); 57 String file = ""; 58 if( mapName.equals("greenland")) 59 { 60 file = "test102.petsc"; 84 61 } 62 else file = "test102.petsc"; 63 size = issmNative.createISSMModel(issmFolder + file); 85 64 } 86 65 //------------------------------------------------------------------------------------------------ 87 66 public void fillBuffer() 88 67 { 89 issmNative.processBuffer( buff);68 issmNative.processBuffer(5,buff); 90 69 } 91 70 //------------------------------------------------------------------------------------------------ … … 104 83 //print result from fac and the first two slot of filled buffer. 105 84 this.output.setText("Result = " + resultfromFac + "\n" 106 + "First two slot from buffer:\n" 107 + buff.get(1) + " " + buff.get(2) 108 + "\nmap name = " + mapName 109 + "\nTxtFile " + textinFile 110 +"\nactualFile " + actualinput); 85 + "First slot from buffer:\n" 86 + buff.get(0) + " size " + size); 111 87 112 88 } -
issm/trunk-jpl/src/android/ISSM/src/com/example/issm/IssmJni.java
r13996 r14046 5 5 { 6 6 public native long fac(long n); 7 public native void processBuffer( DoubleBuffer buff);8 public native void initialize();7 public native void processBuffer(int alpha, DoubleBuffer buff); 8 public native int createISSMModel(String file); 9 9 static 10 10 { -
issm/trunk-jpl/src/android/ISSM/src/com/example/issm/MapSelection.java
r13996 r14046 1 1 package com.example.issm; 2 3 import java.io.File; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.io.OutputStream; 2 8 3 9 import android.app.Activity; 4 10 import android.os.Bundle; 11 import android.os.Environment; 5 12 import android.text.TextUtils; 13 import android.util.Log; 6 14 import android.view.Menu; 7 15 import android.view.View; 8 16 import android.widget.Button; 17 import android.widget.Toast; 9 18 import android.content.Intent; 10 19 import android.content.SharedPreferences; 20 import android.content.res.AssetManager; 21 /////////////////////////////////////////////////////////////////////////// 11 22 public class MapSelection extends Activity 12 23 { 13 private String map;14 24 ISSM issm = new ISSM(); 25 private static final String PREFERENCE_FIRST_RUN = null; 26 private String extStorageDirectory; 27 private String issmFolder; 28 //------------------------------------------------------------------------ 15 29 public void onCreate(Bundle icicle) 16 30 { … … 18 32 setContentView(R.layout.activity_mapselection); 19 33 34 SharedPreferences settings = this.getSharedPreferences("ISSM", 0); 35 boolean firstrun = settings.getBoolean(PREFERENCE_FIRST_RUN, true); 36 extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 37 38 issmFolder = extStorageDirectory + "/ISSM/input_files/"; 39 if (firstrun) 40 { // Checks to see if we've ran the application b4 41 SharedPreferences.Editor e = settings.edit(); 42 e.putBoolean(PREFERENCE_FIRST_RUN, false); 43 44 e.commit(); 45 // If not, run these methods: 46 SetDirectory(issmFolder); 47 } 48 49 20 50 //this button represents greenland and pass signal to issm 21 51 Button gl = (Button) findViewById(R.id.button1); 22 52 gl.setOnClickListener(new View.OnClickListener() 23 53 { 24 25 54 public void onClick(View v) 26 55 { 27 // TODO Auto-generated method stub28 56 Intent i = new Intent(MapSelection.this, ISSM.class); 29 57 i.putExtra("map", "greenland"); 58 i.putExtra("pathToFile", issmFolder); 30 59 startActivity(i); 31 60 } 32 61 }); 33 62 34 //this button represents arta nticeand pass signal to issm63 //this button represents artarctica and pass signal to issm 35 64 Button art = (Button) findViewById(R.id.button2); 36 65 art.setOnClickListener(new View.OnClickListener() 37 66 { 38 39 67 public void onClick(View v) 40 68 { 41 // TODO Auto-generated method stub42 69 Intent i = new Intent(MapSelection.this, ISSM.class); 43 70 i.putExtra("map", "antarctica"); 71 i.putExtra("pathToFile", issmFolder); 44 72 startActivity(i); 45 73 } 46 74 }); 47 75 } 76 //------------------------------------------------------------------------ 77 private void SetDirectory(String directory) 78 { 79 if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) 80 { 81 System.out.println(issmFolder); 82 File txtDirectory = new File(issmFolder); 83 84 // Check and create directory in SDcard 85 if(!txtDirectory.exists()) 86 { 87 txtDirectory.mkdirs(); 88 System.out.println("making directory"); 89 } 90 CopyAssets(); // Then run the method to copy the file. 91 92 } 93 else if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED_READ_ONLY)) 94 { 95 Toast toast = Toast.makeText(this.getApplicationContext(), "Memory is not mounted to device", Toast.LENGTH_LONG); 96 toast.show(); 97 } 98 99 } 100 //---------------------------------------------------------------------------- 101 /** 102 * -- Copy the file from the assets folder to the sdCard 103 * =========================================================== 104 **/ 105 private void CopyAssets() 106 { 107 AssetManager assetManager = getAssets(); 108 String[] files = null; 109 try { 110 files = assetManager.list("Map"); 111 } catch (IOException e) { 112 Log.e("tag", e.getMessage()); 113 } 114 for (int i = 0; i < files.length; i++) { 115 InputStream in = null; 116 OutputStream out = null; 117 try { 118 in = assetManager.open("Map/"+files[i]); 119 out = new FileOutputStream(issmFolder + files[i]); 120 copyFile(in, out); 121 in.close(); 122 in = null; 123 out.flush(); 124 out.close(); 125 out = null; 126 } catch (Exception e) { 127 Log.e("tag", e.getMessage()); 128 } 129 } 130 System.out.println("Done"); 131 } 132 //---------------------------------------------------------------------------- 133 private void copyFile(InputStream in, OutputStream out) throws IOException 134 { 135 byte[] buffer = new byte[1024]; 136 int read; 137 while ((read = in.read(buffer)) != -1) { 138 out.write(buffer, 0, read); 139 } 140 } 141 //---------------------------------------------------------------------------- 48 142 } 49 143 ///////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.