Commit 9ffacf2a authored by rakam's avatar rakam
Browse files

Side Change on SingleMatchActivity

parent 59183f73
package fr.istic.masteru.android.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.koushikdutta.async.future.FutureCallback;
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.automate.SimplePoint;
import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.utils.ScoreSyncManager;
import fr.istic.masteru.android.views.MatchScoreView;
......@@ -22,44 +33,48 @@ public class SingleMatchActivity extends Activity {
// todo get it from the MatchList
private int idMatch = 25;
private TextView scoreA, scoreB;
private Button pointAButton, pointBButton;
private ImageView serviceA, serviceB;
private TextView playerLeftName, playerRightName;
private TextView playerLeftNat, playerRightNat;
private ImageView playerLeftPhoto, playerRightPhoto;
private TextView scorePlayerA, scorePlayerB;
private Button pointLeftButton, pointRightButton;
private ImageView serviceLeft, serviceRight;
private MatchScoreView matchScoreView;
private Button backButton;
private TextView gameTime;
private Automate automate = new AutomateSimple(0, false);
private PlayerInfo playerInfoA;
private PlayerInfo playerInfoB;
private boolean isPlayerALeft;
private Automate automate;
private ScoreSyncManager syncManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
automate = new AutomateSimple(0, true);
syncManager = new ScoreSyncManager(this, idMatch);
playerInfoA = new PlayerInfo("Player A", "Nat A", "http://37.187.238.24/photos/federer.jpg");
playerInfoB = new PlayerInfo("Player B", "Nat B", "http://37.187.238.24/photos/monfils.jpg");
setContentView(R.layout.single_match_activity);
scoreA = (TextView) findViewById(R.id.scoreA);
scoreB = (TextView) findViewById(R.id.scoreB);
pointAButton = (Button) findViewById(R.id.pointAButton);
pointBButton = (Button) findViewById(R.id.pointBButton);
serviceA = (ImageView) findViewById(R.id.serviceA);
serviceB = (ImageView) findViewById(R.id.serviceB);
playerLeftName = (TextView) findViewById(R.id.playerLeftNameTV);
playerRightName = (TextView) findViewById(R.id.playerRightNameTV);
playerLeftNat = (TextView) findViewById(R.id.playerLeftNatTV);
playerRightNat = (TextView) findViewById(R.id.playerRightNatTV);
playerLeftPhoto = (ImageView) findViewById(R.id.playerLeftPhoto);
playerRightPhoto = (ImageView) findViewById(R.id.playerRightPhoto);
pointLeftButton = (Button) findViewById(R.id.pointLeftButton);
pointRightButton = (Button) findViewById(R.id.pointRightButton);
serviceLeft = (ImageView) findViewById(R.id.serviceLeft);
serviceRight = (ImageView) findViewById(R.id.serviceRight);
matchScoreView = (MatchScoreView) findViewById(R.id.matchScoreView);
backButton = (Button) findViewById(R.id.back);
gameTime = (TextView) findViewById(R.id.gameTime);
pointAButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Score newScore = automate.point(0);
updateScore(newScore);
}
});
pointBButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Score newScore = automate.point(1);
updateScore(newScore);
}
});
Score initScore = automate.getPoint(0);
setPlayerSide(initScore);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......@@ -67,7 +82,26 @@ public class SingleMatchActivity extends Activity {
updateScore(newScore);
}
});
syncManager = new ScoreSyncManager(this, idMatch);
}
private void updateUI(final Score score) {
if (score.isSideLeftA() != isPlayerALeft) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Changement de côté")
.setMessage(playerInfoA.getName() + " à " + (score.isSideLeftA() ? "gauche" : "droite"))
.setCancelable(false)
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
setPlayerSide(score);
}
})
.show();
} else {
updateScore(score);
}
}
private void updateScore(Score score) {
......@@ -78,15 +112,15 @@ public class SingleMatchActivity extends Activity {
}
if (score.getVainqueur() != -1) {
Toast.makeText(this, "Match terminé, vainqueur:" + score.getVainqueur(), Toast.LENGTH_SHORT).show();
pointAButton.setVisibility(View.GONE);
pointBButton.setVisibility(View.GONE);
pointLeftButton.setVisibility(View.GONE);
pointRightButton.setVisibility(View.GONE);
} else {
pointAButton.setVisibility(View.VISIBLE);
pointBButton.setVisibility(View.VISIBLE);
pointLeftButton.setVisibility(View.VISIBLE);
pointRightButton.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());
scoreA.setText(strScoreA);
scoreB.setText(strScoreB);
scorePlayerA.setText(strScoreA);
scorePlayerB.setText(strScoreB);
setService(score.getService());
matchScoreView.setScore(score.getGamesA(), score.getGamesB(), score.getNumSet(), score.getScoreA(), score.getScoreB());
}
......@@ -94,13 +128,188 @@ public class SingleMatchActivity extends Activity {
syncManager.addScore(score);
}
private void setPlayerSide(final Score score) {
Animation disappearLeft = AnimationUtils.loadAnimation(this, R.anim.disappear_left);
Animation disappearRight = AnimationUtils.loadAnimation(this, R.anim.disappear_right);
final AnimationSet disappearAnimationSet = new AnimationSet(false);
disappearAnimationSet.addAnimation(disappearLeft);
disappearAnimationSet.addAnimation(disappearRight);
disappearAnimationSet.setRepeatCount(0);
playerLeftName.clearAnimation();
playerRightName.clearAnimation();
playerLeftPhoto.setAnimation(disappearLeft);
playerLeftName.setAnimation(disappearLeft);
playerLeftNat.setAnimation(disappearLeft);
pointLeftButton.setAnimation(disappearLeft);
playerRightPhoto.setAnimation(disappearRight);
playerRightName.setAnimation(disappearRight);
playerRightNat.setAnimation(disappearRight);
pointRightButton.setAnimation(disappearRight);
disappearAnimationSet.start();
// Dirty hack beacause of the buggy AnimationListener#onAnimationEnd
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
playerLeftPhoto.setVisibility(View.INVISIBLE);
playerLeftNat.setVisibility(View.INVISIBLE);
playerLeftName.setVisibility(View.INVISIBLE);
pointLeftButton.setVisibility(View.INVISIBLE);
playerRightPhoto.setVisibility(View.INVISIBLE);
playerRightNat.setVisibility(View.INVISIBLE);
playerRightName.setVisibility(View.INVISIBLE);
pointRightButton.setVisibility(View.INVISIBLE);
isPlayerALeft = score.isSideLeftA();
if (isPlayerALeft) {
scorePlayerA = (TextView) findViewById(R.id.scoreLeft);
scorePlayerB = (TextView) findViewById(R.id.scoreRight);
playerLeftName.setText(playerInfoA.getName());
playerRightName.setText(playerInfoB.getName());
playerLeftNat.setText(playerInfoA.getNationality());
playerRightNat.setText(playerInfoB.getNationality());
if (playerInfoA.getPhoto() == null) {
Ion.with(SingleMatchActivity.this).load(playerInfoA.getPhotoUrl()).asBitmap().setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
playerInfoA.setPhoto(result);
playerLeftPhoto.setImageBitmap(playerInfoA.getPhoto());
}
});
}
if (playerInfoB.getPhoto() == null) {
Ion.with(SingleMatchActivity.this).load(playerInfoB.getPhotoUrl()).asBitmap().setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
playerInfoB.setPhoto(result);
playerRightPhoto.setImageBitmap(playerInfoA.getPhoto());
}
});
}
playerLeftPhoto.setImageBitmap(playerInfoA.getPhoto());
playerRightPhoto.setImageBitmap(playerInfoB.getPhoto());
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);
}
});
} else {
//Score
scorePlayerA = (TextView) findViewById(R.id.scoreRight);
scorePlayerB = (TextView) findViewById(R.id.scoreLeft);
//Names
playerLeftName.setText(playerInfoB.getName());
playerRightName.setText(playerInfoA.getName());
//Nat
playerLeftNat.setText(playerInfoB.getNationality());
playerRightNat.setText(playerInfoA.getNationality());
//Photos
if (playerInfoA.getPhoto() == null) {
Ion.with(SingleMatchActivity.this).load(playerInfoA.getPhotoUrl())
.asBitmap()
.setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
playerInfoA.setPhoto(result);
playerRightPhoto.setImageBitmap(playerInfoA.getPhoto());
}
});
}
if (playerInfoB.getPhoto() == null) {
Ion.with(SingleMatchActivity.this).load(playerInfoB.getPhotoUrl())
.asBitmap()
.setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
playerInfoB.setPhoto(result);
playerLeftPhoto.setImageBitmap(playerInfoA.getPhoto());
}
});
}
playerLeftPhoto.setImageBitmap(playerInfoB.getPhoto());
playerRightPhoto.setImageBitmap(playerInfoA.getPhoto());
//Buttons
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);
}
});
}
updateScore(score);
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);
}
}, disappearAnimationSet.getDuration());
}
private void setService(int player) {
if (player == 0) {
serviceA.setVisibility(View.VISIBLE);
serviceB.setVisibility(View.INVISIBLE);
} else if (player == 1) {
serviceA.setVisibility(View.INVISIBLE);
serviceB.setVisibility(View.VISIBLE);
if (isPlayerALeft) {
if (player == 0) {
serviceLeft.setVisibility(View.VISIBLE);
serviceRight.setVisibility(View.INVISIBLE);
} else if (player == 1) {
serviceLeft.setVisibility(View.INVISIBLE);
serviceRight.setVisibility(View.VISIBLE);
}
} else {
if (player == 1) {
serviceLeft.setVisibility(View.VISIBLE);
serviceRight.setVisibility(View.INVISIBLE);
} else if (player == 0) {
serviceLeft.setVisibility(View.INVISIBLE);
serviceRight.setVisibility(View.VISIBLE);
}
}
}
}
......@@ -51,22 +51,22 @@ public class DoublePoint {
/* Init service B avec A à gauche*/
case -11:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, true,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, true, false, false, 1);
break;
/* Init service A avec A à gauche*/
case -10:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, true,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, true, false, false, 1);
break;
/* Init service B avec A à droite*/
case -1:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, false,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, false, false, false, 1);
break;
/* Init service A avec A à droite*/
case 0:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, false,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, false, false, false, 1);
break;
/* A marque 15 point */
case 1:
......@@ -260,7 +260,7 @@ public class DoublePoint {
score.setScoreA(a);
}
/* Calcul pour déterminer le serveur */
score.setTieService(score.getTieService()-1);
score.setTieService(score.getTieService() - 1);
if (score.getTieService() == 0) {
score.setTieService(2);
score.setService((score.getService() + 1) % 2);
......@@ -327,7 +327,7 @@ public class DoublePoint {
score.setScoreB(b);
}
/* Calcul pour déterminer le serveur */
score.setTieService(score.getTieService()-1);
score.setTieService(score.getTieService() - 1);
if (score.getTieService() == 0) {
score.setTieService(2);
score.setService((score.getService() + 1) % 2);
......@@ -388,7 +388,7 @@ public class DoublePoint {
score.setScoreA(a);
}
/* Calcul pour déterminer le serveur */
score.setTieService(score.getTieService()-1);
score.setTieService(score.getTieService() - 1);
if (score.getTieService() == 0) {
score.setTieService(2);
score.setService((score.getService() + 1) % 2);
......@@ -449,7 +449,7 @@ public class DoublePoint {
score.setScoreB(b);
}
/* Calcul pour déterminer le serveur */
score.setTieService(score.getTieService()-1);
score.setTieService(score.getTieService() - 1);
if (score.getTieService() == 0) {
score.setTieService(2);
score.setService((score.getService() + 1) % 2);
......
......@@ -52,22 +52,22 @@ public class DoubleProPoint {
/* Init service B avec A à gauche*/
case -11:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, true,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, true, false, false, 1);
break;
/* Init service A avec A à gauche*/
case -10:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, true,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, true, false, false, 1);
break;
/* Init service B avec A à droite*/
case -1:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, false,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 1, null, -1, false, false, false, 1);
break;
/* Init service A avec A à droite*/
case 0:
/* Init score, tie-break & tie-service */
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, false,false,false,1);
score = new InfoScore(0, 0, 0, 0, 0, 0, 0, 0, 0, null, -1, false, false, false, 1);
break;
/* A marque 15 point */
case 1:
......@@ -243,7 +243,7 @@ public class DoubleProPoint {
score.setScoreA(a);
}
/* Calcul pour déterminer le serveur */
score.setTieService(score.getTieService()-1);
score.setTieService(score.getTieService() - 1);
if (score.getTieService() == 0) {
score.setTieService(2);
score.setService((score.getService() + 1) % 2);
......@@ -305,7 +305,7 @@ public class DoubleProPoint {
score.setScoreB(b);
}
/* Calcul pour déterminer le serveur */
score.setTieService(score.getTieService()-1);
score.setTieService(score.getTieService() - 1);
if (score.getTieService() == 0) {
score.setTieService(2);
score.setService((score.getService() + 1) % 2);
......
......@@ -33,7 +33,7 @@ public class InfoScore {
this.service = 0;
this.previousSet = null;
this.vainqueur = -1;
this.sideLeftA=false;
this.sideLeftA = false;
}
public InfoScore(int id, int numSet, int setA, int setB, int gamesA, int gamesB, int scoreA, int scoreB, int service, PreviousSet previousSet, int vainqueur, boolean sideLeftA, boolean tieBreak, boolean superTieBreak, int tieService) {
......@@ -48,10 +48,10 @@ public class InfoScore {
this.service = service;
this.previousSet = previousSet;
this.vainqueur = vainqueur;
this.sideLeftA=sideLeftA;
this.tieBreak=tieBreak;
this.superTieBreak=superTieBreak;
this.tieService=tieService;
this.sideLeftA = sideLeftA;
this.tieBreak = tieBreak;
this.superTieBreak = superTieBreak;
this.tieService = tieService;
}
public int getVainqueur() {
......@@ -66,6 +66,10 @@ public class InfoScore {
return sideLeftA;
}
public void setSideLeftA(boolean sideLeftA) {
this.sideLeftA = sideLeftA;
}
public void setSideA(boolean sideLeftA) {
this.sideLeftA = sideLeftA;
}
......@@ -188,6 +192,38 @@ public class InfoScore {
this.service = service;
}
public InfoScore copy() {
return new InfoScore(id, numSet, setA, setB, gamesA, gamesB, scoreA, scoreB, service, previousSet, vainqueur, sideLeftA, tieBreak, superTieBreak, tieService);
}
public Score getScore() {
return new Score(id, numSet, setA, setB, gamesA, gamesB, scoreA, scoreB, service, previousSet, vainqueur, sideLeftA);
}
public boolean isTieBreak() {
return tieBreak;
}
public void setTieBreak(boolean tieBreak) {
this.tieBreak = tieBreak;
}
public boolean isSuperTieBreak() {
return superTieBreak;
}
public void setSuperTieBreak(boolean superTieBreak) {
this.superTieBreak = superTieBreak;
}
public int getTieService() {
return tieService;
}
public void setTieService(int tieService) {
this.tieService = tieService;
}
public static class PreviousSet {
private int setA;
private int setB;
......@@ -221,40 +257,4 @@ public class InfoScore {
'}';
}
}
public InfoScore copy() {
return new InfoScore(id, numSet, setA, setB, gamesA, gamesB, scoreA, scoreB, service, previousSet, vainqueur, sideLeftA, tieBreak, superTieBreak, tieService);
}
public void setSideLeftA(boolean sideLeftA) {
this.sideLeftA = sideLeftA;
}
public Score getScore() {
return new Score(id, numSet, setA, setB, gamesA, gamesB, scoreA, scoreB, service, previousSet, vainqueur, sideLeftA);
}
public boolean isTieBreak() {
return tieBreak;
}
public void setTieBreak(boolean tieBreak) {
this.tieBreak = tieBreak;
}
public boolean isSuperTieBreak() {
return superTieBreak;
}
public void setSuperTieBreak(boolean superTieBreak) {
this.superTieBreak = superTieBreak;
}
public int getTieService() {