Example usage for android.view MotionEvent getAction

List of usage examples for android.view MotionEvent getAction

Introduction

In this page you can find the example usage for android.view MotionEvent getAction.

Prototype

public final int getAction() 

Source Link

Document

Return the kind of action being performed.

Usage

From source file:com.androtex.viewpagerindicator.CirclePageIndicator.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        final int count = mViewPager.getAdapter().getCount();
        final int longSize = (mOrientation == HORIZONTAL) ? getWidth() : getHeight();
        final float halfLongSize = longSize / 2;
        final float halfCircleLongSize = (count * 3 * mRadius) / 2;
        final float pointerValue = (mOrientation == HORIZONTAL) ? event.getX() : event.getY();

        if ((mCurrentPage > 0) && (pointerValue < halfLongSize - halfCircleLongSize)) {
            setCurrentItem(mCurrentPage - 1);
            return true;
        } else if ((mCurrentPage < count - 1) && (pointerValue > halfLongSize + halfCircleLongSize)) {
            setCurrentItem(mCurrentPage + 1);
            return true;
        }/*  w w  w.  ja  va2 s  . c om*/
    }

    return super.onTouchEvent(event);
}

From source file:cn.ieclipse.af.view.ScrollLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (debug) {/*w  w  w.j av a2s . c o m*/
        Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop);
    }

    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
        return true;
    }

    final float x = ev.getX();
    final float y = ev.getY();

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        final int xDiff = (int) Math.abs(mLastMotionX - x);
        if (xDiff > mTouchSlop) {
            mTouchState = TOUCH_STATE_SCROLLING;

        }
        break;

    case MotionEvent.ACTION_DOWN:
        mLastMotionX = x;
        mLastMotionY = y;
        mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
        break;

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mTouchState = TOUCH_STATE_REST;
        break;
    }

    return mTouchState != TOUCH_STATE_REST;
}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.MovieListAdapter.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    // when the user touches an item, onTouch is called for action down and again for action up
    // we only want to do something on one of those actions. event tells us which action.
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // onTouch is passed the textview's parent view, a linearlayout - what we set the
        // event on. Look at its children to find the textview
        if (v instanceof android.widget.LinearLayout) {
            android.widget.LinearLayout layView = (android.widget.LinearLayout) v;
            // the layout (from list_item.xml should only have one child, but, here's how
            // you find the children of a layout or other view group.
            for (int i = 0; i <= layView.getChildCount(); i++) {
                if (layView.getChildAt(i) instanceof TextView) {
                    // keep track of TV stuff was most recently touched to un-highlighted
                    if (currSelection != null) {
                        currSelection.setBackgroundColor(parent.getResources().getColor(R.color.light_blue));
                    }// ww  w  .  j  a va 2 s . c om
                    TextView tmp = ((TextView) layView.getChildAt(i));
                    currSelection = tmp;
                    parent.setSelectedStuff(tmp.getText().toString());
                    // create an intent (in the name of the parent activity) to start the WebViewActivity
                    // pass the web view activity two strings: the url and the name of the selected item.
                    // expect the WebViewActivity to return a result, which will be picked up in the
                    // requesting activity -- MainActivity.
                    Intent movieDetails = new Intent(parent, MovieDetails.class);
                    //                        movieDetails.putExtra("MovieLibrary",(parent.movieLibrary));
                    movieDetails.putExtra("movieName", ((TextView) layView.getChildAt(i)).getText().toString());
                    //                        try {
                    //                            movieDetails.putExtra("genreName", getGenre(((TextView) layView.getChildAt(i)).getText().toString()));
                    //                        } catch (JSONException e) {
                    //                            e.printStackTrace();
                    //                        };
                    parent.startActivity(movieDetails);
                }
            }
        }
        // code below should never executes. onTouch is called for textview's linearlayout parent
        if (v instanceof TextView) {
            android.util.Log.d(this.getClass().getSimpleName(),
                    "in onTouch called for: " + ((TextView) v).getText());
        }
    }
    return true;
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

    mTickersContainer = (FixedGridView) getView().findViewById(R.id.tickersContainer);
    mTickersContainer.setExpanded(true);
    final int dashboardSpacing = getResources().getDimensionPixelSize(R.dimen.dashboard_spacing);
    final int dashboardItemSize = getResources().getDimensionPixelSize(R.dimen.dashboard_item_size);
    mTickersContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override//ww  w  .  jav a  2 s  . c  om
                public void onGlobalLayout() {
                    if (mTickersDashboardAdapter.getNumColumns() == 0) {
                        final int numColumns = (int) Math
                                .floor(mTickersContainer.getWidth() / (dashboardSpacing + dashboardItemSize));
                        if (numColumns > 0) {
                            mTickersDashboardAdapter.setNumColumns(numColumns);
                            mTickersContainer.setNumColumns(numColumns);
                        }
                    }
                }
            });
    mTickersDashboardAdapter = new TickersDashboardAdapter(getActivity(), this);
    updateStorageWithTickers();
    mTickersDashboardAdapter.update();
    mTickersContainer.setAdapter(mTickersDashboardAdapter);
    TextView emptyView = (TextView) getView().findViewById(R.id.emptyView);
    mTickersContainer.setEmptyView(emptyView);
    mTickersContainer.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return event.getAction() == MotionEvent.ACTION_MOVE;
        }
    });

    //Broadcast receiver initialization
    mGetStatsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (isVisible()) {
                if (mRefreshItem != null) {
                    mRefreshItem.collapseActionView();
                    mRefreshItem.setActionView(null);
                }
                mTickersDashboardAdapter.update();
            }
        }
    };

    LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(mGetStatsReceiver,
            new IntentFilter("UpdateTickers"));

    //Trade listener, once "Buy" or "Sell" clicked, send the order to server
    View.OnClickListener tradeListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new RegisterTradeRequestTask().execute((v.getId() == R.id.BuyButton) ? "buy" : "sell");
        }
    };

    Button SellButton = (Button) getView().findViewById(R.id.SellButton);
    Button BuyButton = (Button) getView().findViewById(R.id.BuyButton);
    SellButton.setOnClickListener(tradeListener);
    BuyButton.setOnClickListener(tradeListener);

    Button UpdateAccountInfoButton = (Button) getView().findViewById(R.id.UpdateAccountInfoButton);

    UpdateAccountInfoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new UpdateFundsTask().execute();
        }
    });

    //start service to get new data once Dashboard is opened
    getActivity().sendBroadcast(new Intent(getActivity(), StartServiceReceiver.class));
}

