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;
@ -15,6 +14,14 @@ public class PenaltyTimer extends Activity
private JammerButton[] jbs = new JammerButton[2]; private JammerButton[] jbs = new JammerButton[2];
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() {
@ -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]);
TimerButton b;
top.addView(tr, i); TextView v;
for (int j = 0; j < 2; j += 1) {
TimerButton b;
TextView v;
if (i == 0) {
JammerButton jb = new JammerButton(this, now);
if (p != null) {
jb.penalized = p.penalized[j];
}
jbs[j] = jb;
b = jb;
} else {
b = new TimerButton(this, now);
}
if (i < 2) {
JammerButton jb = new JammerButton(this, btn, now);
if (p != null) { if (p != null) {
int idx = i*2 + j; jb.penalized = p.penalized[i];
b.startTime = p.startTime[idx];
b.duration = p.duration[idx];
b.running = p.running[idx];
} }
jbs[i] = jb;
tr.addView(b.getButton()); b = jb;
} else {
tbs[i*2 + j] = b; b = new TimerButton(this, btn, now);
} }
if (p != null) {
b.startTime = p.startTime[i];
b.duration = p.duration[i];
b.running = p.running[i];
}
tbs[i] = 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);