OSDN Git Service

Fixed chattering workspace_1.1.1
authorHideki Saito <hidekis@gmail.com>
Wed, 10 Jun 2009 09:51:22 +0000 (02:51 -0700)
committerHideki Saito <hidekis@gmail.com>
Wed, 10 Jun 2009 09:51:22 +0000 (02:51 -0700)
src/hsware/HSTempo/HSTempo.java

index 1310195..0fbc06c 100644 (file)
@@ -84,6 +84,7 @@ public class HSTempo extends Activity {
         // 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);
@@ -101,8 +102,26 @@ public class HSTempo extends Activity {
         
     
     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
@@ -111,46 +130,51 @@ public class HSTempo extends Activity {
      */
     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;
+       }
         
         
 
@@ -367,6 +391,7 @@ public class HSTempo extends Activity {
        mHandler.removeCallbacks(VBItimeout);
        ImageView light = (ImageView) findViewById(R.id.VBILamp);
        light.setImageResource(R.drawable.lamp_red);
+       accept_beat = true;
        UpdateDisplay();
     }