Changeset 13996


Ignore:
Timestamp:
11/21/12 17:20:36 (12 years ago)
Author:
ltnguyen
Message:

New java files create map selection activities, and read external files

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  
    11package com.example.issm;
     2
     3import java.io.IOException;
     4import java.io.InputStream;
     5import java.nio.ByteBuffer;
     6import java.nio.ByteOrder;
     7import java.nio.DoubleBuffer;
    28
    39import android.os.Bundle;
    410import android.app.Activity;
     11import android.content.res.AssetManager;
    512import android.text.TextUtils;
    613import android.view.Menu;
     
    1219
    1320
    14 public class ISSM extends Activity implements OnClickListener {
     21public class ISSM extends Activity implements OnClickListener
     22{
    1523        private EditText input;
    1624        private TextView output;
     25        private DoubleBuffer buff;
     26        private IssmJni issmNative;
     27        private String mapName;
     28        private String textinFile;
     29        private String actualinput;
    1730    @Override
     31  //------------------------------------------------------------------------------------------------   
    1832    public void onCreate(Bundle savedInstanceState) {
    1933        super.onCreate(savedInstanceState);
     34        Bundle map = getIntent().getExtras();
     35        {
     36                if(map!= null)
     37                {
     38                        mapName = map.getString("map");
     39                }
     40        }
    2041        setContentView(R.layout.activity_issm);
    2142        this.input  = (EditText) super.findViewById(R.id.input);
     
    2344        Button button = (Button) super.findViewById(R.id.button1);
    2445        button.setOnClickListener(this);
     46        this.readFile(mapName);
    2547       
     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");
    2653    }
    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)
    2993        {
    30                 // TODO Auto-generated method stub
     94                //factorial method
    3195                String input = this.input.getText().toString();
    3296                if(TextUtils.isEmpty(input))
    3397                {
    3498                        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
    38112        }
    39113}
  • TabularUnified issm/trunk-jpl/src/android/ISSM/src/com/example/issm/IssmJni.java

    r13931 r13996  
    11package com.example.issm;
     2import java.nio.DoubleBuffer;
    23
    3 public class IssmJni
     4class IssmJni
    45{
    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        {
    711        System.loadLibrary("IssmJni");
    812    }
    9         public static long facIterative(long n)
    10         {
    11                 return fac(n);
    12         }
    1313}
Note: See TracChangeset for help on using the changeset viewer.