Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #20 from brianPlummer/feature/doubleTapToHide
Browse files Browse the repository at this point in the history
attach gesture detector to listen for double tap so we can hide tiny dancer (do the right thing)
  • Loading branch information
brianPlummer committed Nov 26, 2015
2 parents 7a720d1 + bf8b41e commit 18e336e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public void show(Context context) {
return;
}

//are we running? if so, just return and ignore
//are we running? if so, call tinyCoach.show() and return
if (tinyCoach != null) {
tinyCoach.show();
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codemonkeylabs.fpslibrary.ui;

import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
Expand All @@ -16,15 +17,18 @@ public class DancerTouchListener implements View.OnTouchListener {

private WindowManager.LayoutParams paramsF;
private WindowManager windowManager;
private GestureDetector gestureDetector;

public DancerTouchListener(WindowManager.LayoutParams paramsF,
WindowManager windowManager) {
WindowManager windowManager, GestureDetector gestureDetector) {
this.windowManager = windowManager;
this.paramsF = paramsF;
this.gestureDetector = gestureDetector;
}

@Override
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initialX = paramsF.x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.app.Application;
import android.app.Service;
import android.graphics.PixelFormat;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
Expand All @@ -19,12 +21,22 @@

public class TinyCoach
{

private FPSConfig fpsConfig;
private View meterView;
private final WindowManager windowManager;
private int shortAnimationDuration = 200, longAnimationDuration = 700;

// detect double tap so we can hide tinyDancer
private GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener(){
@Override
public boolean onDoubleTap(MotionEvent e)
{
// hide but don't remove view
hide(false);
return super.onDoubleTap(e);
}
};

public TinyCoach(Application context, FPSConfig config) {

fpsConfig = config;
Expand Down Expand Up @@ -57,8 +69,14 @@ private void addViewToWindow(View view) {
// add view to the window
windowManager.addView(view, paramsF);

//attach touch listener
meterView.setOnTouchListener(new DancerTouchListener(paramsF, windowManager));
// create gesture detector to listen for double taps
GestureDetector gestureDetector = new GestureDetector(view.getContext(), simpleOnGestureListener);

// attach touch listener
view.setOnTouchListener(new DancerTouchListener(paramsF, windowManager, gestureDetector));

// disable haptic feedback
view.setHapticFeedbackEnabled(false);

// show the meter
show();
Expand Down

0 comments on commit 18e336e

Please sign in to comment.