List of usage examples for android.view MotionEvent ACTION_POINTER_UP
int ACTION_POINTER_UP
To view the source code for android.view MotionEvent ACTION_POINTER_UP.
Click Source Link
From source file:com.limewoodmedia.nsdroid.fragments.NavigationDrawerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup layout = (ViewGroup) (inflater.inflate(R.layout.fragment_navigation_drawer, container, false)); MenuItemHolder[] holders = new MenuItemHolder[] { new MenuItemHolder(R.id.menu_start, R.drawable.icon_start, R.string.menu_start), new MenuItemHolder(R.id.menu_nation, R.drawable.icon_nation, R.string.menu_nation), new MenuItemHolder(R.id.submenu_issues, R.drawable.icon_issues, R.string.menu_issues), new MenuItemHolder(R.id.submenu_dossier, R.drawable.icon_dossier, R.string.menu_dossier), new MenuItemHolder(R.id.menu_region, R.drawable.icon_region, R.string.menu_region), new MenuItemHolder(R.id.submenu_rmb, R.drawable.icon_rmb, R.string.menu_rmb), new MenuItemHolder(R.id.submenu_officers, R.drawable.icon_officers, R.string.menu_officers), new MenuItemHolder(R.id.submenu_embassies, R.drawable.icon_embassies, R.string.menu_embassies), new MenuItemHolder(R.id.menu_world, R.drawable.icon_world, R.string.menu_world), new MenuItemHolder(R.id.menu_wa, R.drawable.icon_wa, R.string.menu_wa), new MenuItemHolder(R.id.menu_news, R.drawable.icon_news, R.string.menu_news), new MenuItemHolder(R.id.menu_settings, R.drawable.icon_settings, R.string.menu_settings), new MenuItemHolder(R.id.menu_logout, R.drawable.icon_logout, R.string.menu_logout) }; View view;/*w ww. j a v a 2 s . co m*/ for (final MenuItemHolder holder : holders) { view = layout.findViewById(holder.viewId); if (view == null) continue; ((ImageView) view.findViewById(R.id.menu_item_image)).setImageResource(holder.imageId); ((TextView) view.findViewById(R.id.menu_item_text)).setText(holder.textId); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectMenuItem(holder.viewId); } }); view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: view.setBackgroundColor(getActivity().getResources().getColor(R.color.menu_item_selected)); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_OUTSIDE: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_HOVER_EXIT: case MotionEvent.ACTION_POINTER_UP: view.setBackgroundColor(0x00000000); break; } return false; } }); } // layout.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View view, MotionEvent motionEvent) { // return true; // } // }); return layout; }
From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java
@Override public boolean onInterceptTouchEvent(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.onInterceptTouchEvent(ev); }/*w w w . jav a2s . c o m*/ if (action == MotionEvent.ACTION_DOWN) { mVelocityTracker.clear(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mOpenOnClick = isListChildUnderClipped(x, y) && mCollapsibleHeight > 0; } break; case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float dy = y - mInitialTouchY; boolean isSlidingUp = Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null && mCollapseOffset > 0; boolean isSlidingDown = mCollapseOffset == 0 && dy > mTouchSlop; if (isSlidingUp || isSlidingDown) { mActivePointerId = ev.getPointerId(0); mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { resetTouch(); } break; } if (mIsDragging) { mScroller.abortAnimation(); } return mIsDragging || mOpenOnClick; }
From source file:com.github.barteksc.pdfviewpager.view.ScrollBar.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_POINTER_DOWN: float y = event.getY(); if (y < 0 || y > getHeight()) return true; int pageNum = (int) Math.floor(y / handleHeight); float handleY = pageNum * handleHeight; if (handleY < 0) { handleY = 0;/* www .j a v a 2 s. c o m*/ } else if (y + handleHeight / 2 > getHeight()) { handleY = getHeight() - handleHeight; } handlePos.y = handleY; if (pageNum != currentPage) { indicator.setPageNum(pageNum + 1); } currentPage = pageNum; indicator.setVisibility(VISIBLE); indicator.setScroll(handleY); invalidate(); return true; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: int pgNum = (int) Math.floor(event.getY() / handleHeight); programmaticPageChangeLocked = true; viewPager.setCurrentItem(pgNum); currentPage = pgNum; indicator.setVisibility(INVISIBLE); invalidate(); return true; } return super.onTouchEvent(event); }
From source file:de.lmu.ifi.medien.probui.system.ProbUIManager.java
public void manageHelper(MotionEvent ev) throws WrongObservationDelegationException { this.currentTouchObservations.clear(); int action = MotionEventCompat.getActionMasked(ev); int index = MotionEventCompat.getActionIndex(ev); int pointerID = ev.getPointerId(index); int type = -1; switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: type = ProbObservationTouch.TYPE_TOUCH_DOWN; break;//from w ww .j a v a2 s .c o m case MotionEvent.ACTION_MOVE: type = ProbObservationTouch.TYPE_TOUCH_MOVE; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: type = ProbObservationTouch.TYPE_TOUCH_UP; break; default: type = -1; break; } long timestamp = ev.getEventTime(); ProbObservationTouch observation = ProbObservationFactory.createTouchObservation(ev.getX(index), ev.getY(index), ev.getX(index) * 1.0 / container.getWidth(), ev.getY(index) * 1.0 / container.getHeight(), ev.getOrientation(index), ev.getTouchMinor(index) * 1.0 / container.getWidth(), ev.getTouchMajor(index) * 1.0 / container.getHeight(), ev.getPressure(index), type, pointerID, timestamp); this.currentTouchObservations.add(observation); // Since move is always associated with the first pointer, // we need to manually duplicate it for the second one // (TODO: and for further pointers, if we change it to more than 2): if (ev.getPointerCount() == 2 && type == ProbObservationTouch.TYPE_TOUCH_MOVE) { ProbObservationTouch observation2 = ProbObservationFactory.createTouchObservation(ev.getX(index), ev.getY(index), ev.getX(1) * 1.0 / container.getWidth(), ev.getY(1) * 1.0 / container.getHeight(), ev.getOrientation(1), ev.getToolMinor(1) * 1.0 / container.getWidth(), ev.getToolMajor(1) * 1.0 / container.getHeight(), ev.getPressure(1), type, ev.getPointerId(1), timestamp); this.currentTouchObservations.add(observation2); } //Log.d("MULTITOUCH", "type: " + type + ", index: " + pointerID + ", size: " + ev.getTouchMajor(index) * 1.0 / container.getHeight()); // Distribute touch observation to the cores of all probInteractors // (for reasoning by these interactor cores!, not for visual feedback etc. - that comes below: interactor.onTouchDown etc.) boolean passedOn = false; for (ProbInteractor interactor : this.probInteractors) { for (int i = 0; i < this.currentTouchObservations.size(); i++) { ProbObservationTouch obs = this.currentTouchObservations.get(i); if (obs == null) continue; if (obs.getNominalFeatures()[0] != ProbObservationTouch.TYPE_TOUCH_MOVE || this.currentTouchObservations.size() != this.previousTouchObservations.size()) { interactor.getCore().onTouchObservation(obs); passedOn = true; } else { // This code filters out move events that moved very little (potentially improves performance): double[] obsXY = this.currentTouchObservations.get(i).getRealFeatures(); double[] obsPrevXY = this.previousTouchObservations.get(i).getRealFeatures(); double dx = obsXY[0] - obsPrevXY[0]; double dy = obsXY[1] - obsPrevXY[1]; double dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0.0125) { // TODO: movement threshold currently hardcoded: 0.0125 interactor.getCore().onTouchObservation(obs); passedOn = true; } else { } } } } if (passedOn) { this.previousTouchObservations.clear(); this.previousTouchObservations.addAll(this.currentTouchObservations); } // Forward the touch observation for probInteractors // to react (e.g. visual feedback, triggering actions, nothing to do with the mediation): for (ProbInteractor interactor : this.probInteractors) { for (ProbObservationTouch obs : this.currentTouchObservations) { if (obs != null) { switch (obs.getNominalFeatures()[0]) { case ProbObservationTouch.TYPE_TOUCH_DOWN: interactor.onTouchDown(obs); break; case ProbObservationTouch.TYPE_TOUCH_MOVE: interactor.onTouchMove(obs); break; case ProbObservationTouch.TYPE_TOUCH_UP: interactor.onTouchUp(obs, ev.getPointerCount() - 1); break; default: break; } } } } // If no element is determined yet (i.e. no decision yet), update the reasoning process. if (!isOneDetermined() && passedOn) { this.mediator.mediate(false); } // Post mediation: Forward the touch observation again // to the post-mediation versions of the onTouch... methods for (ProbInteractor interactor : this.probInteractors) { for (ProbObservationTouch obs : this.currentTouchObservations) { if (obs != null) { switch (obs.getNominalFeatures()[0]) { case ProbObservationTouch.TYPE_TOUCH_DOWN: interactor.onTouchDownPost(obs); break; case ProbObservationTouch.TYPE_TOUCH_MOVE: interactor.onTouchMovePost(obs); break; case ProbObservationTouch.TYPE_TOUCH_UP: interactor.onTouchUpPost(obs, ev.getPointerCount() - 1); break; default: break; } } } } // Pass on to other GUI elements: if (!isOneDetermined()) { for (View view : this.nonProbInteractors) { if (view.isFocusable() && view.isEnabled()) view.onTouchEvent(ev); } } }
From source file:com.tasomaniac.openwith.resolver.ResolverDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_DOWN) { mVelocityTracker.clear();//from www .j a v a 2 s.com } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(0); final float y = ev.getY(0); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mOpenOnClick = isListChildUnderClipped(x, y) && mCollapsibleHeight > 0; } break; case MotionEvent.ACTION_MOVE: { final float x = ev.getX(0); final float y = ev.getY(0); final float dy = y - mInitialTouchY; if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null && (getNestedScrollAxes() & ViewCompat.SCROLL_AXIS_VERTICAL) == 0) { mActivePointerId = ev.getPointerId(0); mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { resetTouch(); } break; } if (mIsDragging) { abortAnimation(); } return mIsDragging || mOpenOnClick; }
From source file:de.gobro.andreas.pa.pa_cleint_java.SendTouch.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: { Log.d("down", "action_down"); break;/*from w ww . ja v a2s. com*/ } case MotionEvent.ACTION_MOVE: { for (Integer i = 0; (i < ev.getPointerCount()) && (i < maxPoints); i++) { //final Integer pointerIndex = MotionEventCompat.getActionIndex(ev); Integer id = ev.getPointerId(i); Log.d("ind", "pinterindex" + i.toString()); Log.d("ind", "ID" + id.toString()); Log.d("pos", "(" + String.valueOf(MotionEventCompat.getX(ev, i)) + ";" + String.valueOf(MotionEventCompat.getY(ev, i)) + ")"); Log.d("test", "action_move"); try { serializer.startTag("", "touch"); serializer.startTag("", "dx"); serializer.text(String.valueOf(MotionEventCompat.getX(ev, i) / size.x)); serializer.endTag("", "dx"); serializer.startTag("", "dy"); serializer.text(String.valueOf(MotionEventCompat.getY(ev, i) / size.y)); serializer.endTag("", "dy"); serializer.startTag("", "id"); serializer.text(id.toString()); serializer.endTag("", "id"); serializer.endTag("", "touch"); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } // try { // writer.writeStartElement("touch"); // writer.writeStartElement("dx"); // writer.writeCharacters(String.valueOf(MotionEventCompat.getX(ev, i)/size.x)); // writer.writeEndElement(); // writer.writeStartElement("dy"); // writer.writeCharacters(String.valueOf(MotionEventCompat.getY(ev, i)/size.y)); // writer.writeEndElement(); // writer.writeStartElement("id"); // writer.writeCharacters(id.toString()); // writer.writeEndElement(); // writer.writeEndElement(); // } catch (XMLStreamException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } //write the stuff to the network try { serializer.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); finish(); } break; } case MotionEvent.ACTION_UP: { Log.d("test", "action_up"); break; } case MotionEvent.ACTION_CANCEL: { Log.d("test", "action_cancel"); break; } case MotionEvent.ACTION_POINTER_DOWN: { Log.d("down", "action_p_down"); break; } case MotionEvent.ACTION_POINTER_UP: { Log.d("test", "action_p_up"); break; } } return true; }
From source file:com.csounds.examples.tests.MultiTouchXYActivity.java
/** Called when the activity is first created. */ @Override/*from www. j a v a 2 s .c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); for (int i = 0; i < touchIds.length; i++) { touchIds[i] = -1; touchX[i] = -1; touchY[i] = -1; } /* File outputFile = new File(DIR_NAME); File outputDir = this.getCacheDir(); // context being the Activity pointer try { outputFile = File.createTempFile("temp", "txt", outputDir); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ContextWrapper cw = new ContextWrapper(this); File directory = cw.getExternalFilesDir(null); txtfile = new File(directory,"temp.txt"); */ multiTouchView = new View(this); setContentView(R.layout.multitouchxy); multiTouchView = (RelativeLayout) findViewById(R.id.multitouchxy); Button loadPresetButton = (Button) findViewById(R.id.load_button); this.createLoadListener(loadPresetButton); multiTouchView.setOnTouchListener(new OnTouchListener() { /* (non-Javadoc) * @see android.view.View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent) */ public boolean onTouch(View v, MotionEvent event) { final int action = event.getAction() & MotionEvent.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: for (int i = 0; i < event.getPointerCount(); i++) { int pointerId = event.getPointerId(i); int id = getTouchId(pointerId); if (id == -1) { id = getTouchIdAssignment(); if (id != -1) { touchIds[id] = pointerId; touchX[id] = event.getX(i) / multiTouchView.getWidth(); touchY[id] = 1 - (event.getY(i) / multiTouchView.getHeight()); //TODO calculte interval Y int a = Math.round(id / 440); System.out.println("y " + a); if (touchXPtr[id] != null) { //TODO swtich touchid Log.d("touchXtouchY", "touchX[id]) " + touchX[id] + " touchY[id]) " + touchY[id] + " multitouchview width " + multiTouchView.getWidth() + " multitouchview width " + multiTouchView.getHeight()); // get the key from the touch coordinates float[] touchArray = new float[2]; touchArray = evaluateTouchKey(touchX[id], touchY[id]); touchX[id] = touchArray[0]; touchY[id] = touchArray[1]; Log.d("touchXtouchY", "touchX[id]) " + touchX[id] + " touchY[id]) " + touchY[id]); touchXPtr[id].SetValue(0, touchX[id]); touchYPtr[id].SetValue(0, touchY[id]); csoundObj.sendScore(String.format("i1.%d 0 -2 %d", id, id)); } //write file /* System.out.println(String.format( "i1.%d 0 -2 %d", id, a)); writeToFile(String.format( "i1.%d 0 -2 %d", id, a)); */ } } } break; case MotionEvent.ACTION_MOVE: for (int i = 0; i < event.getPointerCount(); i++) { int pointerId = event.getPointerId(i); int id = getTouchId(pointerId); if (id != -1) { touchX[id] = event.getX(i) / multiTouchView.getWidth(); touchY[id] = 1 - (event.getY(i) / multiTouchView.getHeight()); } //write file /* System.out.println(String.format( "i1.%d 0 -2 %d", id, id)); writeToFile(String.format( "i1.%d 0 -2 %d", id, id)); */ } break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: { int activePointerIndex = event.getActionIndex(); int pointerId = event.getPointerId(activePointerIndex); int id = getTouchId(pointerId); if (id != -1) { touchIds[id] = -1; csoundObj.sendScore(String.format("i-1.%d 0 0 %d", id, id)); } //write file /* System.out.println(String.format( "i1.%d 0 -2 %d", id, id)); writeToFile(String.format( "i1.%d 0 -2 %d", id, id)); */ } break; } return true; } }); setContentView(multiTouchView); String csd = getResourceFileAsString(R.raw.multitouch_xy_kx); File f = createTempFile(csd); csoundObj.addBinding(this); csoundObj.startCsound(f); }
From source file:com.intel.xdk.multitouch.MultiTouch.java
public void queueMultitouchData(String js, int id, int maskedAction) { //Log.i("[appMobi]", "queueMultitouchData:"+js); if (maskedAction == MotionEvent.ACTION_POINTER_DOWN || maskedAction == MotionEvent.ACTION_DOWN) { //touchstart: create list //this.multitouchMap.put(id, new ArrayList<String>()); } else if (maskedAction == MotionEvent.ACTION_POINTER_UP || maskedAction == MotionEvent.ACTION_UP) { //touchend: remove list this.multitouchMap.remove(id); } else if (maskedAction == MotionEvent.ACTION_MOVE) { //touchmove: flush stale touchmove events and and update list String stale = this.multitouchMap.get(id); this.multitouchQueue.remove(stale); this.multitouchMap.put(id, js); }/*from w ww .j av a 2 s.co m*/ this.multitouchQueue.add(js); }
From source file:com.zenithed.core.widget.scaledimageview.ScaledImageView.java
/** * Handler for the touch event if the user has done performing the gesture. *//*from ww w .j av a2 s .c om*/ private boolean handleDefaultTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_2_UP: // Trigger load of tiles now required refreshRequiredTiles(true); return true; } return false; }
From source file:org.telegraph.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, Context context) { super(context); showStickers = needStickers;//from www . j a v a2s . c o m for (int i = 0; i < Emoji.data.length + 1; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1); gridView.setAdapter(emojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); adapters.add(emojiGridAdapter); } if (showStickers) { StickersQuery.checkStickers(); stickersGridView = new GridView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || !((StickerEmojiCell) view).showingBitmap()) { return super.onInterceptTouchEvent(event); } startX = x; startY = y; currentStickerPreviewCell = (StickerEmojiCell) view; openStickerPreviewRunnable = new Runnable() { @Override public void run() { if (openStickerPreviewRunnable == null) { return; } stickersGridView.setOnItemClickListener(null); stickersGridView.requestDisallowInterceptTouchEvent(true); openStickerPreviewRunnable = null; StickerPreviewViewer.getInstance().setParentActivity((Activity) getContext()); StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance().open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); } }; AndroidUtilities.runOnUIThread(openStickerPreviewRunnable, 200); return true; } } return false; } }; stickersGridView.setSelector(R.drawable.transparent); stickersGridView.setColumnWidth(AndroidUtilities.dp(72)); stickersGridView.setNumColumns(-1); stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0); stickersGridView.setClipToPadding(false); views.add(stickersGridView); stickersGridAdapter = new StickersGridAdapter(context); stickersGridView.setAdapter(stickersGridAdapter); stickersGridView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openStickerPreviewRunnable != null || StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { stickersGridView.setOnItemClickListener(stickersOnItemClickListener); } }, 150); if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } else if (StickerPreviewViewer.getInstance().isVisible()) { StickerPreviewViewer.getInstance().close(); if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (StickerPreviewViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_MOVE) { int x = (int) event.getX(); int y = (int) event.getY(); int count = stickersGridView.getChildCount(); for (int a = 0; a < count; a++) { View view = stickersGridView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); int left = view.getLeft(); int right = view.getRight(); if (top > y || bottom < y || left > x || right < x) { continue; } if (!(view instanceof StickerEmojiCell) || view == currentStickerPreviewCell) { break; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); } currentStickerPreviewCell = (StickerEmojiCell) view; StickerPreviewViewer.getInstance() .setKeyboardHeight(EmojiView.this.getMeasuredHeight()); StickerPreviewViewer.getInstance() .open(currentStickerPreviewCell.getSticker()); currentStickerPreviewCell.setScaled(true); return true; } } return true; } else if (openStickerPreviewRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(10)) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } else { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } } } } return false; } }); stickersOnItemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { if (!(view instanceof StickerEmojiCell)) { return; } if (openStickerPreviewRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openStickerPreviewRunnable); openStickerPreviewRunnable = null; } if (currentStickerPreviewCell != null) { currentStickerPreviewCell.setScaled(false); currentStickerPreviewCell = null; } StickerEmojiCell cell = (StickerEmojiCell) view; if (cell.isDisabled()) { return; } cell.disable(); TLRPC.Document document = cell.getSticker(); Integer count = stickersUseHistory.get(document.id); if (count == null) { count = 0; } if (count == 0 && stickersUseHistory.size() > 19) { for (int a = recentStickers.size() - 1; a >= 0; a--) { TLRPC.Document sticker = recentStickers.get(a); stickersUseHistory.remove(sticker.id); recentStickers.remove(a); if (stickersUseHistory.size() <= 19) { break; } } } stickersUseHistory.put(document.id, ++count); long id = StickersQuery.getStickerSetId(document); if (id != -1) { count = stickerSetsUseCount.get(id); if (count == null) { count = 0; } stickerSetsUseCount.put(id, ++count); } saveRecentStickers(); if (listener != null) { listener.onStickerSelected(document); } } }; stickersGridView.setOnItemClickListener(stickersOnItemClickListener); AndroidUtilities.setListViewEdgeEffectColor(stickersGridView, 0xfff5f6f7); stickersWrap = new FrameLayout(context); stickersWrap.addView(stickersGridView); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setTextColor(0xff888888); stickersWrap.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); stickersGridView.setEmptyView(textView); scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (Build.VERSION.SDK_INT >= 11) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip); if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } return super.onTouchEvent(ev); } }; scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7); scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7); scrollSlidingTabStrip.setVisibility(INVISIBLE); addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x); updateStickerTabs(); scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (page == 0) { pager.setCurrentItem(0); return; } else if (page == 1 && !recentStickers.isEmpty()) { views.get(6).setSelection(0); return; } int index = page - (recentStickers.isEmpty() ? 1 : 2); if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index))); } }); stickersGridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int count = view.getChildCount(); for (int a = 0; a < count; a++) { View child = view.getChildAt(a); if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) { firstVisibleItem++; } else { break; } } scrollSlidingTabStrip .onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, 0); } }); } setBackgroundColor(0xfff5f6f7); pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); pagerSlidingTabStripContainer = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL); pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7); addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); pagerSlidingTabStripContainer.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (listener != null && listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); recentsWrap = new FrameLayout(context); recentsWrap.addView(views.get(0)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); recentsWrap.addView(textView); views.get(0).setEmptyView(textView); addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0)); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }