Working with big huge buttons

This commit is contained in:
Neale Pickett 2012-12-08 18:33:50 -07:00
parent 15787dee79
commit 4a46c159fc
4 changed files with 39 additions and 41 deletions

View File

@ -29,9 +29,9 @@ define(row, `<LinearLayout
/> />
</LinearLayout>') </LinearLayout>')
row(jl, jr) row(jl, jr)
row(bl1, br1) row(b1l, b1r)
row(bl2, br2) row(b2l, b2r)
row(bl3, br3) row(b3l, b3r)
<Button <Button
android:id="@+id/pause" android:id="@+id/pause"
android:text="Jam End" android:text="Jam End"

View File

@ -1,6 +1,7 @@
package org.woozle.penaltytimer; package org.woozle.penaltytimer;
import android.content.Context; import android.content.Context;
import android.widget.Button;
import android.view.View; import android.view.View;
import android.view.View.*; import android.view.View.*;
@ -10,12 +11,12 @@ public class JammerButton extends TimerButton
public boolean penalized = false; public boolean penalized = false;
private JammerButton peer; private JammerButton peer;
public JammerButton(Context context, long now) { public JammerButton(Context context, Button btn, long now) {
super(context, now); super(context, btn, now);
} }
public String str(long remain, boolean tenths) { public String str(long remain, boolean tenths) {
return bstr(remain, tenths) + " J"; return bstr(remain, tenths) + " ";
} }
public void setOther(JammerButton other) { public void setOther(JammerButton other) {

View File

@ -1,8 +1,7 @@
package org.woozle.penaltytimer; package org.woozle.penaltytimer;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.*;
import android.widget.Toast;
import android.widget.*; import android.widget.*;
import android.os.*; import android.os.*;
import java.lang.Math; import java.lang.Math;
@ -16,6 +15,14 @@ public class PenaltyTimer extends Activity
private TimerButton[] tbs = new TimerButton[8]; private TimerButton[] tbs = new TimerButton[8];
private boolean paused = false; private boolean paused = false;
private int[] btns = {
R.id.jl, R.id.jr,
R.id.b1l, R.id.b1r,
R.id.b2l, R.id.b2r,
R.id.b3l, R.id.b3r,
};
private Runnable pulse = new Runnable() { private Runnable pulse = new Runnable() {
public void run() { public void run() {
long now = SystemClock.uptimeMillis(); long now = SystemClock.uptimeMillis();
@ -39,45 +46,36 @@ public class PenaltyTimer extends Activity
Persistence p = (Persistence)getLastNonConfigurationInstance(); Persistence p = (Persistence)getLastNonConfigurationInstance();
long now = SystemClock.uptimeMillis(); long now = SystemClock.uptimeMillis();
LinearLayout top; LinearLayout top;
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 0, (float)2.0);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.main); setContentView(R.layout.main);
top = (LinearLayout)findViewById(R.id.main); top = (LinearLayout)findViewById(R.id.main);
// Create all the buttons // Set up all the buttons
for (int i = 0; i < 4; i += 1) { for (int i = 0; i < 8; i += 1) {
LinearLayout tr = new LinearLayout(this); Button btn = (Button)findViewById(btns[i]);
top.addView(tr, i);
for (int j = 0; j < 2; j += 1) {
TimerButton b; TimerButton b;
TextView v; TextView v;
if (i == 0) { if (i < 2) {
JammerButton jb = new JammerButton(this, now); JammerButton jb = new JammerButton(this, btn, now);
if (p != null) { if (p != null) {
jb.penalized = p.penalized[j]; jb.penalized = p.penalized[i];
} }
jbs[j] = jb; jbs[i] = jb;
b = jb; b = jb;
} else { } else {
b = new TimerButton(this, now); b = new TimerButton(this, btn, now);
} }
if (p != null) { if (p != null) {
int idx = i*2 + j; b.startTime = p.startTime[i];
b.duration = p.duration[i];
b.startTime = p.startTime[idx]; b.running = p.running[i];
b.duration = p.duration[idx];
b.running = p.running[idx];
} }
tr.addView(b.getButton()); tbs[i] = b;
tbs[i*2 + j] = b;
}
} }

View File

@ -29,11 +29,10 @@ public class TimerButton
static ColorFilter standColor = new PorterDuffColorFilter(0xffffff88, PorterDuff.Mode.MULTIPLY); static ColorFilter standColor = new PorterDuffColorFilter(0xffffff88, PorterDuff.Mode.MULTIPLY);
static ColorFilter normalColor = new PorterDuffColorFilter(0xffff8888, PorterDuff.Mode.MULTIPLY); static ColorFilter normalColor = new PorterDuffColorFilter(0xffff8888, PorterDuff.Mode.MULTIPLY);
public TimerButton(Context context, long now) { public TimerButton(Context context, Button btn, long now) {
b = new Button(context);
vibr = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); vibr = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
b = btn;
b.setText("--:--"); b.setText("--:--");
b.setTextSize(24); b.setTextSize(24);
b.setGravity(Gravity.CENTER); b.setGravity(Gravity.CENTER);