Revision: 49792
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49792
Author:   alexk
Date:     2012-08-11 00:59:47 +0000 (Sat, 11 Aug 2012)
Log Message:
-----------
Adding Sensor support for Android (Java side)
Some cleanup
Adding static PathsHelper class for getting app path and installing libs. File 
releated routines goes here.
Logcat FPS counter (Should be removed from final versions for speed probably)
The functions that are exported to jni have "export_" prefex

Modified Paths:
--------------
    
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/BlenderNativeAPI.java
    
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/ControlCenterActivity.java
    
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/CopyIntern.java
    
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/GhostActivity.java
    
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/makesActivity.java

Added Paths:
-----------
    
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/PathsHelper.java

Modified: 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/BlenderNativeAPI.java
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/BlenderNativeAPI.java
        2012-08-11 00:34:27 UTC (rev 49791)
+++ 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/BlenderNativeAPI.java
        2012-08-11 00:59:47 UTC (rev 49792)
@@ -9,7 +9,7 @@
                System.loadLibrary("main");
     }
        
-       
+       public static native void SetASystem(GhostActivity jsys);
        public static native void SetScreen(GhostSurface win);
        public static native void Swap();
        public static native void StartBlender(String filepath);
@@ -19,6 +19,9 @@
        public static native void eventWindowsFocus();
        public static native void eventWindowsDefocus();
        
+       public static native void eventSensor3D(int type, float x, float y, 
float z);
+       public static native void eventSensor1D(int type, float x);
+       
        public static native void actionClose();
        
        public static native void eventTouch(int type, float x, float y);       

Modified: 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/ControlCenterActivity.java
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/ControlCenterActivity.java
   2012-08-11 00:34:27 UTC (rev 49791)
+++ 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/ControlCenterActivity.java
   2012-08-11 00:59:47 UTC (rev 49792)
@@ -1,8 +1,6 @@
 package org.blender.play;
 
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
@@ -16,8 +14,12 @@
 import android.view.*;
 import android.view.View.*;
 
+
+
+
 public class ControlCenterActivity extends Activity {
 
+       private Button b_downloadlib;
        private Button b_startgame;
        private Button b_selectgame;
        private TextView t_gamename;
@@ -25,20 +27,26 @@
        
        private String gamepath = null;
        
+       private String appdirbase;
+       
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
+           PathsHelper.installIfNeeded(this);
            
+           
+           
            setContentView(R.layout.main);
 
+           appdirbase = PathsHelper.getBaseAppDir(this);
            
-           
            b_startgame = (Button)findViewById(R.id.startbutton);
            b_selectgame = (Button)findViewById(R.id.gameselecterbutton);
            t_gamename = (TextView)findViewById(R.id.gamenametext);
            
            
+           
            b_startgame.setOnClickListener(new OnClickListener() {           
             @Override
             public void onClick(View v) {
@@ -48,6 +56,7 @@
                intent.setData(Uri.parse("file://" + gamepath));
                
                startActivity(intent); 
+               BlenderNativeAPI.exit(0);
             }
         });
            
@@ -74,19 +83,19 @@
         });
            
            updatePlayable();
-           
-           // TODO Auto-generated method stub
+
        }
 
        void updatePlayable()
        {
-               if(gamepath != null)
+               if(gamepath != null && (new 
File(appdirbase+"libblenderplayer.so")).exists())
                        b_startgame.setEnabled(true);
                else
                        b_startgame.setEnabled(false);
        }
        
        
+               
     protected void onActivityResult(int requestCode, int resultCode, Intent 
data) {
         switch (requestCode) {
             case 0:      
@@ -113,7 +122,7 @@
     super.onActivityResult(requestCode, resultCode, data);
     }
        
-       void InstallFile(String installpath, String basepath)
+       public void InstallFile(String installpath, String basepath)
        {
         try
         {
@@ -168,7 +177,7 @@
                String path =  intentdata.getEncodedPath();
                if(path != null)
                {
-                       Log.i("rrrr","Started " + path);
+                       Log.i("Blender","Started " + path);
                        
                    String basedir = getBaseContext().getFilesDir().getPath();
                    basedir = basedir.substring(0, basedir.lastIndexOf("/")+1);
@@ -176,11 +185,14 @@
                    InstallFile(path, basedir);
                        
                }
-               else Log.i("rrrr","No path");
-        } else Log.i("rrrr","No data");
+               else Log.i("Blender","No path");
+        } else Log.i("Blender","No data");
        
 
         
 
        }
+       
+       
+
 }

Modified: 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/CopyIntern.java
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/CopyIntern.java
      2012-08-11 00:34:27 UTC (rev 49791)
+++ 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/CopyIntern.java
      2012-08-11 00:59:47 UTC (rev 49792)
@@ -53,7 +53,7 @@
        public void onStart() {
                super.onStart();
                MainFunc();
-
+               finish();
                BlenderNativeAPI.exit(0);
            
        }

Modified: 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/GhostActivity.java
===================================================================
--- 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/GhostActivity.java
   2012-08-11 00:34:27 UTC (rev 49791)
+++ 
branches/soc-2012-swiss_cheese/source/android/app/src/org/blender/play/GhostActivity.java
   2012-08-11 00:59:47 UTC (rev 49792)
@@ -2,10 +2,13 @@
 
 
 
+import java.util.*;
+
 import android.app.Activity;
 import android.os.Bundle;
 import android.view.*;
 import android.content.*;
