List of usage examples for android.view MotionEvent ACTION_UP
int ACTION_UP
To view the source code for android.view MotionEvent ACTION_UP.
Click Source Link
From source file:ch.jeda.platform.android.CanvasFragment.java
@Override public boolean onTouch(final View view, final MotionEvent event) { int index;// www . ja va 2s . c om switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: index = event.getActionIndex(); this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_DOWN, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: index = event.getActionIndex(); this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_UP, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); break; case MotionEvent.ACTION_MOVE: for (index = 0; index < event.getPointerCount(); ++index) { this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_MOVED, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); } break; } return true; }
From source file:ca.hoogit.garagepi.Controls.DoorView.java
private void init(Context context, AttributeSet attrs, int defStyle) { inflate(getContext(), R.layout.door_view, this); ButterKnife.bind(this); final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DoorView, defStyle, 0); mOpenedColor = a.getColor(R.styleable.DoorView_openedColor, ContextCompat.getColor(context, R.color.colorAccent)); mClosedColor = a.getColor(R.styleable.DoorView_closedColor, ContextCompat.getColor(context, R.color.colorPrimary)); mDoorName = a.getString(R.styleable.DoorView_doorName); a.recycle();//from w w w . j a v a 2 s .c om mContext = context; mToggleContainer.setOnClickListener(OnSingleClickListener.wrap(v -> { if (mOnToggle != null) { mOnToggle.onToggle(mDoorName); } })); mToggleContainer.setOnTouchListener((v, event) -> { int origColor = mDoorValue ? mOpenedColor : mClosedColor; if (event.getAction() == MotionEvent.ACTION_DOWN) { mToggleContainer.setBackgroundColor(ColorUtil.darken(origColor)); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { mToggleContainer.setBackgroundColor(origColor); } return false; }); setupViews(); }
From source file:android.support.v7.widget.AbsActionBarView.java
@Override public boolean onTouchEvent(MotionEvent ev) { // ActionBarViews always eat touch events, but should still respect the touch event dispatch // contract. If the normal View implementation doesn't want the events, we'll just silently // eat the rest of the gesture without reporting the events to the default implementation // since that's what it expects. final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_DOWN) { mEatingTouch = false;// ww w . j a v a2s .co m } if (!mEatingTouch) { final boolean handled = super.onTouchEvent(ev); if (action == MotionEvent.ACTION_DOWN && !handled) { mEatingTouch = true; } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mEatingTouch = false; } return true; }
From source file:br.com.bioscada.apps.biotracks.fragments.StatsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); handler = new Handler(); Spinner activityTypeIcon = (Spinner) getView().findViewById(R.id.stats_activity_type_icon); activityTypeIcon.setAdapter(TrackIconUtils.getIconSpinnerAdapter(getActivity(), "")); activityTypeIcon.setOnTouchListener(new View.OnTouchListener() { @Override/* ww w . jav a 2s . c om*/ public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { ((TrackDetailActivity) getActivity()).chooseActivityType(category); } return true; } }); activityTypeIcon.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { ((TrackDetailActivity) getActivity()).chooseActivityType(category); } return true; } }); }
From source file:com.alex.vmandroid.display.main.fragments.fragments.LoopAdvertisementFragment.java
@Override public void setViewPagerData(List<Integer> pictureList) { LoopAdvertisementAdapter mBannerPagerAdapter = new LoopAdvertisementAdapter(getActivity(), pictureList); mViewPager.setAdapter(mBannerPagerAdapter); mViewPager.setOnTouchListener(new View.OnTouchListener() { int flage = 0; @Override// w w w.ja v a 2 s .co m public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: flage = 0; mIsUserTouched = true; break; case MotionEvent.ACTION_MOVE: mIsUserTouched = true; flage = 1; break; case MotionEvent.ACTION_UP: mIsUserTouched = false; if (flage == 0) { int item = mViewPager.getCurrentItem(); mPresenter.onViewPagerItemClick(item); } break; } return false; } }); startBannerTimer(); }
From source file:com.android.deskclock.VerticalViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { try {/*www. j ava 2 s . com*/ initializeParent(); final float x = ev.getX(); final float y = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mLastMotionX = x; mLastMotionY = y; if (!mParentViewPager.onTouchEvent(ev)) return false; return verticalDrag(ev); } case MotionEvent.ACTION_MOVE: { final float xDiff = Math.abs(x - mLastMotionX); final float yDiff = Math.abs(y - mLastMotionY); if (!mHorizontalDrag && !mVerticalDrag) { if (xDiff > mTouchSlop && xDiff > yDiff) { // Swiping left and right mHorizontalDrag = true; } else if (yDiff > mTouchSlop && yDiff > xDiff) { //Swiping up and down mVerticalDrag = true; } } if (mHorizontalDrag) { return mParentViewPager.onTouchEvent(ev); } else if (mVerticalDrag) { return verticalDrag(ev); } } case MotionEvent.ACTION_UP: { if (mHorizontalDrag) { mHorizontalDrag = false; return mParentViewPager.onTouchEvent(ev); } if (mVerticalDrag) { mVerticalDrag = false; return verticalDrag(ev); } } } // Set both flags to false in case user lifted finger in the parent view pager mHorizontalDrag = false; mVerticalDrag = false; } catch (Exception e) { // The mParentViewPager shouldn't be null, but just in case. If this happens, // app should not crash, instead just ignore the user swipe input // TODO: handle the exception gracefully } return false; }
From source file:com.intel.xdk.multitouch.MultiTouch.java
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); //get convenience reference to activity activity = cordova.getActivity();//from w ww .j a v a 2 s . c o m activity.runOnUiThread(new Runnable() { public void run() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class); m.invoke(WebView.class, true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //WebView.setWebContentsDebuggingEnabled(true); } } }); touchy = new View.OnTouchListener() { private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>(); @Override public boolean onTouch(View v, MotionEvent ev) { if (isMultitouchEnabled) { int pointerCount = ev.getPointerCount(); //get the correct action int maskedAction = ev.getActionMasked(); int idx = ev.getActionIndex(); try { String js = null; if (maskedAction == MotionEvent.ACTION_POINTER_DOWN || maskedAction == MotionEvent.ACTION_DOWN) { int x = (int) ev.getX(idx); int y = (int) ev.getY(idx); int h = (int) v.getHeight(); int w = (int) v.getWidth(); int id = ev.getPointerId(idx); //make a timestamp identifier and store it long identifier = System.currentTimeMillis(); pointerId2Identifier.put(id, identifier); js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y, h, w); queueMultitouchData(js, id, maskedAction); } else if (maskedAction == MotionEvent.ACTION_POINTER_UP || maskedAction == MotionEvent.ACTION_UP) { int x = (int) ev.getX(idx); int y = (int) ev.getY(idx); int h = (int) v.getHeight(); int w = (int) v.getWidth(); int id = ev.getPointerId(idx); js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},", pointerId2Identifier.get(id), x, y, h, w); pointerId2Identifier.remove(id); queueMultitouchData(js, id, maskedAction); } else if (maskedAction == MotionEvent.ACTION_MOVE) { //send all events if it is a move for (int i = 0; i < pointerCount; i++) { int x = (int) ev.getX(i); int y = (int) ev.getY(i); int h = (int) v.getHeight(); int w = (int) v.getWidth(); int id = ev.getPointerId(i); js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},", pointerId2Identifier.get(id), x, y, h, w); queueMultitouchData(js, id, maskedAction); } } else { Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev); } //Log.i("[intel.xdk]", "onTouchEvent:"+js); } catch (Exception e) { Log.e("[intel.xdk]", "Got an exception back from WebView: ", e); } return true; } else { return false; } } }; webView.setOnTouchListener(touchy); lock = this; messages = new ArrayList<String>(0); }
From source file:android.support.v7.widget.DropDownListView.java
/** * Handles forwarded events./* w ww . j a v a 2 s . com*/ * * @param activePointerId id of the pointer that activated forwarding * @return whether the event was handled */ public boolean onForwardedEvent(MotionEvent event, int activePointerId) { boolean handledEvent = true; boolean clearPressedItem = false; final int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_CANCEL: handledEvent = false; break; case MotionEvent.ACTION_UP: handledEvent = false; // $FALL-THROUGH$ case MotionEvent.ACTION_MOVE: final int activeIndex = event.findPointerIndex(activePointerId); if (activeIndex < 0) { handledEvent = false; break; } final int x = (int) event.getX(activeIndex); final int y = (int) event.getY(activeIndex); final int position = pointToPosition(x, y); if (position == INVALID_POSITION) { clearPressedItem = true; break; } final View child = getChildAt(position - getFirstVisiblePosition()); setPressedItem(child, position, x, y); handledEvent = true; if (actionMasked == MotionEvent.ACTION_UP) { clickPressedItem(child, position); } break; } // Failure to handle the event cancels forwarding. if (!handledEvent || clearPressedItem) { clearPressedItem(); } // Manage automatic scrolling. if (handledEvent) { if (mScrollHelper == null) { mScrollHelper = new ListViewAutoScrollHelper(this); } mScrollHelper.setEnabled(true); mScrollHelper.onTouch(this, event); } else if (mScrollHelper != null) { mScrollHelper.setEnabled(false); } return handledEvent; }
From source file:au.com.wallaceit.reddinator.TabWebFragment.java
@SuppressLint("SetJavaScriptEnabled") public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContext = this.getActivity(); if (container == null) { return null; }/*from ww w.ja v a 2 s . co m*/ if (mFirstTime) { // get shared preferences SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this.getActivity().getApplicationContext()); // work out the url this instance should load boolean commentswv = false; if (this.getArguments() != null) { commentswv = this.getArguments().getBoolean("loadcom", false); } int fontsize; String url; if (commentswv) { url = "http://reddit.com" + getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_PERMALINK) + ".compact"; fontsize = Integer.parseInt(prefs.getString("commentfontpref", "22")); } else { url = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_URL); fontsize = Integer.parseInt(prefs.getString("contentfontpref", "18")); } // setup progressbar mActivity = this.getActivity(); mActivity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); ll = (LinearLayout) inflater.inflate(R.layout.tab1, container, false); mWebView = (WebView) ll.findViewById(R.id.webView1); // fixes for webview not taking keyboard input on some devices mWebView.requestFocus(View.FOCUS_DOWN); mWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); mWebView.getSettings().setJavaScriptEnabled(true); // enable ecmascript mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setUseWideViewPort(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.getSettings().setDisplayZoomControls(true); mWebView.getSettings().setDefaultFontSize(fontsize); mChromeClient = newchromeclient; mWebView.setWebChromeClient(mChromeClient); mWebView.setWebViewClient(new WebViewClient()); mWebView.loadUrl(url); mFirstTime = false; //System.out.println("Created fragment"); } else { ((ViewGroup) ll.getParent()).removeView(ll); } return ll; }
From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { //super.onInterceptTouchEvent(event); float endX = event.getX(); float endY = event.getY(); if (isAClick(startX, endX, startY, endY)) { if (mOnItemClickListener != null) { mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem()); }//from ww w . j a v a2 s . c om } else { super.onInterceptTouchEvent(event); } } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { startX = event.getX(); startY = event.getY(); } float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { return super.onInterceptTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }