Commit d53129e1 authored by rakam's avatar rakam
Browse files

basis for the stats UI

parent eaa98372
...@@ -13,13 +13,16 @@ import android.widget.TextView; ...@@ -13,13 +13,16 @@ import android.widget.TextView;
import com.koushikdutta.async.future.FutureCallback; import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion; import com.koushikdutta.ion.Ion;
import java.util.ArrayList;
import java.util.List;
import fr.istic.masteru.android.R; import fr.istic.masteru.android.R;
import fr.istic.masteru.android.automate.Automate; import fr.istic.masteru.android.automate.Automate;
import fr.istic.masteru.android.automate.AutomateDouble; import fr.istic.masteru.android.automate.AutomateDouble;
import fr.istic.masteru.android.automate.AutomateDoublePro; import fr.istic.masteru.android.automate.AutomateDoublePro;
import fr.istic.masteru.android.automate.Score;
import fr.istic.masteru.android.model.PlayerInfo; import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.utils.Utils; import fr.istic.masteru.android.utils.Utils;
import fr.istic.masteru.android.views.SecureDelayButton;
/** /**
* Activity pour un match double. * Activity pour un match double.
...@@ -140,20 +143,7 @@ public class DoubleMatchActivity extends MatchActivity { ...@@ -140,20 +143,7 @@ public class DoubleMatchActivity extends MatchActivity {
playerRight2Photo.setImageBitmap(result); playerRight2Photo.setImageBitmap(result);
} }
}); });
pointLeftButton.setOnClickListener(new View.OnClickListener() { setStatsButtonsForPlayerALeft();
@Override
public void onClick(View view) {
Score newScore = automate.point(0);
updateUI(newScore);
}
});
pointRightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Score newScore = automate.point(1);
updateUI(newScore);
}
});
} }
@Override @Override
...@@ -203,47 +193,39 @@ public class DoubleMatchActivity extends MatchActivity { ...@@ -203,47 +193,39 @@ public class DoubleMatchActivity extends MatchActivity {
playerLeft2Photo.setImageBitmap(result); playerLeft2Photo.setImageBitmap(result);
} }
}); });
pointLeftButton.setOnClickListener(new View.OnClickListener() { setStatsButtonsForPlayerARight();
@Override
public void onClick(View view) {
Score newScore = automate.point(1);
updateUI(newScore);
}
});
pointRightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Score newScore = automate.point(0);
updateUI(newScore);
}
});
} }
@Override @Override
protected void fadeIn(Runnable onComplete) { protected void fadeIn(Runnable onComplete) {
View.OnClickListener leftClickListener = pointLeftButton.getOnClickListener(); List<View.OnClickListener> leftListeners = new ArrayList<>();
View.OnClickListener rightClickListener = pointRightButton.getOnClickListener(); List<View.OnClickListener> rightListeners = new ArrayList<>();
pointLeftButton.setOnClickListener(null);
pointRightButton.setOnClickListener(null);
Animation appearLeft = AnimationUtils.loadAnimation(DoubleMatchActivity.this, R.anim.appear_left); Animation appearLeft = AnimationUtils.loadAnimation(DoubleMatchActivity.this, R.anim.appear_left);
Animation appearRight = AnimationUtils.loadAnimation(DoubleMatchActivity.this, R.anim.appear_right); Animation appearRight = AnimationUtils.loadAnimation(DoubleMatchActivity.this, R.anim.appear_right);
AnimationSet appearAnimationSet = new AnimationSet(true); AnimationSet appearAnimationSet = new AnimationSet(true);
appearAnimationSet.addAnimation(appearLeft); appearAnimationSet.addAnimation(appearLeft);
appearAnimationSet.addAnimation(appearRight); appearAnimationSet.addAnimation(appearRight);
playerLeft1Photo.setAnimation(appearLeft); playerLeft1Photo.setAnimation(appearLeft);
playerLeft2Photo.setAnimation(appearLeft); playerLeft2Photo.setAnimation(appearLeft);
playerLeft1Name.setAnimation(appearLeft); playerLeft1Name.setAnimation(appearLeft);
playerLeft2Name.setAnimation(appearLeft); playerLeft2Name.setAnimation(appearLeft);
playerLeftNat.setAnimation(appearLeft); playerLeftNat.setAnimation(appearLeft);
pointLeftButton.setAnimation(appearLeft); for (SecureDelayButton button : animatedLeftButtons) {
leftListeners.add(button.getOnClickListener());
button.setOnClickListener(null);
button.setAnimation(appearLeft);
}
playerRight1Photo.setAnimation(appearRight); playerRight1Photo.setAnimation(appearRight);
playerRight2Photo.setAnimation(appearRight); playerRight2Photo.setAnimation(appearRight);
playerRight1Name.setAnimation(appearRight); playerRight1Name.setAnimation(appearRight);
playerRight2Name.setAnimation(appearRight); playerRight2Name.setAnimation(appearRight);
playerRightNat.setAnimation(appearRight); playerRightNat.setAnimation(appearRight);
pointRightButton.setAnimation(appearRight); for (SecureDelayButton button : animatedRightButtons) {
rightListeners.add(button.getOnClickListener());
button.setOnClickListener(null);
button.setAnimation(appearRight);
}
appearAnimationSet.start(); appearAnimationSet.start();
...@@ -252,17 +234,23 @@ public class DoubleMatchActivity extends MatchActivity { ...@@ -252,17 +234,23 @@ public class DoubleMatchActivity extends MatchActivity {
playerLeftNat.setVisibility(View.VISIBLE); playerLeftNat.setVisibility(View.VISIBLE);
playerLeft1Name.setVisibility(View.VISIBLE); playerLeft1Name.setVisibility(View.VISIBLE);
playerLeft2Name.setVisibility(View.VISIBLE); playerLeft2Name.setVisibility(View.VISIBLE);
pointLeftButton.setVisibility(View.VISIBLE); int i = 0;
for (SecureDelayButton button : animatedLeftButtons) {
button.setVisibility(View.VISIBLE);
button.setOnClickListener(leftListeners.get(i++));
}
playerRight1Photo.setVisibility(View.VISIBLE); playerRight1Photo.setVisibility(View.VISIBLE);
playerRight2Photo.setVisibility(View.VISIBLE); playerRight2Photo.setVisibility(View.VISIBLE);
playerRightNat.setVisibility(View.VISIBLE); playerRightNat.setVisibility(View.VISIBLE);
playerRight1Name.setVisibility(View.VISIBLE); playerRight1Name.setVisibility(View.VISIBLE);
playerRight2Name.setVisibility(View.VISIBLE); playerRight2Name.setVisibility(View.VISIBLE);
pointRightButton.setVisibility(View.VISIBLE); i = 0;
for (SecureDelayButton button : animatedRightButtons) {
button.setVisibility(View.VISIBLE);
button.setOnClickListener(rightListeners.get(i++));
}
pointLeftButton.setOnClickListener(leftClickListener);
pointRightButton.setOnClickListener(rightClickListener);
if (onComplete != null) { if (onComplete != null) {
new Handler().postDelayed(onComplete, appearAnimationSet.getDuration()); new Handler().postDelayed(onComplete, appearAnimationSet.getDuration());
} }
...@@ -270,8 +258,10 @@ public class DoubleMatchActivity extends MatchActivity { ...@@ -270,8 +258,10 @@ public class DoubleMatchActivity extends MatchActivity {
@Override @Override
protected void fadeOut(final Runnable onComplete) { protected void fadeOut(final Runnable onComplete) {
pointLeftButton.setOnClickListener(null); for (SecureDelayButton button : animatedLeftButtons)
pointRightButton.setOnClickListener(null); button.setOnClickListener(null);
for (SecureDelayButton button : animatedRightButtons)
button.setOnClickListener(null);
Animation disappearLeft = AnimationUtils.loadAnimation(this, R.anim.disappear_left); Animation disappearLeft = AnimationUtils.loadAnimation(this, R.anim.disappear_left);
Animation disappearRight = AnimationUtils.loadAnimation(this, R.anim.disappear_right); Animation disappearRight = AnimationUtils.loadAnimation(this, R.anim.disappear_right);
final AnimationSet disappearAnimationSet = new AnimationSet(false); final AnimationSet disappearAnimationSet = new AnimationSet(false);
...@@ -289,14 +279,16 @@ public class DoubleMatchActivity extends MatchActivity { ...@@ -289,14 +279,16 @@ public class DoubleMatchActivity extends MatchActivity {
playerLeft1Name.setAnimation(disappearLeft); playerLeft1Name.setAnimation(disappearLeft);
playerLeft2Name.setAnimation(disappearLeft); playerLeft2Name.setAnimation(disappearLeft);
playerLeftNat.setAnimation(disappearLeft); playerLeftNat.setAnimation(disappearLeft);
pointLeftButton.setAnimation(disappearLeft); for (SecureDelayButton button : animatedLeftButtons)
button.setAnimation(disappearLeft);
playerRight1Photo.setAnimation(disappearRight); playerRight1Photo.setAnimation(disappearRight);
playerRight2Photo.setAnimation(disappearRight); playerRight2Photo.setAnimation(disappearRight);
playerRight1Name.setAnimation(disappearRight); playerRight1Name.setAnimation(disappearRight);
playerRight2Name.setAnimation(disappearRight); playerRight2Name.setAnimation(disappearRight);
playerRightNat.setAnimation(disappearRight); playerRightNat.setAnimation(disappearRight);
pointRightButton.setAnimation(disappearRight); for (SecureDelayButton button : animatedRightButtons)
button.setAnimation(disappearRight);
disappearAnimationSet.start(); disappearAnimationSet.start();
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
...@@ -307,14 +299,16 @@ public class DoubleMatchActivity extends MatchActivity { ...@@ -307,14 +299,16 @@ public class DoubleMatchActivity extends MatchActivity {
playerLeftNat.setVisibility(View.INVISIBLE); playerLeftNat.setVisibility(View.INVISIBLE);
playerLeft1Name.setVisibility(View.INVISIBLE); playerLeft1Name.setVisibility(View.INVISIBLE);
playerLeft2Name.setVisibility(View.INVISIBLE); playerLeft2Name.setVisibility(View.INVISIBLE);
pointLeftButton.setVisibility(View.INVISIBLE); for (SecureDelayButton button : animatedLeftButtons)
button.setVisibility(View.INVISIBLE);
playerRight1Photo.setVisibility(View.INVISIBLE); playerRight1Photo.setVisibility(View.INVISIBLE);
playerRight2Photo.setVisibility(View.INVISIBLE); playerRight2Photo.setVisibility(View.INVISIBLE);
playerRightNat.setVisibility(View.INVISIBLE); playerRightNat.setVisibility(View.INVISIBLE);
playerRight1Name.setVisibility(View.INVISIBLE); playerRight1Name.setVisibility(View.INVISIBLE);
playerRight2Name.setVisibility(View.INVISIBLE); playerRight2Name.setVisibility(View.INVISIBLE);
pointRightButton.setVisibility(View.INVISIBLE); for (SecureDelayButton button : animatedRightButtons)
button.setVisibility(View.INVISIBLE);
if (onComplete != null) if (onComplete != null)
onComplete.run(); onComplete.run();
......
...@@ -12,6 +12,9 @@ import android.widget.Button; ...@@ -12,6 +12,9 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import fr.istic.masteru.android.R; import fr.istic.masteru.android.R;
import fr.istic.masteru.android.automate.Automate; import fr.istic.masteru.android.automate.Automate;
import fr.istic.masteru.android.automate.FileManager; import fr.istic.masteru.android.automate.FileManager;
...@@ -19,6 +22,7 @@ import fr.istic.masteru.android.automate.Score; ...@@ -19,6 +22,7 @@ import fr.istic.masteru.android.automate.Score;
import fr.istic.masteru.android.automate.SimplePoint; import fr.istic.masteru.android.automate.SimplePoint;
import fr.istic.masteru.android.listeners.OnSyncFinishListener; import fr.istic.masteru.android.listeners.OnSyncFinishListener;
import fr.istic.masteru.android.model.Match; import fr.istic.masteru.android.model.Match;
import fr.istic.masteru.android.model.Point;
import fr.istic.masteru.android.utils.ScoreSyncManager; import fr.istic.masteru.android.utils.ScoreSyncManager;
import fr.istic.masteru.android.utils.Utils; import fr.istic.masteru.android.utils.Utils;
import fr.istic.masteru.android.views.MatchScoreView; import fr.istic.masteru.android.views.MatchScoreView;
...@@ -43,12 +47,16 @@ public abstract class MatchActivity extends Activity { ...@@ -43,12 +47,16 @@ public abstract class MatchActivity extends Activity {
protected Automate automate; protected Automate automate;
protected boolean isPlayerALeft; protected boolean isPlayerALeft;
protected MatchScoreView matchScoreView; protected MatchScoreView matchScoreView;
protected SecureDelayButton pointLeftButton, pointRightButton;
protected TextView scorePlayerA, scorePlayerB; protected TextView scorePlayerA, scorePlayerB;
protected Match match; protected Match match;
private ImageView serviceLeft, serviceRight; private ImageView serviceLeft, serviceRight;
private Button backButton; private Button backButton;
private TextView gameTime; private TextView gameTime;
protected View leftButtons, rightButtons;
protected SecureDelayButton leftPointButton, rightPointButton;
protected SecureDelayButton leftAceButton, rightAceButton;
protected List<SecureDelayButton> animatedLeftButtons = new ArrayList<>();
protected List<SecureDelayButton> animatedRightButtons = new ArrayList<>();
private ScoreSyncManager syncManager; private ScoreSyncManager syncManager;
...@@ -58,8 +66,19 @@ public abstract class MatchActivity extends Activity { ...@@ -58,8 +66,19 @@ public abstract class MatchActivity extends Activity {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
match = (Match) getIntent().getSerializableExtra(MATCH); match = (Match) getIntent().getSerializableExtra(MATCH);
matchScoreView = (MatchScoreView) findViewById(R.id.matchScoreView); matchScoreView = (MatchScoreView) findViewById(R.id.matchScoreView);
pointLeftButton = (SecureDelayButton) findViewById(R.id.pointLeftButton); leftButtons = findViewById(R.id.leftButtons);
pointRightButton = (SecureDelayButton) findViewById(R.id.pointRightButton); rightButtons = findViewById(R.id.rightButtons);
leftAceButton = (SecureDelayButton) findViewById(R.id.aceLeft);
leftPointButton = (SecureDelayButton) findViewById(R.id.pointLeft);
animatedLeftButtons.add(leftAceButton);
animatedLeftButtons.add(leftPointButton);
rightAceButton = (SecureDelayButton) findViewById(R.id.aceRight);
rightPointButton = (SecureDelayButton) findViewById(R.id.pointRight);
animatedRightButtons.add(rightAceButton);
animatedRightButtons.add(rightPointButton);
serviceLeft = (ImageView) findViewById(R.id.serviceLeft); serviceLeft = (ImageView) findViewById(R.id.serviceLeft);
serviceRight = (ImageView) findViewById(R.id.serviceRight); serviceRight = (ImageView) findViewById(R.id.serviceRight);
gameTime = (TextView) findViewById(R.id.gameTime); gameTime = (TextView) findViewById(R.id.gameTime);
...@@ -96,14 +115,15 @@ public abstract class MatchActivity extends Activity { ...@@ -96,14 +115,15 @@ public abstract class MatchActivity extends Activity {
setPlayerALeft(); setPlayerALeft();
else else
setPlayerARight(); setPlayerARight();
updateScore(initScore); updateScore(new Point(initScore, null));
fadeIn(null); fadeIn(null);
backButton.setOnClickListener(new View.OnClickListener() { backButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Score newScore = automate.back(); Score previousScore = automate.back();
updateUI(newScore); Point previousPoint = new Point(previousScore, null);
updateUI(previousPoint);
} }
}); });
} }
...@@ -178,7 +198,8 @@ public abstract class MatchActivity extends Activity { ...@@ -178,7 +198,8 @@ public abstract class MatchActivity extends Activity {
} }
protected void updateUI(final Score score) { protected void updateUI(final Point point) {
Score score = point.getScore();
if (score.isSideLeftA() != isPlayerALeft && score.getVainqueur() == -1) { if (score.isSideLeftA() != isPlayerALeft && score.getVainqueur() == -1) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Changement de côté") builder.setMessage("Changement de côté")
...@@ -186,7 +207,7 @@ public abstract class MatchActivity extends Activity { ...@@ -186,7 +207,7 @@ public abstract class MatchActivity extends Activity {
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
updateScoreAndSide(score); updateScoreAndSide(point);
} }
}) })
.show(); .show();
...@@ -197,35 +218,36 @@ public abstract class MatchActivity extends Activity { ...@@ -197,35 +218,36 @@ public abstract class MatchActivity extends Activity {
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
updateScore(automate.back()); updateScore(new Point(automate.back(), null));
} }
}); });
builder.setPositiveButton("Confirmer", new DialogInterface.OnClickListener() { builder.setPositiveButton("Confirmer", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
updateScore(score); updateScore(point);
} }
}); });
builder.setCancelable(false); builder.setCancelable(false);
builder.show(); builder.show();
} else { } else {
updateScore(score); updateScore(point);
} }
} }
/** /**
* Update the score and synchonize it with the server. * Update the score and synchonize it with the server.
* *
* @param score * @param point
*/ */
private void updateScore(Score score) { private void updateScore(Point point) {
Score score = point.getScore();
if (score.getPreviousSet() != null) { if (score.getPreviousSet() != null) {
matchScoreView.setScore(score.getPreviousSet().getSetA(), score.getPreviousSet().getSetB(), matchScoreView.setScore(score.getPreviousSet().getSetA(), score.getPreviousSet().getSetB(),
score.getNumSet() - 1, 0, 0); score.getNumSet() - 1, 0, 0);
} }
if (score.getVainqueur() != -1) { if (score.getVainqueur() != -1) {
pointLeftButton.setVisibility(View.GONE); leftButtons.setVisibility(View.GONE);
pointRightButton.setVisibility(View.GONE); rightButtons.setVisibility(View.GONE);
final ProgressDialog dialog = new ProgressDialog(this); final ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Match terminé, Synchronisation en cours...\nVeuillez patienter. "); dialog.setMessage("Match terminé, Synchronisation en cours...\nVeuillez patienter. ");
...@@ -251,8 +273,8 @@ public abstract class MatchActivity extends Activity { ...@@ -251,8 +273,8 @@ public abstract class MatchActivity extends Activity {
} }
}); });
} else { } else {
pointLeftButton.setVisibility(View.VISIBLE); leftButtons.setVisibility(View.VISIBLE);
pointRightButton.setVisibility(View.VISIBLE); rightButtons.setVisibility(View.VISIBLE);
String strScoreA = score.getScoreA() == SimplePoint.AV ? "AV" : String.valueOf(score.getScoreA()); String strScoreA = score.getScoreA() == SimplePoint.AV ? "AV" : String.valueOf(score.getScoreA());
String strScoreB = score.getScoreB() == SimplePoint.AV ? "AV" : String.valueOf(score.getScoreB()); String strScoreB = score.getScoreB() == SimplePoint.AV ? "AV" : String.valueOf(score.getScoreB());
scorePlayerA.setText(strScoreA); scorePlayerA.setText(strScoreA);
...@@ -267,18 +289,19 @@ public abstract class MatchActivity extends Activity { ...@@ -267,18 +289,19 @@ public abstract class MatchActivity extends Activity {
/** /**
* Makes an update between #fadeOut and #fadeIn * Makes an update between #fadeOut and #fadeIn
* *
* @param score * @param point
*/ */
private void updateScoreAndSide(final Score score) { private void updateScoreAndSide(final Point point) {
fadeOut(new Runnable() { fadeOut(new Runnable() {
@Override @Override
public void run() { public void run() {
Score score = point.getScore();
if (score.isSideLeftA()) { if (score.isSideLeftA()) {
setPlayerALeft(); setPlayerALeft();
} else { } else {
setPlayerARight(); setPlayerARight();
} }
updateScore(score); updateScore(point);
fadeIn(null); fadeIn(null);
} }
...@@ -311,6 +334,62 @@ public abstract class MatchActivity extends Activity { ...@@ -311,6 +334,62 @@ public abstract class MatchActivity extends Activity {
} }
} }
protected void setStatsButtonsForPlayerALeft() {
leftPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(0), null));
}
});
leftAceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(0), "ACE"));
}
});
rightPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(1), null));
}
});
rightAceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(1), "ACE"));
}
});
}
protected void setStatsButtonsForPlayerARight() {
leftPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(1), null));
}
});
leftAceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(1), "ACE"));
}
});
rightPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(0), null));
}
});
rightAceButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(new Point(automate.point(0), "ACE"));
}
});
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// Do nothing when back button is pressed // Do nothing when back button is pressed
......
...@@ -2,11 +2,6 @@ package fr.istic.masteru.android.activities; ...@@ -2,11 +2,6 @@ package fr.istic.masteru.android.activities;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;