+import android.hardware.*;
 import android.util.*;
 import android.net.*;
 import javax.microedition.khronos.egl.*;
@@ -14,11 +17,16 @@
 
 
 
-public class GhostActivity extends Activity
+public class GhostActivity extends Activity implements SensorEventListener
 {
     /** Called when the activity is first created. */
        private GhostSurface mainSurface;
        
+       private SensorManager sensors;
+       private Sensor accelerometer;
+       private Sensor gyroscope;
+       private Sensor magneticfield;
+       
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
@@ -27,19 +35,73 @@
         
         
         Uri data = getIntent().getData();
-        if(data != null){
+        if(data != null || true){
       
         Log.i("Blender","Started");
-        mainSurface = new GhostSurface(data.getPath(), getApplication());
+        mainSurface = new GhostSurface(data != null ? data.getPath() : 
"/sdcard/test.blend", getApplication());
         setContentView(mainSurface);
         SurfaceHolder holder = mainSurface.getHolder();
         Log.v("Blender", "Surface valid: " + 
Boolean.toString(holder.getSurface().isValid()));
+       // holder.setFixedSize(240, 400);
+        
         //mainSurface.initSurface();
      //setContentView(R.layout.main);
+        
+        sensors = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+        
+        accelerometer = sensors.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+        gyroscope = sensors.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
+        magneticfield = sensors.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
+        
+        BlenderNativeAPI.SetASystem(this);
+        //sensors.registerListener(this, accelerometer, 
SensorManager.SENSOR_DELAY_GAME);
+        
+        //sensors.registerListener(this, gyroscope, 
SensorManager.SENSOR_DELAY_GAME);        
+        
+        
         }
            
     }
     
+    public int export_getSensorsAvailability(int type)
+    {
+       switch(type)
+       {
+               case 1: return accelerometer == null ? 0 : 1;
+               case 2: return gyroscope == null ? 0 : 1;
+               case 3: return magneticfield == null ? 1 : 0;
+       }
+       return 0;       
+    }
+    
+    public int export_setSensorsState(int type, int enable)
+    {
+       Sensor cs = null;
+       switch(type)
+       {
+               case 1: cs = accelerometer ; break;
+               case 2: cs =  gyroscope; break;
+               case 3: cs =  magneticfield; break;
+               default: return 0;
+       }
+       
+       if(cs==null)
+               return 0;
+       
+       if(enable != 0)
+       {
+               return sensors.registerListener(this, cs, 
SensorManager.SENSOR_DELAY_GAME) ? 1 : 0;
+               
+       } else
+       {
+               sensors.unregisterListener(this, cs);
+               return 1;
+               
+       }
+       
+       
+    }
+    
     public void onStart()
     {
        super.onStart();
@@ -47,7 +109,7 @@
        
 
     }
-    
+        
     @Override
     public boolean onTouchEvent(MotionEvent event)
     {
@@ -61,14 +123,42 @@
        super.onPause();
        BlenderNativeAPI.actionClose();
        
-       finish();       
+       finish(); 
+       BlenderNativeAPI.exit(0);
     }
+        
     
+
+    
+    @Override
+    public void onAccuracyChanged(Sensor sensor, int accuracy) 
+    {
+
+    }
+    
+    @Override
+    public void onSensorChanged(SensorEvent event) 
+    {
+       switch(event.sensor.getType())
+       {
+               case Sensor.TYPE_ACCELEROMETER:
+                       BlenderNativeAPI.eventSensor3D(0, event.values[0], 
event.values[1], event.values[2]);
+                       break;
+               case Sensor.TYPE_GYROSCOPE:
+                       BlenderNativeAPI.eventSensor3D(1, event.values[0], 
event.values[1], event.values[2]);
+                       break;  
+               case Sensor.TYPE_MAGNETIC_FIELD:
+                       BlenderNativeAPI.eventSensor3D(2, event.values[0], 
event.values[1], event.values[2]);
+                       break;          
+       
+       }
+       
+    }
 }
 
 
 
-class GhostSurface extends SurfaceView implements SurfaceHolder.Callback {
+class GhostSurface extends SurfaceView implements SurfaceHolder.Callback{
 
        private EGLDisplay egldisplay = null;
        private EGLSurface surface = null;
@@ -77,6 +167,7 @@
        
        private String filepath;
        
+       long lasttime;
        
        @Override
        public boolean onTouchEvent(MotionEvent event)
@@ -92,11 +183,14 @@
                
                this.filepath = filepath;
                
+               lasttime = Calendar.getInstance().getTimeInMillis();
+               
                getHolder().addCallback(this); 
                getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
         setFocusable(true);
         setFocusableInTouchMode(true);
         requestFocus();
+        
        }
        
     public void surfaceCreated(SurfaceHolder holder) {
@@ -109,6 +203,8 @@
        BlenderNativeAPI.eventWindowsResize(this.getWidth(), this.getHeight());
        BlenderNativeAPI.eventWindowsFocus();
        BlenderNativeAPI.eventWindowsUpdate();
+       
+       export_getWindowSize();
     }
        
     
@@ -119,6 +215,8 @@
                BlenderNativeAPI.eventWindowsResize(width, height);
                BlenderNativeAPI.eventWindowsFocus();
                BlenderNativeAPI.eventWindowsUpdate();
+               
+               
        }
     
     public void surfaceDestroyed(SurfaceHolder holder) {
@@ -126,6 +224,11 @@

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to