List of usage examples for android.view MotionEvent getRawX
public final float getRawX()
From source file:com.wytiger.common.widget.SlideSwitch.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!mEnable) { return super.onTouchEvent(event); }/*from w ww . j a v a 2s .c o m*/ int action = MotionEventCompat.getActionMasked(event); int diffX; int eventLastX; switch (action) { case MotionEvent.ACTION_DOWN: eventStartX = (int) event.getRawX(); break; case MotionEvent.ACTION_MOVE: eventLastX = (int) event.getRawX(); diffX = eventLastX - eventStartX; int tempX = diffX + frontRect_left_begin; tempX = (tempX > max_left ? max_left : tempX); tempX = (tempX < min_left ? min_left : tempX); if (tempX >= min_left && tempX <= max_left) { frontRect_left = tempX; alpha = (int) (255 * (float) tempX / (float) max_left); invalidateView(); } break; case MotionEvent.ACTION_UP: int wholeX = (int) (event.getRawX() - eventStartX); frontRect_left_begin = frontRect_left; boolean toRight; toRight = frontRect_left_begin > max_left / 2; if (Math.abs(wholeX) < 3) { toRight = !toRight; } moveToDest(toRight); break; default: break; } return true; }
From source file:ca.shoaib.ping.PingListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_ping_list, container, false); mListView = (ListView) rootView.findViewById(R.id.list_ping); pingListAdapter = new PingListAdapter(getActivity(), R.layout.ping_row, pingList); mListView.setAdapter(pingListAdapter); //mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// ww w. j a v a 2 s.c om public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mPingListCallback.onPingSelected(pingList.get(position)); mActivatedPosition = position; setActivatedPosition(position); //Log.d(TAG, "ArtistId: " + artistList.get(position).getArtistId()); } }); pb = (ProgressBar) rootView.findViewById(R.id.progress_bar); et = (EditText) rootView.findViewById(R.id.ping_destination); tv = (TextView) rootView.findViewById(R.id.ping_result); btn = (Button) rootView.findViewById(R.id.ping_start); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String stringUrl = et.getText().toString(); ConnectivityManager connMgr = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { AsyncTask pingTask = new PingTask(getActivity(), pingList, pingListAdapter).execute(stringUrl); } else { tv.setTextSize(20); tv.setTextColor(Color.RED); tv.setText(R.string.no_internet); } InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); } }); et.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getRawX() >= (et.getRight() - et.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { et.setText(""); et.selectAll(); return true; } } return false; } }); return rootView; }
From source file:com.numicago.guiahollywood.pager.SwipeyTabsView.java
public boolean onTouch(View v, MotionEvent event) { float x = event.getRawX(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDragX = x;//from w w w. j a v a2s. com mPager.beginFakeDrag(); break; case MotionEvent.ACTION_MOVE: if (!mPager.isFakeDragging()) break; mPager.fakeDragBy((mDragX - x) * (-1)); mDragX = x; break; case MotionEvent.ACTION_UP: if (!mPager.isFakeDragging()) break; mPager.endFakeDrag(); break; } return v.equals(this) ? true : super.onTouchEvent(event); }
From source file:com.dean.phonesafe.ui.SlideSwitch.java
@Override public boolean onTouchEvent(MotionEvent event) { if (slideable == false) return super.onTouchEvent(event); int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: eventStartX = (int) event.getRawX(); break;/*from w w w .j a v a 2 s. c o m*/ case MotionEvent.ACTION_MOVE: eventLastX = (int) event.getRawX(); diffX = eventLastX - eventStartX; int tempX = diffX + frontRect_left_begin; tempX = (tempX > max_left ? max_left : tempX); tempX = (tempX < min_left ? min_left : tempX); if (tempX >= min_left && tempX <= max_left) { frontRect_left = tempX; alpha = (int) (255 * (float) tempX / (float) max_left); invalidateView(); } break; case MotionEvent.ACTION_UP: int wholeX = (int) (event.getRawX() - eventStartX); frontRect_left_begin = frontRect_left; boolean toRight; toRight = (frontRect_left_begin > max_left / 2 ? true : false); if (Math.abs(wholeX) < 10) { toRight = !toRight; } moveToDest(toRight); break; default: break; } return true; }
From source file:com.audionote.widget.SlideSwitch.java
@Override public boolean onTouchEvent(MotionEvent event) { if (slideable == false) return super.onTouchEvent(event); int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: eventStartX = (int) event.getRawX(); break;//from ww w . j a va 2 s. c o m case MotionEvent.ACTION_MOVE: eventLastX = (int) event.getRawX(); diffX = eventLastX - eventStartX; int tempX = diffX + frontRect_left_begin; tempX = (tempX > max_left ? max_left : tempX); tempX = (tempX < min_left ? min_left : tempX); if (tempX >= min_left && tempX <= max_left) { frontRect_left = tempX; alpha = (int) (255 * (float) tempX / (float) max_left); invalidateView(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: int wholeX = (int) (event.getRawX() - eventStartX); frontRect_left_begin = frontRect_left; boolean toRight; toRight = (frontRect_left_begin > max_left / 2 ? true : false); if (Math.abs(wholeX) < 3) { toRight = !toRight; } moveToDest(toRight); break; default: Log.d("motion", action + ""); break; } return true; }
From source file:com.xee.auth.SignInButton.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { // detect if user is clicking outside Rect viewRect = new Rect(); getGlobalVisibleRect(viewRect);/*from ww w . j a v a 2 s. co m*/ if (viewRect.contains((int) event.getRawX(), (int) event.getRawY())) { if (mListener != null) { mListener.onClick(this); } if (mConnectionCallback != null) { signIn(); } } } return super.dispatchTouchEvent(event); }
From source file:cz.urbangaming.galgs.GAlg.java
@Override public boolean onTouchEvent(MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (action) { case (MotionEvent.ACTION_DOWN): Point2D point2d = new Point2D(event.getRawX(), event.getRawY()); Log.d(DEBUG_TAG, "Action was DOWN " + point2d.toString()); switch (currentWorkMode) { case WORK_MODE_ADD: pointsRenderer.addVertex(point2d); break; case WORK_MODE_DELETE: pointsRenderer.removeVertex(point2d); break; case WORK_MODE_EDIT: pointsRenderer.selectVertex(point2d); break; default:// w w w . j av a 2 s.c o m break; } return true; case (MotionEvent.ACTION_MOVE): if (currentWorkMode == WORK_MODE_EDIT) { pointsRenderer.moveSelectedVertexTo(event.getRawX(), event.getRawY()); } return true; case (MotionEvent.ACTION_UP): Log.d(DEBUG_TAG, "Action was UP"); if (currentWorkMode == WORK_MODE_EDIT) { pointsRenderer.deselectVertex(); } return true; case (MotionEvent.ACTION_CANCEL): Log.d(DEBUG_TAG, "Action was CANCEL"); return true; case (MotionEvent.ACTION_OUTSIDE): Log.d(DEBUG_TAG, "Movement occurred outside bounds of current screen element"); return true; default: return super.onTouchEvent(event); } }
From source file:com.scigames.slidegame.Registration1UserNameActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { View v = getCurrentFocus();//from w w w . j a v a 2s . c om boolean ret = super.dispatchTouchEvent(event); if (v instanceof EditText) { View w = getCurrentFocus(); int scrcoords[] = new int[2]; w.getLocationOnScreen(scrcoords); float x = event.getRawX() + w.getLeft() - scrcoords[0]; float y = event.getRawY() + w.getTop() - scrcoords[1]; Log.d("Activity", "Touch event " + event.getRawX() + "," + event.getRawY() + " " + x + "," + y + " rect " + w.getLeft() + "," + w.getTop() + "," + w.getRight() + "," + w.getBottom() + " coords " + scrcoords[0] + "," + scrcoords[1]); if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0); } } return ret; }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. *//* w w w .j a v a2 s. co m*/ private void createFloatingWindow() { SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.putInt("float", 1); editor.commit(); windowManager = (WindowManager) getApplicationContext().getSystemService("window"); wmParams = ((MyApplication) getApplication()).getMywmParams(); wmParams.type = 2002; wmParams.flags |= 8; wmParams.gravity = Gravity.LEFT | Gravity.TOP; wmParams.x = 0; wmParams.y = 0; wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.format = 1; windowManager.addView(viFloatingWindow, wmParams); viFloatingWindow.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { x = event.getRawX(); y = event.getRawY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // state = MotionEvent.ACTION_DOWN; startX = x; startY = y; mTouchStartX = event.getX(); mTouchStartY = event.getY(); Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY); break; case MotionEvent.ACTION_MOVE: // state = MotionEvent.ACTION_MOVE; updateViewPosition(); break; case MotionEvent.ACTION_UP: // state = MotionEvent.ACTION_UP; updateViewPosition(); // showImg();//? mTouchStartX = mTouchStartY = 0; break; } return true; } }); // btnWifi.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // try { // btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); // String buttonText = (String) btnWifi.getText(); // String wifiText = getResources().getString( // R.string.openwifi); // if (buttonText.equals(wifiText)) { // wifiManager.setWifiEnabled(true); // btnWifi.setText(R.string.closewifi); // } else { // wifiManager.setWifiEnabled(false); // btnWifi.setText(R.string.openwifi); // } // } catch (Exception e) { // Toast.makeText(viFloatingWindow.getContext(), "?wifi", // Toast.LENGTH_LONG).show(); // Log.e(LOG_TAG, e.toString()); // } // } // }); //? imgClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub showMemi(); } }); }
From source file:org.videolan.vlc.gui.view.PopupLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { if (mWindowManager == null) return false; if (mScaleGestureDetector != null) mScaleGestureDetector.onTouchEvent(event); if (mGestureDetector != null && mGestureDetector.onTouchEvent(event)) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = mLayoutParams.x;//from w w w . j a v a 2 s. c o m initialY = mLayoutParams.y; initialTouchX = event.getRawX(); initialTouchY = event.getRawY(); updateWindowSize(); return true; case MotionEvent.ACTION_UP: return true; case MotionEvent.ACTION_MOVE: if (mScaleGestureDetector == null || !mScaleGestureDetector.isInProgress()) { mLayoutParams.x = initialX + (int) (event.getRawX() - initialTouchX); mLayoutParams.y = initialY - (int) (event.getRawY() - initialTouchY); containInScreen(mLayoutParams.width, mLayoutParams.height); mWindowManager.updateViewLayout(PopupLayout.this, mLayoutParams); return true; } } return false; }