List of usage examples for android.view MotionEvent TOOL_TYPE_STYLUS
int TOOL_TYPE_STYLUS
To view the source code for android.view MotionEvent TOOL_TYPE_STYLUS.
Click Source Link
From source file:Main.java
/** * Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button * pressed./*from w w w .j a v a 2s . com*/ * * @param event The event to check. * @return Whether a stylus button press occurred. */ public static boolean isStylusButtonPressed(MotionEvent event) { return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS && event.isButtonPressed(MotionEvent.BUTTON_SECONDARY); }
From source file:Main.java
/** * Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button * pressed./*from w w w. j a va2 s.co m*/ * * @param event The event to check. * @return Whether a stylus button press occurred. */ private static boolean isStylusButtonPressed(MotionEvent event) { return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS && ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) == MotionEvent.BUTTON_SECONDARY); }
From source file:com.mylikes.likes.etchasketch.Slate.java
private void drawStrokeDebugInfo(Canvas c) { final int ROW_HEIGHT = 24; final int ROW_MARGIN = 6; final int COLUMN_WIDTH = 55; final float FIRM_PRESSURE_LOW = 0.85f; final float FIRM_PRESSURE_HIGH = 1.25f; if (mStrokeDebugGraph == null) { final int width = c.getWidth() - 128; final int height = ROW_HEIGHT * mStrokes.length + 2 * ROW_MARGIN; mStrokeDebugGraph = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); if (mStrokeDebugGraph == null) { throw new RuntimeException( "drawStrokeDebugInfo: couldn't create debug bitmap (" + width + "x" + height + ")"); }//from w ww . ja v a 2 s. com mGraphPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG); } Canvas graph = new Canvas(mStrokeDebugGraph); graph.save(); graph.clipRect(new Rect(0, 0, COLUMN_WIDTH, graph.getHeight())); graph.drawColor(0, PorterDuff.Mode.CLEAR); graph.restore(); int left = 4; int bottom = graph.getHeight() - ROW_MARGIN; final int STEP = 4; for (MarkersPlotter st : mStrokes) { float r = st.getLastPressure(); if (r >= FIRM_PRESSURE_LOW && r <= FIRM_PRESSURE_HIGH) mGraphPaint1.setColor(0xFF33FF33); else if (r < FIRM_PRESSURE_LOW) mGraphPaint1.setColor(0xFF808080); else mGraphPaint1.setColor(0xFFFF8000); String s = (r < 0) ? "--" : String.format("%s %.4f", ((st.getLastTool() == MotionEvent.TOOL_TYPE_STYLUS) ? "S" : "F"), r); graph.drawText(s, left, bottom - 2, mGraphPaint1); if (mGraphX + COLUMN_WIDTH > graph.getWidth()) { mGraphX = 0; graph.save(); graph.clipRect(new Rect(30, 0, graph.getWidth(), graph.getHeight())); graph.drawColor(0, PorterDuff.Mode.CLEAR); graph.restore(); } if (r >= 0) { int barsize = (int) (r * ROW_HEIGHT); graph.drawRect(mGraphX + COLUMN_WIDTH, bottom - barsize, mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1); } else { graph.drawPoint(mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1); } bottom -= (ROW_HEIGHT + ROW_MARGIN); } mGraphX += STEP; final int x = 96; final int y = 64; c.drawBitmap(mStrokeDebugGraph, x, y, null); invalidate(new Rect(x, y, x + c.getWidth(), y + c.getHeight())); }
From source file:com.mylikes.likes.etchasketch.Slate.java
@SuppressLint("NewApi") final static int getToolTypeCompat(MotionEvent me, int index) { if (hasToolType()) { return me.getToolType(index); }/*from w w w . j ava 2 s . c o m*/ // dirty hack for the HTC Flyer if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { if ("flyer".equals(Build.HARDWARE)) { if (me.getSize(index) <= 0.1f) { // with very high probability this is the stylus return MotionEvent.TOOL_TYPE_STYLUS; } } } return MotionEvent.TOOL_TYPE_FINGER; }