Java Code Examples for android.view.MotionEvent

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Android-automation, under directory /Tmts_Java/src/com/taobao/tmts/framework/utils/.

Source file: ClickUtils.java

  19 
vote

/** 
 * Clicks on a given coordinate on the screen
 * @param x the x coordinate
 * @param y the y coordinate
 */
public static void clickOnScreen(Instrumentation instrumentation,float x,float y){
  long downTime=SystemClock.uptimeMillis();
  long eventTime=SystemClock.uptimeMillis();
  MotionEvent event=MotionEvent.obtain(downTime,eventTime,MotionEvent.ACTION_DOWN,x,y,0);
  MotionEvent event2=MotionEvent.obtain(downTime,eventTime,MotionEvent.ACTION_UP,x,y,0);
  try {
    instrumentation.sendPointerSync(event);
    instrumentation.sendPointerSync(event2);
    Log.i(LOG_TAG,"sent motionevent to click, x is " + x + " y is "+ y);
  }
 catch (  SecurityException e) {
    Assert.assertTrue("Click can not be completed!",false);
  }
}
 

Example 2

From project android-marvin, under directory /marvin/src/main/java/de/akquinet/android/marvin/actions/.

Source file: BaseAction.java

  18 
vote

public void click(float x,float y){
  MotionEvent downEvent=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,x,y,0);
  MotionEvent upEvent=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,x,y,0);
  try {
    instrumentation.sendPointerSync(downEvent);
    instrumentation.sendPointerSync(upEvent);
  }
 catch (  SecurityException e) {
    Assert.fail("Click on (" + x + ","+ y+ ") failed.");
  }
}
 

Example 3

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/keyboard/.

Source file: LatinKeyboardView.java

  18 
vote

@Override public boolean onDoubleTapEvent(MotionEvent secondTap){
  if (mProcessingShiftDoubleTapEvent && secondTap.getAction() == MotionEvent.ACTION_DOWN) {
    final MotionEvent secondDown=secondTap;
    final int pointerIndex=secondDown.getActionIndex();
    final int id=secondDown.getPointerId(pointerIndex);
    final PointerTracker tracker=getPointerTracker(id);
    if (tracker.isOnShiftKey((int)secondDown.getX(),(int)secondDown.getY())) {
      onDoubleTapShiftKey(tracker,mKeyTimerHandler.isIgnoringDoubleTap());
      return true;
    }
    mProcessingShiftDoubleTapEvent=false;
  }
  return mProcessingShiftDoubleTapEvent;
}
 

Example 4

From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/ui/.

Source file: GestureRecognizer.java

  18 
vote

public void cancelScale(){
  long now=SystemClock.uptimeMillis();
  MotionEvent cancelEvent=MotionEvent.obtain(now,now,MotionEvent.ACTION_CANCEL,0,0,0);
  mScaleDetector.onTouchEvent(cancelEvent);
  cancelEvent.recycle();
}
 

Example 5

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: RenderView.java

  18 
vote

@Override public boolean onTouchEvent(MotionEvent event){
  if (mGL == null) {
    return false;
  }
  if (mTouchEventQueue.size() > 8 && event.getAction() == MotionEvent.ACTION_MOVE)   return true;
synchronized (mTouchEventQueue) {
    MotionEvent eventCopy=MotionEvent.obtain(event);
    mTouchEventQueue.addLast(eventCopy);
    requestRender();
  }
  return true;
}
 

Example 6

From project android_7, under directory /src/org/immopoly/android/widget/.

Source file: ViewPager.java

  17 
vote

