List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:circleplus.app.LocationFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState != null) { mMapView.onRestoreInstanceState(savedInstanceState); }/* ww w.ja v a 2 s . c o m*/ // Register click listeners mSearchButton.setOnClickListener(this); mGetLocationButton.setOnClickListener(this); mGetLocationButton.setText("Locate"); mCurBtnType = ButtonType.LOC; mMapController.setZoom(LocationUtils.DEFAULT_ZOOM); mMapController.enableClick(LocationUtils.ENABLE_MAP_CLICK); mMapView.setBuiltInZoomControls(LocationUtils.ENABLE_BUILT_IN_ZOOM_CONTROLS); mMapView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: // Transfer from FOLLOW to LOCATE (NORMAL) when moving if (mCurBtnType == ButtonType.FOLLOW) { mLocationOverlay.setLocationMode(MyLocationOverlay.LocationMode.NORMAL); } mGetLocationButton.setText("Locate"); mCurBtnType = ButtonType.LOC; break; } return false; } }); // Initialize locating mHasLocationData = false; mLocationClient = new LocationClient(getActivity().getApplicationContext()); mLocationData = new LocationData(); mLocationClient.registerLocationListener(mLocationListener); LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving); option.setOpenGps(LocationUtils.OPEN_GPS); option.setCoorType(LocationUtils.COORDINATE_TYPE); option.setScanSpan(LocationUtils.SCAN_SPAN); option.setIsNeedAddress(LocationUtils.NEED_ADDRESS); mLocationClient.setLocOption(option); mLocationClient.start(); // Initialize location overlay mLocationOverlay.setLocationMode(MyLocationOverlay.LocationMode.NORMAL); mLocationOverlay.setData(mLocationData); // Add location overlay to map view mMapView.getOverlays().add(mLocationOverlay); mLocationOverlay.enableCompass(); // Refresh on setting location data mMapView.refresh(); // Initialize search mSearch = new MKSearch(); CirclePlusApp app = (CirclePlusApp) getActivity().getApplicationContext(); mFragSearchListener = new FragSearchListener(); mSearch.init(app.mBMapManager, mFragSearchListener); mSuggestAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line); mSearchText.setAdapter(mSuggestAdapter); mSearchText.addTextChangedListener(new SearchTextWatcher()); }
From source file:com.android.ex.photo.PhotoViewPager.java
/** * {@inheritDoc}/*from w w w.j a v a2 s .c o m*/ * <p> * We intercept touch event intercepts so we can prevent switching views when the * current view is internally scrollable. */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY) : InterceptType.NONE; final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT); final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT); // Only check ability to page if we can't scroll in one / both directions final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mActivePointerId = INVALID_POINTER; } switch (action) { case MotionEvent.ACTION_MOVE: { if (ignoreScrollLeft || ignoreScrollRight) { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); if (ignoreScrollLeft && ignoreScrollRight) { mLastMotionX = x; return false; } else if (ignoreScrollLeft && (x > mLastMotionX)) { mLastMotionX = x; return false; } else if (ignoreScrollRight && (x < mLastMotionX)) { mLastMotionX = x; return false; } } break; } case MotionEvent.ACTION_DOWN: { mLastMotionX = ev.getX(); // Use the raw x/y as the children can be located anywhere and there isn't a // single offset that would be meaningful mActivatedX = ev.getRawX(); mActivatedY = ev.getRawY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { // Our active pointer going up; select a new active pointer final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } break; } } return super.onInterceptTouchEvent(ev); }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. *//*from ww w. j a v a 2 s. c o 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:ca.frozen.rpicameraviewer.activities.VideoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_video, container, false); // configure the name nameView = (TextView) view.findViewById(R.id.video_name); nameView.setText(camera.name);/*from w ww . jav a 2s. c om*/ // initialize the message messageView = (TextView) view.findViewById(R.id.video_message); messageView.setTextColor(App.getClr(R.color.good_text)); messageView.setText(R.string.initializing_video); // set the texture listener textureView = (ZoomPanTextureView) view.findViewById(R.id.video_surface); textureView.setSurfaceTextureListener(this); textureView.setZoomRange(MIN_ZOOM, MAX_ZOOM); textureView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: stopFadeOutTimer(); break; case MotionEvent.ACTION_UP: if (e.getPointerCount() == 1) { startFadeOutTimer(false); } break; } return false; } }); // create the snapshot button snapshotButton = (Button) view.findViewById(R.id.video_snapshot); snapshotButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int check = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (check != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_EXTERNAL_STORAGE); } else { takeSnapshot(); } } }); // move the snapshot button over to account for the navigation bar if (fullScreen) { float scale = getContext().getResources().getDisplayMetrics().density; int margin = (int) (5 * scale + 0.5f); int extra = Utils.getNavigationBarHeight(getContext(), Configuration.ORIENTATION_LANDSCAPE); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) snapshotButton.getLayoutParams(); lp.setMargins(margin, margin, margin + extra, margin); } return view; }
From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java
@Override public void onStart() { Log.i(TAG, "onStart()"); super.onStart(); mainLayout = (FrameLayout) this.findViewById(R.id.mainLayout); mainLayout.setOnTouchListener(new View.OnTouchListener() { @Override// w w w .j av a 2 s . c o m public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { //focusOnTouch(event); } return true; } }); // Bundle extras = getIntent().getExtras(); // String videoUrl = extras.getString("videoUrl"); // Log.i(TAG, videoUrl); try { movieController = new MovieController(this.getCacheDir() + "/" + movieFile); //movieController = new MovieController("http://133.130.111.186/pilot/uploads/p1270436.MP4"); //movieController = new MovieController(videoUrl); movieController.mLoop = true; movieController.mStartPaused = true; } catch (IOException e) { Log.e(TAG, "Unable to create movie controller."); movieController = null; } ARMovieActivity.nativeStart(); }
From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java
@SuppressWarnings("deprecation") // FILL_PARENT still required for API level 7 (Android 2.1) @Override//from ww w. j av a 2s . c o m public void onResume() { Log.i(TAG, "onResume()"); super.onResume(); // Update info on whether we have an Internet connection. ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); nativeSetInternetState(isConnected ? 1 : 0); // In order to ensure that the GL surface covers the camera preview each time onStart // is called, remove and add both back into the FrameLayout. // Removing GLSurfaceView also appears to cause the GL surface to be disposed of. // To work around this, we also recreate GLSurfaceView. This is not a lot of extra // work, since Android has already destroyed the OpenGL context too, requiring us to // recreate that and reload textures etc. // Create the camera view. camSurface = new CameraSurface(this); camSurface.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { focusOnTouch(event); } return true; } }); // Create/recreate the GL view. glView = new GLSurfaceView(this); //glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); // Do we actually need a transparent surface? I think not, (default is RGB888 with depth=16) and anyway, Android 2.2 barfs on this. Renderer r = new Renderer(); r.setMovieController(movieController); glView.setRenderer(r); glView.setZOrderMediaOverlay(true); // Request that GL view's SurfaceView be on top of other SurfaceViews (including CameraPreview's SurfaceView). mainLayout.addView(camSurface, new LayoutParams(128, 128)); mainLayout.addView(glView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); if (glView != null) glView.onResume(); // Resume movieController after resuming glView. if (movieController != null) movieController.onResume(glView); }
From source file:com.android.hiparker.lierda_light.view.viewpagerindicator.LinePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }// w ww . j av a2 s . c om if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { mViewPager.fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage - 1); } return true; } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { if (action != MotionEvent.ACTION_CANCEL) { mViewPager.setCurrentItem(mCurrentPage + 1); } return true; } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: currPercentage = 0;// w w w .j av a 2s . co m downEvent = MotionEvent.obtain(event); prevY = downEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (downEvent != null && !returningToStart) { final float eventY = event.getY(); float yDiff = eventY - downEvent.getY(); if (yDiff > touchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > distanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( accelerateInterpolator.getInterpolation(yDiff / distanceToTriggerSync)); float offsetTop = yDiff; if (prevY > eventY) { offsetTop = yDiff - touchSlop; } updateContentOffsetTop((int) (offsetTop)); // if (prevY > eventY && (target.getTop() < touchSlop)) { if (prevY > eventY && (circle.getTop() < touchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(cancel); } else { updatePositionTimeout(); } prevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (downEvent != null) { downEvent.recycle(); downEvent = null; } break; } return handled; }
From source file:android.melbournehistorymap.MapsActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: lastTouched = SystemClock.uptimeMillis(); break;/*from www .j a v a 2 s . c o m*/ case MotionEvent.ACTION_UP: final long now = SystemClock.uptimeMillis(); if (now - lastTouched > delay) { //check if place details is open, if not then update the map if (expandedTile.getVisibility() == View.GONE) { // Update the map updateMap(); } } break; } return super.dispatchTouchEvent(ev); }
From source file:com.microsoft.windowsazure.mobileservices.authentication.LoginManager.java
/** * Creates the UI for the interactive authentication process * * @param startUrl The initial URL for the authentication process * @param endUrl The final URL for the authentication process * @param context The context used to create the authentication dialog * @param callback Callback to invoke when the authentication process finishes */// w w w .j a v a 2s. co m private void showLoginUIInternal(final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); wv.getSettings().setJavaScriptEnabled(true); DisplayMetrics displaymetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int webViewHeight = displaymetrics.heightPixels - 100; wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight)); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }