com.google.android.glass.touchpad.Gesture Java Examples

The following examples show how to use com.google.android.glass.touchpad.Gesture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectValueActivity.java    From PTVGlass with MIT License 6 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    switch (gesture) {
        case TAP:
            Intent resultIntent = new Intent();
            resultIntent.putExtra(EXTRA_SELECTED_VALUE, getView().getSelectedItemPosition());
            setResultInternal(RESULT_OK, resultIntent);
            playSoundEffect(Sounds.TAP);
            finish();
            return true;
        case SWIPE_DOWN:
            setResultInternal(RESULT_CANCELED, null);
            playSoundEffect(Sounds.DISMISSED);
            finish();
            return true;
        default:
            return false;
    }
}
 
Example #2
Source File: SetTimerActivity.java    From PTVGlass with MIT License 6 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    if (gesture == Gesture.TAP) {
        int position = mView.getSelectedItemPosition();
        SetTimerScrollAdapter.TimeComponents component =
                (SetTimerScrollAdapter.TimeComponents) mAdapter.getItem(position);
        Intent selectValueIntent = new Intent(this, SelectValueActivity.class);

        selectValueIntent.putExtra(SelectValueActivity.EXTRA_COUNT, component.getMaxValue());
        selectValueIntent.putExtra(
                SelectValueActivity.EXTRA_INITIAL_VALUE,
                (int) mAdapter.getTimeComponent(component));
        startActivityForResult(selectValueIntent, SELECT_VALUE);
        mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
        return true;
    }
    return false;
}
 
Example #3
Source File: MainActivity.java    From Bluetooth-Manager-for-Glass with MIT License 6 votes vote down vote up
private GestureDetector createGestureDetector(Context context) {
    GestureDetector gestureDetector = new GestureDetector(context);
    //Create a base listener for generic gestures
    gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            if (gesture == Gesture.TAP) {
                AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                audio.playSoundEffect(Sounds.TAP);
                openOptionsMenu();
                return true;
            }
            return false;
        }
    });
    return gestureDetector;
}
 
Example #4
Source File: SelectValueActivityTest.java    From PTVGlass with MIT License 6 votes vote down vote up
@UiThreadTest
public void testOnGestureTapSupported() {
    MockSelectValueActivity activity = startActivity(mActivityIntent, null, null);
    int expectedSelectedValue = 35;

    activity.onResume();
    activity.getView().setSelection(expectedSelectedValue);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());

    assertTrue(isFinishCalled());
    assertEquals(Activity.RESULT_OK, activity.mResultCode);
    assertNotNull(activity.mResultIntent);
    assertEquals(
            expectedSelectedValue,
            activity.mResultIntent.getIntExtra(SelectValueActivity.EXTRA_SELECTED_VALUE, 0));
}
 
Example #5
Source File: SetTimerActivity.java    From gdk-timer-sample with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    switch (gesture) {
        case TAP:
            long timeMinutes = TimeUnit.SECONDS.toMinutes((long) mTimeSeconds);

            if (timeMinutes > 0) {
                playSoundEffect(Sounds.TAP);
                openOptionsMenu();
                mOptionMenuOpen = true;
            } else {
                playSoundEffect(Sounds.DISALLOWED);
            }
            return true;
        case SWIPE_DOWN:
            setResultInternal(RESULT_CANCELED, null);
            playSoundEffect(Sounds.DISMISSED);
            finish();
            return true;
        default:
            return false;
    }
}
 
Example #6
Source File: SetTimerActivityTest.java    From PTVGlass with MIT License 6 votes vote down vote up
@UiThreadTest
public void testOnGestureSwipeDownSupported() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);
    SetTimerScrollAdapter adapter = (SetTimerScrollAdapter) activity.getView().getAdapter();
    long expectedDuration = TimeUnit.SECONDS.toMillis(45);

    adapter.setDurationMillis(expectedDuration);
    assertTrue(activity.onGesture(Gesture.SWIPE_DOWN));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.DISMISSED, activity.mPlayedSoundEffects.get(0).intValue());

    assertTrue(isFinishCalled());
    assertEquals(Activity.RESULT_OK, activity.mResultCode);
    assertNotNull(activity.mResultIntent);
    assertEquals(
            expectedDuration,
            activity.mResultIntent.getLongExtra(SetTimerActivity.EXTRA_DURATION_MILLIS, 0));
}
 
