Android Open Source - Android-Gestures Gestures






From Project

Back to project page Android-Gestures.

License

The source code is released under:

Copyright (c) 2010, Michael Marner (michael@20papercups.net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the fol...

If you think the Android project Android-Gestures 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) 2010, Michael Marner (michael@20papercups.net) 
 * All rights reserved.//  w ww.j  a v a 2  s . c o  m
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the <organization> nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.michaelmarner.gesturedemo;

import com.michaelmarner.gesturedemo.R;

import android.app.Activity;
import android.os.Bundle;
import android.graphics.*;
import android.graphics.Bitmap.*;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import com.michaelmarner.gestures.*;


public class Gestures extends Activity implements GestureListener, TextWatcher, OnClickListener {
    /** Called when the activity is first created. */
    
    GestureView gv;
    Button recordButton;
    EditText gestureName;
    TextView statusBar;
    GestureEngine engine;
    GestureMode opMode;
    
    public void onCreate(Bundle savedInstanceState) {
        
      super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        engine = new GestureEngine();
        gv = (GestureView) findViewById(R.id.gesture_view);
        recordButton = (Button) findViewById(R.id.ok);
        recordButton.setEnabled(false);
        recordButton.setOnClickListener(this);
        
        gestureName = (EditText) findViewById(R.id.entry);
        gestureName.addTextChangedListener(this);
        
        statusBar = (TextView) findViewById(R.id.status);
        
        gv.addListener(this);
        opMode = GestureMode.RECOGNISE;

    }
    
    public void handleGesture(Gesture g) {
      switch(opMode) {
      case RECOGNISE:
        try {
          GestureMatch match = engine.recognise(g);
          statusBar.setText(match.gesture.name);
        }
        catch (Exception e) {}
        break;
      case RECORD:
        g.name = gestureName.getText().toString();
        engine.addGesture(g);
        gestureName.getText().clear();
        statusBar.setText(R.string.status_recorded);
        opMode = GestureMode.RECOGNISE;
        break;
      }
    }

  public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub
    
  }

  public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
    // TODO Auto-generated method stub
    
  }

  public void onTextChanged(CharSequence s, int start, int before, int count) {
    if (gestureName.getText().length() > 0) {
      recordButton.setEnabled(true);
    }
    else {
      recordButton.setEnabled(false);
    }
  }

  public void onClick(View v) {
    // TODO Auto-generated method stub
    opMode = GestureMode.RECORD;
    statusBar.setText(R.string.status_recording);
    recordButton.setEnabled(false);
  }
}




Java Source Code List

com.michaelmarner.gesturedemo.GestureListener.java
com.michaelmarner.gesturedemo.GestureMode.java
com.michaelmarner.gesturedemo.GestureView.java
com.michaelmarner.gesturedemo.Gestures.java
com.michaelmarner.gestures.BoundingBox.java
com.michaelmarner.gestures.GestureEngine.java
com.michaelmarner.gestures.GestureMatch.java
com.michaelmarner.gestures.Gesture.java
com.michaelmarner.gestures.Point.java