/** 
 * Start a fake drag of the pager. <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager with the touch scrolling of another view, while still letting the ViewPager control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.) Call  {@link #fakeDragBy(float)} to simulate the actual drag motion. Call{@link #endFakeDrag()} to complete the fake drag and fling as necessary.<p>During a fake drag the ViewPager will ignore all touch events. If a real drag is already in progress, this method will return false.
 * @return true if the fake drag began successfully, false if it could not be started.
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag(){
  if (mIsBeingDragged) {
    return false;
  }
  mFakeDragging=true;
  setScrollState(SCROLL_STATE_DRAGGING);
  mInitialMotionX=mLastMotionX=0;
  if (mVelocityTracker == null) {
    mVelocityTracker=VelocityTracker.obtain();
  }
 else {
    mVelocityTracker.clear();
  }
  final long time=SystemClock.uptimeMillis();
  final MotionEvent ev=MotionEvent.obtain(time,time,MotionEvent.ACTION_DOWN,0,0,0);
  mVelocityTracker.addMovement(ev);
  ev.recycle();
  mFakeDragBeginTime=time;
  return true;
}
 

Example 7

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuItemView.java

  15 
vote

@Override public boolean dispatchHoverEvent(MotionEvent event){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return onHoverEvent(event);
  }
  return false;
}
 

Example 8

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuItemView.java

  15 
vote

@Override public boolean dispatchHoverEvent(MotionEvent event){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return onHoverEvent(event);
  }
  return false;
}
 

Example 9

From project abalone-android, under directory /src/com/bytopia/abalone/.

Source file: SelectLayoutActivity.java

  15 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  layouts=new ArrayList<Layout>();
  for (  String layout : getResources().getStringArray(R.array.game_layouts)) {
    String tempAi="com.bytopia.abalone.mechanics." + layout;
    try {
      Class layoutClass=Class.forName(tempAi);
      Layout l=(Layout)layoutClass.newInstance();
      layouts.add(l);
    }
 catch (    Exception e1) {
      e1.printStackTrace();
    }
  }
  setContentView(R.layout.layout_selecting);
  boardView=new BoardView(getApplicationContext()){
    @Override public boolean onTouchEvent(    MotionEvent e){
      if (e.getAction() == MotionEvent.ACTION_UP) {
        String name=layouts.get(index).getClass().getName();
        SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        preferences.edit().putString("layout",name).commit();
        finish();
      }
      return true;
    }
  }
;
  prev=(Button)findViewById(R.id.slect_layout_prev);
  next=(Button)findViewById(R.id.slect_layout_next);
  refrashLayout();
  LinearLayout linearLayout=(LinearLayout)findViewById(R.id.layout_selecting_layout);
  linearLayout.addView(boardView);
}
 

Example 10

From project AChartEngine, under directory /achartengine/src/org/achartengine/.

Source file: GraphicalView.java

  15 
vote

@Override public boolean onTouchEvent(MotionEvent event){
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
    oldX=event.getX();
    oldY=event.getY();
  }
  if (mRenderer != null && (mRenderer.isPanEnabled() || mRenderer.isZoomEnabled())) {
    if (mTouchHandler.handleTouch(event)) {
      return true;
    }
  }
  return super.onTouchEvent(event);
}
 

Example 11

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuItemView.java

  15 
vote

@Override public boolean dispatchHoverEvent(MotionEvent event){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return onHoverEvent(event);
  }
  return false;
}
 

Example 12

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/event/ui/.

Source file: ScrollEvent.java

  15 
vote

public ScrollEvent(MotionEvent event1,MotionEvent event2,float distanceX,float distanceY){
  this.event1=event1;
  this.event2=event2;
  this.distanceX=distanceX;
  this.distanceY=distanceY;
}
 

Example 13

From project aksunai, under directory /src/org/androidnerds/app/aksunai/ui/.

Source file: ChatActivity.java

  15 
vote

@Override public void onCreate(Bundle appState){
  super.onCreate(appState);
  setContentView(R.layout.chat);
  slideLeftIn=AnimationUtils.loadAnimation(this,R.anim.slide_left_in);
  slideLeftOut=AnimationUtils.loadAnimation(this,R.anim.slide_left_out);
  slideRightIn=AnimationUtils.loadAnimation(this,R.anim.slide_right_in);
  slideRightOut=AnimationUtils.loadAnimation(this,R.anim.slide_right_out);
  mFlipper=(ViewFlipper)findViewById(R.id.chat_flipper);
  entry=(EditText)findViewById(R.id.ircedit);
  entry.setSingleLine();
  entry.setOnKeyListener(mKeyListener);
  Button btnSend=(Button)findViewById(R.id.btnSend);
  btnSend.setOnClickListener(mClickListener);
  gestureDetector=new GestureDetector(new MyGestureDetector());
  gestureListener=new View.OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      return gestureDetector.onTouchEvent(event);
    }
  }
;
  mFlipper.setOnTouchListener(gestureListener);
  mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
 

Example 14

From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/entities/.

Source file: PictoView.java

  15 
vote

/** 
 * Show an event in the LogCat view, for debugging
 * @param event
 */
