List of usage examples for android.view MotionEvent getPressure
public final float getPressure()
From source file:io.github.developersofcydonia.freedtouch.FreeDTouch.java
@Override public boolean onTouch(View v, MotionEvent event) { mLastMotionEvent = event;// w ww. j a va2 s.co m if (!mIsPeeking) { mComputedPressureThreshold = getComputedPressureThreshold(event.getPressure(), mSensibility); mComputedSurfaceThreshold = getComputedPressureThreshold(event.getSize(), mSensibility); } else { mPeekHandler.removeCallbacks(mPeekRunnable); if (event.getPressure() >= mComputedPressureThreshold || event.getSize() >= mComputedSurfaceThreshold) { mIsPeeking = false; destroyPopup(); mListener.onPop(mPopup, v, event); } if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { mIsPeeking = false; destroyPopup(); mPeekHandler.removeCallbacks(mPeekRunnable); mListener.onCancel(mPopup, mView, event); } } return mGestureDetector.onTouchEvent(event); }
From source file:com.htc.sample.pen.phonegap.PenPlugin.java
@Override public PluginResult execute(final String action, final JSONArray data, final String callbackId) { Log.d(LOG_TAG, "Plugin Called"); final boolean isPenSupportedAction = IS_PEN_SUPPORTED_ACTION.equals(action); final boolean isStartPenCaptureActivityAction = START_PEN_CAPTURE_ACTIVITY_ACTION.equals(action); final boolean isStartPaintingActivityAction = START_PAINTINT_ACTIVITY_ACTION.equals(action); final boolean isRegisterAction = REGISTER_ACTION.equals(action); final PluginResult result; // If one of our two valid actions was requested... if (isPenSupportedAction || isStartPenCaptureActivityAction || isStartPaintingActivityAction || isRegisterAction) {/*from w w w .j a v a 2s .c om*/ // Check if the pen is supported. boolean isPenSupported = PenFeatureDetector.hasPenEvent(ctx); if (isPenSupported) { // If it is and starting the native Activity was requested, do so now. if (isStartPenCaptureActivityAction) { Intent intent = new Intent(ctx, PenCaptureActivity.class); ctx.startActivity(intent); } else if (isStartPaintingActivityAction) { Intent intent = new Intent(ctx, DrawSignatureActivity.class); ctx.startActivity(intent); } else if (isRegisterAction) { startJaja(callbackId); final View.OnTouchListener penListener = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final boolean isPenEvent = PenEvent.isPenEvent(event); final int action = PenEvent.PenButton(event); final boolean isPenButton1 = (PenEvent.PEN_BUTTON1 == action); final boolean isPenButton2 = (PenEvent.PEN_BUTTON2 == action); final float penPressure = event.getPressure(); sendPenEventToJavascript(callbackId, isPenEvent, isPenButton1, isPenButton2, penPressure); return false; } }; webView.setOnTouchListener(penListener); PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); return pluginResult; } } // Return if the pen was supported. result = new PluginResult(Status.OK, isPenSupported); // Otherwise it is an error. } else { result = new PluginResult(Status.INVALID_ACTION); Log.d(LOG_TAG, "Invalid action : " + action + " passed"); } return result; }
From source file:com.p3authentication.preferences.Prefs.java
@SuppressWarnings("static-access") @Override/*from w w w . j av a 2 s .com*/ public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub int action = event.getAction(); int N = event.getHistorySize(); if (action == event.ACTION_DOWN) { calibrator.setColorFilter(Color.BLACK); for (int i = 0; i < N; i++) { calibrate(event.getHistoricalX(i), event.getHistoricalY(i), event.getHistoricalPressure(i), event.getHistoricalSize(i)); } calibrate(event.getX(), event.getY(), event.getPressure(), event.getSize()); } else if (action == event.ACTION_UP) { Float temp = Collections.max(CalList); temp = (float) Math.ceil((Double.parseDouble(Float.valueOf(temp).toString())) / 10); LargeValue = temp * 10; calibrator.setColorFilter(Color.GREEN); // Largest.setText(String.valueOf(LargeValue)); } return true; }
From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java
@Override public boolean onTouchEvent(MotionEvent e) { // MotionEvent reports input details from the touch screen // and other input controls. In this case, you are only // interested in events where the touch position changed. switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else {//from w w w. j a va 2 s.com mVelocityTracker.clear(); } queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasStarted(); } }); // No break is intentional case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(e); // Compute velocity in pixels per second mVelocityTracker.computeCurrentVelocity(1); final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1); Vector2 viewportPosition; Vector2 viewportVelocity = new Vector2( VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()), VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex())); // Add previous touch coordinates for (int i = 0; i < e.getHistorySize(); i++) { viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i)); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getHistoricalSize(i), e.getHistoricalPressure(i))); } // Add current touch coordinates viewportPosition = new Vector2(e.getX(), e.getY()); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getSize(), e.getPressure())); // Ensure we call switchMode() on the OpenGL thread. // queueEvent() is a method of GLSurfaceView that will do this for us. queueEvent(new Runnable() { @Override public void run() { mRenderer.addTouchData(touchDataList); } }); requestRender(); break; case MotionEvent.ACTION_UP: queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasEnded(); } }); requestRender(); break; } return true; }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
/** * Called by the framework when your view for creating input needs to * be generated. This will be called the first time your input method * is displayed, and every time it needs to be re-created such as due to * a configuration change.// w ww. ja v a 2s . c o m */ @Override public View onCreateInputView() { mInputView = (KbLatinKeyboardView) getLayoutInflater().inflate(R.layout.input, null); mInputView.setKeyboard(mQwertyKeyboard); mInputView.setOnKeyboardActionListener(this); /****************************************************edit 2**************************************************************/ featuredb = new DataDBHelper(this); KbSoftKeyboard gd = new KbSoftKeyboard(); sf = new Save_feature(); swipeWord = new GetSwipeWord(this); //gDetect.setOnDoubleTapListener(gd); mInputView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int index = event.getActionIndex(); int action = event.getActionMasked(); int pointerId = event.getPointerId(index); //check for actions of motion event if (event.getAction() == MotionEvent.ACTION_DOWN) { //retrieve key at current char ch = getkeylabel(event); if (ch > 0) swipe += ch; // test+=swipe.charAt(0); //set up start timer for measuring duration // start=System.currentTimeMillis(); //setup velocity tracker if (mvel == null) { // Retrieve a new VelocityTracker object to watch the velocity of a motion. mvel = VelocityTracker.obtain(); } else { // Reset the velocity tracker back to its initial state. mvel.clear(); } } if (event.getAction() == MotionEvent.ACTION_MOVE) { mvel.addMovement(event); mvel.computeCurrentVelocity(1000); // Log velocity of pixels per second // Best practice to use VelocityTrackerCompat where possible. x_vel += abs(VelocityTrackerCompat.getXVelocity(mvel, pointerId)); y_vel += abs(VelocityTrackerCompat.getYVelocity(mvel, pointerId)); n_event += 1; // Log.d("", "X velocity: " + x_vel); // Log.d("", "Y velocity: " + y_vel); } if (event.getAction() == MotionEvent.ACTION_UP) { //record time when finger lifted up // end=System.currentTimeMillis(); //calculate duration // duration=(end-start)/100; //calculate velocity pixels per sec // Log.d("", "X velocity: " + x_vel); // Log.d("", "Y velocity: " + y_vel); velocity = Math.sqrt(x_vel * x_vel + y_vel * y_vel); //obtain pressure pressure += event.getPressure(); np_event += 1; swipe2 = get_final_string(swipe); swipe = ""; if (swipe2 == null) swipe2 = ""; //print generated string System.out.println(swipe + "\n 2nd " + swipe2); } if (((int) old_x) == 0 & ((int) old_y) == 0) { old_x = event.getX(); old_y = event.getY(); swipe += getkeylabel(event); } else if (((int) olddir_x) == 0 & ((int) olddir_y) == 0) { olddir_x = event.getX() - old_x; olddir_y = event.getY() - old_y; old_x = event.getX(); old_y = event.getY(); } else { check_change(event); } // Return false to avoid consuming the touch event return false; } }); //***********************************************edit 2 end***************************************************************** //Saved my life if (mInputView.isPreviewEnabled()) mInputView.setPreviewEnabled(false); return mInputView; }