Example #7
Source File: SetTimerActivityTest.java    From PTVGlass with MIT License 6 votes vote down vote up
@UiThreadTest
public void testOnGestureTapSupportedSelectValueForMinutes() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    activity.onResume();
    activity.getView().setSelection(1);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());

    Intent startedIntent = getStartedActivityIntent();

    assertNotNull(startedIntent);
    assertEquals(
            SelectValueActivity.class.getName(), startedIntent.getComponent().getClassName());
    assertEquals(
            SetTimerScrollAdapter.TimeComponents.MINUTES.getMaxValue(),
            startedIntent.getIntExtra(SelectValueActivity.EXTRA_COUNT, 0));
    assertEquals(
            5, startedIntent.getIntExtra(SelectValueActivity.EXTRA_INITIAL_VALUE, 0));
    assertEquals(SetTimerActivity.SELECT_VALUE, getStartedActivityRequest());
    assertFalse(isFinishCalled());
}
 
Example #8
Source File: SetTimerActivityTest.java    From PTVGlass with MIT License 6 votes vote down vote up
@UiThreadTest
public void testOnGestureTapSupported() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    activity.onResume();
    activity.getView().setSelection(0);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());

    Intent startedIntent = getStartedActivityIntent();

    assertNotNull(startedIntent);
    assertEquals(
            SelectValueActivity.class.getName(), startedIntent.getComponent().getClassName());
    assertEquals(
            SetTimerScrollAdapter.TimeComponents.HOURS.getMaxValue(),
            startedIntent.getIntExtra(SelectValueActivity.EXTRA_COUNT, 0));
    assertEquals(
            0, startedIntent.getIntExtra(SelectValueActivity.EXTRA_INITIAL_VALUE, 0));
    assertEquals(SetTimerActivity.SELECT_VALUE, getStartedActivityRequest());
    assertFalse(isFinishCalled());
}
 
Example #9
Source File: DiscreteGesturesActivity.java    From PTVGlass with MIT License 6 votes vote down vote up
/**
 * This method includes special behavior to handle SWIPE_DOWN gestures. The first time the user
 * swipes down, we return true so that the user can still see the feedback in the gesture
 * label, and we fade in an instructional tip label. The second time the user swipes down, we
 * return false so that the activity can handle the event and return to the previous activity.
 */
