List of usage examples for android.view MotionEvent getRawY
public final float getRawY()
From source file:timer.com.maydaysdk.MayDayVideoCallFragment.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View viewInfo = inflater.inflate(R.layout.videochat, container, false); // Initialize view mLinearLayoutControls = (LinearLayout) viewInfo.findViewById(R.id.linearLayout_Controls); mLinearLayoutVideo = (LinearLayout) viewInfo.findViewById(R.id.linearLayout_video); mImageViewMute = (ImageView) viewInfo.findViewById(R.id.imageView_mute_audio); mImageViewFullScreen = (ImageView) viewInfo.findViewById(R.id.imageView_fullscreen); mImageViewAnswer = (ImageView) viewInfo.findViewById(R.id.imageView_answer); ImageView imageViewHang = (ImageView) viewInfo.findViewById(R.id.imageView_hangup); mAlertDialog = new AlertDialog.Builder(getActivity()).create(); mImageViewFullScreen.setOnClickListener(this); mImageViewMute.setOnClickListener(this); imageViewHang.setOnClickListener(this); mImageViewAnswer.setOnClickListener(this); Bundle bundle = getArguments();//from w w w . j av a2s. c o m if (bundle.getString(MayDayConstant.AGENT_NAME) != null) { mAgentName = bundle.getString(MayDayConstant.AGENT_NAME); } if (bundle.getString(MayDayConstant.DOMAIN_ADDRESS) != null) { mDomainAddress = bundle.getString(MayDayConstant.DOMAIN_ADDRESS); } if (bundle.getString(MayDayConstant.VIDEO_CALL) != null) { mVideoCall = bundle.getString(MayDayConstant.VIDEO_CALL); } try { //get last device register name mDevice = RCClient.listDevices().get(0); } catch (NullPointerException e) { e.printStackTrace(); } mScalingType = VideoRendererGui.ScalingType.SCALE_ASPECT_FILL; mVideoView = (GLSurfaceView) viewInfo.findViewById(R.id.glView_call); final Intent intent = getActivity().getIntent(); if (intent.getExtras() != null) { if (intent.getAction().equals(RCDevice.OUTGOING_CALL) || intent.getAction().equals(RCDevice.INCOMING_MESSAGE)) { mImageViewAnswer.setVisibility(View.INVISIBLE); } else { mImageViewAnswer.setVisibility(View.VISIBLE); } } // Get device resolution width and height Point size = new Point(); getActivity().getWindowManager().getDefaultDisplay().getSize(size); final int windowWidth = size.x; final int windowHeight = size.y; // GLVideo resize from top to left corner mLinearLayoutVideo.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mLinearLayoutVideo .getLayoutParams(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: int x_cord = (int) event.getRawX(); int y_cord = (int) event.getRawY(); if (x_cord > windowWidth) { x_cord = windowWidth; } if (y_cord > windowHeight) { y_cord = windowHeight; } layoutParams.leftMargin = x_cord - LEFT_MARGIN; layoutParams.topMargin = y_cord - TOP_MARGIN; mLinearLayoutVideo.setLayoutParams(layoutParams); break; default: break; } return true; } }); // Setup video stuff VideoRendererGui.setView(mVideoView, new Runnable() { @Override public void run() { if (mVideoCall != null) { if (mVideoCall.equalsIgnoreCase(MayDayConstant.OUTGOING)) { callAgent(); } } else { videoContextReady(intent); } } }); // Create video renderers. mRemoteRender = VideoRendererGui.create(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIGHT, mScalingType, false); mLocalRender = VideoRendererGui.create(LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, mScalingType, true); mImageViewMute.setVisibility(View.INVISIBLE); return viewInfo; }
From source file:com.jackie.refresh.RefreshLayoutBase.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.d(TAG, "onInterceptTouchEvent() called with: " + "ev = [" + ev.toString() + "]"); // ?//from w w w . j a va2 s .c o m final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { return false; } switch (action) { case MotionEvent.ACTION_DOWN: mLastY = (int) ev.getRawY(); break; case MotionEvent.ACTION_MOVE: mYOffset = (int) ev.getRawX() - mLastY; // ,,,onTouchEvent()?? if (isTop() && mYOffset > 0) { return true; } break; } return false; }
From source file:com.hybunion.common.view.SwipeRefreshLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: firstTouchY = event.getRawY(); break;// w w w.j a va 2s . co m case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: lastTouchY = event.getRawY(); if (canLoadMore()) { loadData(); } break; default: break; } return super.dispatchTouchEvent(event); }
From source file:com.tmall.wireless.tangram3.view.BannerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = ev.getAction(); float x = ev.getRawX(); float y = ev.getRawY(); switch (action) { case MotionEvent.ACTION_DOWN: xDown = x;//from w w w . j a v a 2s. c o m yDown = y; break; case MotionEvent.ACTION_MOVE: int xDiff = (int) (x - xDown); int yDiff = (int) (y - yDown); direction = -xDiff; if (Math.abs(xDiff) >= Math.abs(yDiff)) { getParent().requestDisallowInterceptTouchEvent(true); } else { getParent().requestDisallowInterceptTouchEvent(false); } break; case MotionEvent.ACTION_UP: direction = 1; break; default: break; } return false; }
From source file:com.haarman.listviewanimations.itemmanipulation.SwipeDismissListViewTouchListener.java
private boolean handleDownEvent(MotionEvent motionEvent) { if (mPaused) { return false; }/* w w w . j a v a 2 s. co m*/ mSwipeInitiated = false; // Find the child view that was touched (perform a hit test) Rect rect = new Rect(); int childCount = mListView.getChildCount(); int[] listViewCoords = new int[2]; mListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View downView = null; for (int i = 0; i < childCount && downView == null; i++) { View child = mListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { downView = child; } } if (downView != null) { Log.d("SwipeDismissListViewTouchListener", "hit child !"); mDownX = motionEvent.getRawX(); mDownY = motionEvent.getRawY(); int downPosition = mListView.getPositionForView(downView); mCurrentDismissData = createPendingDismissData(downPosition, downView); if (mPendingDismisses.contains(mCurrentDismissData) || downPosition >= mVirtualListCount) { // Cancel, we're already processing this position mCurrentDismissData = null; return false; } else { mTouchChildTouched = !mIsParentHorizontalScrollContainer && (mResIdOfTouchChild == 0); if (mResIdOfTouchChild != 0) { mIsParentHorizontalScrollContainer = false; final View childView = downView.findViewById(mResIdOfTouchChild); if (childView != null) { final Rect childRect = getChildViewRect(mListView, childView); if (childRect.contains((int) mDownX, (int) mDownY)) { mTouchChildTouched = true; mListView.requestDisallowInterceptTouchEvent(true); } } } if (mIsParentHorizontalScrollContainer) { // Do it now and don't wait until the user moves more than // the slop factor. mTouchChildTouched = true; mListView.requestDisallowInterceptTouchEvent(true); } mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } } return true; }
From source file:com.android.deskclock.alarms.AlarmActivity.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mAlarmHandled) { LogUtils.v(LOGTAG, "onTouch ignored: %s", motionEvent); return false; }// w ww . j a v a 2s . co m final int[] contentLocation = { 0, 0 }; mContentView.getLocationOnScreen(contentLocation); final float x = motionEvent.getRawX() - contentLocation[0]; final float y = motionEvent.getRawY() - contentLocation[1]; final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft(); final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight(); final float snoozeFraction, dismissFraction; if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x); dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x); } else { snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x); dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x); } setAnimatedFractions(snoozeFraction, dismissFraction); switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: LogUtils.v(LOGTAG, "onTouch started: %s", motionEvent); // Stop the pulse, allowing the last pulse to finish. mPulseAnimator.setRepeatCount(0); break; case MotionEvent.ACTION_UP: LogUtils.v(LOGTAG, "onTouch ended: %s", motionEvent); if (snoozeFraction == 1.0f) { snooze(); } else if (dismissFraction == 1.0f) { dismiss(); } else { if (snoozeFraction > 0.0f || dismissFraction > 0.0f) { // Animate back to the initial state. AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator); } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) { // User touched the alarm button, hint the dismiss action hintDismiss(); } // Restart the pulse. mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE); if (!mPulseAnimator.isStarted()) { mPulseAnimator.start(); } } break; case MotionEvent.ACTION_CANCEL: resetAnimations(); break; default: break; } return true; }
From source file:de.Maxr1998.xposed.maxlock.ui.LockFragment.java
@SuppressWarnings("deprecation") private void setupKnockCodeLayout() { final View container = rootView.findViewById(R.id.container); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) container.getLayoutParams(); params.setMargins(0, 0, 0, 0);// w ww .ja v a 2s . c o m container.setLayoutParams(params); container.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { if (e.getActionMasked() == MotionEvent.ACTION_DOWN) { mInputText.append("\u2022"); // Center values int[] loc = new int[2]; container.getLocationOnScreen(loc); int viewCenterX = loc[0] + container.getWidth() / 2; int viewCenterY = loc[1] + container.getHeight() / 2; // Track touch positions knockCodeX.add(e.getRawX()); knockCodeY.add(e.getRawY()); if (knockCodeX.size() != knockCodeY.size()) { throw new RuntimeException("The amount of the X and Y coordinates doesn't match!"); } // Calculate center float centerX; float differenceX = Collections.max(knockCodeX) - Collections.min(knockCodeX); if (differenceX > 50) { centerX = Collections.min(knockCodeX) + differenceX / 2; } else centerX = viewCenterX; float centerY; float differenceY = Collections.max(knockCodeY) - Collections.min(knockCodeY); if (differenceY > 50) { centerY = Collections.min(knockCodeY) + differenceY / 2; } else centerY = viewCenterY; // Calculate key key.setLength(0); for (int i = 0; i < knockCodeX.size(); i++) { float x = knockCodeX.get(i), y = knockCodeY.get(i); if (x < centerX && y < centerY) key.append("1"); else if (x > centerX && y < centerY) key.append("2"); else if (x < centerX && y > centerY) key.append("3"); else if (x > centerX && y > centerY) key.append("4"); } checkInput(); return true; } return false; } }); divider = new View(getActivity()); divider.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Math.round(getResources().getDisplayMetrics().density))); divider.setBackgroundColor(getResources().getColor(R.color.light_white)); ((ViewGroup) container).addView(divider); if (prefs.getBoolean(Common.INVERT_COLOR, false) && prefs.getBoolean(Common.KC_SHOW_DIVIDERS, true)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) divider.setBackground(getResources().getDrawable(android.R.color.black)); else divider.setBackgroundDrawable(getResources().getDrawable(android.R.color.black)); } else if (!prefs.getBoolean(Common.KC_SHOW_DIVIDERS, true) || screenWidth > screenHeight) { divider.setVisibility(View.GONE); } }
From source file:demo.camera.library.ui.CameraCaptureActivity.java
public void setUpUi() { mBlockerSpinner = (RelativeLayout) findViewById(R.id.blocker); mBlockerSpinner.setVisibility(View.GONE); mTouchIndicator = (ImageView) findViewById(R.id.touchIndicator); mTouchInterceptor = (RelativeLayout) findViewById(R.id.touch_interceptor); mTouchInterceptor.setOnTouchListener(new View.OnTouchListener() { @Override/*from ww w .j av a 2 s . c om*/ public boolean onTouch(View v, MotionEvent event) { mTouchIndicator.setImageResource(R.drawable.white_circle); mTouchIndicator.setVisibility(View.VISIBLE); final int X = (int) event.getRawX(); final int Y = (int) event.getRawY(); RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) mTouchIndicator .getLayoutParams(); lParams.leftMargin = X - mTouchIndicator.getWidth() / 2; lParams.topMargin = Y - mTouchIndicator.getHeight() / 2; mTouchIndicator.setLayoutParams(lParams); mTouchIndicator.invalidate(); ScaleAnimation scaleUpAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5); scaleUpAnimation.setDuration(350); scaleUpAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mTouchIndicator.postDelayed(new Runnable() { @Override public void run() { mTouchIndicator.setVisibility(View.GONE); } }, 100); } @Override public void onAnimationRepeat(Animation animation) { } }); mTouchIndicator.startAnimation(scaleUpAnimation); return false; } }); // mTouchInterceptor.setVisibility(View.GONE); mRecordButton = (Button) findViewById(R.id.recordButton); mExtrasContainer = (LinearLayout) findViewById(R.id.settings_container); mMoreOptions = (ImageView) findViewById(R.id.icon_more); mMoreOptions.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mMoreOptions.setSelected(!mMoreOptions.isSelected()); if (mMoreOptions.isSelected()) { mExtrasContainer.setVisibility(View.VISIBLE); } else { mExtrasContainer.setVisibility(View.GONE); } } }); // mRecordButton .setOnClickListener(mRecordButtonClickListener); setUpTouchInterceptor(mRecordButton); setUpHeaders(); setUpFlashButton(); setUpProgressIndicator(); // setupFilterSpinner(); setupCameraFlipper(); }
From source file:com.timemachine.controller.ControllerActivity.java
private void setupUI() { // Set layout listener View controllerView = findViewById(R.id.controllerView); ViewTreeObserver vto = controllerView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override// w ww. j a v a2s .c om public void onGlobalLayout() { runOnUiThread(new Runnable() { public void run() { locationSliderHeight = locationSlider.getHeight(); originLocationSliderContainerY = locationSliderContainer.getY(); originPlayPauseButtonY = playPause.getY(); minLocationSliderContainerY = originLocationSliderContainerY; maxLocationSliderContainerY = originLocationSliderContainerY + locationSliderHeight; midLocationSliderContainerY = (minLocationSliderContainerY + maxLocationSliderContainerY) / 2; } }); System.out.println("locationSliderHeight: " + locationSliderHeight); System.out.println("locationSliderContainerY: " + originLocationSliderContainerY); locationSlider.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); // Connect to controller.html controllerURL = "http://" + ipText + ":8080/controller.html"; locationSlider = (WebView) findViewById(R.id.webview); locationSliderContainer = (FrameLayout) findViewById(R.id.sliderContainer); locationSlider.setBackgroundColor(Color.TRANSPARENT); locationSlider.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); locationSlider.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { System.out.println("onReceivedError"); showConnectDialog("Error while connecting to controller. Connect again."); } @Override public void onLoadResource(WebView view, String url) { if (url.contains("thumbnail")) isMasterConnected = true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { isMasterConnectedTimerTask = null; isMasterConnectedTimerTask = new TimerTask() { @Override public void run() { if (isMasterConnected == false) showConnectDialog("Master is not loaded in the browser. Connect again."); } }; isMasterConnectedTimer.schedule(isMasterConnectedTimerTask, 6000); } @Override public void onPageFinished(WebView view, String url) { if (url.contains(controllerURL)) { drag.setVisibility(View.VISIBLE); playPause.setVisibility(View.VISIBLE); loadPreferences(); } super.onPageFinished(view, url); } }); try { locationSlider.loadUrl(controllerURL); } catch (Exception e) { e.printStackTrace(); } // Set JavaScript Interface locationSlider.addJavascriptInterface(this, "androidObject"); WebSettings webSettings = locationSlider.getSettings(); webSettings.setJavaScriptEnabled(true); // Set the play-pause button playPause = (ImageButton) findViewById(R.id.playPauseButton); playPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { socket.emit("handlePlayPauseServer"); } }); socket.emit("setControllerPlayButton"); // Set the drag button drag = (ImageButton) findViewById(R.id.drag); drag.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { dragYDiffBetweenFingerAndSliderTop = locationSliderContainer.getY() - event.getRawY(); dragYDiffBetweenFingerAndPlayPauseTop = playPause.getY() - event.getRawY(); } if (event.getAction() == MotionEvent.ACTION_MOVE) { // Move the slider based on current finger location float newSliderY = event.getRawY() + dragYDiffBetweenFingerAndSliderTop; float newPlayPauseY = event.getRawY() + dragYDiffBetweenFingerAndPlayPauseTop; if (newSliderY > minLocationSliderContainerY && newSliderY < maxLocationSliderContainerY) { locationSliderContainer.setY(newSliderY); playPause.setY(newPlayPauseY); } } if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getEventTime() - event.getDownTime() <= tapTimeout) { // Tap is detected, toggle the slider System.out.println("onTap"); runOnUiThread(new Runnable() { public void run() { toggleSlider(); } }); } else { // Not a tap gesture, slide up or down based on the slider's current position if (locationSliderContainer.getY() > midLocationSliderContainerY) slideDown(); else slideUp(); } } return true; } }); // Set the Google map setUpMapIfNeeded(); }
From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mAlarmHandled) { LogUtils.v(LOGTAG, "onTouch ignored: %s", motionEvent); return false; }// ww w. j a v a 2s.co m final int[] contentLocation = { 0, 0 }; mContentView.getLocationOnScreen(contentLocation); final float x = motionEvent.getRawX() - contentLocation[0]; final float y = motionEvent.getRawY() - contentLocation[1]; final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft(); final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight(); final float snoozeFraction, dismissFraction; if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL) { snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x); dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x); } else { snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x); dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x); } // API >= 17 /*if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x); dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x); } else { snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x); dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x); }*/ setAnimatedFractions(snoozeFraction, dismissFraction); switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: LogUtils.v(LOGTAG, "onTouch started: %s", motionEvent); // Stop the pulse, allowing the last pulse to finish. mPulseAnimator.setRepeatCount(0); break; case MotionEvent.ACTION_UP: LogUtils.v(LOGTAG, "onTouch ended: %s", motionEvent); if (snoozeFraction == 1.0f) { snooze(); } else if (dismissFraction == 1.0f) { dismiss(); } else { if (snoozeFraction > 0.0f || dismissFraction > 0.0f) { // Animate back to the initial state. AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator); } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) { // User touched the alarm button, hint the dismiss action hintDismiss(); } // Restart the pulse. mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE); if (!mPulseAnimator.isStarted()) { mPulseAnimator.start(); } } break; case MotionEvent.ACTION_CANCEL: resetAnimations(); break; default: break; } return true; }