Commit 23f9c3ba authored by rakam's avatar rakam

DoubleFaultButton

parent 84e911c3
......@@ -81,10 +81,10 @@ public class HomeActivity extends Activity {
String isoA = jsonMatch.get("Team_A").getAsString();
String isoB = jsonMatch.get("Team_B").getAsString();
String teamNameA = jsonMatch.get("NameTeam_A").getAsString();
String teamNameB = jsonMatch.get("NameTeam_B").getAsString();
String flagA = jsonMatch.get("UrlTeam_A").getAsString();
String flagB = jsonMatch.get("UrlTeam_B").getAsString();
String teamNameA = Utils.getStringFromJson(jsonMatch, "NameTeam_A");
String teamNameB = Utils.getStringFromJson(jsonMatch, "NameTeam_B");
String flagA = Utils.getStringFromJson(jsonMatch, "UrlTeam_A");
String flagB = Utils.getStringFromJson(jsonMatch, "UrlTeam_B");
TeamInfo teamA = new TeamInfo(isoA, teamNameA, flagA);
TeamInfo teamB = new TeamInfo(isoB, teamNameB, flagB);
......
......@@ -29,6 +29,7 @@ import fr.istic.masteru.android.automate.Stats;
import fr.istic.masteru.android.listeners.OnSyncFinishListener;
import fr.istic.masteru.android.model.MatchInfo;
import fr.istic.masteru.android.model.PlayerInfo;
import fr.istic.masteru.android.utils.Constants;
import fr.istic.masteru.android.utils.ScoreSyncManager;
import fr.istic.masteru.android.utils.Utils;
import fr.istic.masteru.android.views.MatchScoreView;
......@@ -59,6 +60,8 @@ public abstract class MatchActivity extends Activity {
private Button backButton;
private TextView gameTime;
private Point currentPoint;
protected TextView playerLeft1Name, playerRight1Name;
protected TextView playerLeft2Name, playerRight2Name;
protected TextView playerLeftNat, playerRightNat;
......@@ -71,6 +74,7 @@ public abstract class MatchActivity extends Activity {
protected Button fsfButton;
protected View leftButtons, rightButtons;
protected SecureDelayButton leftPointButton, rightPointButton; // "Normal" point are considered as Forced Error
protected SecureDelayButton leftDoubleFaultButton, rightDoubleFaultButton;
protected SecureDelayButton leftAceButton, rightAceButton;
protected SecureDelayButton leftWinnerServeButton, rightWinnerServeButton;
protected SecureDelayButton leftWinnerPointButton, rightWinnerPointButton;
......@@ -116,22 +120,26 @@ public abstract class MatchActivity extends Activity {
rightButtons = findViewById(R.id.rightButtons);
leftAceButton = (SecureDelayButton) findViewById(R.id.aceLeft);
leftDoubleFaultButton = (SecureDelayButton) findViewById(R.id.doubleFaultLeft);
leftPointButton = (SecureDelayButton) findViewById(R.id.pointLeft);
leftWinnerServeButton = (SecureDelayButton) findViewById(R.id.winnerServeLeft);
leftWinnerPointButton = (SecureDelayButton) findViewById(R.id.winnerPointLeft);
leftUnforcedErrorButton = (SecureDelayButton) findViewById(R.id.unforcedErrorLeft);
animatedLeftButtons.add(leftAceButton);
animatedLeftButtons.add(leftDoubleFaultButton);
animatedLeftButtons.add(leftPointButton);
animatedLeftButtons.add(leftWinnerServeButton);
animatedLeftButtons.add(leftWinnerPointButton);
animatedLeftButtons.add(leftUnforcedErrorButton);
rightAceButton = (SecureDelayButton) findViewById(R.id.aceRight);
rightDoubleFaultButton = (SecureDelayButton) findViewById(R.id.doubleFaultRight);
rightPointButton = (SecureDelayButton) findViewById(R.id.pointRight);
rightWinnerServeButton = (SecureDelayButton) findViewById(R.id.winnerServeRight);
rightWinnerPointButton = (SecureDelayButton) findViewById(R.id.winnerPointRight);
rightUnforcedErrorButton = (SecureDelayButton) findViewById(R.id.unforcedErrorRight);
animatedRightButtons.add(rightAceButton);
animatedRightButtons.add(rightDoubleFaultButton);
animatedRightButtons.add(rightPointButton);
animatedRightButtons.add(rightWinnerServeButton);
animatedRightButtons.add(rightWinnerPointButton);
......@@ -141,6 +149,18 @@ public abstract class MatchActivity extends Activity {
@Override
public void onClick(View v) {
fsfButton.setSelected(!fsfButton.isSelected());
if (fsfButton.isSelected() && currentPoint != null) {
int serv = currentPoint.getScore().getService();
if (serv == Constants.PLAYER_A && isPlayerALeft ||
serv == Constants.PLAYER_B && !isPlayerALeft) {
rightDoubleFaultButton.setEnabled(true);
} else {
leftDoubleFaultButton.setEnabled(true);
}
} else if (!fsfButton.isSelected()) {
leftDoubleFaultButton.setEnabled(false);
rightDoubleFaultButton.setEnabled(false);
}
}
});
......@@ -266,9 +286,7 @@ public abstract class MatchActivity extends Activity {
}
}
protected void updateUI(final Point point, final boolean sync) {
fsfButton.setSelected(false);
Score score = point.getScore();
if (score.isSideLeftA() != isPlayerALeft && score.getVainqueur() == -1) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
......@@ -302,6 +320,9 @@ public abstract class MatchActivity extends Activity {
} else {
updateScore(point, sync);
}
fsfButton.setSelected(false);
leftDoubleFaultButton.setEnabled(false);
rightDoubleFaultButton.setEnabled(false);
}
/**
......@@ -310,6 +331,7 @@ public abstract class MatchActivity extends Activity {
* @param point
*/
private void updateScore(Point point, boolean sync) {
currentPoint = point;
Score score = point.getScore();
if (score.getPreviousSet() != null) {
matchScoreView.setScore(score.getPreviousSet().getSetA(), score.getPreviousSet().getSetB(),
......@@ -426,6 +448,12 @@ public abstract class MatchActivity extends Activity {
updateUI(automate.point(new Stats(Stats.Type.ACE, fsfButton.isSelected(), leftPlayer)), true);
}
});
leftDoubleFaultButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(automate.point(new Stats(Stats.Type.DF, true, leftPlayer)), true);
}
});
leftWinnerServeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -457,6 +485,12 @@ public abstract class MatchActivity extends Activity {
updateUI(automate.point(new Stats(Stats.Type.ACE, fsfButton.isSelected(), rightPlayer)), true);
}
});
rightDoubleFaultButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI(automate.point(new Stats(Stats.Type.DF, true, rightPlayer)), true);
}
});
rightWinnerServeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......
......@@ -12,4 +12,6 @@ public class Constants {
public static final int A_IS_LEFT = 1;
public static final int A_IS_RIGHT = 2;
public static final int PLAYER_A = 0;
public static final int PLAYER_B = 1;
}
......@@ -19,24 +19,19 @@ public class Utils {
private static Bitmap person;
public static int getCountryName(String countryCode) {
if (countryCode.equals("FRA"))
return R.string.france;
if (countryCode.equals("USA"))
return R.string.usa;
if (countryCode.equals("CHN"))
return R.string.china;
if (countryCode.equals("DEU"))
return R.string.germany;
if (countryCode.equals("GBR"))
return R.string.gbr;
if (countryCode.equals("RUS"))
return R.string.russia;
if (countryCode.equals("IRL"))
return R.string.ireland;
if (countryCode.equals("BEL"))
return R.string.belgium;
return -1;
/**
* @param o
* @param key
* @return the string value for the key or null
*/
public static String getStringFromJson(JsonObject o, String key) {
String s;
try {
s = o.get(key).getAsString();
} catch (Exception e) {
s = null;
}
return s;
}
public static int getRefereeingTypeName(int refereeingType) {
......
......@@ -13,6 +13,8 @@ public class SecureDelayButton extends Button implements View.OnClickListener {
private static final int DELAY_MS = 555;
private OnClickListener onClickListener;
private boolean securing;
private boolean keepDisabled;
public SecureDelayButton(Context context) {
super(context);
......@@ -35,25 +37,38 @@ public class SecureDelayButton extends Button implements View.OnClickListener {
@Override
public void onClick(View view) {
securing = true;
if (onClickListener != null)
onClickListener.onClick(this);
setEnabled(false);
super.setEnabled(false);
Timer buttonTimer = new Timer();
buttonTimer.schedule(new TimerTask() {
@Override
public void run() {
post(new Runnable() {
@Override
public void run() {
setEnabled(true);
if (keepDisabled) {
keepDisabled = false;
} else {
SecureDelayButton.super.setEnabled(true);
}
securing = false;
}
});
}
}, DELAY_MS);
}
@Override
public void setEnabled(boolean enabled) {
if (securing && !enabled)
keepDisabled = true;
else
super.setEnabled(enabled);
}
public OnClickListener getOnClickListener() {
return onClickListener;
}
......
......@@ -214,28 +214,31 @@
android:layout_weight="30">
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/pointLeft"
android:id="@+id/aceLeft"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/POINT"
android:text="@string/ace"
style="@style/StatsButton"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/aceLeft"
android:id="@+id/winnerServeLeft"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/ace"
android:text="@string/SERVICE_GAGNANT"
style="@style/StatsButton"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/winnerServeLeft"
android:id="@+id/doubleFaultLeft"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/SERVICE_GAGNANT"
style="@style/StatsButton"/>
android:text="@string/double_fault"
style="@style/StatsButton"
android:enabled="false"
android:textSize="20sp"
android:visibility="visible"/>
</LinearLayout>
......@@ -246,30 +249,29 @@
android:layout_weight="30">
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/winnerPointLeft"
android:id="@+id/pointLeft"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/COUP_GAGNANT"
android:text="@string/POINT"
style="@style/StatsButton"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/unforcedErrorLeft"
android:id="@+id/winnerPointLeft"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/FAUTE_DIRECT_ADV"
style="@style/StatsButton"
android:textSize="20sp"/>
android:text="@string/COUP_GAGNANT"
style="@style/StatsButton"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/unforcedErrorLeft"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text=""
android:text="@string/FAUTE_DIRECT_ADV"
style="@style/StatsButton"
android:textSize="20sp"
android:visibility="invisible"/>
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
......@@ -293,27 +295,30 @@
android:layout_weight="30">
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/winnerServeRight"
android:id="@+id/doubleFaultRight"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/SERVICE_GAGNANT"
style="@style/StatsButton"/>
android:text="@string/double_fault"
style="@style/StatsButton"
android:enabled="false"
android:textSize="20sp"
android:visibility="visible"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/aceRight"
android:id="@+id/winnerServeRight"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/ace"
android:text="@string/SERVICE_GAGNANT"
style="@style/StatsButton"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/pointRight"
android:id="@+id/aceRight"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/POINT"
android:text="@string/ace"
style="@style/StatsButton"/>
</LinearLayout>
......@@ -324,15 +329,6 @@
android:layout_height="0px"
android:layout_weight="30">
<fr.istic.masteru.android.views.SecureDelayButton
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text=""
style="@style/StatsButton"
android:textSize="20sp"
android:visibility="invisible"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/unforcedErrorRight"
android:layout_width="0px"
......@@ -350,6 +346,14 @@
style="@style/StatsButton"
android:text="@string/COUP_GAGNANT"/>
<fr.istic.masteru.android.views.SecureDelayButton
android:id="@+id/pointRight"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30"
android:text="@string/POINT"
style="@style/StatsButton"/>
</LinearLayout>
</LinearLayout>
......
......@@ -40,5 +40,6 @@
<string name="SERVICE_GAGNANT">SERVICE GAGNANT</string>
<string name="no_match_setting_up">Aucun match disponible.\nLa compétition n\'a pas commencé.</string>
<string name="no_matchs_all_ended">Tous les matchs de la phase courante ont été terminés.</string>
<string name="double_fault">DOUBLE FAUTE DE L\'ADVERSAIRE</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment