Android Open Source - gdk-apidemo-sample-master Discrete Gestures Activity






From Project

Back to project page gdk-apidemo-sample-master.

License

The source code is released under:

Apache License

If you think the Android project gdk-apidemo-sample-master listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 The Android Open Source Project
 *//from  w  ww .java2 s  .c o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.glass.sample.apidemo.touchpad;

import com.google.android.glass.sample.apidemo.R;
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TextView;

/**
 * Displays information about the discrete gestures reported by the gesture detector (i.e., basic
 * tap/swipe gestures and finger counts).
 */
public class DiscreteGesturesActivity extends Activity
        implements GestureDetector.BaseListener, GestureDetector.FingerListener {

    private TextView mLastGesture;
    private TextView mFingerCount;
    private TextView mSwipeAgainTip;
    private GestureDetector mGestureDetector;

    private boolean mSwipedDownOnce;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_discrete_gestures);

        mLastGesture = (TextView) findViewById(R.id.last_gesture);
        mFingerCount = (TextView) findViewById(R.id.finger_count);
        mSwipeAgainTip = (TextView) findViewById(R.id.swipe_again_tip);

        // Initialize the gesture detector and set the activity to listen to discrete gestures.
        mGestureDetector = new GestureDetector(this).setBaseListener(this).setFingerListener(this);
    }

    /**
     * Overridden to allow the gesture detector to process motion events that occur anywhere within
     * the activity.
     */
    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        return mGestureDetector.onMotionEvent(event);
    }

    /**
     * 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;
        }
    }

    @Override
    public void onFingerCountChanged(int previousCount, int currentCount) {
        mFingerCount.setText(Integer.toString(currentCount));
    }
}




Java Source Code List

com.google.android.glass.sample.apidemo.ApiDemoActivity.java
com.google.android.glass.sample.apidemo.BuildConfig.java
com.google.android.glass.sample.apidemo.card.CardAdapter.java
com.google.android.glass.sample.apidemo.card.CardBuilderActivity.java
com.google.android.glass.sample.apidemo.card.CardScrollViewActivity.java
com.google.android.glass.sample.apidemo.card.EmbeddedCardLayoutActivity.java
com.google.android.glass.sample.apidemo.card.EmbeddedCardLayoutAdapter.java
com.google.android.glass.sample.apidemo.card.SimpleTableItem.java
com.google.android.glass.sample.apidemo.opengl.CubeRenderer.java
com.google.android.glass.sample.apidemo.opengl.Cube.java
com.google.android.glass.sample.apidemo.opengl.MenuActivity.java
com.google.android.glass.sample.apidemo.opengl.OpenGlService.java
com.google.android.glass.sample.apidemo.slider.SliderActivity.java
com.google.android.glass.sample.apidemo.theming.TextAppearanceActivity.java
com.google.android.glass.sample.apidemo.theming.TextAppearanceAdapter.java
com.google.android.glass.sample.apidemo.touchpad.ContinuousGesturesActivity.java
com.google.android.glass.sample.apidemo.touchpad.DiscreteGesturesActivity.java
com.google.android.glass.sample.apidemo.touchpad.SelectGestureDemoActivity.java
com.google.android.glass.sample.apidemo.touchpad.TouchpadView.java
com.google.android.glass.sample.apidemo.voicemenu.VoiceMenuActivity.java