title: A button should be clicked only two times in a minute, how should I check it?
body: <p>A button should be clicked only two times in a minute. If the user is clicked for the third time for example in 50. second , app will warn user via toast message. Moreover for the 4. and 2. clicks there should be also 60 seconds. I tried to write a method for this , </p>
  
  <pre><code>int counter = 0;
  long counterOne = 0;
  long counterTwo = 0;
  long counterThree = 0;
  
  private boolean checkTime() {
      counter++;
      if (counter == 1) {
          counterOne = System.currentTimeMillis();
      }
      if (counter == 2) {
          counterTwo = System.currentTimeMillis();
      }
      if (counter == 3) {
          counterThree = System.currentTimeMillis();
      }
  
      if (counterThree != 0) {
          if (counterThree &lt; (counterOne + (60 * 1000))) {
              counter--;
              return false;
          }
      }
  
      if (counter == 1 || counter == 2 || counterThree &gt; (counterOne + (60 * 1000))) {
  
          if (counter == 3) {
              counter = 1;
              counterOne = counterThree;
          }
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>and I want to use it as;</p>
  
  <pre><code>        img_number_search.setOnClickListener(view -&gt; {
          if (checkTime()) {
  
             // TODO
          }
          else {
              Toast.makeText(context, "You can use this property only two times in a minute", Toast.LENGTH_SHORT).show();
          }
      });
  </code></pre>