Permalink
Browse files

Imagebutton demo added

  • Loading branch information...
1 parent e70feb2 commit 31a63f120c4cac5e4d64193208f6c13a16bac1db @Neugebauer committed Feb 21, 2012
Showing with 52 additions and 25 deletions.
  1. +26 −24 res/layout/main.xml
  2. +26 −1 src/com/example/thor/threeby3/ThreeBy3Activity.java
View
@@ -132,19 +132,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
-
- <HorizontalScrollView
- android:id="@+id/horizontalScrollView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" >
-
- <LinearLayout
- android:id="@+id/linearLayout1"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal" >
- </LinearLayout>
- </HorizontalScrollView>
<TextView
android:id="@+id/textView1"
@@ -168,16 +155,31 @@
android:gravity = "center">
</TextView>
- <CheckBox
- android:id="@+id/checkBoxAI"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Vs Computer" />
+ <TableRow
+ android:id="@+id/TopRow2"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:baselineAligned="true" >
+
+ <CheckBox
+ android:id="@+id/checkBoxAI"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Vs Computer" />
- <CheckBox
- android:id="@+id/checkBoxToe"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Toe" />
-
+ <CheckBox
+ android:id="@+id/checkBoxToe"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Toe" />
+
+ <ImageButton
+ android:id="@+id/imageButton1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="changeImage"
+ android:src="@drawable/x" />
+
+ </TableRow>
+
</TableLayout>
@@ -8,8 +8,11 @@
import android.app.Activity;
import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.LightingColorFilter;
+import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
@@ -26,6 +29,7 @@
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
+import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
@@ -62,6 +66,7 @@
public Random rand = new Random();
//private static final String SERVLET_URL = "http://";
public boolean online = false;
+ public final int buttonimages[] = {R.drawable.o, R.drawable.x, R.drawable.xxx, R.drawable.ooo, R.drawable.toe};
//private static final String TAG = "MyActivity";
/** Called when the activity is first created. */
@@ -87,6 +92,11 @@ public void onCreate(Bundle savedInstanceState) {
gamewin = sounds.load(this, R.raw.gamewin, 1);
gametie = sounds.load(this, R.raw.gametie, 1);
//music = MediaPlayer.create(context, R.raw.something);
+ ImageButton imagebutton = (ImageButton) findViewById(R.id.imageButton1);
+ Drawable da = getResources().getDrawable(R.drawable.x);
+ imagebutton.getLayoutParams().height = da.getMinimumHeight();
+ imagebutton.getLayoutParams().width = da.getMinimumWidth();
+
showWhoseTurn();
showScore();
CheckBox cbAI =(CheckBox)findViewById(R.id.checkBoxAI);
@@ -156,7 +166,7 @@ public void playOnlineRegister() {
public void playOnline() {
online = true;
- //DisableXOButtons
+ buttonsClickable(false);
//WaitForServletToSayItsYourMove
}
@@ -178,6 +188,17 @@ public void buttonsClickable(boolean clickable) {
}
}
+ public void reportStats() {
+ //Update/InsertToPlayerTableRecordsTable()
+ //DeleteFromGamesTableMovesTable()
+ }
+
+ public void changeImage(View view) {
+ int randomimage = rand.nextInt(buttonimages.length);
+ ImageButton imagebutton = (ImageButton) findViewById(R.id.imageButton1);
+ imagebutton.setImageDrawable(getResources().getDrawable(buttonimages[randomimage]));
+ }
+
//When button is clicked
public void claimSquare(View view) {
if (gameover == true) {
@@ -232,6 +253,8 @@ public void claimSquare(View view) {
tv.setText("Player " + playername + " WINS!");
tvs.setText("Click Any Square To Start New Game");
gameover = true;
+ if (online)
+ reportStats();
return;
}
else {
@@ -241,6 +264,8 @@ public void claimSquare(View view) {
tscore += 1;
tvs.setText("Click Any Square To Start New Game");
gameover = true;
+ if (online)
+ reportStats();
return;
}
}

0 comments on commit 31a63f1

Please sign in to comment.