@SuppressWarnings("unused") private void dumpEvent(MotionEvent event){
  String names[]={"DOWN","UP","MOVE","CANCEL","OUTSIDE","POINTER_DOWN","POINTER_UP","7?","8?","9?"};
  StringBuilder sb=new StringBuilder();
  int action=event.getAction();
  int actionCode=action & MotionEvent.ACTION_MASK;
  sb.append("event ACTION_").append(names[actionCode]);
  if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {
    sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
    sb.append(")");
  }
  sb.append("[");
  for (int i=0; i < event.getPointerCount(); i++) {
    sb.append("#").append(i);
    sb.append("(pid ").append(event.getPointerId(i));
    sb.append(")=").append((int)event.getX(i));
    sb.append(",").append((int)event.getY(i));
    if (i + 1 < event.getPointerCount())     sb.append(";");
  }
  sb.append("]");
  Log.d(Constants.PROJECT_TAG,sb.toString());
}
 

Example 15

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuItemView.java

  15 
vote

@Override public boolean dispatchHoverEvent(MotionEvent event){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return onHoverEvent(event);
  }
  return false;
}
 

Example 16

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/widget/.

Source file: PullToRefreshListView.java

  15 
vote

@Override public boolean onTouchEvent(MotionEvent event){
  Log.d(TAG,"onTouchEvent");
  final int y=(int)event.getY();
  mBounceHack=false;
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
    if (!isVerticalScrollBarEnabled()) {
      setVerticalScrollBarEnabled(true);
    }
  if (getFirstVisiblePosition() == 0 && mRefreshState != REFRESHING) {
    if ((mRefreshView.getBottom() >= mRefreshViewHeight || mRefreshView.getTop() >= 0) && mRefreshState == RELEASE_TO_REFRESH) {
      mRefreshState=REFRESHING;
      prepareForRefresh();
      onRefresh();
    }
 else     if (mRefreshView.getBottom() < mRefreshViewHeight || mRefreshView.getTop() <= 0) {
      resetHeader();
      setSelection(1);
    }
  }
break;
case MotionEvent.ACTION_DOWN:
mLastMotionY=y;
break;
case MotionEvent.ACTION_MOVE:
applyHeaderPadding(event);
break;
}
Log.d(TAG,"calling super.onTouchEvent()");
return super.onTouchEvent(event);
}
 

Example 17

From project and-bible, under directory /AndBible/src/net/bible/android/view/activity/page/.

Source file: BibleGestureListener.java

  15 
vote

/** 
 * WebView does not handle long presses automatically via onCreateContextMenu so do it here
 */
@Override public void onLongPress(MotionEvent e){
  Log.d(TAG,"onLongPress");
  super.onLongPress(e);
  if (!CommonUtils.isGingerBreadPlus()) {
    mainBibleActivity.openContextMenu();
  }
}
 

Example 18

From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuItemView.java

  15 
vote

@Override public boolean dispatchHoverEvent(MotionEvent event){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return onHoverEvent(event);
  }
  return false;
}
 

Example 19

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: BetterPopupWindow.java

  15 
vote

/** 
 * Create a BetterPopupWindow
 * @param anchor the view that the BetterPopupWindow will be displaying 'from'
 */
