François Gautrais 8 年 前
コミット
c02d872dc1

+ 2 - 0
app/src/main/java/app/brest/app/brest/ui/CameraPreview.java

@@ -60,6 +60,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
             return;
         }
 
+
         // stop preview before making changes
         try {
             mCamera.stopPreview();
@@ -88,3 +89,4 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
 
     }
 }
+

+ 15 - 2
app/src/main/java/app/brest/testmin3d/ARActivity.java

@@ -4,14 +4,17 @@ import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.graphics.PixelFormat;
 import android.hardware.Camera;
+import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.view.WindowManager;
 import android.widget.Button;
 import android.widget.FrameLayout;
+import android.widget.MediaController;
 import android.widget.TextView;
 import android.widget.Toast;
+import android.widget.VideoView;
 
 import org.w3c.dom.Text;
 
@@ -103,6 +106,7 @@ public class ARActivity extends RendererActivity
     public void initScene()
     {
         // !important
+        scene.clear();
         scene.backgroundColor().setAll(0x00000000);
         scene.lights().add(new Light());
         scene.lights().add(new Light());
@@ -146,6 +150,7 @@ public class ARActivity extends RendererActivity
                 scene.addChild(oo);
             }
         }
+
         final String td = toDisplay;
         mAngle.getHandler().post(new Runnable() {
             public void run() {
@@ -179,10 +184,13 @@ public class ARActivity extends RendererActivity
         mGame = (Game) getIntent().getSerializableExtra("game");
         mGame.newSensorManager(this);
 
+
+
     }
 
 
 
+
     @Override
     /**
      * Verifie si on doit afficher des resources et gere le bouton de capture
@@ -244,7 +252,6 @@ public class ARActivity extends RendererActivity
         super.onResume();
         mGame.onResume(this);
         scene.clear();
-
         synchronized (mLock)
         {
             isPausing=false;
@@ -295,8 +302,12 @@ public class ARActivity extends RendererActivity
     {
         boolean stageFinished = mGame.pickResource();
         boolean finished = false;
+        mGame.printNResource("Pick up");
 
         //TDOD: Nouvelle activité pour afficher la ressource
+        /*Intent intent = new Intent(this, ResourceListActivity.class);
+        intent.putExtra("game", mGame );
+        startActivity(intent);
 
         if(stageFinished)
         {
@@ -306,7 +317,9 @@ public class ARActivity extends RendererActivity
         if(finished)
         {
 
-        }
+        }*/
+
+
 
     }
 

+ 29 - 3
app/src/main/java/app/brest/testmin3d/MenuActivity.java

@@ -7,14 +7,18 @@ import android.support.design.widget.FloatingActionButton;
 import android.support.design.widget.Snackbar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
+import android.util.Log;
 import android.view.Display;
 import android.view.View;
 import android.widget.ImageButton;
 import android.widget.LinearLayout;
+import android.widget.Toast;
 
 import app.brest.testmin3d.R;
 import app.brest.utils.Settings;
 import app.brest.utils.app.brest.game.Game;
+import app.brest.utils.app.brest.game.Resource;
+import app.brest.utils.app.brest.game.Stage;
 
 public class MenuActivity extends AppCompatActivity {
     protected Game mGame;
@@ -34,7 +38,7 @@ public class MenuActivity extends AppCompatActivity {
         display.getSize(size);
         int width = size.x;
         int height = size.y;
-        int buttonHieght = (height-4*40)/5;
+        int buttonHieght = (height-5*40)/6;
         mICarte = (ImageButton) findViewById(R.id.ib_carte);
         mIInventaire = (ImageButton) findViewById(R.id.ib_inventaire);
         mIOptions = (ImageButton) findViewById(R.id.ib_options);
@@ -45,22 +49,38 @@ public class MenuActivity extends AppCompatActivity {
         mIOptions.setLayoutParams(new LinearLayout.LayoutParams(buttonHieght, buttonHieght));
         mIScanner.setLayoutParams(new LinearLayout.LayoutParams(buttonHieght, buttonHieght));
 
+
         Game g = null;//Game.load(this);
 
         if (g!= null && mGame==null) {
             mGame = g;
             mGame.newSensorManager(this);
+            Toast.makeText(this, "Chargement", Toast.LENGTH_LONG).show();
         }
         else if( mGame==null)
         {
             mGame = new Game("game_medium", this);
-
+            Toast.makeText(this, "Nouveau Jeu", Toast.LENGTH_LONG).show();
         }else if( mGame==null)
         {
+            Toast.makeText(this, "Erreur", Toast.LENGTH_LONG).show();
             throw new Error("Le jeu n'est pas sauvegardé");
         }
+        if(mGame!=null)
+        {
+            mGame.pickResource("b");
+            mGame.pickResource("c");
+            mGame.pickResource("d");
+            mGame.pickResource("e");
+        }
     }
 
+    public void onResume()
+    {
+        super.onResume();
+        mGame.printNResource("N res Resume");
+        Log.e("________", "mGame : "+mGame);
+    }
 
     public void onOptionsClick(View v)
     {
@@ -94,5 +114,11 @@ public class MenuActivity extends AppCompatActivity {
     }
 
 
-
+    public void onInfoClick(View v) {
+        Intent intent = new Intent(this, ViewerActivity.class);
+        Stage s = mGame.getCurrentStageObj();
+        Resource r = (s!=null)?s.getResource(): null;
+        intent.putExtra("resource", r );
+        startActivity(intent);
+    }
 }

+ 1 - 5
app/src/main/java/app/brest/testmin3d/ResourceListActivity.java

@@ -74,11 +74,7 @@ public class ResourceListActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_resource_list);
         mGame = (Game)getIntent().getSerializableExtra("game");
-        if(mGame!=null)
-        {
-            mGame.pickResource("camaro");
-            mGame.pickResource("face");
-        }
+
         mLayout = (LinearLayout) findViewById(R.id.list_layout);
         fill();
     }

+ 2 - 0
app/src/main/java/app/brest/testmin3d/SettingsActivity.java

@@ -94,6 +94,8 @@ public class SettingsActivity extends Activity {
     }
 
 
+
+
     private void setResults()
     {
         mGame.getmSettings().setAccelerometerDebug(mAccelerometer.isChecked());

+ 24 - 4
app/src/main/java/app/brest/testmin3d/ViewerActivity.java

@@ -2,11 +2,13 @@ package app.brest.testmin3d;
 
 import android.annotation.SuppressLint;
 import android.content.Intent;
+import android.net.Uri;
 import android.provider.ContactsContract;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.os.Handler;
+import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.WindowManager;
@@ -15,6 +17,7 @@ import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
+import android.widget.VideoView;
 
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -55,21 +58,35 @@ public class ViewerActivity extends RendererActivity {
         if(getIntent().hasExtra("resource"))
         {
             mResource = (Resource) getIntent().getSerializableExtra("resource");
-            setTitle(mResource.getTitle());
+            if(mResource!=null) setTitle(mResource.getTitle());
         }
 
+        VideoView m_c = (VideoView)findViewById(R.id.vv_media);
+        m_c.setVisibility(View.INVISIBLE);
         if(mResource != null && !getIntent().hasExtra("information") && !getIntent().hasExtra("map"))
         {
             if(mResource.getType().compareTo("Image")==0)
             {
-                int id = getResources().getIdentifier(mResource.getName()+"_res","drawable", getPackageName());
+                int id = getResources().getIdentifier(mResource.getName(),"drawable", getPackageName());
                 mImageView.setImageResource(id);
                 mAttacher = new PhotoViewAttacher(mImageView);
             }
-            else if(mResource.getType().compareTo("3D")==0)
-            {
+            else if(mResource.getType().compareTo("3D")==0) {
                 mFrameLayout.addView(_glSurfaceView);
+            }else
+            {
+                String path="android.resource://app.brest.testmin3d/raw/"+mResource.getName();
+                if(mResource.getType().compareTo("Audio")==0) path+="_audio";
+                else path+="_video";
+                mImageView.setVisibility(View.INVISIBLE);
+                _glSurfaceView.setVisibility(View.INVISIBLE);
+                VideoView mc = (VideoView)findViewById(R.id.vv_media);
+                mc.setVisibility(View.VISIBLE);
+                Uri video = Uri.parse(path);
+                mc.setVideoURI(video);
+                mc.start();
             }
+
         } else if(getIntent().hasExtra("map") )
         {
             int id = getResources().getIdentifier(getIntent().getStringExtra("map"),"drawable", getPackageName());
@@ -86,6 +103,9 @@ public class ViewerActivity extends RendererActivity {
             mFrameLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
         }
 
+
+
+
     }
 
     public void onClickInfo(View v)

+ 14 - 0
app/src/main/java/app/brest/utils/ResourceManager.java

@@ -52,11 +52,13 @@ public class ResourceManager implements Serializable{
         {
             if(mResourcesLeft.get(i).getName().compareTo(name)==0)
             {
+
                 mResourcesAquiered.get(mResourcesAquiered.size()-1).add(mResourcesLeft.get(i));
                 mResourcesLeft.remove(i);
                 return true;
             }
         }
+        Log.e("________", "aucune ressource ajoutée");
         return false;
     }
 
@@ -83,4 +85,16 @@ public class ResourceManager implements Serializable{
             mAllResources.get(i).delete3DModel();
     }
 
+    public int getNResourceAcquired()
+    {
+        if(mResourcesAquiered.size()>0)
+            return mResourcesAquiered.get(mResourcesAquiered.size()-1).size();
+        return 0;
+    }
+
+    public int getNResourceLeft()
+    {
+        return mResourcesLeft.size();
+    }
+
 }

+ 11 - 2
app/src/main/java/app/brest/utils/SensorsManager.java

@@ -14,6 +14,8 @@ import android.location.LocationManager;
 import android.os.Bundle;
 import android.provider.Settings;
 import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
+import android.widget.Toast;
 
 import app.brest.testmin3d.ARActivity;
 import app.brest.utils.geometry.GPSPoint;
@@ -88,8 +90,15 @@ public class SensorsManager implements SensorEventListener, LocationListener {
                 ActivityCompat.checkSelfPermission(mParent, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
 
         }
-
-        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+        if (ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_FINE_LOCATION) ==
+                PackageManager.PERMISSION_GRANTED &&
+                ContextCompat.checkSelfPermission(parent, android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
+                        PackageManager.PERMISSION_GRANTED) {
+            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+        } else {
+            Toast.makeText(parent,"Error", Toast.LENGTH_LONG).show();
+            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+        }
     }
 
     public void onResume() {

+ 4 - 4
app/src/main/java/app/brest/utils/SlideBuffer.java

@@ -56,13 +56,13 @@ public class SlideBuffer {
         if(mSize<mData.length) mSize++;
     }
 
-    private float[] exponentialSmoothing( float[] input, float[] output, float alpha ) {
-        if ( output == null )
+    private float[] exponentialSmoothing( float[] input, float[] output_mkv, float alpha ) {
+        if ( output_mkv == null )
             return input;
         for ( int i=0; i<input.length; i++ ) {
-            output[i] = output[i] + alpha * (input[i] - output[i]);
+            output_mkv[i] = output_mkv[i] + alpha * (input[i] - output_mkv[i]);
         }
-        return output;
+        return output_mkv;
     }
 
     public float average()

+ 1 - 1
app/src/main/java/app/brest/utils/app/brest/game/Area.java

@@ -53,7 +53,7 @@ public class Area  implements Serializable {
         return mResourceName;
     }
 
-    public Resource getResource(Activity act) {
+    public Resource getResource() {
         return mResource;
     }
 

+ 51 - 12
app/src/main/java/app/brest/utils/app/brest/game/Game.java

@@ -28,25 +28,34 @@ import app.brest.utils.Settings;
  */
 public class Game  implements Serializable {
 
-    protected ArrayList<Area> mAreas = new ArrayList<Area>();
-    protected ArrayList<Area> mCurrentStageAreas = new ArrayList<Area>();
-    protected int             mNStages;
-    protected int             mCurrentStage=0;
-    protected Player          mPlayer;
-    protected ResourceManager mResources;
-    protected String          mName;
-    protected Settings        mSettings = new Settings();
+    protected ArrayList<Area>  mAreas = new ArrayList<Area>();
+    protected ArrayList<Area>  mCurrentStageAreas = new ArrayList<Area>();
+    protected ArrayList<Stage> mStages = new ArrayList<Stage>();
+    protected int              mNStages;
+    protected int              mCurrentStage=0;
+    protected Player           mPlayer;
+    protected ResourceManager  mResources;
+    protected String           mName;
+    protected Settings         mSettings = new Settings();
 
     public Game(String name, Activity act)
     {
+        Log.e("_______", "Nouveau jeu");
         JSONObject root = JSONLoader.load(act, name);
         mName=name;
         mPlayer = new Player(act);
         try {
             JSONArray areas = root.getJSONArray("areas");
+            JSONArray stages = root.getJSONArray("stages_list");
             for(int i=0; i<areas.length(); i++)
                 mAreas.add(new Area(areas.getJSONObject(i), act));
             mResources = new ResourceManager(this, act);
+            for(int i=0; i<stages.length(); i++) {
+                Stage s = new Stage(stages.getJSONObject(i));
+                Resource r = findResource(s.getResourceName());
+                s.setResource(r);
+                mStages.add(s);
+            }
             findMaxStage();
             nextStage();
 
@@ -54,6 +63,15 @@ public class Game  implements Serializable {
             e.printStackTrace();
         }
     }
+    public Stage getCurrentStageObj()
+    {
+        return mStages.get(mCurrentStage-1);
+    }
+
+    public Stage getStage(int i)
+    {
+        return mStages.get(i);
+    }
 
     public Settings getmSettings(){return mSettings;}
     public void setSettings(Settings s){ mSettings=s;}
@@ -124,13 +142,16 @@ public class Game  implements Serializable {
     public boolean pickResource()
     {
         ArrayList<Resource> r = getResourcesNextToPlayer();
+        Log.e("_______", "N Res Left : "+mResources.getNResourceAcquired());
         for(int i=0; i<r.size(); i++) {
             for (int j = 0; j < mCurrentStageAreas.size(); j++)
                 if (r.get(i).getName().compareTo(mCurrentStageAreas.get(j).getName())==0) {
                     removeArea(j);
                 }
-            mResources.pickUpResource(r.get(i).getName());
+            pickResource(r.get(i).getName());
         }
+        Log.e("_______", "N Res Left : "+mResources.getNResourceAcquired());
+        Log.e("_______", toString()+"____________________________\n");
         return mCurrentStageAreas.size()==0;
     }
 
@@ -151,10 +172,16 @@ public class Game  implements Serializable {
 
     public String toString()
     {
-        String out = "mAreas[]:\n";
+        String out = "Game : "+super.toString();
+                out+="mAreas[]:\n";
         for(int i=0; i<mAreas.size(); i++)
             out+="\tmAres["+i+"] = "+mAreas.get(i).getJson().toString()+"\n";
         out+="\nmResourcesAcquired[] : \n";
+        for(int i=0; i<mResources.getResourceAquiered().size(); i++) {
+            out+="\tmResourcesAcquired["+i+"][] : \n";
+            for (int j = 0; j < mResources.getResourceAquiered().get(i).size(); j++)
+                out += "\t\tmResourcesAcquired[" + i + "]["+j+"] = " + mResources.getResourceAquiered().get(i).get(j).getJson().toString() + "\n";
+        }
         out+="mNStages :" +mNStages +"\n";
         out+="mCurrentStage" + mCurrentStage +"\n";
         return out;
@@ -198,7 +225,7 @@ public class Game  implements Serializable {
         ArrayList<Resource> tmp = new ArrayList<Resource>();
         for(int i=0; i<mAreas.size(); i++)
             if(!tmp.contains(mAreas.get(i)))
-                tmp.add(mAreas.get(i).getResource(act));
+                tmp.add(mAreas.get(i).getResource());
         return tmp;
     }
 
@@ -234,6 +261,14 @@ public class Game  implements Serializable {
         mPlayer.setSensorsManager(sm);
     }
 
+    public Resource findResource(String name)
+    {
+        for(int i=0; i<mAreas.size(); i++)
+            if(mAreas.get(i).getResourceName().compareTo(name)==0)
+                return mAreas.get(i).getResource();
+        return null;
+    }
+
     /**
      * Charge la ressource 3d quand on entre dans une zone
      */
@@ -266,6 +301,7 @@ public class Game  implements Serializable {
         {
             //probleme de GPS..
             boolean b = mCurrentStageAreas.get(i).isOnArea(mPlayer);
+
             if(b)
             {
 
@@ -325,5 +361,8 @@ public class Game  implements Serializable {
     {
         mPlayer.getSensorsManager().stopSensors();
     }
-
+    public void printNResource(String str)
+    {
+        Log.e("_______", str+" : "+mResources.getNResourceAcquired());
+    }
 }

+ 1 - 0
app/src/main/java/app/brest/utils/app/brest/game/Place.java

@@ -26,6 +26,7 @@ public class Place  implements Serializable {
         } catch (JSONException e) {
             e.printStackTrace();
         }
+
     }
 
     protected GPSPoint  mLocation;

+ 1 - 0
app/src/main/java/app/brest/utils/app/brest/game/Resource.java

@@ -146,4 +146,5 @@ public class Resource implements Serializable {
     {
         return mTitle;
     }
+
 }

+ 55 - 0
app/src/main/java/app/brest/utils/app/brest/game/Stage.java

@@ -0,0 +1,55 @@
+package app.brest.utils.app.brest.game;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.Serializable;
+
+/**
+ * Created by ptitcois on 27/08/16.
+ */
+public class Stage implements Serializable {
+    public Stage()
+    {
+
+    }
+
+    public Stage(JSONObject obj)
+    {
+        try {
+            mStage=obj.getInt("stage");
+            mResourceName=obj.getString("resource");
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    protected int mStage;
+    protected Resource mResource;
+    protected String mResourceName;
+
+    public int getStage() {
+        return mStage;
+    }
+
+    public void setStage(int mStage) {
+        this.mStage = mStage;
+    }
+
+    public Resource getResource() {
+        return mResource;
+    }
+
+    public void setResource(Resource mResource) {
+        this.mResource = mResource;
+    }
+
+    public String getResourceName() {
+        return mResourceName;
+    }
+
+    public void setResourceName(String mResourceName) {
+        this.mResourceName = mResourceName;
+    }
+}

+ 1 - 1
app/src/main/java/min3d/vos/TextureVo.java

@@ -39,7 +39,7 @@ public class TextureVo
 	public float offsetV = 0;
 	
 	/**
-	 * A list of TexEnvVo's that define how texture is composited in the output.
+	 * A list of TexEnvVo's that define how texture is composited in the output_mkv.
 	 * Normally contains just one element.
 	 */
 	public ArrayList<TexEnvxVo> textureEnvs;