@Override
public boolean onGesture(Gesture gesture) {
    mLastGesture.setText(gesture.name());

    if (gesture == Gesture.SWIPE_DOWN) {
        if (!mSwipedDownOnce) {
            mSwipeAgainTip.animate().alpha(1.0f);
            mSwipedDownOnce = true;
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
Example #10
Source File: DiscreteGesturesActivity.java    From gdk-apidemo-sample with Apache License 2.0 6 votes vote down vote up
/**
 * This method includes special behavior to handle SWIPE_DOWN gestures. The first time the user
 * swipes down, we return true so that the user can still see the feedback in the gesture
 * label, and we fade in an instructional tip label. The second time the user swipes down, we
 * return false so that the activity can handle the event and return to the previous activity.
 */
@Override
public boolean onGesture(Gesture gesture) {
    mLastGesture.setText(gesture.name());

    if (gesture == Gesture.SWIPE_DOWN) {
        if (!mSwipedDownOnce) {
            mSwipeAgainTip.animate().alpha(1.0f);
            mSwipedDownOnce = true;
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
Example #11
Source File: MemoScrollActivity.java    From open-quartz with Apache License 2.0 6 votes vote down vote up
private GestureDetector createGestureDetector(final Context context) {
    final GestureDetector gestureDetector = new GestureDetector(context);
    // Create a base listener for generic gestures
    gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            if (gesture == Gesture.LONG_PRESS) {
                // create intent to open the menu
                final Intent intent = new Intent(context, MemoScrollMenuActivity.class);
                // pass card index and card text to the intent
                intent.putExtra("scrollposition",
                    mCardScrollView.getSelectedItemPosition())
                    .putExtra("memotext",
                        memoList.get(mCardScrollView.getSelectedItemPosition()));
                // open the menu
                startActivity(intent);
                return true;
            }
            return false;
        }
    });
    return gestureDetector;
}
 
Example #12
Source File: TutorialActivity.java    From gdk-charades-sample with Apache License 2.0 6 votes vote down vote up
/**
 * Overridden to only allow the tap gesture on the "Tap to score" screen and to only allow the
 * swipe gesture on the "Swipe to pass" screen. The game is also automatically ended when the
 * final card is either tapped or swiped.
 */
@Override
protected void handleGameGesture(Gesture gesture) {
    int phraseIndex = getCharadesModel().getCurrentPhraseIndex();
    switch (gesture) {
        case TAP:
            if (phraseIndex != SWIPE_TO_PASS_CARD) {
                score();
            }
            break;
        case SWIPE_RIGHT:
            if (phraseIndex == SWIPE_TO_PASS_CARD) {
                pass();
            }
            break;
    }

    // Finish the tutorial if we transitioned away from the final card.
    if (phraseIndex == getCharadesModel().getPhraseCount() - 1) {
        finish();
    }
}
 
Example #13
Source File: BaseGameActivity.java    From gdk-charades-sample with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    if (areGesturesEnabled()) {
        switch (gesture) {
            case SWIPE_LEFT:
                // Swipe left (backward) is always handled here to provide a brief
                // "disallowed" tug animation.
                tugPhrase();
                return true;
            case TAP:
            case SWIPE_RIGHT:
                // Delegate tap and swipe right (forward) to the subclass so that the
                // tutorial and actual game can handle them differently.
                handleGameGesture(gesture);
                return true;
            default:
                return false;
        }
    }
    return false;
}
 
Example #14
Source File: BaseGlassActivity.java    From BarcodeEye with Apache License 2.0 5 votes vote down vote up
private GestureDetector createGestureDetector(Context context) {
    GestureDetector gestureDetector = new GestureDetector(context);
    //Create a base listener for generic gestures
    gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            if (gesture == Gesture.TAP) {
                Log.v(TAG, "onSwipeTap");
                return onTap();
            } else if (gesture == Gesture.TWO_TAP) {
                Log.v(TAG, "onSwipeTwoTap");
                return onTwoTap();
            } else if (gesture == Gesture.SWIPE_RIGHT) {
                Log.v(TAG, "onSwipeRight");
                return onSwipeRight();
            } else if (gesture == Gesture.SWIPE_LEFT) {
                Log.v(TAG, "onSwipeLeft");
                return onSwipeLeft();
            }
            return false;
        }
    });

    gestureDetector.setFingerListener(this);
    gestureDetector.setScrollListener(this);
    return gestureDetector;
}
 
Example #15
Source File: SetTimerActivityTest.java    From gdk-timer-sample with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
public void testOnGestureTapSupported() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());
    assertTrue(activity.mOptionsMenuOpen);
}
 
Example #16
Source File: SetTimerActivityTest.java    From gdk-timer-sample with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
public void testOnGestureTapDisallowed() {
    mActivityIntent.removeExtra(SetTimerActivity.EXTRA_DURATION_MILLIS);
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.DISALLOWED, activity.mPlayedSoundEffects.get(0).intValue());
    assertFalse(activity.mOptionsMenuOpen);
}
 
Example #17
Source File: SetTimerActivityTest.java    From gdk-timer-sample with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
public void testOnGestureSwipeDownSupported() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    assertTrue(activity.onGesture(Gesture.SWIPE_DOWN));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.DISMISSED, activity.mPlayedSoundEffects.get(0).intValue());

    assertTrue(isFinishCalled());
    assertEquals(Activity.RESULT_CANCELED, activity.mResultCode);
    assertNull(activity.mResultIntent);
}
 