public BetterPopupWindow(View anchor){
  this.anchor=anchor;
  this.window=new PopupWindow(anchor.getContext());
  this.window.setTouchInterceptor(new OnTouchListener(){
    @Override public boolean onTouch(    View v,    MotionEvent event){
      if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        BetterPopupWindow.this.window.dismiss();
        return true;
      }
      return false;
    }
  }
);
  this.windowManager=(WindowManager)this.anchor.getContext().getSystemService(Context.WINDOW_SERVICE);
  onCreate();
}
 

Example 20

From project android-client_2, under directory /src/org/mifos/androidclient/main/.

Source file: CollectionSheetActivity.java

  15 
vote

@Override public boolean onTouch(View view,MotionEvent motionEvent){
  CollectionSheetCustomer center=findCenterFromCollection(mCollectionSheetData);
  CollectionSheetHolder.setCurrentCustomer(center);
  Intent intent=new Intent().setClass(this,CollectionSheetCustomerActivity.class);
  intent.putExtra(CollectionSheetCustomer.BUNDLE_KEY,center);
  startActivity(intent);
  return true;
}
 

Example 21

From project android-cropimage, under directory /src/com/android/camera/.

Source file: CropImage.java

  15 
vote

private void recomputeFocus(MotionEvent event){
  for (int i=0; i < mHighlightViews.size(); i++) {
    HighlightView hv=mHighlightViews.get(i);
    hv.setFocus(false);
    hv.invalidate();
  }
  for (int i=0; i < mHighlightViews.size(); i++) {
    HighlightView hv=mHighlightViews.get(i);
    int edge=hv.getHit(event.getX(),event.getY());
    if (edge != HighlightView.GROW_NONE) {
      if (!hv.hasFocus()) {
        hv.setFocus(true);
        hv.invalidate();
      }
      break;
    }
  }
  invalidate();
}
 

Example 22

From project Android-Flashcards, under directory /src/com/secretsockssoftware/androidflashcards/.

Source file: CardRunner.java

  15 
vote

@Override public boolean onSingleTapUp(MotionEvent e){
  if ((System.currentTimeMillis() - lastTap) < 500)   return true;
  lastTap=System.currentTimeMillis();
  FixedFlipper cur=currentView();
  if (showingFront) {
    cur.showNext();
    showingFront=false;
  }
 else {
    cur.showNext();
    showingFront=true;
  }
  return true;
}
 

Example 23

From project android-flip, under directory /Legacy/Demo-Touch/src/com/aphidmobile/flip/.

Source file: FlipCards.java

  15 
vote

public boolean handleTouchEvent(MotionEvent event){
  if (frontTexture == null)   return false;
  float delta;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    lastY=event.getY();
  setState(STATE_TOUCH);
return true;
case MotionEvent.ACTION_MOVE:
delta=lastY - event.getY();
rotateBy(180 * delta / frontTexture.getContentHeight() * MOVEMENT_RATE);
lastY=event.getY();
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
delta=lastY - event.getY();
rotateBy(180 * delta / frontTexture.getContentHeight() * MOVEMENT_RATE);
if (angle < 90) forward=false;
 else forward=true;
setState(STATE_AUTO_ROTATE);
return true;
}
return false;
}
 

Example 24

From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/.

Source file: BrowseGifsActivity.java

  15 
vote

@Override public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
  try {
    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)     return false;
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
      browseNext();
    }
 else     if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
      browsePrev();
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return false;
}
 

Example 25

From project android-gltron, under directory /GlTron/src/com/glTron/.

Source file: OpenGLView.java

  15 
vote

public boolean onTouchEvent(final MotionEvent event){
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
    _x=event.getX();
    _y=event.getY();
    _renderer.onTouch(_x,_y);
  }
  return true;
}
 

Example 26

From project android-joedayz, under directory /Proyectos/GreenDroid/src/greendroid/widget/.

Source file: PagedView.java

  15 
vote

@Override public boolean onInterceptTouchEvent(MotionEvent ev){
  final int action=ev.getAction();
  if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
    return true;
  }
  final int x=(int)ev.getX();
