List of usage examples for android.view MotionEvent ACTION_OUTSIDE
int ACTION_OUTSIDE
To view the source code for android.view MotionEvent ACTION_OUTSIDE.
Click Source Link
From source file:com.gigamole.library.NavigationTabBar.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 w w w. j a v a 2 s. c om if (!mIsViewPagerMode) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; else mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); else mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { if (mIsHorizontalOrientation) setModelIndex((int) (event.getX() / mModelSize)); else setModelIndex((int) (event.getY() / mModelSize)); } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:talex.zsw.baselibrary.widget.NavigationTabBar.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 ww w . jav a2s .c om*/ if (!mIsViewPagerMode) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) { mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; } else { mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; } break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) { mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); } else { mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); } break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { if (mIsHorizontalOrientation) { setModelIndex((int) (event.getX() / mModelSize)); } else { setModelIndex((int) (event.getY() / mModelSize)); } } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int action = event.getAction(); action = action & MotionEvent.ACTION_MASK; mGestureDetector.onTouchEvent(event); boolean scaleInProgress = scaleInProgress(); mScaleGestureDetector.onTouchEvent(event); if (mInteractionMode == InteractionMode.SCALE) { return true; }//from w w w . j ava 2s. c o m if (!scaleInProgress() && scaleInProgress) { // If we were scaling, the scale will stop but we will // still issue an ACTION_UP. Let the subclasses know. mFinishedScalingOperation = true; } int ex = (int) event.getX(); int ey = (int) event.getY(); if (action == MotionEvent.ACTION_DOWN) { mInteractionMode = InteractionMode.MOVE; mTouchDown.x = ex; mTouchDown.y = ey; mTouchShowOriginalDate = System.currentTimeMillis(); mShowOriginalDirection = 0; MasterImage.getImage().setOriginalTranslation(MasterImage.getImage().getTranslation()); } if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) { mTouch.x = ex; mTouch.y = ey; float scaleFactor = MasterImage.getImage().getScaleFactor(); if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) { float translateX = (mTouch.x - mTouchDown.x) / scaleFactor; float translateY = (mTouch.y - mTouchDown.y) / scaleFactor; Point originalTranslation = MasterImage.getImage().getOriginalTranslation(); Point translation = MasterImage.getImage().getTranslation(); translation.x = (int) (originalTranslation.x + translateX); translation.y = (int) (originalTranslation.y + translateY); MasterImage.getImage().setTranslation(translation); mTouchShowOriginal = false; } else if (enableComparison() && !mOriginalDisabled && (System.currentTimeMillis() - mTouchShowOriginalDate > mTouchShowOriginalDelayMin) && event.getPointerCount() == 1) { mTouchShowOriginal = true; } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mInteractionMode = InteractionMode.NONE; mTouchShowOriginal = false; mTouchDown.x = 0; mTouchDown.y = 0; mTouch.x = 0; mTouch.y = 0; if (MasterImage.getImage().getScaleFactor() <= 1) { MasterImage.getImage().setScaleFactor(1); MasterImage.getImage().resetTranslation(); } } float scaleFactor = MasterImage.getImage().getScaleFactor(); Point translation = MasterImage.getImage().getTranslation(); constrainTranslation(translation, scaleFactor); MasterImage.getImage().setTranslation(translation); invalidate(); return true; }
From source file:pl.edu.agh.mindmapex.gui.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); progressDialog = ProgressDialog.show(this, "Drawing", "Please wait...", true, false); if (WelcomeScreen.workbook != null) { workbook = WelcomeScreen.workbook; }// w ww .j av a 2 s .c o m res = getResources(); if (handler == null) { handler = WorkbookHandler.createNewWorkbook(); } if (workbook == null) { workbook = handler.getWorkbook(); styleSheet = workbook.getStyleSheet(); style1 = styleSheet.createStyle(IStyle.TOPIC); styleSheet.addStyle(style1, IStyleSheet.NORMAL_STYLES); } styleSheet = workbook.getStyleSheet(); sheet1 = workbook.getPrimarySheet(); res = getResources(); if (style == null) { Intent intent = getIntent(); style = intent.getStringExtra(WelcomeScreen.STYLE); } if (root == null) { // Display display = getWindowManager().getDefaultDisplay(); setContentView(R.layout.main_content_view); lay = (DrawView) findViewById(R.id.main_draw_view); lay.post(new Runnable() { @Override public void run() { rootTopic = sheet1.getRootTopic(); root = new Box(); // Point size = new Point(lay.getWidth(), lay.getHeight()); // width = size.x / 2; // height = size.y / 2; root.setPoint(new pl.edu.agh.mindmapex.common.Point( lay.getWidth() / 2 - getResources().getDimensionPixelSize(R.dimen.init_box_size), lay.getHeight() / 2 - getResources().getDimensionPixelSize(R.dimen.init_box_size_height))); lay.setZOrderOnTop(true); if (style.equals("ReadyMap")) { if (sheet1.getTheme() == null) { root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height)); final HashMap<String, Box> boxes = new HashMap<>(); root.topic = rootTopic; if (root.topic.getStyleId() != null) { checkStyle(root); } else { root.setDrawableShape(res.getDrawable(R.drawable.round_rect)); } root.topic.setFolded(false); boxes.put(root.topic.getId(), root); for (ITopic t : root.topic.getAllChildren()) { Box b = new Box(); b.topic = t; boxes.put(root.topic.getId(), root); b.point = new pl.edu.agh.mindmapex.common.Point(); if (b.topic.getStyleId() != null) { checkStyle(b); } else { b.setDrawableShape(res.getDrawable(R.drawable.round_rect)); } b.parent = root; root.addChild(b); rootTopic.add(b.topic, 0, ITopic.ATTACHED); Utils.fireAddSubtopic(b, boxes); boxes.put(t.getId(), b); } Utils.findRelationships(boxes); } else { if (sheet1.getTheme().getName().equals("%classic") || sheet1.getTheme().getName().equals("%comic")) { root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height)); root.topic = rootTopic; final HashMap<String, Box> boxes = new HashMap<>(); if (root.topic.getStyleId() != null) { checkStyle(root); } else { root.setDrawableShape(res.getDrawable(R.drawable.elipse)); } root.topic.setFolded(false); boxes.put(root.topic.getId(), root); for (ITopic t : root.topic.getAllChildren()) { Box b = new Box(); b.topic = t; b.point = new pl.edu.agh.mindmapex.common.Point(); boxes.put(root.topic.getId(), root); if (b.topic.getStyleId() != null) { checkStyle(b); } else { b.setDrawableShape(res.getDrawable(R.drawable.round_rect)); } b.parent = root; root.addChild(b); Utils.fireAddSubtopic(b, boxes); rootTopic.add(b.topic, 0, ITopic.ATTACHED); boxes.put(t.getId(), b); } Utils.findRelationships(boxes); } else if (sheet1.getTheme().getName().equals("%simple")) { root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height)); final HashMap<String, Box> boxes = new HashMap<>(); root.topic = rootTopic; if (root.topic.getStyleId() != null) { checkStyle(root); } else { root.setDrawableShape(res.getDrawable(R.drawable.elipse)); } root.topic.setFolded(false); boxes.put(root.topic.getId(), root); for (ITopic t : root.topic.getAllChildren()) { Box b = new Box(); b.topic = t; b.point = new pl.edu.agh.mindmapex.common.Point(); boxes.put(root.topic.getId(), root); if (b.topic.getStyleId() != null) { checkStyle(b); } else { b.setDrawableShape(res.getDrawable(R.drawable.no_border)); } b.parent = root; root.addChild(b); rootTopic.add(b.topic, 0, ITopic.ATTACHED); Utils.fireAddSubtopic(b, boxes); boxes.put(t.getId(), b); } Utils.findRelationships(boxes); } else if (sheet1.getTheme().getName().equals("%bussiness")) { root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height)); final HashMap<String, Box> boxes = new HashMap<>(); root.topic = rootTopic; if (root.topic.getStyleId() != null) { checkStyle(root); } else { root.setDrawableShape(res.getDrawable(R.drawable.round_rect)); } root.topic.setFolded(false); boxes.put(root.topic.getId(), root); for (ITopic t : root.topic.getAllChildren()) { Box b = new Box(); b.topic = t; b.point = new pl.edu.agh.mindmapex.common.Point(); boxes.put(root.topic.getId(), root); if (b.topic.getStyleId() != null) { checkStyle(b); } else { b.setDrawableShape(res.getDrawable(R.drawable.rect)); } b.parent = root; root.addChild(b); rootTopic.add(b.topic, 0, ITopic.ATTACHED); Utils.fireAddSubtopic(b, boxes); boxes.put(t.getId(), b); } Utils.findRelationships(boxes); } else if (sheet1.getTheme().getName().equals("%academese")) { root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height)); final HashMap<String, Box> boxes = new HashMap<>(); root.topic = rootTopic; if (root.topic.getStyleId() != null) { checkStyle(root); } else { root.setDrawableShape(res.getDrawable(R.drawable.rect)); } root.topic.setFolded(false); Style s = (Style) workbook.getStyleSheet().createStyle(IStyle.MAP); s.setProperty(Styles.FillColor, Integer.toString(res.getColor(R.color.dark_gray), 16)); styleSheet.addStyle(s, IStyleSheet.NORMAL_STYLES); sheet1.setStyleId(s.getId()); lay.setBackgroundColor(res.getColor(R.color.dark_gray)); boxes.put(root.topic.getId(), root); for (ITopic t : root.topic.getAllChildren()) { Box b = new Box(); b.topic = t; b.point = new pl.edu.agh.mindmapex.common.Point(); boxes.put(root.topic.getId(), root); if (b.topic.getStyleId() != null) { checkStyle(b); } else { b.setDrawableShape(res.getDrawable(R.drawable.elipse)); } b.parent = root; root.addChild(b); Utils.fireAddSubtopic(b, boxes); rootTopic.add(b.topic, 0, ITopic.ATTACHED); boxes.put(t.getId(), b); } Utils.findRelationships(boxes); } } } else if (style.equals("Default")) { rootTopic.setTitleText("Central Topic"); root.topic = rootTopic; root.topic.setFolded(false); root.setDrawableShape(res.getDrawable(R.drawable.round_rect)); IStyle style3 = styleSheet.createStyle(IStyle.TOPIC); style3.setProperty(Styles.FillColor, "#CCE5FF"); style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ROUNDEDRECT); style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_STRAIGHT); styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES); rootTopic.setStyleId(style3.getId()); } else if (style.equals("Classic")) { rootTopic.setTitleText("Central Topic"); root.topic = rootTopic; root.topic.setFolded(false); root.setDrawableShape(res.getDrawable(R.drawable.elipse)); IStyle style2 = styleSheet.createStyle(IStyle.THEME); style2.setName("%classic"); style2.setProperty(Styles.FillColor, String.valueOf(res.getColor(R.color.light_yellow))); styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES); sheet1.setThemeId(style2.getId()); IStyle style3 = styleSheet.createStyle(IStyle.TOPIC); style3.setProperty(Styles.FillColor, "#9ACD32"); style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ELLIPSE); style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_CURVE); styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES); style2.setProperty(Style.TOPIC, style3.getId()); rootTopic.setStyleId(style3.getId()); } else if (style.equals("Simple")) { rootTopic.setTitleText("Central Topic"); root.topic = rootTopic; root.topic.setFolded(false); root.setDrawableShape(res.getDrawable(R.drawable.elipse)); IStyle style2 = styleSheet.createStyle(IStyle.THEME); style2.setName("%simple"); style2.setProperty(Styles.FillColor, String.valueOf(res.getColor(R.color.white))); styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES); sheet1.setThemeId(style2.getId()); IStyle style3 = styleSheet.createStyle(IStyle.TOPIC); style3.setProperty(Styles.FillColor, "#FFFFFF"); style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ELLIPSE); style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_CURVE); styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES); style2.setProperty(Style.TOPIC, style3.getId()); rootTopic.setStyleId(style3.getId()); } else if (style.equals("Business")) { rootTopic.setTitleText("Central Topic"); root.topic = rootTopic; root.topic.setFolded(false); root.setDrawableShape(res.getDrawable(R.drawable.round_rect)); IStyle style2 = styleSheet.createStyle(IStyle.THEME); style2.setName("%business"); style2.setProperty(Styles.FillColor, String.valueOf(res.getColor(R.color.white))); styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES); sheet1.setThemeId(style2.getId()); IStyle style3 = styleSheet.createStyle(IStyle.TOPIC); style3.setProperty(Styles.FillColor, "#B87333"); style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ROUNDEDRECT); style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_CURVE); styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES); style2.setProperty(Style.TOPIC, style3.getId()); rootTopic.setStyleId(style3.getId()); } else if (style.equals("Academese")) { rootTopic.setTitleText("Central Topic"); root.topic = rootTopic; root.topic.setFolded(false); root.setDrawableShape(res.getDrawable(R.drawable.rect)); IStyle style2 = styleSheet.createStyle(IStyle.THEME); style2.setProperty(Styles.FillColor, "#404040"); styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES); sheet1.setStyleId(style2.getId()); lay.setBackgroundColor(res.getColor(R.color.dark_gray)); IStyle style3 = styleSheet.createStyle(IStyle.TOPIC); style3.setProperty(Styles.FillColor, "#404040"); style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_RECT); style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_STRAIGHT); style3.setProperty(Styles.LineColor, "#FFFFFF"); styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES); style2.setProperty(Style.TOPIC, style3.getId()); rootTopic.setStyleId(style3.getId()); } } }); } else { setContentView(R.layout.main_content_view); lay = (DrawView) findViewById(R.id.main_draw_view); lay.setZOrderOnTop(true); } gestureDetector = new GestureDetector(this, gestList); Utils.lay = lay; if (lay != null) { lay.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); switch (event.getActionMasked()) { case (MotionEvent.ACTION_OUTSIDE): return true; case (MotionEvent.ACTION_UP): break; case MotionEvent.ACTION_POINTER_UP: if (!detector.isInProgress()) { int count = event.getPointerCount(); // Number of 'fingers' in this time Utils.getCoordsInView(lay, event, 1); boxEdited = Utils.whichBox(lay, event); float[] tab1 = Utils.getCoordsInView(lay, event, 0); float[] tab = Utils.getCoordsInView(lay, event, 1); if (count == 2 && boxEdited != null) { if (tab.length == 2) { if (mTourGuide != null) mTourGuide.cleanUp(); Box box1 = new Box(); box1.setPoint(new pl.edu.agh.mindmapex.common.Point( (int) tab[0] - (box1.getWidth() / 2), (int) tab[1] - (box1.getHeight() / 2))); AddBox addBox = new AddBox(); Properties properties = new Properties(); properties.put("box", MainActivity.boxEdited); properties.put("new_box", box1); properties.put("root", root); properties.put("res", res); properties.put("style", style); addBox.execute(properties); MainActivity.addCommendUndo(addBox); editContent(box1, addBox); lay.updateBoxWithText(box1); } } break; } default: break; } boolean response = gestureDetector.onTouchEvent(event); lay.requestFocus(); InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(lay.getApplicationWindowToken(), 0); return response; } }); lay.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } Utils.context = this; this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.show(); detector = new ScaleGestureDetector(this, new SimpleOnScaleGestureListener() { @Override public boolean onScaleBegin(ScaleGestureDetector detector) { mScaling = true; return true; } @Override public boolean onScale(ScaleGestureDetector detector) { // float focusX = detector.getFocusX(); // float focusY = detector.getFocusY(); //// lay.setPivotX(mid.x); //// lay.setPivotY(mid.y); //// lay.pivotx = (int) (lastFocusX + detector.getFocusX())/2; //// lay.pivoty = (int) (lastFocusY+ detector.getFocusY())/2; // // lay.pivotx = (int) mid.x; // // lay.pivoty = (int) mid.y; // // lay.canvas.translate(-focusX,-focusY); lay.pivotx = detector.getFocusX(); lay.pivoty = detector.getFocusY(); // lay.transx = (lay.pivotx); // lay.transy = (lay.pivoty); // lay.pivotx = (int) mid.x; // lay.pivoty = (int) mid.y; // lay.setPivotX(lastFocusX); // lay.setPivotY(lastFocusY); float SF = detector.getScaleFactor(); lay.zoomx *= SF; lay.zoomy *= SF; // lay.canvas.scale(SF, SF, mid.x, mid.y); // float focusShiftX = focusX - lastFocusX; // float focusShiftY = focusY - lastFocusY; //lay.canvas.translate(focusX + focusShiftX, focusY + focusShiftY); // lastFocusX = focusX; // lastFocusY = focusY; // lay.transy = detector.getFocusY(); // lay.zoomx = Math.max(0.1f, Math.min(lay.zoomx, 5.0f)); // lay.zoomy = Math.max(0.1f, Math.min(lay.zoomy, 5.0f)); return true; } }); progressDialog.dismiss(); lay.setId(View.generateViewId()); lay.setSaveEnabled(true); if (savedInstanceState != null) { lay.transx = savedInstanceState.getFloat(TRANSX_KEY); lay.transy = savedInstanceState.getFloat(TRANSY_KEY); lay.zoomx = savedInstanceState.getFloat(ZOOMX_KEY); lay.zoomy = savedInstanceState.getFloat(ZOOMY_KEY); lay.pivotx = savedInstanceState.getFloat(PIVOTX_KEY); lay.pivoty = savedInstanceState.getFloat(PIVOTY_KEY); } }
From source file:devlight.io.library.ArcProgressStackView.java
@Override public boolean onTouchEvent(final MotionEvent event) { if (!mIsDragged) return super.onTouchEvent(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mActionMoveModelIndex = DISABLE_ANIMATE_INDEX; // Get current move angle and check whether touched angle is in sweep angle zone float currentAngle = getActionMoveAngle(event.getX(), event.getY()); if (currentAngle > mSweepAngle && currentAngle < MAX_ANGLE) break; for (int i = 0; i < mModels.size(); i++) { final Model model = mModels.get(i); // Check if our model contains touch points if (model.mBounds.contains(event.getX(), event.getY())) { // Check variables for handle touch in progress model zone float modelRadius = model.mBounds.width() * 0.5F; float modelOffset = mProgressModelSize * 0.5F; float mainRadius = mSize * 0.5F; // Get distance between 2 points final float distance = (float) Math .sqrt(Math.pow(event.getX() - mainRadius, 2) + Math.pow(event.getY() - mainRadius, 2)); if (distance > modelRadius - modelOffset && distance < modelRadius + modelOffset) { mActionMoveModelIndex = i; mIsActionMoved = true; handleActionMoveModel(event); animateActionMoveProgress(); }// w w w .j a v a2 s . com } } break; case MotionEvent.ACTION_MOVE: if (mActionMoveModelIndex == DISABLE_ANIMATE_INDEX && !mIsActionMoved) break; if (mProgressAnimator.isRunning()) break; handleActionMoveModel(event); postInvalidate(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset values mActionMoveLastSlice = DEFAULT_SLICE; mActionMoveSliceCounter = 0; mIsActionMoved = false; break; } // If we have parent, so requestDisallowInterceptTouchEvent if (event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) getParent().requestDisallowInterceptTouchEvent(true); return true; }
From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.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;//w w w .ja v a 2s .c om if (!mIsViewPagerMode) break; if (!mIsSwiped) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; else mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); else mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { playSoundEffect(SoundEffectConstants.CLICK); if (mIsHorizontalOrientation) setModelIndex((int) (event.getX() / mModelSize)); else setModelIndex((int) (event.getY() / mModelSize)); } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java
@Override public boolean onTouch(View v, MotionEvent event) { int id = v.getId(); if (id == CRes.plugin_chatkeyboard_btn_voice_input) { float btnWidth = mBtnVoiceInput.getWidth() / 2; float btnHeight = mBtnVoiceInput.getHeight() / 2; float x = event.getX() - btnWidth; float y = event.getY() - btnHeight; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handleRecordWhenDown();/*from ww w. j ava 2 s.com*/ Message message = new Message(); message.what = TIMER_HANDLER_MESSAGE_WHAT; message.arg1 = 0; timerHandler.sendMessage(message); jsonVoiceActionCallback(0); break; case MotionEvent.ACTION_UP: if (mRecordTipsLayout.getVisibility() != View.VISIBLE) { break; } completeRecord(); if (Math.abs(x) > btnWidth || Math.abs(y) > btnWidth) { jsonVoiceActionCallback(-1); } else { jsonVoiceActionCallback(1); } break; case MotionEvent.ACTION_CANCEL: completeRecord(); jsonVoiceActionCallback(-1); break; case MotionEvent.ACTION_OUTSIDE: completeRecord(); jsonVoiceActionCallback(-1); break; case MotionEvent.ACTION_MASK: completeRecord(); jsonVoiceActionCallback(-1); break; case MotionEvent.ACTION_MOVE: if (Math.abs(x) > btnWidth || Math.abs(y) > btnWidth) { mRecordTimes.setVisibility(View.GONE); if (mDragOutsideImg != null) { mRecordTipsImage.setImageDrawable(mDragOutsideImg); } else { mRecordTipsImage.setImageDrawable(mDragOutsideImgDefaule); } } else { mRecordTimes.setVisibility(View.VISIBLE); if (mTouchDownImg != null) { mRecordTipsImage.setImageDrawable(mTouchDownImg); } else { mRecordTipsImage.setImageDrawable(mTouchDownImgDefaule); } } break; } return true; } // outOfTouchView else if (id == CRes.plugin_chatkeyboard_parent_layout) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (!isKeyBoardVisible && !mPagerLayout.isShown()) { return false; } DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); float h = mEditLayout.getHeight(); h = h + (mPagerLayout.isShown() ? mPagerLayout.getHeight() : 0); float y = event.getY(); if (dm.heightPixels - Math.abs(y) > h) { outOfViewTouch(); return true; } } return false; } else if (v == mOutOfTouchView) { if (isKeyBoardVisible || mPagerLayout.isShown()) { outOfViewTouch(); return true; } return false; } return true; }