// Listen for Beat Button Clicks
Button beatbutton = (Button)findViewById(R.id.BeatButton);
beatbutton.setOnTouchListener(onBeatPress);
+ beatbutton.setOnClickListener(onButtonRelease);
// Listen for Reset Button Clicks
Button resetbutton = (Button)findViewById(R.id.ResetButton);
boolean session_active = false;
+ boolean accept_beat = true;
long starttime = 0;
+
+ /**
+ * Listen for beat button release
+ * @author Hideki Saito
+ * @version 1.1.1
+ * @since 1.1.1
+ */
+
+ private OnClickListener onButtonRelease = new OnClickListener()
+ {
+ // Now the beat counts
+ public void onClick(View v)
+ {
+ accept_beat = true;
+ }
+ };
+
/**
* Listen for beat button
* @author Hideki Saito
*/
private OnTouchListener onBeatPress = new OnTouchListener()
{
- public boolean onTouch(View v, MotionEvent m)
- {
- // To send a result, simply call setResult() before your
- // activity is finished, building an Intent with the data
- // you wish to send.
- if(session_active == false)
- {
- Button resetbutton = (Button)findViewById(R.id.ResetButton);
- resetbutton.setEnabled(true);
- starttime = System.currentTimeMillis();
- prev = starttime;
-// atbeat = System.currentTimeMillis();
- Log.i("Calc","Starttime is "+String.valueOf(starttime));
- session_active = true;
- beatcount++;
- bpmvalue = 0;
- mHandler.removeCallbacks(autoUpdateDisp);
- mHandler.postDelayed(autoUpdateDisp, 100);
- }
- else
- {
- double bpmvalue_double;
- long atbeat = System.currentTimeMillis();
- bpmvalue_double = (double)((double)beatcount / (double)((atbeat - starttime))*1000*60);
- Log.i("Calc","Beatcount is "+String.valueOf(bpmvalue_double));
- Log.i("Calc","Timeoffset is "+String.valueOf(atbeat - starttime));
- Log.i("Calc","BPM value is "+String.valueOf(bpmvalue));
- EditText interval = (EditText) findViewById(R.id.Interval);
- interval.setText(String.valueOf(atbeat - prev));
- prev = atbeat;
- bpmvalue = (int) Math.round(bpmvalue_double);
- beatcount++;
- }
- ImageView light = (ImageView) findViewById(R.id.VBILamp);
- light.setImageResource(R.drawable.lamp_white);
- mHandler.postDelayed(VBItimeout, 20);
- // Finally, update the display.
- UpdateDisplay();
- return true;
- }
+ public boolean onTouch(View v, MotionEvent m)
+ {
+ if(accept_beat)
+ {
+ // To send a result, simply call setResult() before your
+ // activity is finished, building an Intent with the data
+ // you wish to send.
+ if(session_active == false)
+ {
+ Button resetbutton = (Button)findViewById(R.id.ResetButton);
+ resetbutton.setEnabled(true);
+ starttime = System.currentTimeMillis();
+ prev = starttime;
+ // atbeat = System.currentTimeMillis();
+ Log.i("Calc","Starttime is "+String.valueOf(starttime));
+ session_active = true;
+ beatcount++;
+ bpmvalue = 0;
+ mHandler.removeCallbacks(autoUpdateDisp);
+ mHandler.postDelayed(autoUpdateDisp, 100);
+ }
+ else
+ {
+ double bpmvalue_double;
+ long atbeat = System.currentTimeMillis();
+ bpmvalue_double = (double)((double)beatcount / (double)((atbeat - starttime))*1000*60);
+ Log.i("Calc","Beatcount is "+String.valueOf(bpmvalue_double));
+ Log.i("Calc","Timeoffset is "+String.valueOf(atbeat - starttime));
+ Log.i("Calc","BPM value is "+String.valueOf(bpmvalue));
+ EditText interval = (EditText) findViewById(R.id.Interval);
+ interval.setText(String.valueOf(atbeat - prev));
+ prev = atbeat;
+ bpmvalue = (int) Math.round(bpmvalue_double);
+ beatcount++;
+ }
+ ImageView light = (ImageView) findViewById(R.id.VBILamp);
+ light.setImageResource(R.drawable.lamp_white);
+ mHandler.postDelayed(VBItimeout, 20);
+ // Finally, update the display.
+ UpdateDisplay();
+ accept_beat = false;
+ return true;
+ }
+ return false;
+ }
mHandler.removeCallbacks(VBItimeout);
ImageView light = (ImageView) findViewById(R.id.VBILamp);
light.setImageResource(R.drawable.lamp_red);
+ accept_beat = true;
UpdateDisplay();
}