List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java
@Override public void onCreate(Bundle saveInstanceState) { super.onCreate(saveInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); Bundle b = getIntent().getExtras();/* www .j av a2 s. c om*/ SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE); imageOptions = new DisplayImageOptions.Builder().cacheInMemory(false).cacheOnDisk(true) .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY) .showImageOnLoading(R.drawable.connecting_anim).build(); config = new ImageLoaderConfiguration.Builder(getApplicationContext()).diskCacheExtraOptions(480, 320, null) .defaultDisplayImageOptions(imageOptions).build(); if (imageLoader == null) imageLoader = ImageLoader.getInstance(); if (!imageLoader.isInited()) imageLoader.init(config); setContentView(R.layout.link_dialog); imageFrame = (FrameLayout) findViewById(R.id.image_frame); iBottomPanel = (ImageView) findViewById(R.id.bottom_panel); lArtistLink = (RelativeLayout) findViewById(R.id.l_artist_link); bPopUpClose = (ImageView) findViewById(R.id.b_popup_close); bPopUpClose.setOnClickListener(this); tEchoNest = (TextView) findViewById(R.id.t_echo_nest); tAttribution = (TextView) findViewById(R.id.t_attribution); tArtistName = (TextView) findViewById(R.id.t_artist_name); tArtistName.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //isMove = false; mTouchX = event.getRawX(); mTouchY = event.getRawY(); break; case MotionEvent.ACTION_UP: //Log.i("musicInfo", "ACTION_UP! TouchY:" + mTouchY + " UpY: " + event.getRawY() + " Move: " + (mTouchY - event.getRawY())); int RawY = (int) event.getRawY(); int dY = (int) (mTouchY - event.getRawY()); if (dY > 200) { imageLoader.resume(); //Log.i("musicInfo", "mGridView TOP = " + mGridView.getTop() + " mGridView TransitionY =" + mGridView.getTranslationY()); while (mGridView.getTranslationY() > tArtistName.getHeight()) { //Log.i("musicInfo", "Moving UP! mGridView: " + mGridView.getTranslationY() + " tArtistName: " + tArtistName.getTranslationY()); mGridView.setTranslationY(mGridView.getTranslationY() - 1); tArtistName.setTranslationY(tArtistName.getTranslationY() - 1); } } else if (dY > 5 && dY <= 200 || (dY <= 5 && tArtistName.getTranslationY() < 0)) { while (tArtistName.getTranslationY() < 0) { //Log.i("musicInfo", "Moving DOWN! mGridView: " + mGridView.getTranslationY() + " tArtistName: " + tArtistName.getTranslationY()); mGridView.setTranslationY(mGridView.getTranslationY() + 1); tArtistName.setTranslationY(tArtistName.getTranslationY() + 1); } imageLoader.pause(); } break; case MotionEvent.ACTION_MOVE: //isMove = true; //int top = tArtistName.getTop(); //int bottom = tArtistName.getBottom(); //int left = tArtistName.getLeft(); //int right = tArtistName.getRight(); int x = (int) (event.getRawX() - mTouchX); int y = (int) (event.getRawY() - mTouchY); final int num = 5; if (y > -num && y < num) { //isMove = false; break; } else if (y > 0) { } else { imageFrame.bringChildToFront(mGridView); tArtistName.setTranslationY((float) y); mGridView.setTranslationY((float) (SGVtransition + y)); //Log.i("musicInfo", String.format("T: %d, B: %d", mGridView.getTop(), mGridView.getBottom())); } break; } return true; } }); ArtistImage = (ImageView) findViewById(R.id.artist_image); lLinkList = (LinearLayout) findViewById(R.id.l_link_list); mGridView = (StaggeredGridView) findViewById(R.id.SG_view); SGVtransition = 900; mGridView.setTranslationY(SGVtransition); JSONObject artist_info = null; try { artist_info = new JSONObject(b.getString("artist_info")); Log.i("musicInfo", "LinkPopUp. OnCreate" + artist_info.toString()); displayArtistInfo(artist_info); } catch (JSONException e) { e.printStackTrace(); } if (artist_info != null) jArtists.put(artist_info); if (prefs.getBoolean("SimilarOn", false)) { getSimilarArtistsInfo((String) tArtistName.getText()); ArtistImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //isMove = false; mTouchX = event.getRawX(); mTouchY = event.getRawY(); break; case MotionEvent.ACTION_UP: //Log.i("musicInfo", "ACTION_UP! TouchY:" + mTouchY + " UpY: " + event.getRawY() + " Move: " + (mTouchY - event.getRawY())); int dX = (int) (mTouchX - event.getRawX()); if (dX > 5) { if (jArtists.length() > 1) { imageLoader.stop(); try { if (artistNum == 0) { artistNum = jArtists.length() - 1; } else { artistNum--; } displayArtistInfo(jArtists.getJSONObject(artistNum)); imageLoader.resume(); } catch (JSONException e) { e.printStackTrace(); } } } else if (dX < -5) { if (jArtists.length() > 1) { imageLoader.stop(); try { if (artistNum == jArtists.length() - 1) { artistNum = 0; } else { artistNum++; } displayArtistInfo(jArtists.getJSONObject(artistNum)); imageLoader.resume(); } catch (JSONException e) { e.printStackTrace(); } } } break; case MotionEvent.ACTION_MOVE: break; } return true; } }); } mGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { //Log.d("musicInfo", "SGV onScrollStateChanged:" + scrollState); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { //Log.d("musicInfo", "SGV onScroll firstVisibleItem:" + firstVisibleItem + " visibleItemCount:" + visibleItemCount + " totalItemCount:" + totalItemCount); // our handling if (!mHasRequestedMore) { int lastInScreen = firstVisibleItem + visibleItemCount; if (lastInScreen >= totalItemCount) { //Log.d("musicInfo", "SGV onScroll lastInScreen - so load more"); mHasRequestedMore = true; onLoadMoreItems(); } } } private void onLoadMoreItems() { if (jVideoArray == null) return; final ArrayList<JSONObject> sampleData = generateImageData(jVideoArray); for (JSONObject data : sampleData) { mAdapter.add(data); } // stash all the data in our backing store mData.addAll(sampleData); // notify the adapter that we can update now mAdapter.notifyDataSetChanged(); mHasRequestedMore = false; } }); mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), "Open the Video...", Toast.LENGTH_SHORT).show(); StaggeredViewAdapter.ViewHolder vh = (StaggeredViewAdapter.ViewHolder) view.getTag(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse((String) vh.url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); //finish(); } }); //int[] lArtistLinkPosition = new int[2]; //int[] tArtistNamePosition = new int[2]; //lArtistLink.getLocationOnScreen(lArtistLinkPosition); //tArtistName.getLocationOnScreen(tArtistNamePosition); //Log.d("musicInfo", "SGV transition = " + SGVtransition); }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;/*from www . ja v a 2 s . co m*/ if (!mIsViewPagerMode) break; // Detect if we touch down on tab, later to move mIsTabActionDown = (int) (event.getX() / mTabSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If tab touched, so move if (mIsTabActionDown) { mViewPager.setCurrentItem((int) (event.getX() / mTabSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set tab index relative to current coordinate if (mIsActionDown) setTabIndex((int) (event.getX() / mTabSize)); case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsTabActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.amazon.appstream.fireclient.FireClientActivity.java
/** * A "touch event" includes mouse motion when the mouse button * is down./*from w ww . j av a 2 s .co m*/ */ @Override public boolean dispatchTouchEvent(MotionEvent event) { if (mKeyboardActive) { if (mGestureDetector.onTouchEvent(event)) { return true; } } if (super.dispatchTouchEvent(event)) return true; int flags = 0; if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) { flags = AppStreamInterface.CET_TOUCH_FLAG; } event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, flags); break; case MotionEvent.ACTION_DOWN: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_DOWN | flags); break; case MotionEvent.ACTION_UP: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_UP | flags); break; } return true; }
From source file:com.benefit.buy.library.viewpagerindicator.TitlePageIndicator.java
@Override public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from ww w. j a v a2 s . c o m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } } else if (eventX > rightThird) { if (mCurrentPage < (count - 1)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } else { //Middle third if ((mCenterItemClickListener != null) && (action != MotionEvent.ACTION_CANCEL)) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) { mViewPager.endFakeDrag(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:cl.ipp.katbag.fragment.Player.java
public void setSensing(String[] line, int lineNumber) { switch (Integer.parseInt(line[3])) { case 0:/*from ww w . java2 s . c o m*/ boolean ex = false; for (int z = 0; z < touchEventId.size(); z++) { if (line[0].contentEquals(String.valueOf(touchEventId.get(z)))) { ex = true; break; } } if (!ex) { int last = -1; for (int i = lineNumber + 1; i < develop.size(); i++) { String[] it = develop.get(i).split("&&"); last = i; if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) { last--; break; } } if ((lineNumber + 1) <= last) { touchEventId.add(Integer.valueOf(line[0])); touchEventDrawing.add(Integer.valueOf(line[4])); // drawing touchEventBgn.add(lineNumber + 1); // begin in touchEventLst.add(last); // ends final KatbagDrawing drawing = (KatbagDrawing) v.findViewById(Integer.valueOf(line[4])); if (drawing != null) { drawing.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: for (int i = 0; i < touchEventDrawing.size(); i++) { if (touchEventDrawing.get(i) == drawing.getId()) { setBranchTreeCondition(touchEventId.get(i), 1); if (checkTreeCondition(touchEventId.get(i))) { Log.d("ply", "touchEventDrawing - ini:" + touchEventBgn.get(i) + ", last:" + touchEventLst.get(i)); play(touchEventBgn.get(i), touchEventLst.get(i) + 1); break; } } } break; case MotionEvent.ACTION_UP: for (int i = 0; i < touchEventDrawing.size(); i++) { if (touchEventDrawing.get(i) == drawing.getId()) { setBranchTreeCondition(touchEventId.get(i), 0); break; } } break; } return true; } }); Log.d("ply", "setSensing - touchEvent add! count:" + touchEventId.size() + ", drawing:" + touchEventDrawing.get(touchEventDrawing.size() - 1) + " ini:" + touchEventBgn.get(touchEventBgn.size() - 1) + " last:" + touchEventLst.get(touchEventLst.size() - 1)); } } if (last > -1) if ((last + 1) < develop.size()) play((last + 1), develop.size()); } break; case 1: boolean ex1 = false; for (int z = 0; z < shakeId.size(); z++) { if (line[0].contentEquals(String.valueOf(shakeId.get(z)))) { ex1 = true; break; } } if (!ex1) { int last1 = -1; for (int i = lineNumber + 1; i < develop.size(); i++) { String[] it = develop.get(i).split("&&"); last1 = i; if (Integer.parseInt(line[8]) >= Integer.parseInt(it[8])) { last1--; break; } } if ((lineNumber + 1) <= last1) { shakeId.add(Integer.valueOf(line[0])); shakeBgn.add(lineNumber + 1); // begin in shakeLst.add(last1); // ends sensorManager = (SensorManager) mainActivity.context.getSystemService(Context.SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_FASTEST); useAccelerometer = true; Log.d("ply", "setSensing - shake add! count:" + shakeId.size() + ", ini:" + shakeBgn.get(shakeBgn.size() - 1) + " last:" + shakeLst.get(shakeLst.size() - 1)); } if (last1 > -1) if ((last1 + 1) < develop.size()) play((last1 + 1), develop.size()); } break; } }
From source file:cfb.com.dailydevelopment4.example12.library.TitlePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w ww.ja v a2s. c om*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } else { //Middle third if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * Creates the selection layer.// w ww . ja v a 2 s . c om * * @param context */ protected void createSelectionLayer(Context context) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mSelectionDragLayer = (DragLayer) inflater.inflate(R.layout.selection_drag_layer, null); // Make sure it's filling parent mDragController = new DragController(context); mDragController.setDragListener(this); mDragController.addDropTarget(mSelectionDragLayer); mSelectionDragLayer.setDragController(mDragController); mStartSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.startHandle); mStartSelectionHandle.setTag(new Integer(SELECTION_START_HANDLE)); mEndSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.endHandle); mEndSelectionHandle.setTag(new Integer(SELECTION_END_HANDLE)); OnTouchListener handleTouchListener = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean handledHere = false; final int action = event.getAction(); // Down event starts drag for handle. if (action == MotionEvent.ACTION_DOWN) { handledHere = startDrag(v); mLastTouchedSelectionHandle = (Integer) v.getTag(); } return handledHere; } }; mStartSelectionHandle.setOnTouchListener(handleTouchListener); mEndSelectionHandle.setOnTouchListener(handleTouchListener); }
From source file:cn.chuangblog.simplebanner1.indicator.TitlePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w ww.j a va 2s. c o m*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = InfiniteViewPager.FakePositionHelper.getAdapterSize(mViewPager); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } else { //Middle third if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.android.core.view.indicator.TitlePageIndicator.java
@SuppressLint("ClickableViewAccessibility") public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from ww w.ja v a 2 s. c om if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } else { //Middle third if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); }//from w ww .j a va 2 s .com int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: if (mScroller.computeScrollOffset()) { mScroller.abortAnimation(); invalidate(); } stopLongClick(); triggleLongClick(event.getX(), event.getY()); touchBegan(event); return true; case MotionEvent.ACTION_MOVE: touchMoved(event); return true; case MotionEvent.ACTION_UP: touchEnded(event); stopLongClick(); return true; } return false; }