|
@@ -1,29 +1,28 @@
|
|
package app.mar.activities;
|
|
package app.mar.activities;
|
|
|
|
|
|
|
|
+import android.app.Activity;
|
|
import android.app.Fragment;
|
|
import android.app.Fragment;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
-import android.support.annotation.CallSuper;
|
|
|
|
-import android.util.Log;
|
|
|
|
import android.util.TypedValue;
|
|
import android.util.TypedValue;
|
|
import android.view.KeyEvent;
|
|
import android.view.KeyEvent;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
-import android.widget.Button;
|
|
|
|
-import android.widget.EditText;
|
|
|
|
-import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Timer;
|
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
-import app.mar.utils.game.Game;
|
|
|
|
-import app.mar.utils.game.challenges.Challenge;
|
|
|
|
-import app.mar.utils.game.challenges.GeoIndice;
|
|
|
|
-import app.mar.utils.game.challenges.Indice;
|
|
|
|
-import app.mar.utils.game.challenges.TextIndice;
|
|
|
|
|
|
+import app.mar.game.Area;
|
|
|
|
+import app.mar.game.challenges.Challenge;
|
|
|
|
+import app.mar.game.challenges.GeoIndice;
|
|
|
|
+import app.mar.game.challenges.IGeoTreasure;
|
|
|
|
+import app.mar.game.challenges.Indice;
|
|
|
|
+import app.mar.game.challenges.TextIndice;
|
|
|
|
|
|
public abstract class ChallengeFragment extends Fragment {
|
|
public abstract class ChallengeFragment extends Fragment {
|
|
public abstract boolean check();
|
|
public abstract boolean check();
|
|
@@ -35,8 +34,15 @@ public abstract class ChallengeFragment extends Fragment {
|
|
protected LinearLayout mUITextIndices;
|
|
protected LinearLayout mUITextIndices;
|
|
protected TextView mUIGeoIndice;
|
|
protected TextView mUIGeoIndice;
|
|
protected LinearLayout mUIGlobalIndice;
|
|
protected LinearLayout mUIGlobalIndice;
|
|
|
|
+ protected Challenge mChallenge;
|
|
|
|
|
|
- protected Challenge mChallenge;
|
|
|
|
|
|
+ protected Timer mTimer;
|
|
|
|
+
|
|
|
|
+ private Runnable mTimerTick = new Runnable() {
|
|
|
|
+ public void run() {
|
|
|
|
+ onGeoUpdateTimer();
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
public void resetUi()
|
|
public void resetUi()
|
|
@@ -59,7 +65,7 @@ public abstract class ChallengeFragment extends Fragment {
|
|
private void updateIndices()
|
|
private void updateIndices()
|
|
{
|
|
{
|
|
ArrayList<Indice> inds = mChallenge.getIndices();
|
|
ArrayList<Indice> inds = mChallenge.getIndices();
|
|
- if(mUIGlobalIndice!=null && inds.size()>0) mUIGlobalIndice.setVisibility(View.VISIBLE);
|
|
|
|
|
|
+ if(inds.size()>0) mUIGlobalIndice.setVisibility(View.VISIBLE);
|
|
for(int i=0; i<inds.size(); i++)
|
|
for(int i=0; i<inds.size(); i++)
|
|
{
|
|
{
|
|
Indice ind = inds.get(i);
|
|
Indice ind = inds.get(i);
|
|
@@ -78,6 +84,7 @@ public abstract class ChallengeFragment extends Fragment {
|
|
public Indice showIndice()
|
|
public Indice showIndice()
|
|
{
|
|
{
|
|
Indice ind = mChallenge.nextIndice();
|
|
Indice ind = mChallenge.nextIndice();
|
|
|
|
+ int indInd = mChallenge.getIndiceIndex();
|
|
if(ind!=null)
|
|
if(ind!=null)
|
|
{
|
|
{
|
|
if(getActivity() instanceof ChallengeDriver)
|
|
if(getActivity() instanceof ChallengeDriver)
|
|
@@ -86,7 +93,9 @@ public abstract class ChallengeFragment extends Fragment {
|
|
{
|
|
{
|
|
if(mUIGeoIndice!=null)
|
|
if(mUIGeoIndice!=null)
|
|
{
|
|
{
|
|
|
|
+ mUIGlobalIndice.setVisibility(View.VISIBLE);
|
|
mUIGeoIndice.setVisibility(View.VISIBLE);
|
|
mUIGeoIndice.setVisibility(View.VISIBLE);
|
|
|
|
+ startGeoUpdateTimer();
|
|
ind.discover();
|
|
ind.discover();
|
|
return ind;
|
|
return ind;
|
|
}
|
|
}
|
|
@@ -95,9 +104,11 @@ public abstract class ChallengeFragment extends Fragment {
|
|
{
|
|
{
|
|
if(mUITextIndices!=null)
|
|
if(mUITextIndices!=null)
|
|
{
|
|
{
|
|
|
|
+ mUIGlobalIndice.setVisibility(View.VISIBLE);
|
|
TextView tv = new TextView(getActivity());
|
|
TextView tv = new TextView(getActivity());
|
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
|
- tv.setText(((TextIndice) ind).getText());
|
|
|
|
|
|
+ tv.setText(" Indice "+(indInd+1)+" : "+((TextIndice) ind).getText());
|
|
|
|
+ mUITextIndices.addView(tv);
|
|
ind.discover();
|
|
ind.discover();
|
|
return ind;
|
|
return ind;
|
|
}
|
|
}
|
|
@@ -107,36 +118,59 @@ public abstract class ChallengeFragment extends Fragment {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
- Log.e("______", "Calling onCreate ______________ : "+getClass().toString());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,int res) {
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,int res) {
|
|
// Inflate the layout for this fragment
|
|
// Inflate the layout for this fragment
|
|
View v = inflater.inflate(res, container, false);
|
|
View v = inflater.inflate(res, container, false);
|
|
- Log.e("______________", "super.onCreateView: "+mUIGlobalIndice);
|
|
|
|
mUITextIndices= (LinearLayout) v.findViewById(R.id.ll_textIndices);
|
|
mUITextIndices= (LinearLayout) v.findViewById(R.id.ll_textIndices);
|
|
mUIGeoIndice= (TextView) v.findViewById(R.id.tv_geoIndice);
|
|
mUIGeoIndice= (TextView) v.findViewById(R.id.tv_geoIndice);
|
|
mUIGlobalIndice = (LinearLayout) v.findViewById(R.id.ll_rootIndices);
|
|
mUIGlobalIndice = (LinearLayout) v.findViewById(R.id.ll_rootIndices);
|
|
- Log.e("______________", "Ici: "+mUIGlobalIndice);
|
|
|
|
- Log.e("#########", "setFragment Commit : false");
|
|
|
|
return v;
|
|
return v;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initChallenge(Challenge c)
|
|
public void initChallenge(Challenge c)
|
|
{
|
|
{
|
|
- Log.e("#########", "initChallenges");
|
|
|
|
mChallenge=c;
|
|
mChallenge=c;
|
|
- updateIndices();
|
|
|
|
|
|
+ resetUi();
|
|
onInitChallenge(c);
|
|
onInitChallenge(c);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ protected void ready()
|
|
|
|
+ {
|
|
|
|
+ Activity act = getActivity();
|
|
|
|
+ if(act instanceof ChallengeDriver)
|
|
|
|
+ {
|
|
|
|
+ ChallengeDriver cd = (ChallengeDriver)act;
|
|
|
|
+ cd.onReady();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
public void onStart() {
|
|
public void onStart() {
|
|
super.onStart();
|
|
super.onStart();
|
|
- Log.e("---------", "OnStart !");
|
|
|
|
|
|
+ ready();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onStop() {
|
|
|
|
+ super.onStop();
|
|
|
|
+ stopGeoUpdateTimer();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void onResume() {
|
|
|
|
+ super.onResume();
|
|
|
|
+ updateIndices();
|
|
}
|
|
}
|
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
@@ -145,16 +179,7 @@ public abstract class ChallengeFragment extends Fragment {
|
|
|
|
|
|
private OnFragmentInteractionListener mListener;
|
|
private OnFragmentInteractionListener mListener;
|
|
|
|
|
|
- /**
|
|
|
|
- * This interface must be implemented by activities that contain this
|
|
|
|
- * fragment to allow an interaction in this fragment to be communicated
|
|
|
|
- * to the activity and potentially other fragments contained in that
|
|
|
|
- * activity.
|
|
|
|
- * <p>
|
|
|
|
- * See the Android Training lesson <a href=
|
|
|
|
- * "http://developer.android.com/training/basics/fragments/communicating.html"
|
|
|
|
- * >Communicating with Other Fragments</a> for more information.
|
|
|
|
- */
|
|
|
|
|
|
+
|
|
public interface OnFragmentInteractionListener {
|
|
public interface OnFragmentInteractionListener {
|
|
// TODO: Update argument type and name
|
|
// TODO: Update argument type and name
|
|
void onFragmentInteraction(Uri uri);
|
|
void onFragmentInteraction(Uri uri);
|
|
@@ -177,7 +202,6 @@ public abstract class ChallengeFragment extends Fragment {
|
|
+ " must implement OnFragmentInteractionListener");
|
|
+ " must implement OnFragmentInteractionListener");
|
|
}
|
|
}
|
|
|
|
|
|
- Log.e("______", "Calling class ______________ : "+getClass().toString());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -189,4 +213,51 @@ public abstract class ChallengeFragment extends Fragment {
|
|
public Challenge getChallenge() {
|
|
public Challenge getChallenge() {
|
|
return mChallenge;
|
|
return mChallenge;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ // Timer géolocalisation
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ protected void onGeoUpdateTimer()
|
|
|
|
+ {
|
|
|
|
+ IGeoTreasure gt = null;
|
|
|
|
+ ChallengeDriver cd = (ChallengeDriver) getActivity();
|
|
|
|
+ if(!(mChallenge instanceof IGeoTreasure))
|
|
|
|
+ throw new RuntimeException("Erreur l'indice géographique est demandé, mais le challenge n'est pas compatible");
|
|
|
|
+ gt=(IGeoTreasure) mChallenge;
|
|
|
|
+
|
|
|
|
+ Area a = gt.getArea();
|
|
|
|
+ mUIGeoIndice.setText("Distance "+(int)cd.getDistanceWith(a)+" m");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void stopGeoUpdateTimer()
|
|
|
|
+ {
|
|
|
|
+ mTimer.cancel();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void startGeoUpdateTimer()
|
|
|
|
+ {
|
|
|
|
+ mTimer = new Timer();
|
|
|
|
+ mTimer.schedule(new TimerTask() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ timerCallback();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }, 0, 1000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void timerCallback()
|
|
|
|
+ {
|
|
|
|
+ getActivity().runOnUiThread(mTimerTick);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ // Fin de Timer géolacalisation
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|