Example #18
Source File: MainActivity.java    From open-quartz with Apache License 2.0 5 votes vote down vote up
/**
 * Gesture detection for fingers on the Glass
 */
private GestureDetector createGestureDetector(Context context) {
    final GestureDetector gestureDetector = new GestureDetector(context);

    //Create a base listener for generic gestures
    gestureDetector.setBaseListener(new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            // Make sure view is initiated
            if (cameraView != null) {
                // Tap with a single finger for photo
                if (gesture == Gesture.TAP) {
                    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
                        TAKE_PICTURE_REQUEST);

                    return true;
                } else if (gesture == Gesture.TWO_TAP) {
                    // Tap with 2 fingers for video
                    startActivityForResult(new Intent(MediaStore.ACTION_VIDEO_CAPTURE),
                        TAKE_VIDEO_REQUEST);

                    return true;
                }
            }

            return false;
        }
    });

    return gestureDetector;
}
 
Example #19
Source File: RecognitionActivity.java    From android-unispeech with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    Log.v(TAG, "onGesture: " + gesture);
    switch (gesture) {
    }
    return false;
}
 
Example #20
Source File: SelectValueActivity.java    From PTVGlass with MIT License 5 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    if (gesture == Gesture.TAP) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(EXTRA_SELECTED_VALUE, mView.getSelectedItemPosition());
        setResult(RESULT_OK, resultIntent);
        mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
        finish();
        return true;
    }
    return false;
}
 
Example #21
Source File: SelectValueActivityTest.java    From PTVGlass with MIT License 5 votes vote down vote up
@UiThreadTest
public void testOnGestureSwipeDownSupported() {
    MockSelectValueActivity activity = startActivity(mActivityIntent, null, null);

    assertTrue(activity.onGesture(Gesture.SWIPE_DOWN));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.DISMISSED, activity.mPlayedSoundEffects.get(0).intValue());

    assertTrue(isFinishCalled());
    assertEquals(Activity.RESULT_CANCELED, activity.mResultCode);
    assertNull(activity.mResultIntent);
}
 
Example #22
Source File: SetTimerActivity.java    From PTVGlass with MIT License 5 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    switch (gesture) {
        case TAP:
            int position = getView().getSelectedItemPosition();
            SetTimerScrollAdapter.TimeComponents component =
                    (SetTimerScrollAdapter.TimeComponents) mAdapter.getItem(position);
            Intent selectValueIntent = new Intent(this, SelectValueActivity.class);

            selectValueIntent.putExtra(
                SelectValueActivity.EXTRA_COUNT, component.getMaxValue());
            selectValueIntent.putExtra(
                    SelectValueActivity.EXTRA_INITIAL_VALUE,
                    (int) mAdapter.getTimeComponent(component));
            startActivityForResult(selectValueIntent, SELECT_VALUE);
            playSoundEffect(Sounds.TAP);
            return true;
        case SWIPE_DOWN:
            Intent resultIntent = new Intent();
            resultIntent.putExtra(EXTRA_DURATION_MILLIS, mAdapter.getDurationMillis());
            setResultInternal(RESULT_OK, resultIntent);
            playSoundEffect(Sounds.DISMISSED);
            finish();
            return true;
        default:
            return false;
    }
}
 
Example #23
Source File: GameplayActivity.java    From gdk-charades-sample with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleGameGesture(Gesture gesture) {
    switch (gesture) {
        case TAP:
            score();
            if (getCharadesModel().areAllPhrasesGuessedCorrectly()) {
                endGame();
            }
            break;
        case SWIPE_RIGHT:
            pass();
            break;
    }
}
 
Example #24
Source File: StartGameActivity.java    From gdk-charades-sample with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    if (gesture == Gesture.TAP) {
        mAudioManager.playSoundEffect(Sounds.TAP);
        openOptionsMenu();
        return true;
    } else {
        return false;
    }
}
 
