Changeset 13996
- Timestamp:
- 11/21/12 17:20:36 (12 years ago)
- Location:
- issm/trunk-jpl/src/android/ISSM/src/com/example/issm
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/android/ISSM/src/com/example/issm/ISSM.java ¶
r13931 r13996 1 1 package com.example.issm; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.nio.ByteBuffer; 6 import java.nio.ByteOrder; 7 import java.nio.DoubleBuffer; 2 8 3 9 import android.os.Bundle; 4 10 import android.app.Activity; 11 import android.content.res.AssetManager; 5 12 import android.text.TextUtils; 6 13 import android.view.Menu; … … 12 19 13 20 14 public class ISSM extends Activity implements OnClickListener { 21 public class ISSM extends Activity implements OnClickListener 22 { 15 23 private EditText input; 16 24 private TextView output; 25 private DoubleBuffer buff; 26 private IssmJni issmNative; 27 private String mapName; 28 private String textinFile; 29 private String actualinput; 17 30 @Override 31 //------------------------------------------------------------------------------------------------ 18 32 public void onCreate(Bundle savedInstanceState) { 19 33 super.onCreate(savedInstanceState); 34 Bundle map = getIntent().getExtras(); 35 { 36 if(map!= null) 37 { 38 mapName = map.getString("map"); 39 } 40 } 20 41 setContentView(R.layout.activity_issm); 21 42 this.input = (EditText) super.findViewById(R.id.input); … … 23 44 Button button = (Button) super.findViewById(R.id.button1); 24 45 button.setOnClickListener(this); 46 this.readFile(mapName); 25 47 48 //load up the ISSM library and create double buffer in java 49 //which later on will be pass for native allocation. 50 issmNative = new IssmJni(); 51 buff = ByteBuffer.allocateDirect(15*8).order(ByteOrder.nativeOrder()).asDoubleBuffer(); 52 this.createModel("Model"); 26 53 } 27 28 public void onClick(View view) 54 //------------------------------------------------------------------------------------------------ 55 public void createModel(String Model) 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(); 84 } 85 } 86 //------------------------------------------------------------------------------------------------ 87 public void fillBuffer() 88 { 89 issmNative.processBuffer(buff); 90 } 91 //------------------------------------------------------------------------------------------------ 92 public void onClick(View view) 29 93 { 30 // TODO Auto-generated method stub94 //factorial method 31 95 String input = this.input.getText().toString(); 32 96 if(TextUtils.isEmpty(input)) 33 97 { 34 98 return; 35 } 36 long result = IssmJni.facIterative(Long.parseLong(input)); 37 this.output.setText("Result = " + result + "\n"); 99 } 100 long resultfromFac = issmNative.fac(Long.parseLong(input)); 101 //example of how to fill buffer Native 102 this.fillBuffer(); 103 104 //print result from fac and the first two slot of filled buffer. 105 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); 111 38 112 } 39 113 } -
TabularUnified issm/trunk-jpl/src/android/ISSM/src/com/example/issm/IssmJni.java ¶
r13931 r13996 1 1 package com.example.issm; 2 import java.nio.DoubleBuffer; 2 3 3 publicclass IssmJni4 class IssmJni 4 5 { 5 public static native long fac(long n); 6 static { 6 public native long fac(long n); 7 public native void processBuffer(DoubleBuffer buff); 8 public native void initialize(); 9 static 10 { 7 11 System.loadLibrary("IssmJni"); 8 12 } 9 public static long facIterative(long n)10 {11 return fac(n);12 }13 13 }
Note:
See TracChangeset
for help on using the changeset viewer.