From source file:it.angrydroids.epub3reader.TextSelectionSupport.java

private void createSelectionLayer(Context context) {
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSelectionDragLayer = (DragLayer) inflater.inflate(R.layout.selection_drag_layer, null);
    mDragController = new DragController(context);
    mDragController.setDragListener(this);
    mDragController.addDropTarget(mSelectionDragLayer);
    mSelectionDragLayer.setDragController(mDragController);
    mStartSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.startHandle);
    mStartSelectionHandle.setTag(HandleType.START);
    mEndSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.endHandle);
    mEndSelectionHandle.setTag(HandleType.END);
    final OnTouchListener handleTouchListener = new OnTouchListener() {
        @Override/*  w w  w. j a v  a2s .  c o  m*/
        public boolean onTouch(View v, MotionEvent event) {
            boolean handledHere = false;
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                handledHere = startDrag(v);
                mLastTouchedSelectionHandle = (HandleType) v.getTag();
            }
            return handledHere;
        }
    };
    mStartSelectionHandle.setOnTouchListener(handleTouchListener);
    mEndSelectionHandle.setOnTouchListener(handleTouchListener);
}

From source file:com.adwhirl.AdWhirlLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    // Sending on an ACTION_DOWN isn't 100% correct... user could have touched
    // down and dragged out. Unlikely though.
    case MotionEvent.ACTION_DOWN:
        Log.d(AdWhirlUtil.ADWHIRL, "Intercepted ACTION_DOWN event");
        if (activeRation != null) {
            countClick();// w w w  . ja va2 s  .c o m

            if (activeRation.type == 9) {
                if (custom != null && custom.link != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(custom.link));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        if (activityReference == null) {
                            return false;
                        }
                        Activity activity = activityReference.get();
                        if (activity == null) {
                            return false;
                        }
                        activity.startActivity(intent);
                    } catch (Exception e) {
                        Log.w(AdWhirlUtil.ADWHIRL, "Could not handle click to " + custom.link, e);
                    }
                } else {
                    Log.w(AdWhirlUtil.ADWHIRL, "In onInterceptTouchEvent(), but custom or custom.link is null");
                }
            }
            break;
        }
    }

    // Return false so subViews can process event normally.
    return false;
}

