List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:atownsend.swipeopenhelper.SwipeOpenItemTouchHelper.java
private View findChildView(MotionEvent event) { // first check elevated views, if none, then call RV final float x = event.getX(); final float y = event.getY(); if (selected != null) { final View selectedView = selected.getViewHolder().itemView; if (hitTest(selectedView, x, y, selectedStartX + dX, selectedStartY + dY)) { return selectedView; }//from www. ja va2 s. c o m } for (int i = recoverAnimations.size() - 1; i >= 0; i--) { final RecoverAnimation anim = recoverAnimations.get(i); final View view = anim.mViewHolder.getViewHolder().itemView; if (hitTest(view, x, y, anim.mX, anim.mY)) { return view; } } return recyclerView.findChildViewUnder(x, y); }
From source file:com.roger.lineselectionwebview.LSWebView.java
@SuppressWarnings("deprecation") @Override//from w w w. j av a 2s . c o m public boolean onTouch(View v, MotionEvent event) { if (!isLineMode) { return false; } @SuppressWarnings("deprecation") float xPoint = getDensityIndependentValue(event.getX(), mContext) / getDensityIndependentValue(getScale(), mContext); float yPoint = getDensityIndependentValue(event.getY(), mContext) / getDensityIndependentValue(getScale(), mContext); if (event.getAction() == MotionEvent.ACTION_DOWN) { String startTouchUrl = String.format(Locale.US, "javascript:android.selection.startTouch(%f, %f);", xPoint, yPoint); mLastTouchX = xPoint; mLastTouchY = yPoint; loadUrl(startTouchUrl); // Tell the javascript to handle this if not in selection mode if (!isInSelectionMode()) { loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; } // Flag scrolling for first touch // mScrolling = !isInSelectionMode(); } else if (event.getAction() == MotionEvent.ACTION_UP) { // Check for scrolling flag if (!mScrolling) { mScrolling = false; endSelectionMode(); return false; } mScrolling = false; // Fixes 4.4 double selection return true; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { mLastTouchX = xPoint; mLastTouchY = yPoint; } // If this is in selection mode, then nothing else should handle this // touch return false; }
From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_ticket_home); myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);/* w w w . j av a 2 s . c om*/ //synchTrips(); assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); spBoard = (Spinner) findViewById(R.id.spBoard); spBuses = (Spinner) findViewById(R.id.spBusNo); spTrips = (Spinner) findViewById(R.id.spTripType); spHighlight = (Spinner) findViewById(R.id.spHighlight); mAccount = CreateSyncAccount(this); mQueue = Volley.newRequestQueue(getApplicationContext()); rQSyncTicket = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext()); rQSyncBalance = Volley.newRequestQueue(getApplicationContext()); rqTrip = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketing = Volley.newRequestQueue(getApplicationContext()); rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext()); //Key methods needed to be sent to server on activity created syncTicketing(); syncTickets(); apps = db.getApp(Installation.appId(getApplicationContext())); EMAIL = apps.getRoute_name(); NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount(); // Get the content resolver for your app mResolver = getContentResolver(); /* * Turn on periodic syncing */ mTitle = mDrawerTitle = getTitle(); ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL); String[] tdata = populateTerminals(); String[] bdata = populateBuses(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBoard.setAdapter(adapter);/**/ ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata); Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spHighlight.setAdapter(Hadapter); ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata); gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spBuses.setAdapter(gadapter); ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes, android.R.layout.simple_spinner_item); tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata); badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/ spTrips.setAdapter(tadapter); spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); bus = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); board = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); highlight = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE); //((TextView) parent.getChildAt(0)).setTextSize(25); trip = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); btnGenerate = (Button) findViewById(R.id.btnGenerate); btnGenerate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // get a new activity to show invoice preview sendData(); } }); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit) // And passing the titles,icons,header view name, header view email, // and header view profile picture // Setting the adapter to RecyclerView //mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mAdapter); Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is // open I am not going to put anything here) invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // Code here will execute once drawer is closed invalidateOptionsMenu(); } }; // Drawer Toggle Object Made Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY()); if (child != null && mGestureDetector.onTouchEvent(motionEvent)) { Drawer.closeDrawers(); if (recyclerView.getChildPosition(child) == 1) { } else if (recyclerView.getChildPosition(child) == 2) { Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 3) { Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class); startActivity(intent); } else if (recyclerView.getChildPosition(child) == 4) { syncTicketingSynchronize(); syncTicketsSynchronize(); synchAccount(); insertBuses(); //insertTerminals(); //syncTickets(); //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true); /*new Thread(new Runnable() { @Override public void run() { Looper.prepare(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() {*/ // insertTerminals(); // insertBuses(); //getTickets(); //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show(); /*handler.removeCallbacks(this); Looper.myLooper().quit(); } }, 30000); Looper.loop(); } }).start();*/ } else if (recyclerView.getChildPosition(child) == 5) { if (apps.getLicenceNo() != null) { Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class); startActivity(intent); } else { //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class); //startActivity(intent); Toast.makeText(TicketingHomeActivity.this, "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT) .show(); } } else if (recyclerView.getChildPosition(child) == 6) { Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class); startActivity(intent); // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show(); } return true; } return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } }); List<Ticket> issuedTickets = db.getIssuedTickets(); Log.e("SYNC LOG", issuedTickets.toString()); }
From source file:com.cdwx.moka.widget.SwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();// ww w . j a v a2s .c o m final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } if (!isEnabled() || mReturningToStart) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; mCurrPercentage = 0; mStartPoint = mInitialMotionY; //up/down???????? //????canChildScrollUp/canChildScrollDown //???????? up = canChildScrollUp(); down = canChildScrollDown(); break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id."); return false; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); // final float yDiff = y - mInitialMotionY; final float yDiff = y - mStartPoint; //???? if ((mLastDirection == Mode.PULL_FROM_START && yDiff < 0) || (mLastDirection == Mode.PULL_FROM_END && yDiff > 0)) { return false; } //??? //mStartPoint if ((canChildScrollUp() && yDiff > 0) || (canChildScrollDown() && yDiff < 0)) { mStartPoint = y; } // if (yDiff > mTouchSlop) { //??? if (canChildScrollUp() || mLastDirection == Mode.PULL_FROM_END) { mIsBeingDragged = false; return false; } if ((mMode == Mode.PULL_FROM_START) || (mMode == Mode.BOTH)) { mLastMotionY = y; mIsBeingDragged = true; mLastDirection = Mode.PULL_FROM_START; } } // else if (-yDiff > mTouchSlop) { //??? if (canChildScrollDown() || mLastDirection == Mode.PULL_FROM_START) { mIsBeingDragged = false; return false; } //???????? if (!up && !down && !loadNoFull) { mIsBeingDragged = false; return false; } if ((mMode == Mode.PULL_FROM_END) || (mMode == Mode.BOTH)) { mLastMotionY = y; mIsBeingDragged = true; mLastDirection = Mode.PULL_FROM_END; } } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mCurrPercentage = 0; mActivePointerId = INVALID_POINTER; mLastDirection = Mode.DISABLED; break; } return mIsBeingDragged; }
From source file:android.support.v7.widget.SwitchCompat.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from ww w. j a va 2 s .c o m final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); if (isEnabled() && hitThumb(x, y)) { mTouchMode = TOUCH_MODE_DOWN; mTouchX = x; mTouchY = y; } break; } case MotionEvent.ACTION_MOVE: { switch (mTouchMode) { case TOUCH_MODE_IDLE: // Didn't target the thumb, treat normally. break; case TOUCH_MODE_DOWN: { final float x = ev.getX(); final float y = ev.getY(); if (Math.abs(x - mTouchX) > mTouchSlop || Math.abs(y - mTouchY) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; getParent().requestDisallowInterceptTouchEvent(true); mTouchX = x; mTouchY = y; return true; } break; } case TOUCH_MODE_DRAGGING: { final float x = ev.getX(); final int thumbScrollRange = getThumbScrollRange(); final float thumbScrollOffset = x - mTouchX; float dPos; if (thumbScrollRange != 0) { dPos = thumbScrollOffset / thumbScrollRange; } else { // If the thumb scroll range is empty, just use the // movement direction to snap on or off. dPos = thumbScrollOffset > 0 ? 1 : -1; } if (ViewUtils.isLayoutRtl(this)) { dPos = -dPos; } final float newPos = constrain(mThumbPosition + dPos, 0, 1); if (newPos != mThumbPosition) { mTouchX = x; setThumbPosition(newPos); } return true; } } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { if (mTouchMode == TOUCH_MODE_DRAGGING) { stopDrag(ev); // Allow super class to handle pressed state, etc. super.onTouchEvent(ev); return true; } mTouchMode = TOUCH_MODE_IDLE; mVelocityTracker.clear(); break; } } return super.onTouchEvent(ev); }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityCreateOrEditRoute.java
/** onSingleTapUp(MotionEvent e) * updates the {@link AutoCompleteTextView} fields on map movement *//*w ww .jav a 2s . co m*/ @Override public boolean onSingleTapUp(MotionEvent e) { GeoPoint gp = mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY()); MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(gp); addPoint(mapLocation); fillFieldsOnClick(); return false; }
From source file:com.cssweb.android.view.KlineMini.java
public void touchesMoved(MotionEvent event) { //Log.i("========currentPositionX==========", currentPositionX+">>>>>>>>>>"); //Log.i("========currentPositionY==========", currentPositionY+">>>>>>>>>>"); currentPositionX = event.getX();//from w w w. j a v a 2 s. c om currentPositionY = event.getY(); float deltaX = startPositionX - currentPositionX; float deltaY = startPositionY - currentPositionY; //Log.i("========Math.abs(delta)==========", Math.abs(deltaX)+">>>>>>>>>>"+Math.abs(deltaY)); if (Math.abs(deltaX) < 8 && Math.abs(deltaY) < 8) { isTouchMoved = false; } else { isTouchMoved = true; } if (quoteData == null) return; int mouseX = (int) event.getX(); int mouseY = (int) event.getY(); if (mouseX <= klineX || mouseY <= axisLabelHeight || mouseY >= height - axisLabelHeight - zbmenuHeight) return; if (isTrackStatus) {//?? isSingleMoved = false;//??? double sep = (shapeWidth + spaceWidth); visualPos = (int) ((mouseX - klineX) / sep + 1); if (visualPos >= this.actualDataLen - actualPos) { visualPos = this.actualDataLen - actualPos; } else if (visualPos < 1) visualPos = 1; int idx = actualPos + visualPos - 1; if (mouseX > klineX) { trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2); } if (idx < actualDataLen) { isTrackNumber = idx; } else { isTrackNumber = this.actualDataLen - 1; } Log.i("@@@@@@@@@@isTrackNumber@@@@@@@@@@", isTrackNumber + ">>>>>>>>>"); Log.i("@@@@@@@@@@idx@@@@@@@@@@", idx + ">>>>>>>>>"); Log.i("@@@@@@@@@@actualPos@@@@@@@@@@", actualPos + ">>>>>>>>>"); Log.i("@@@@@@@@@@visualPos@@@@@@@@@@", visualPos + ">>>>>>>>>"); this.invalidate(); } else {//K? isSingleMoved = true; if (deltaX < -50 && deltaY < 10) { moveRight(1); } else if (deltaX > 50 && deltaY < 10) { moveLeft(1); } } }
From source file:com.cssweb.android.view.KlineMini.java
public void touchesEnded(MotionEvent event) { isTouched = false;/*from ww w. ja v a 2 s . c o m*/ if (isTouchMoved == false) { isTouchMoved = false; isTrackStatus = !isTrackStatus; if (isTrackStatus) {//?? int mouseX = (int) event.getX(); int mouseY = (int) event.getY(); if (mouseX <= klineX || mouseY <= axisLabelHeight || mouseY >= height - axisLabelHeight - zbmenuHeight) return; double sep = (shapeWidth + spaceWidth); visualPos = (int) ((mouseX - klineX) / sep + 1); if (visualPos >= this.actualDataLen - actualPos) { visualPos = this.actualDataLen - actualPos; isTrackNumber = actualDataLen - 1; } else { isTrackNumber = actualPos + visualPos - 1; } trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2); Log.i("========isTouched222==========", trackLineV + ">>>>>" + visualKLineCount + ">>>>>" + isTrackNumber); Log.i("========isTouchMoved==========", actualDataLen + ">>>>" + actualPos + ">>>>>>" + visualPos); } else { isSingleMoved = true; } } else { } this.invalidate(); //Log.i("========isTouched==========", isTouched+">>>>>>>>>>"); //Log.i("========isTouchMoved==========", isTouchMoved+">>>>>>>>>>"); //Log.i("========isTrackStatus==========", isTrackStatus+">>>>>>>>>>"); }
From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java
/** * Checks if is in ignored view./*from w w w . java2s . c o m*/ * * @param ev the ev * @return true, if is in ignored view */ private boolean isInIgnoredView(MotionEvent ev) { Rect rect = new Rect(); for (View v : mIgnoredViews) { v.getHitRect(rect); if (rect.contains((int) ev.getX(), (int) ev.getY())) return true; } return false; }