]> Pileus Git - ~andy/spades/commitdiff
Add connect button
authorAndy Spencer <andy753421@gmail.com>
Sun, 26 Apr 2015 22:03:55 +0000 (22:03 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 26 Apr 2015 22:03:55 +0000 (22:03 +0000)
res/layout/main.xml
src/org/pileus/spades/Main.java

index cde15f7d4edf739818f914539d483813f69da63e..129e58a2e52c5fa63fb0d859b3cd4c3b707226b6 100644 (file)
                                                android:layout_width="wrap_content"
                                                android:layout_height="fill_parent"
                                                android:layout_weight="1" />
+                                       <Button
+                                               android:id="@+id/connect"
+                                               android:layout_width="wrap_content"
+                                               android:layout_height="fill_parent"
+                                               android:onClick="onConnect"
+                                               android:text="Connect" />
                                        <Button
                                                android:id="@+id/send"
+                                               android:visibility="gone"
                                                android:layout_width="wrap_content"
                                                android:layout_height="fill_parent"
                                                android:onClick="onSend"
index 4d32742b2c3f71de75a259a052163f19962fe186..231fee0e16994447bbf9a21258c3e6bdf2850ac5 100644 (file)
@@ -48,6 +48,7 @@ public class Main extends Activity
        private LinearLayout chat;
        private TextView     log;
        private EditText     input;
+       private Button       connect;
        private Button       send;
        private LinearLayout spades;
        private TextView     debug;
@@ -137,13 +138,20 @@ public class Main extends Activity
                this.log.append(span);
        }
 
+       private void update(boolean running)
+       {
+               this.running = running;
+               this.connect.setVisibility(running ? View.GONE : View.VISIBLE);
+               this.send.setVisibility(running ? View.VISIBLE : View.GONE);
+       }
+
        /* Private handler methods */
        private void onRegister(Task task)
        {
                Os.debug("Main: onRegister");
                this.task      = task;
                this.game.task = task;
-               this.running   = this.task.isRunning();
+               this.update(this.task.isRunning());
                this.log.setText("");
                this.debug.setText("");
                for (Object obj : this.task.getLog()) {
@@ -211,7 +219,7 @@ public class Main extends Activity
                Os.debug("Main: connect");
                startService(new Intent(this, Task.class)
                                .putExtra("Command", Task.CONNECT));
-               this.running = true;
+               this.update(true);
        }
 
        private void disconnect()
@@ -219,7 +227,7 @@ public class Main extends Activity
                Os.debug("Main: disconnect");
                startService(new Intent(this, Task.class)
                                .putExtra("Command", Task.DISCONNECT));
-               this.running = false;
+               this.update(false);
        }
 
        private void quit()
@@ -234,6 +242,11 @@ public class Main extends Activity
        }
 
        /* Widget callback functions */
+       public void onConnect(View btn)
+       {
+               this.connect();
+       }
+
        public void onSend(View btn)
        {
                if (this.task == null)
@@ -272,6 +285,7 @@ public class Main extends Activity
                        this.chat      = (LinearLayout) findViewById(R.id.chat);
                        this.log       = (TextView)     findViewById(R.id.log);
                        this.input     = (EditText)     findViewById(R.id.input);
+                       this.connect   = (Button)       findViewById(R.id.connect);
                        this.send      = (Button)       findViewById(R.id.send);
                        this.spades    = (LinearLayout) findViewById(R.id.spades);
                        this.debug     = (TextView)     findViewById(R.id.debug);
@@ -408,10 +422,10 @@ public class Main extends Activity
                                        Main.this.onMessage((Message)msg.obj);
                                        break;
                                case Task.CONNECT:
-                                       Main.this.running = true;
+                                       Main.this.update(true);
                                        break;
                                case Task.DISCONNECT:
-                                       Main.this.running = false;
+                                       Main.this.update(false);
                                        break;
                                case Task.NOTIFY:
                                        Main.this.onNotify((String)msg.obj);