From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*from   w ww  .  j a va  2 s  . co  m*/
        mDownEvent = MotionEvent.obtain(event);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart && !mRefreshing && !mUserInteracting) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    mUserInteracting = true;
                    startRefresh();
                    handled = true;
                    break;
                }
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updatePositionTimeout();
                handled = true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mUserInteracting = false;
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:gov.sfmta.sfpark.AnnotationsOverlay.java

@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
    int fingers = e.getPointerCount();
    int action = e.getAction();

    Log.v(TAG, "onTouchEvent " + action);

    if (action == MotionEvent.ACTION_DOWN) {
        isPinch = false;//from w w w  .  j  a v a 2 s . co  m
    }

    if (action == MotionEvent.ACTION_MOVE && fingers == 2) {
        isPinch = true;
    }

    if (popupView != null) {
        MainScreenActivity.mapView.removeView(popupView);
        popupView = null;
    }

    return super.onTouchEvent(e, mapView);
}

From source file:com.cubic9.android.droidglove.Main.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mYPointWhenDown = event.getY();/* w w w. j a v  a  2  s  .c o  m*/
        break;
    case MotionEvent.ACTION_MOVE:
        mYDiff = event.getY() - mYPointWhenDown;
        if (mYDiff < 0) {
            mYDiff = 0;
            mYPointWhenDown = event.getY();
        } else if (mYDiff > 100) {
            mYDiff = 100;
            mYPointWhenDown = event.getY() - 100;
        }
        break;
    case MotionEvent.ACTION_UP:
        mYDiff = 0;
        break;
    default:
        break;
    }
    return true;
}

From source file:com.ppdl.microphone.MainActivity.java

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

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    sp.edit().remove(Constant.EXTRA_INFILE).commit(); // infile?PCM?????

    Button recordButton = (Button) findViewById(R.id.buttonRecord);
    recordButton.setOnTouchListener(new View.OnTouchListener() {

        @Override// www  .j a va  2  s  . c o  m
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startRecording();
                Toast.makeText(MainActivity.this, "Start Recording", Toast.LENGTH_SHORT).show();
                break;

            case MotionEvent.ACTION_UP:
                stopRecording();
                v.performClick();
                Toast.makeText(MainActivity.this, "Stop Recording", Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
            }
            return false;
        }
    });

    Button playButton = (Button) findViewById(R.id.buttonPlay);
    playButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startPlaying();
        }
    });

    Button stopButton = (Button) findViewById(R.id.buttonStop);
    stopButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            stopPlaying();
        }
    });

    Button recognizeButton = (Button) findViewById(R.id.buttonRecognize);
    recognizeButton.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Toast.makeText(MainActivity.this, "Start Recognizing", Toast.LENGTH_SHORT).show();
                speechRecognizer.cancel();
                Intent intent = new Intent();
                bindParams(intent);
                intent.putExtra("vad", "touch");
                speechRecognizer.startListening(intent);
                break;

            case MotionEvent.ACTION_UP:
                v.performClick();
                Toast.makeText(MainActivity.this, "Stop Recognizing", Toast.LENGTH_SHORT).show();
                speechRecognizer.stopListening();
                break;

            default:
                break;
            }
            return false;
        }
    });

    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
            new ComponentName(this, VoiceRecognitionService.class));
    speechRecognizer.setRecognitionListener(mRecognitionListner);
}