Skip to content

Commit

Permalink
Merge pull request #25 from harjot-oberai/master
Browse files Browse the repository at this point in the history
Rematch Option working for single Device
  • Loading branch information
hareshkh committed Mar 9, 2016
2 parents 8725d02 + 1eb8b34 commit a259cdb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class CanvasViewDouble2P extends View { //you have to create a new java f
public static int turn = 0;

public static ConnectedThread connectedThread = null;

AlertDialog alert = null;

public void init(){
Resources r = getResources();
Expand Down Expand Up @@ -222,6 +222,9 @@ public void onClick(DialogInterface dialog, int which) {
case DialogInterface.BUTTON_POSITIVE:
{
try {
String endMsg = "END";
byte[] ByteArray = endMsg.getBytes();
connectedThread.write(ByteArray);
connectedThread.cancel();
connectedThread = null;
bluetoothSocket.close();
Expand All @@ -231,15 +234,23 @@ public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
TwoDevice2P.act_2p.setResult(3, intent);
TwoDevice2P.act_2p.finish();
break;
}
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
{
String msg = "REMATCH";
byte[] ByteArray = msg.getBytes();
connectedThread.write(ByteArray);
init();
postInvalidate();
break;
}
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(str).setPositiveButton("Ok!", dialogClickListener).show();
builder.setMessage(str).setPositiveButton("OK", dialogClickListener).setNegativeButton("REMATCH", dialogClickListener).show();
alert = builder.create();
}

public void updateWin(int i){
Expand Down Expand Up @@ -486,9 +497,9 @@ public void run() {
String readMessage = "";
bytes = mmInStream.read(buffer);
readMessage = new String(buffer, 0, bytes);
Log.i(TAG, "Listening : " + readMessage);
if(readMessage.contains(";")){
// Send the obtained bytes to the UI Activity
Log.i(TAG, "Listening : " + readMessage);
a[0][0] = (int)(readMessage.charAt(0)-48);
a[0][1] = (int)(readMessage.charAt(1)-48);
a[0][2] = (int)(readMessage.charAt(2)-48);
Expand All @@ -510,6 +521,32 @@ public void run() {
check();
}
}
else if(readMessage.equals("REMATCH")){
TwoDevice2P.act_2p.runOnUiThread(
new Runnable() {
@Override
public void run() {
if(alert.isShowing()){
alert.dismiss();
alert = null;
}
}
}
);
init();
postInvalidate();
TwoDevice2P.act_2p.runOnUiThread(
new Runnable() {
@Override
public void run() {
Toast.makeText(TwoDevice2P.act_2p, TwoDevice2P_names.MyName + " vs " + TwoDevice2P_names.OpponentName, Toast.LENGTH_SHORT).show();
}
}
);
}
else if(readMessage.equals("END")){
break;
}
else{
try{
Log.i(TAG,"Hello");
Expand All @@ -530,9 +567,7 @@ public void run() {
}
} catch (Exception e) {
//Log.e(TAG, "disconnected", e);
//TwoDevice2P.act_2p.finish();
//connectionLost();
//break;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,19 @@ public void onClick(DialogInterface dialog, int which) {
case DialogInterface.BUTTON_POSITIVE:
{
SingleDevice2P.act_2p_single.finish();
break;
}
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
{
init();
postInvalidate();
break;
}
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(str).setPositiveButton("Ok!", dialogClickListener).show();
builder.setMessage(str).setPositiveButton("OK", dialogClickListener).setNegativeButton("REMATCH",dialogClickListener).show();
}


Expand Down

0 comments on commit a259cdb

Please sign in to comment.