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