switch (action) {
case MotionEvent.ACTION_DOWN:
    mStartMotionX=x;
  mIsBeingDragged=!mScroller.isFinished();
if (mIsBeingDragged) {
  mScroller.forceFinished(true);
  mHandler.removeCallbacks(mScrollerRunnable);
}
break;
case MotionEvent.ACTION_MOVE:
final int xDiff=(int)Math.abs(x - mStartMotionX);
if (xDiff > mPagingTouchSlop) {
mIsBeingDragged=true;
performStartTracking(x);
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mIsBeingDragged=false;
break;
}
return mIsBeingDragged;
}
 

Example 27

From project Android-MapForgeFragment, under directory /library-common/src/com/jakewharton/android/mapsforge_fragment/.

Source file: MapView.java

  15 
vote

@Override public boolean onTouchEvent(MotionEvent event){
switch (this.touchEventHandler.getAction(event)) {
case MotionEvent.ACTION_DOWN:
    showZoomControls();
  break;
case MotionEvent.ACTION_CANCEL:
hideZoomControlsDelayed();
break;
case MotionEvent.ACTION_UP:
hideZoomControlsDelayed();
break;
default :
break;
}
if (!isClickable()) {
return true;
}
return this.touchEventHandler.handleTouchEvent(event);
}
 

Example 28

From project android-mapviewballoons, under directory /android-mapviewballoons/src/com/readystatesoftware/maps/.

Source file: TapControlledMapView.java

  15 
vote

private void setupGestures(){
  gd=new GestureDetector(this);
  gd.setOnDoubleTapListener(new OnDoubleTapListener(){
    @Override public boolean onSingleTapConfirmed(    MotionEvent e){
      if (singleTapListener != null) {
        return singleTapListener.onSingleTap(e);
      }
 else {
        return false;
      }
    }
    @Override public boolean onDoubleTap(    MotionEvent e){
      TapControlledMapView.this.getController().zoomInFixing((int)e.getX(),(int)e.getY());
      return false;
    }
    @Override public boolean onDoubleTapEvent(    MotionEvent e){
      return false;
    }
  }
);
}
 

Example 29

From project android-pulltorefresh, under directory /pulltorefresh/src/com/markupartist/android/widget/.

Source file: PullToRefreshListView.java

  15 
vote

@Override public boolean onTouchEvent(MotionEvent event){
  final int y=(int)event.getY();
  mBounceHack=false;
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
    if (!isVerticalScrollBarEnabled()) {
      setVerticalScrollBarEnabled(true);
    }
  if (getFirstVisiblePosition() == 0 && mRefreshState != REFRESHING) {
    if ((mRefreshView.getBottom() >= mRefreshViewHeight || mRefreshView.getTop() >= 0) && mRefreshState == RELEASE_TO_REFRESH) {
      mRefreshState=REFRESHING;
      prepareForRefresh();
      onRefresh();
    }
 else     if (mRefreshView.getBottom() < mRefreshViewHeight || mRefreshView.getTop() <= 0) {
      resetHeader();
      setSelection(1);
    }
  }
break;
case MotionEvent.ACTION_DOWN:
mLastMotionY=y;
break;
case MotionEvent.ACTION_MOVE:
applyHeaderPadding(event);
break;
}
return super.onTouchEvent(event);
}
 

Example 30

From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/list/view/.

Source file: SwipeListItemWrapper.java

  15 
vote

@Override public boolean onInterceptTouchEvent(MotionEvent ev){
  final int action=ev.getAction();
  final int x=(int)ev.getX();
  final int y=(int)ev.getY();
  boolean stealEvent=false;
switch (action) {
case MotionEvent.ACTION_MOVE:
    Log.d(cTag,"move event");
  if (isValidSwipe(x,y)) {
    stealEvent=true;
  }
break;
case MotionEvent.ACTION_DOWN:
Log.d(cTag,"down event");
mStartX=x;
mStartY=y;
break;
case MotionEvent.ACTION_CANCEL:
Log.d(cTag,"cancel event");
mPosition=AdapterView.INVALID_POSITION;
break;
case MotionEvent.ACTION_UP:
Log.d(cTag,"up event");
break;
}
return stealEvent;
}
 

