List of usage examples for android.view MotionEvent getMetaState
public final int getMetaState()
From source file:Main.java
public static JSONObject CreateJSonObjectFromMotionEvent(MotionEvent e) throws JSONException { JSONObject jObj = new JSONObject(); jObj.put("downTime", e.getDownTime()); jObj.put("eventTime", e.getEventTime()); jObj.put("action", e.getAction()); jObj.put("pointerCount", e.getPointerCount()); jObj.put("metaState", e.getMetaState()); jObj.put("buttonState", e.getButtonState()); jObj.put("xPrecision", e.getXPrecision()); jObj.put("yPrecision", e.getYPrecision()); jObj.put("deviceId", e.getDeviceId()); jObj.put("edgeFlags", e.getEdgeFlags()); jObj.put("source", e.getSource()); jObj.put("flags", e.getFlags()); for (int i = 0; i < e.getPointerCount(); i++) { PointerProperties prop = new PointerProperties(); e.getPointerProperties(i, prop); PointerCoords coords = new PointerCoords(); e.getPointerCoords(i, coords);/*from ww w . j av a 2 s . c o m*/ JSONObject pointer = JObjFromPointer(prop, coords); jObj.accumulate("pointers", pointer); } return jObj; }
From source file:Main.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount; i++) { xy[2 * i] = pointerCoords[i].x;//w w w . j av a 2 s.c om xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount; i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
From source file:Main.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount; i++) { xy[2 * i] = pointerCoords[i].x;//from ww w. ja v a2 s . com xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount; i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
From source file:Main.java
public static MotionEvent hoverMotionEventAtPosition(View view, int action, int xPercent, int yPercent) { MotionEvent ev = motionEventAtPosition(view, action, xPercent, yPercent); MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1]; pointerProperties[0] = new MotionEvent.PointerProperties(); MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1]; pointerCoords[0] = new MotionEvent.PointerCoords(); pointerCoords[0].x = ev.getX();/*from w ww . ja v a 2s . c o m*/ pointerCoords[0].y = ev.getY(); return MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), 1, pointerProperties, pointerCoords, ev.getMetaState(), 0, ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(), ev.getEdgeFlags(), InputDevice.SOURCE_CLASS_POINTER, ev.getFlags()); }
From source file:org.connectbot.util.TerminalTextViewOverlay.java
/** * Takes an android mouse event and produces a Java InputEvent modifiers int which can be * passed to vt320./* w w w .ja v a 2 s .c o m*/ * @param mouseEvent The {@link MotionEvent} which should be a mouse click or release. * @return A Java InputEvent modifier int. See * http://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html */ @TargetApi(14) private static int mouseEventToJavaModifiers(MotionEvent mouseEvent) { if (MotionEventCompat.getSource(mouseEvent) != InputDevice.SOURCE_MOUSE) return 0; int mods = 0; // See http://docs.oracle.com/javase/7/docs/api/constant-values.html int buttonState = mouseEvent.getButtonState(); if ((buttonState & MotionEvent.BUTTON_PRIMARY) != 0) mods |= 16; if ((buttonState & MotionEvent.BUTTON_SECONDARY) != 0) mods |= 8; if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) mods |= 4; // Note: Meta and Ctrl are intentionally swapped here to keep logic in vt320 simple. int meta = mouseEvent.getMetaState(); if ((meta & KeyEvent.META_META_ON) != 0) mods |= 2; if ((meta & KeyEvent.META_SHIFT_ON) != 0) mods |= 1; if ((meta & KeyEvent.META_CTRL_ON) != 0) mods |= 4; return mods; }
From source file:com.jinzht.pro.view.RecyclerViewHeader.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (mRecyclerWantsTouchEvent) { int scrollDiff = mCurrentScroll - mDownScroll; MotionEvent recyclerEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), event.getX(), event.getY() - scrollDiff, event.getMetaState()); mRecycler.onTouchEvent(recyclerEvent); return false; }/*from ww w. j ava 2 s . c o m*/ return super.onTouchEvent(event); }
From source file:org.connectbot.util.TerminalTextViewOverlay.java
/** * @param event/*from w ww. jav a 2 s . c om*/ * @param bridge * @return True if the event is handled. */ @TargetApi(14) private boolean onMouseEvent(MotionEvent event, TerminalBridge bridge) { int row = (int) Math.floor(event.getY() / bridge.charHeight); int col = (int) Math.floor(event.getX() / bridge.charWidth); int meta = event.getMetaState(); boolean shiftOn = (meta & KeyEvent.META_SHIFT_ON) != 0; vt320 vtBuffer = (vt320) bridge.buffer; boolean mouseReport = vtBuffer.isMouseReportEnabled(); // MouseReport can be "defeated" using the shift key. if (!mouseReport || shiftOn) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getButtonState() == MotionEvent.BUTTON_TERTIARY) { // Middle click pastes. pasteClipboard(); return true; } // Begin "selection mode" if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { closeSelectionActionMode(); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { // In the middle of selection. if (selectionActionMode == null) { selectionActionMode = startActionMode(new TextSelectionActionModeCallback()); } int selectionStart = getSelectionStart(); int selectionEnd = getSelectionEnd(); if (selectionStart > selectionEnd) { int tempStart = selectionStart; selectionStart = selectionEnd; selectionEnd = tempStart; } currentSelection = getText().toString().substring(selectionStart, selectionEnd); } } else if (event.getAction() == MotionEvent.ACTION_DOWN) { terminalView.viewPager.setPagingEnabled(false); vtBuffer.mousePressed(col, row, mouseEventToJavaModifiers(event)); return true; } else if (event.getAction() == MotionEvent.ACTION_UP) { terminalView.viewPager.setPagingEnabled(true); vtBuffer.mouseReleased(col, row); return true; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { int buttonState = event.getButtonState(); int button = (buttonState & MotionEvent.BUTTON_PRIMARY) != 0 ? 0 : (buttonState & MotionEvent.BUTTON_SECONDARY) != 0 ? 1 : (buttonState & MotionEvent.BUTTON_TERTIARY) != 0 ? 2 : 3; vtBuffer.mouseMoved(button, col, row, (meta & KeyEvent.META_CTRL_ON) != 0, (meta & KeyEvent.META_SHIFT_ON) != 0, (meta & KeyEvent.META_META_ON) != 0); return true; } return false; }
From source file:com.github.pedrovgs.DraggableView.java
/** * Clone given motion event and set specified action. This method is useful, when we want to * cancel event propagation in child views by sending event with {@link MotionEvent#ACTION_CANCEL} action. * @param event event to clone/*w ww .j a va 2s .c om*/ * @param action new action * @return cloned motion event */ private MotionEvent cloneMotionEventWithAction(MotionEvent event, int action) { return MotionEvent.obtain(event.getDownTime(), event.getEventTime(), action, event.getX(), event.getY(), event.getMetaState()); }
From source file:org.xingjitong.ContactsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mInflater = inflater;/* w w w. j a v a2 s . c o m*/ View view = inflater.inflate(R.layout.contacts_list, container, false); if (getArguments() != null) { editOnClick = getArguments().getBoolean("EditOnClick"); sipAddressToAdd = getArguments().getString("SipAddress"); onlyDisplayChatAddress = getArguments().getBoolean("ChatAddressOnly"); } noSipContact = (TextView) view.findViewById(R.id.noSipContact); noContact = (TextView) view.findViewById(R.id.noContact); contactsList = (ListView) view.findViewById(R.id.contactsList); contactsList.setOnItemClickListener(this); allContacts = (TextView) view.findViewById(R.id.allContacts); allContacts.setOnClickListener(this); allContacts.setVisibility(View.GONE);//yujingjie add //yyppset abc = (ContactView) view.findViewById(R.id.contacts_list_abc); linphoneContacts = (TextView) view.findViewById(R.id.linphoneContacts); linphoneContacts.setOnClickListener(this); linphoneContacts.setVisibility(View.GONE);//yujingjie add //yyppset newContact = (TextView) view.findViewById(R.id.newContact); newContact.setOnClickListener(this); newContact.setEnabled(LinphoneManager.getLc().getCallsNb() == 0); allContacts.setEnabled(onlyDisplayLinphoneContacts); linphoneContacts.setEnabled(!allContacts.isEnabled()); list_str = new ArrayList<String>(); search_text = (SearchText) view.findViewById(R.id.contacts_list_search_text); search_text.setFragment(this); show_img = (TextView) view.findViewById(R.id.contasts_img); show_img.setVisibility(View.INVISIBLE); thread = new Runnable() { @Override public void run() { show_img.setVisibility(View.GONE); } }; abc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getMetaState() == MotionEvent.ACTION_DOWN) { int h = abc.getHeight(); int t = h % 27 == 0 ? h / 27 : h / 27 + 1; float s = event.getY(); int i = (int) (s % t == 0 ? s / t : s / t + 1); if (i > 26) { i = 26; } else if (i < 0) { i = 0; } String key = str.substring(i, i + 1); showImg(key); if ("#".equals(key)) { contactsList.setSelection(0); return true; } if (list_str.contains(key)) { // adapter_abc.setOnClick(arg2); if ("@".equals(key)) { key = "#"; } contactsList.setSelection(ints.get(key)); } } return true; } }); onLongClickListView(); //yyppdialog add return view; }
From source file:org.connectbot.util.TerminalTextViewOverlay.java
@Override @TargetApi(12)//from www. j a v a2s.c o m public boolean onGenericMotionEvent(MotionEvent event) { if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: // Process scroll wheel movement: float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL); vt320 vtBuffer = (vt320) terminalView.bridge.buffer; boolean mouseReport = vtBuffer.isMouseReportEnabled(); if (mouseReport) { int row = (int) Math.floor(event.getY() / terminalView.bridge.charHeight); int col = (int) Math.floor(event.getX() / terminalView.bridge.charWidth); vtBuffer.mouseWheel(yDistance > 0, col, row, (event.getMetaState() & KeyEvent.META_CTRL_ON) != 0, (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0, (event.getMetaState() & KeyEvent.META_META_ON) != 0); return true; } } } return super.onGenericMotionEvent(event); }