List of usage examples for android.view MotionEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view MotionEvent ACTION_DOWN.
Click Source Link
From source file:it.angrydroids.epub3reader.TextSelectionSupport.java
@Override public boolean onTouch(View v, MotionEvent event) { final Context ctx = mActivity; float xPoint = getDensityIndependentValue(event.getX(), ctx) / getDensityIndependentValue(mScale, ctx); float yPoint = getDensityIndependentValue(event.getY(), ctx) / getDensityIndependentValue(mScale, ctx); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: final String startTouchUrl = String.format("javascript:android.selection.startTouch(%f, %f);", xPoint, yPoint);/* ww w.ja v a 2 s . co m*/ mLastTouchX = xPoint; mLastTouchY = yPoint; mWebView.loadUrl(startTouchUrl); break; case MotionEvent.ACTION_UP: if (!mScrolling) { endSelectionMode(); // // Fixes 4.4 double selection // See: // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return false; } } mScrollDiffX = 0; mScrollDiffY = 0; mScrolling = false; // // Fixes 4.4 double selection // See: // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return true; } break; case MotionEvent.ACTION_MOVE: mScrollDiffX += (xPoint - mLastTouchX); mScrollDiffY += (yPoint - mLastTouchY); mLastTouchX = xPoint; mLastTouchY = yPoint; if (Math.abs(mScrollDiffX) > SCROLLING_THRESHOLD || Math.abs(mScrollDiffY) > SCROLLING_THRESHOLD) { mScrolling = true; } break; } return false; }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); virtualIntent.addCategory(Intent.CATEGORY_OPENABLE); virtualIntent.setType("*/*"); virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);//from ww w. j a v a2s. c o m final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { if (DEBUG) { Log.i(TAG, "mState"); } buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = virtualIntent.getType(); final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(virtualIntent); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = virtualIntent.getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }
From source file:android.support.designox.widget.BottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }/* w ww. j a v a 2 s .co m*/ int action = MotionEventCompat.getActionMasked(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.INVALID_POINTER_ID; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return false; } break; case MotionEvent.ACTION_DOWN: int initialX = (int) event.getX(); mInitialY = (int) event.getY(); View scroll = mNestedScrollingChildRef.get(); if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID && !parent.isPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) { return true; } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. View scroll = mNestedScrollingChildRef.get(); return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.easemob.chatuidemo.activity.GroupDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ??groupid/*from w w w . j a v a 2 s .c om*/ groupId = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(groupId); // we are not supposed to show the group if we don't find the group if (group == null) { finish(); return; } setContentView(R.layout.activity_group_details); instance = this; st = getResources().getString(R.string.people); clearAllHistory = (RelativeLayout) findViewById(R.id.clear_all_history); userGridview = (ExpandGridView) findViewById(R.id.gridview); loadingPB = (ProgressBar) findViewById(R.id.progressBar); exitBtn = (Button) findViewById(R.id.btn_exit_grp); deleteBtn = (Button) findViewById(R.id.btn_exitdel_grp); blacklistLayout = (RelativeLayout) findViewById(R.id.rl_blacklist); changeGroupNameLayout = (RelativeLayout) findViewById(R.id.rl_change_group_name); idLayout = (RelativeLayout) findViewById(R.id.rl_group_id); idLayout.setVisibility(View.VISIBLE); idText = (TextView) findViewById(R.id.tv_group_id_value); rl_switch_block_groupmsg = (RelativeLayout) findViewById(R.id.rl_switch_block_groupmsg); iv_switch_block_groupmsg = (ImageView) findViewById(R.id.iv_switch_block_groupmsg); iv_switch_unblock_groupmsg = (ImageView) findViewById(R.id.iv_switch_unblock_groupmsg); rl_switch_block_groupmsg.setOnClickListener(this); Drawable referenceDrawable = getResources().getDrawable(R.drawable.smiley_add_btn); referenceWidth = referenceDrawable.getIntrinsicWidth(); referenceHeight = referenceDrawable.getIntrinsicHeight(); idText.setText(groupId); if (group.getOwner() == null || "".equals(group.getOwner()) || !group.getOwner().equals(EMChatManager.getInstance().getCurrentUser())) { exitBtn.setVisibility(View.GONE); deleteBtn.setVisibility(View.GONE); blacklistLayout.setVisibility(View.GONE); changeGroupNameLayout.setVisibility(View.GONE); } // if (EMChatManager.getInstance().getCurrentUser().equals(group.getOwner())) { exitBtn.setVisibility(View.GONE); deleteBtn.setVisibility(View.VISIBLE); } ((TextView) findViewById(R.id.group_name)) .setText(group.getGroupName() + "(" + group.getAffiliationsCount() + st); List<String> members = new ArrayList<String>(); members.addAll(group.getMembers()); adapter = new GridAdapter(this, R.layout.grid, members); userGridview.setAdapter(adapter); // ???group updateGroup(); // OnTouchListener userGridview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (adapter.isInDeleteMode) { adapter.isInDeleteMode = false; adapter.notifyDataSetChanged(); return true; } break; default: break; } return false; } }); clearAllHistory.setOnClickListener(this); blacklistLayout.setOnClickListener(this); changeGroupNameLayout.setOnClickListener(this); }
From source file:com.android2.calculator3.view.CalculatorPadView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!mInterceptingTouchEvents) { onInterceptTouchEvent(event);/* w ww.j ava 2s.c om*/ return true; } int action = MotionEventCompat.getActionMasked(event); if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); switch (action) { case MotionEvent.ACTION_DOWN: // Handled in intercept break; case MotionEvent.ACTION_MOVE: handleMove(event); break; case MotionEvent.ACTION_UP: handleUp(event); break; } return true; }
From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(@NonNull MotionEvent event) { ensureTarget();// w w w . j av a2 s. com if (!isEnabled() || canChildScrollUp() || isRefreshing()) { return false; } final int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(event, 0); mFirstTouchDownPointY = getMotionEventY(event, mActivePointerId); break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { return false; } final float currentY = getMotionEventY(event, mActivePointerId); if (currentY == -1) { return false; } if (mFirstTouchDownPointY == -1) { mFirstTouchDownPointY = currentY; } final float yDiff = currentY - mFirstTouchDownPointY; // State is changed to drag if over slop if (yDiff > ViewConfiguration.get(getContext()).getScaledTouchSlop() && !isRefreshing()) { mCircleView.makeProgressTransparent(); return true; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mActivePointerId = INVALID_POINTER; break; } return false; }
From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentTouchY = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastDispatchY = currentTouchY;// www.ja v a2s . c o m break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastDispatchY; mLastDispatchY = currentTouchY; if (isContentViewToTop() && isHeaderViewCompleteInvisible()) { if (differentY >= 0 && !mIsInControl) { mIsInControl = true; return resetDispatchTouchEvent(ev); } if (differentY <= 0 && mIsInControl) { mIsInControl = false; return resetDispatchTouchEvent(ev); } } break; } return super.dispatchTouchEvent(ev); }
From source file:ca.frozen.rpicameraviewer.activities.VideoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_video, container, false); // configure the name nameView = (TextView) view.findViewById(R.id.video_name); nameView.setText(camera.name);/*from w w w . j a va 2s .c o m*/ // initialize the message messageView = (TextView) view.findViewById(R.id.video_message); messageView.setTextColor(App.getClr(R.color.good_text)); messageView.setText(R.string.initializing_video); // set the texture listener textureView = (ZoomPanTextureView) view.findViewById(R.id.video_surface); textureView.setSurfaceTextureListener(this); textureView.setZoomRange(MIN_ZOOM, MAX_ZOOM); textureView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: stopFadeOutTimer(); break; case MotionEvent.ACTION_UP: if (e.getPointerCount() == 1) { startFadeOutTimer(false); } break; } return false; } }); // create the snapshot button snapshotButton = (Button) view.findViewById(R.id.video_snapshot); snapshotButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int check = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (check != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_EXTERNAL_STORAGE); } else { takeSnapshot(); } } }); // move the snapshot button over to account for the navigation bar if (fullScreen) { float scale = getContext().getResources().getDisplayMetrics().density; int margin = (int) (5 * scale + 0.5f); int extra = Utils.getNavigationBarHeight(getContext(), Configuration.ORIENTATION_LANDSCAPE); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) snapshotButton.getLayoutParams(); lp.setMargins(margin, margin, margin + extra, margin); } return view; }
From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String data = prefs.getString("AFilmModel", null); Gson gson = new Gson(); AFilmModel aFilm = gson.fromJson(data, AFilmModel.class); String link = "http://nhatphim.com/index/api-detail?id=" + aFilm.getId(); getListVideo(link);//from w w w. j a v a 2 s .c om // contentUri = Uri.parse("http://www.phim3s.net/phim-bo/thien-kim-tro-ve_8328/xem-phim/221808/video.mp4"); /* contentUri = Uri.parse("http://www.phim3s.net/phim-bo/thien-kim-tro-ve_8328/xem-phim/221808/video.mp4");*/ contentType = 2; contentId = "dizzy"; setContentView(R.layout.player_activity); root = findViewById(R.id.root); root.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { toggleControlsVisibility(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { view.performClick(); } return true; } }); shutterView = findViewById(R.id.shutter); debugRootView = findViewById(R.id.controls_root); surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view); surfaceView.getHolder().addCallback(this); debugTextView = (TextView) findViewById(R.id.debug_text_view); playerStateTextView = (TextView) findViewById(R.id.player_state_view); subtitleView = (SubtitleView) findViewById(R.id.subtitles); mediaController = new VideoControllerView(this); mediaController.setAnchorView((FrameLayout) root); mediaController.setPrevNextListeners(new OnClickListener() { @Override public void onClick(View v) { //next button clicked Toast t = Toast.makeText(PlayerActivity.this, "click", Toast.LENGTH_SHORT); t.show(); } }, new OnClickListener() { @Override public void onClick(View v) { Toast t = Toast.makeText(PlayerActivity.this, "pt bt", Toast.LENGTH_SHORT); t.show(); } }); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); videoButton = (Button) findViewById(R.id.video_controls); audioButton = (Button) findViewById(R.id.audio_controls); textButton = (Button) findViewById(R.id.text_controls); DemoUtil.setDefaultCookieManager(); configureSubtitleView(); delegate = new Listener() { @Override public void GetFinish() { // adapter = new NavDrawerListAdapter(PlayerActivity.this,Film.getServer()); // lv.setAdapter(adapter); contentUri = Uri.parse(Film.getServer().get(0).getLink()); if (player == null && contentUri != null) { preparePlayer(); ProgressBar progressBar = (ProgressBar) root.findViewById(R.id.progressBar); progressBar.setVisibility(View.GONE); ///////////////////////////////////////////// FragmentManager fragmentManager; FragmentTransaction fragmentTransaction; fragmentManager = getSupportFragmentManager(); fragmentTransaction = fragmentManager.beginTransaction(); VerticalGridFragment verticalFragment = new VerticalGridFragment(PlayerActivity.this, Film.getServer()); fragmentTransaction.replace(R.id.view_fm, verticalFragment); fragmentTransaction.commit(); } } }; recyclerViewDesign(); }
From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return super.onTouchEvent(ev); }/* www.jav a2 s . co m*/ mVelocityTracker.addMovement(ev); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mActivePointerId = ev.getPointerId(0); if (findChildUnder(mInitialTouchX, mInitialTouchY) == null && mClickOutsideListener != null) { mIsDragging = handled = true; } handled |= mCollapsibleHeight > 0; mScroller.abortAnimation(); } break; case MotionEvent.ACTION_MOVE: { int index = ev.findPointerIndex(mActivePointerId); if (index < 0) { Log.e(TAG, "Bad pointer id " + mActivePointerId + ", resetting"); index = 0; mActivePointerId = ev.getPointerId(0); mInitialTouchX = ev.getX(); mInitialTouchY = mLastTouchY = ev.getY(); } final float x = ev.getX(index); final float y = ev.getY(index); if (!mIsDragging) { final float dy = y - mInitialTouchY; if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) { handled = mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } if (mIsDragging) { final float dy = y - mLastTouchY; performDrag(dy); } mLastTouchY = y; } break; case MotionEvent.ACTION_POINTER_DOWN: { final int pointerIndex = ev.getActionIndex(); final int pointerId = ev.getPointerId(pointerIndex); mActivePointerId = pointerId; mInitialTouchX = ev.getX(pointerIndex); mInitialTouchY = mLastTouchY = ev.getY(pointerIndex); } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_UP: { mIsDragging = false; if (!mIsDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null && findChildUnder(ev.getX(), ev.getY()) == null) { if (mClickOutsideListener != null) { mClickOutsideListener.onClick(this); resetTouch(); return true; } } if (mOpenOnClick && Math.abs(ev.getX() - mInitialTouchX) < mTouchSlop && Math.abs(ev.getY() - mInitialTouchY) < mTouchSlop) { smoothScrollTo(0, 0); return true; } mVelocityTracker.computeCurrentVelocity(1000); final float yvel = mVelocityTracker.getYVelocity(mActivePointerId); if (Math.abs(yvel) > mMinFlingVelocity) { smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel); } else { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); } break; case MotionEvent.ACTION_CANCEL: { if (mIsDragging) { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); return true; } } return handled || (action == MotionEvent.ACTION_MOVE && mCollapseOffset > 0); }