Example 31

From project Android-Terminal-Emulator, under directory /libraries/emulatorview/src/jackpal/androidterm/emulatorview/.

Source file: EmulatorView.java

  15 
vote

public boolean onSingleTapUp(MotionEvent e){
  if (mExtGestureListener != null && mExtGestureListener.onSingleTapUp(e)) {
    return true;
  }
  requestFocus();
  return true;
}
 

Example 32

From project android-tether, under directory /android-misc-widgets/src/org/miscwidgets/widget/.

Source file: Panel.java

  15 
vote

public boolean onFling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY){
  mState=State.FLYING;
  mVelocity=mOrientation == VERTICAL ? velocityY : velocityX;
  post(startAnimation);
  return true;
}
 

Example 33

From project android-voip-service, under directory /src/main/java/org/linphone/ui/.

Source file: Digit.java

  15 
vote

public boolean onTouch(View v,MotionEvent event){
  LinphoneCore lc=LinphoneManager.getLc();
  if (event.getAction() == MotionEvent.ACTION_DOWN && mIsDtmfStarted == false) {
    LinphoneManager.getInstance().playDtmf(getContext().getContentResolver(),mKeyCode.charAt(0));
    mIsDtmfStarted=true;
  }
 else {
    if (event.getAction() == MotionEvent.ACTION_UP)     lc.stopDtmf();
    mIsDtmfStarted=false;
  }
  return false;
}
 

Example 34

From project android-wheel, under directory /wheel/src/kankan/wheel/widget/.

Source file: WheelScroller.java

  15 
vote

/** 
 * Handles Touch event 
 * @param event the motion event
 * @return
 */
public boolean onTouchEvent(MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    lastTouchedY=event.getY();
  scroller.forceFinished(true);
clearMessages();
break;
case MotionEvent.ACTION_MOVE:
int distanceY=(int)(event.getY() - lastTouchedY);
if (distanceY != 0) {
startScrolling();
listener.onScroll(distanceY);
lastTouchedY=event.getY();
}
break;
}
if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
justify();
}
return true;
}
 

Example 35

From project android-wheel-datetime-picker, under directory /src/kankan/wheel/widget/.

Source file: WheelScroller.java

  15 
vote

/** 
 * Handles Touch event 
 * @param event the motion event
 * @return
 */
public boolean onTouchEvent(MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    lastTouchedY=event.getY();
  scroller.forceFinished(true);
clearMessages();
break;
case MotionEvent.ACTION_MOVE:
int distanceY=(int)(event.getY() - lastTouchedY);
if (distanceY != 0) {
startScrolling();
listener.onScroll(distanceY);
lastTouchedY=event.getY();
}
break;
}
if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
justify();
}
return true;
}
 

Example 36

From project android-wheel_1, under directory /wheel/src/kankan/wheel/widget/.

Source file: WheelScroller.java

  15 
vote

/** 
 * Handles Touch event 
 * @param event the motion event
 * @return
 */
public boolean onTouchEvent(MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    lastTouchedY=event.getY();
  scroller.forceFinished(true);
clearMessages();
break;
case MotionEvent.ACTION_MOVE:
int distanceY=(int)(event.getY() - lastTouchedY);
if (distanceY != 0) {
startScrolling();
listener.onScroll(distanceY);
lastTouchedY=event.getY();
}
break;
}
if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
justify();
}
return true;
}
 

Example 37

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/controller/.

Source file: GestureController.java

  15 
vote

public boolean onTrackballEvent(MotionEvent event){
  if (event.getAction() == MotionEvent.ACTION_DOWN)   return keyboardAction(ButtonCodes.KEYBOARD_ENTER);
 else {
    long newstamp=System.currentTimeMillis();
    if (newstamp - mTimestamp > 300) {
      mTimestamp=newstamp;
      if (Math.abs(event.getX()) > 0.15f) {
        return keyboardAction(event.getX() < 0 ? ButtonCodes.KEYBOARD_LEFT : ButtonCodes.KEYBOARD_RIGHT);
      }
 else       if (Math.abs(event.getY()) > 0.15f) {
        return keyboardAction(event.getY() < 0 ? ButtonCodes.KEYBOARD_UP : ButtonCodes.KEYBOARD_DOWN);
      }
    }
  }
  return false;
}
 