Example #25
Source File: MockBaseScrollActivity.java    From PTVGlass with MIT License 4 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture) {
    return false;
}
 
Example #26
Source File: CuxtomCamActivity.java    From CuXtomCam with Apache License 2.0 4 votes vote down vote up
/**
 * Handle Glass Swipe and Tap Gestures
 */

@Override
public synchronized boolean onGesture(Gesture g) {
	switch (g) {
	case TAP:
		if (cameraMode == CAMERA_MODE.PHOTO_MODE) {
			mOverlay.setMode(CameraOverlay.Mode.FOCUS);
			mCamera.takePicture(null, null, mPictureCallback);
			mSoundEffects.shutter();
		} else
			endVideoRecording();

		return true;
	case SWIPE_RIGHT:
		if (enablezoom)
			mPreview.zoomIn();
		return true;
	case TWO_SWIPE_RIGHT:
		if (enablezoom)
			mPreview.zoomIn();
		return true;
	case SWIPE_LEFT:
		if (enablezoom)
			mPreview.zoomOut();
		return true;
	case TWO_SWIPE_LEFT:
		if (enablezoom)
			mPreview.zoomOut();
		return true;
	case SWIPE_DOWN:
		releaseMediaRecorder();
		mSoundEffects.camcorderStop();
		mExecutorService.shutdown();
		Toast.makeText(CuxtomCamActivity.this, "Cancelled", Toast.LENGTH_LONG)
				.show();
		for (int i = 0; i < videoFiles.size(); i++) {
			if(videoFiles.get(0).exists())
			videoFiles.get(i).delete();
		}
		onBackPressed();
		return true;
	default:
		return false;
	}
}
 
Example #27
Source File: MapActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 4 votes vote down vote up
private void initGestureDetector(Context context) {
    mGestureDetector = new GestureDetector(context);
    mGestureDetector.setBaseListener(new GestureDetector.BaseListener() {
      @Override
    public boolean onGesture(Gesture gesture) {
        if(gesture == Gesture.TAP) {
          startActivityForResult(new Intent(MapActivity.this, MenuActivity.class), 1);
          return true;
        } else if(gesture == Gesture.TWO_TAP) {

          return true;
        } else if(gesture == Gesture.SWIPE_RIGHT) {

          return true;
        } else if(gesture == Gesture.SWIPE_LEFT) {

          return true;
        } else if(gesture == Gesture.TWO_LONG_PRESS) {
//          toggleMotionControl();
//          enableMyo();
        }
//        else if(gesture == Gesture.SWIPE_DOWN) {
//          Log.d("ArcGIS", "Received swipe down, about to finish");
//          finish();
//          return true;
//        }
        return false;
      }
    });

    mGestureDetector.setFingerListener(new GestureDetector.FingerListener() {
      @Override
    public void onFingerCountChanged(int previousCount, int currentCount) {

      }
    });

    mGestureDetector.setTwoFingerScrollListener( new GestureDetector.TwoFingerScrollListener() {
      @Override
      public boolean onTwoFingerScroll(float displacement, float delta, float velocity) {
        if((displacement > 0 && delta < 0) || (displacement < 0 && delta > 0)) { delta = -delta;}
        float factor = 1.0f + (delta/100.0f);
//        mMapView.zoomTo(mMapView.getCenter(), factor);
//        mMapView.doubleTapZoom(factor);
        return true;
      }
    });
  }
 
Example #28
Source File: BaseGameActivity.java    From gdk-charades-sample with Apache License 2.0 2 votes vote down vote up
/**
 * Subclasses must override this method to handle {@link Gesture#TAP} and
 * {@link Gesture#SWIPE_RIGHT} gestures that occur during game play. Typically they should
 * call the {@link #score()} method on a tap and the {@link #pass()} method on a swipe, but
 * the tutorial overrides these in certain cases to make the game flow in a predetermined way.
 */
protected abstract void handleGameGesture(Gesture gesture);