Android Open Source - custom-touch-examples Move Logger Activity






From Project

Back to project page custom-touch-examples.

License

The source code is released under:

Copyright (c) 2012 Wireless Designs, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in ...

If you think the Android project custom-touch-examples 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

package com.examples.customtouch;
/*w  ww  .  j  a  v a2  s .  c  o m*/
import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;

/**
 * Created by Dave Smith
 * Double Encore, Inc.
 * Date: 9/24/12
 * MoveLoggerActivity
 */
public class MoveLoggerActivity extends Activity implements View.OnTouchListener {

    public static final String TAG = "MoveLoggerActivity";

    /* Slop constant for this device */
    private int mTouchSlop;
    /* Initial touch point */
    private Point mInitialTouch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.move_logger);

        findViewById(R.id.view_logall).setOnTouchListener(this);
        findViewById(R.id.view_logslop).setOnTouchListener(this);

        mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
        mInitialTouch = new Point();
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
            mInitialTouch.set((int)event.getX(), (int)event.getY());
            //Must declare interest to get more events
            return true;
        } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
            switch (v.getId()) {
                case R.id.view_logall:
                    Log.i(TAG, String.format("Top Move: %.1f,%.1f", event.getX(), event.getY()));
                    break;
                case R.id.view_logslop:
                    if ( Math.abs(event.getX() - mInitialTouch.x) > mTouchSlop
                            || Math.abs(event.getY() - mInitialTouch.y) > mTouchSlop ) {
                        Log.i(TAG, String.format("Bottom Move: %.1f,%.1f", event.getX(), event.getY()));
                    }
                    break;
                default:
                    break;
            }
        }
        //Don't interefere when not necessary
        return false;
    }
}




Java Source Code List

com.examples.customtouch.MainActivity.java
com.examples.customtouch.MoveLoggerActivity.java
com.examples.customtouch.MultitouchActivity.java
com.examples.customtouch.TouchDelegateActivity.java
com.examples.customtouch.TouchForwardActivity.java
com.examples.customtouch.TouchInterceptActivity.java
com.examples.customtouch.TouchListenerActivity.java
com.examples.customtouch.TwoDimensionGestureScrollActivity.java
com.examples.customtouch.TwoDimensionScrollActivity.java
com.examples.customtouch.widget.RotateZoomImageView.java
com.examples.customtouch.widget.TouchDelegateLayout.java
com.examples.customtouch.widget.TouchForwardLayout.java
com.examples.customtouch.widget.TwoDimensionGestureScrollView.java
com.examples.customtouch.widget.TwoDimensionScrollView.java