Example 38

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/activity/.

Source file: ShelvesActivity.java

  15 
vote

public boolean onTouch(View view,MotionEvent event){
  final int action=event.getAction();
  mFingerUp=action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL;
  if (mFingerUp && mScrollState != ShelvesScrollManager.SCROLL_STATE_FLING) {
    postUpdateBookCovers();
  }
  return false;
}
 

Example 39

From project AndroidSensorLogger, under directory /src/com/sstp/androidsensorlogger/.

Source file: CameraActivity.java

  15 
vote

@Override public boolean onTouchEvent(MotionEvent event){
  Log.d(TAG,"onTouchEvent: " + event);
  if (event.getAction() == MotionEvent.ACTION_UP) {
    Log.d(TAG,"prepare to take picture");
    takePicture();
    return true;
  }
  return super.onTouchEvent(event);
}
 

Example 40

From project androidTileMapEditor_1, under directory /src/org/metalev/multitouch/controller/.

Source file: MultiTouchController.java

  15 
vote

/** 
 * Process incoming touch events 
 */
@SuppressWarnings("unused") public boolean onTouchEvent(MotionEvent event){
  try {
    int pointerCount=multiTouchSupported ? (Integer)m_getPointerCount.invoke(event) : 1;
    if (DEBUG)     Log.i("MultiTouch","Got here 1 - " + multiTouchSupported + " "+ mMode+ " "+ handleSingleTouchEvents+ " "+ pointerCount);
    if (mMode == MODE_NOTHING && !handleSingleTouchEvents && pointerCount == 1)     return false;
    if (DEBUG)     Log.i("MultiTouch","Got here 2");
    int action=event.getAction();
    int histLen=event.getHistorySize() / pointerCount;
    for (int histIdx=0; histIdx <= histLen; histIdx++) {
      boolean processingHist=histIdx < histLen;
      if (!multiTouchSupported || pointerCount == 1) {
        if (DEBUG)         Log.i("MultiTouch","Got here 3");
        xVals[0]=processingHist ? event.getHistoricalX(histIdx) : event.getX();
        yVals[0]=processingHist ? event.getHistoricalY(histIdx) : event.getY();
        pressureVals[0]=processingHist ? event.getHistoricalPressure(histIdx) : event.getPressure();
      }
 else {
        if (DEBUG)         Log.i("MultiTouch","Got here 4");
        int numPointers=Math.min(pointerCount,MAX_TOUCH_POINTS);
        if (DEBUG && pointerCount > MAX_TOUCH_POINTS)         Log.i("MultiTouch","Got more pointers than MAX_TOUCH_POINTS");
        for (int ptrIdx=0; ptrIdx < numPointers; ptrIdx++) {
          int ptrId=(Integer)m_getPointerId.invoke(event,ptrIdx);
          pointerIds[ptrIdx]=ptrId;
          xVals[ptrIdx]=(Float)(processingHist ? m_getHistoricalX.invoke(event,ptrIdx,histIdx) : m_getX.invoke(event,ptrIdx));
          yVals[ptrIdx]=(Float)(processingHist ? m_getHistoricalY.invoke(event,ptrIdx,histIdx) : m_getY.invoke(event,ptrIdx));
          pressureVals[ptrIdx]=(Float)(processingHist ? m_getHistoricalPressure.invoke(event,ptrIdx,histIdx) : m_getPressure.invoke(event,ptrIdx));
        }
      }
      decodeTouchEvent(pointerCount,xVals,yVals,pressureVals,pointerIds,processingHist ? MotionEvent.ACTION_MOVE : action,processingHist ? true : action != MotionEvent.ACTION_UP && (action & ((1 << ACTION_POINTER_INDEX_SHIFT) - 1)) != ACTION_POINTER_UP && action != MotionEvent.ACTION_CANCEL,processingHist ? event.getHistoricalEventTime(histIdx) : event.getEventTime());
    }
    return true;
  }
 catch (  Exception e) {
    Log.e("MultiTouchController","onTouchEvent() failed",e);
    return false;
  }
}
 

Example 41

From project androidZenWriter, under directory /library/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenuItemView.java

  15 
vote

@Override public boolean dispatchHoverEvent(MotionEvent event){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    return onHoverEvent(event);
  }
  return false;
}
 

Example 42

From project Android_1, under directory /CompassExample/src/com/novoda/example/compass/view/.

Source file: RotatedImageView.java

  15 
vote

private void updatePointerId(MotionEvent ev){
  final int pointerIndex=(ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
  final int pointerId=ev.getPointerId(pointerIndex);
  if (pointerId == mActivePointerId) {
    final int newPointerIndex=pointerIndex == 0 ? 1 : 0;
    mLastTouchX=ev.getX(newPointerIndex);
    mLastTouchY=ev.getY(newPointerIndex);
    mActivePointerId=ev.getPointerId(newPointerIndex);
  }
}
 

Example 43

From project android_ioio_combination_lock, under directory /src/kankan/wheel/widget/.

Source file: WheelScroller.java

  15 
vote

/** 
 * Handles Touch event 
 * @param event the motion event
 * @return
 */
public boolean onTouchEvent(MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    lastTouchedY=event.getY();
  scroller.forceFinished(true);
clearMessages();
break;
case MotionEvent.ACTION_MOVE:
int distanceY=(int)(event.getY() - lastTouchedY);
if (distanceY != 0) {
startScrolling();
listener.onScroll(distanceY);
lastTouchedY=event.getY();
}
break;
}
if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
justify();
}
return true;
}
 

Example 44

From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/.

Source file: GestureCreateActivity.java

  15 
vote

public void onGestureEnded(GestureOverlayView overlay,MotionEvent event){
  mGesture=overlay.getGesture();
  if (mGesture.getLength() < LENGTH_THRESHOLD) {
    overlay.clear(false);
  }
  if (isThereASimilarGesture(mGesture)) {
    Toast.makeText(GestureCreateActivity.this,R.string.gestures_already_present,Toast.LENGTH_SHORT).show();
  }
  mDoneButton.setEnabled(true);
}
 

Example 45

From project android_packages_apps_CMSettings, under directory /src/com/cyanogenmod/settings/widgets/.

Source file: TouchInterceptor.java

  15 
vote

@Override public boolean onInterceptTouchEvent(MotionEvent ev){
  if (mDragListener != null || mDropListener != null) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
      int x=(int)ev.getX();
    int y=(int)ev.getY();
  int itemnum=pointToPosition(x,y);
if (itemnum == AdapterView.INVALID_POSITION) {
  break;
}
ViewGroup item=(ViewGroup)getChildAt(itemnum - getFirstVisiblePosition());
mDragPoint=y - item.getTop();
mCoordOffset=((int)ev.getRawY()) - y;
View dragger=item.findViewById(R.id.grabber);
Rect r=mTempRect;
dragger.getDrawingRect(r);
if (x < r.right * 2) {
item.setDrawingCacheEnabled(true);
Bitmap bitmap=Bitmap.createBitmap(item.getDrawingCache());
startDragging(bitmap,y);
mDragPos=itemnum;
mFirstDragPos=mDragPos;
mHeight=getHeight();
int touchSlop=mTouchSlop;
mUpperBound=Math.min(y - touchSlop,mHeight / 3);
mLowerBound=Math.max(y + touchSlop,mHeight * 2 / 3);
return false;
}
stopDragging();
break;
}
}
return super.onInterceptTouchEvent(ev);
}
 

Example 46

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: Camera.java

  15 
vote

@Override public boolean onDown(MotionEvent e){
  if (!mPausing && isCameraIdle() && mPreviewing&& mZoomButtons != null) {
    mZoomButtons.setVisible(true);
  }
  return true;
}