List of usage examples for android.view MotionEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view MotionEvent ACTION_DOWN.
Click Source Link
From source file:com.chess.genesis.activity.GameListOnlineFrag.java
@Override public boolean onTouch(final View v, final MotionEvent event) { if (v.getId() == R.id.game_search) v.setBackgroundColor(//from w w w . j a v a 2 s . co m (event.getAction() == MotionEvent.ACTION_DOWN) ? MColors.BLUE_NEON : MColors.CLEAR); return false; }
From source file:com.amazon.appstream.fireclient.FireClientActivity.java
/** * A "touch event" includes mouse motion when the mouse button * is down./*from ww w . j av a 2 s. co m*/ */ @Override public boolean dispatchTouchEvent(MotionEvent event) { if (mKeyboardActive) { if (mGestureDetector.onTouchEvent(event)) { return true; } } if (super.dispatchTouchEvent(event)) return true; int flags = 0; if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) { flags = AppStreamInterface.CET_TOUCH_FLAG; } event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, flags); break; case MotionEvent.ACTION_DOWN: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_DOWN | flags); break; case MotionEvent.ACTION_UP: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_UP | flags); break; } return true; }
From source file:com.android.app.MediaPlaybackActivity.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); TextView tv = textViewForContainer(v); if (tv == null) { return false; }//www .j a v a2s.co m if (action == MotionEvent.ACTION_DOWN) { v.setBackgroundColor(0xff606060); mInitialX = mLastX = (int) event.getX(); mDraggingLabel = false; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { v.setBackgroundColor(0); if (mDraggingLabel) { Message msg = mLabelScroller.obtainMessage(0, tv); mLabelScroller.sendMessageDelayed(msg, 1000); } } else if (action == MotionEvent.ACTION_MOVE) { if (mDraggingLabel) { int scrollx = tv.getScrollX(); int x = (int) event.getX(); int delta = mLastX - x; if (delta != 0) { mLastX = x; scrollx += delta; if (scrollx > mTextWidth) { // scrolled the text completely off the view to the left scrollx -= mTextWidth; scrollx -= mViewWidth; } if (scrollx < -mViewWidth) { // scrolled the text completely off the view to the right scrollx += mViewWidth; scrollx += mTextWidth; } tv.scrollTo(scrollx, 0); } return true; } int delta = mInitialX - (int) event.getX(); if (Math.abs(delta) > mTouchSlop) { // start moving mLabelScroller.removeMessages(0, tv); // Only turn ellipsizing off when it's not already off, because it // causes the scroll position to be reset to 0. if (tv.getEllipsize() != null) { tv.setEllipsize(null); } Layout ll = tv.getLayout(); // layout might be null if the text just changed, or ellipsizing // was just turned off if (ll == null) { return false; } // get the non-ellipsized line width, to determine whether scrolling // should even be allowed mTextWidth = (int) tv.getLayout().getLineWidth(0); mViewWidth = tv.getWidth(); if (mViewWidth > mTextWidth) { tv.setEllipsize(TruncateAt.END); v.cancelLongPress(); return false; } mDraggingLabel = true; tv.setHorizontalFadingEdgeEnabled(true); v.cancelLongPress(); return true; } } return false; }
From source file:fr.cobaltians.cobalt.fragments.CobaltFragment.java
protected void setWebViewSettings(Object javascriptInterface) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD) mWebView.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS); mWebView.setScrollListener(this); mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); // Enables JS WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); // Enables and setups JS local storage webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); //@deprecated since API 19. But calling this method have simply no effect for API 19+ webSettings.setDatabasePath(mContext.getFilesDir().getParentFile().getPath() + "/databases/"); // Enables cross-domain calls for Ajax allowAjax();// w ww . j a v a2 s . co m // Fix some focus issues on old devices like HTC Wildfire // keyboard was not properly showed on input touch. mWebView.requestFocus(View.FOCUS_DOWN); mWebView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!view.hasFocus()) { view.requestFocus(); } break; default: break; } return false; } }); // Add JavaScript interface so JavaScript can call native functions. mWebView.addJavascriptInterface(javascriptInterface, "Android"); mWebView.addJavascriptInterface(new LocalStorageJavaScriptInterface(mContext), "LocalStorage"); WebViewClient webViewClient = new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { executeWaitingCalls(); } }; mWebView.setWebViewClient(webViewClient); }
From source file:cl.monsoon.s1next.widget.PhotoView.java
@Override public boolean onDoubleTapEvent(MotionEvent e) { final int action = e.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: if (mQuickScaleEnabled) { mDownFocusX = e.getX();// w ww . jav a 2s . c o m mDownFocusY = e.getY(); } break; case MotionEvent.ACTION_UP: if (mQuickScaleEnabled) { handled = scale(e); } break; case MotionEvent.ACTION_MOVE: if (mQuickScaleEnabled && mDoubleTapOccurred) { final int deltaX = (int) (e.getX() - mDownFocusX); final int deltaY = (int) (e.getY() - mDownFocusY); int distance = (deltaX * deltaX) + (deltaY * deltaY); if (distance > sTouchSlopSquare) { mDoubleTapOccurred = false; } } break; } return handled; }
From source file:io.selendroid.server.model.AndroidNativeElement.java
private void clickOnScreen(float x, float y) { SelendroidLogger.debug(String.format("Clicking at position [%f, %f]", x, y)); final ServerInstrumentation inst = ServerInstrumentation.getInstance(); long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis(); final MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0); final MotionEvent event2 = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0); try {/*from w w w.ja v a 2s . c om*/ inst.sendPointerSync(event); inst.sendPointerSync(event2); try { Thread.sleep(300); } catch (InterruptedException ignored) { } } catch (SecurityException e) { SelendroidLogger.error("error while clicking element", e); } }
From source file:sjizl.com.FileUploadTest.java
@SuppressLint("NewApi") @Override//from w ww. j a v a 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.fileuploadtest2); //ac_image_grid TextView textView2_under_title; final ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext())); progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole); progressBar_hole.setVisibility(View.INVISIBLE); right_lin = (LinearLayout) findViewById(R.id.right_lin); rand = CommonUtilities.randInt(111, 999); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); //right_lin.setBackgroundColor(Color.BLUE); right_lin = (LinearLayout) findViewById(R.id.right_lin); left_lin1 = (LinearLayout) findViewById(R.id.left_lin1); left_lin3 = (LinearLayout) findViewById(R.id.left_lin3); left_lin4 = (LinearLayout) findViewById(R.id.left_lin4); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); upload_photo_text = (LinearLayout) findViewById(R.id.upload_photo_text); textView2_under_title = (TextView) findViewById(R.id.textView2_under_title); ((LinearLayout) textView2_under_title.getParent()).removeView(textView2_under_title); textView2_under_title.setVisibility(View.GONE); ImageView imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Button upload_photo0 = (Button) findViewById(R.id.upload_photo0); Button upload_photo1 = (Button) findViewById(R.id.upload_photo1); Button upload_photo2 = (Button) findViewById(R.id.upload_photo2); upload_photo0.setVisibility(View.GONE); upload_photo1.setVisibility(View.GONE); upload_photo2.setVisibility(View.GONE); upload_photo0.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CommonUtilities.custom_toast(getApplicationContext(), FileUploadTest.this, "UploadActivity! ", null, R.drawable.iconbd); Intent dashboard = new Intent(getApplicationContext(), UploadActivity.class); startActivity(dashboard); } }); upload_photo1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); upload_photo2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); final ImageView left_button; left_button = (ImageView) findViewById(R.id.imageView1_back); Button button1 = (Button) findViewById(R.id.upload_photo1); SharedPreferences sp = getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE); naam = sp.getString("naam", null); username = sp.getString("username", null); password = sp.getString("password", null); foto = sp.getString("foto", null); foto_num = sp.getString("foto_num", null); imageLoader.displayImage("http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, imageView2_dashboard, options); Brows(); listView.setLongClickable(true); registerForContextMenu(listView); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //startImagePagerActivity(position); if (position == 0) { openGallery(SELECT_FILE1); } else { listView.showContextMenuForChild(view); // registerForContextMenu(view); // openContextMenu(view); // unregisterForContextMenu(view); } } }); left_lin1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) { left_lin1.setBackgroundColor(Color.DKGRAY); v.setBackgroundColor(Color.DKGRAY); onBackPressed(); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { left_lin1.setBackgroundColor(Color.BLACK); v.setBackgroundColor(Color.BLACK); } return false; } }); CommonUtilities u = new CommonUtilities(); u.setHeaderConrols(getApplicationContext(), this, right_lin, left_lin3, left_lin4, left_lin1, left_button); ; middle_lin.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) { middle_lin.setBackgroundColor(Color.DKGRAY); v.setBackgroundColor(Color.DKGRAY); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { middle_lin.setBackgroundColor(Color.BLACK); v.setBackgroundColor(Color.BLACK); } return false; } }); }
From source file:com.achep.acdisplay.ui.widgets.CircleView.java
public boolean sendTouchEvent(@NonNull MotionEvent event) { final int action = event.getActionMasked(); // If current circle is canceled then // ignore all actions except of touch down (to reset state.) if (mCanceled && action != MotionEvent.ACTION_DOWN) return false; // Cancel the current circle on two-or-more-fingers touch. if (event.getPointerCount() > 1) { cancelCircle();// w ww. j av a 2s . c o m return false; } final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: clearAnimation(); Config config = Config.getInstance(); // Corner actions int width = getWidth(); int height = getHeight(); int radius = Math.min(width, height) / 3; if (MathUtils.isInCircle(x, y, 0, 0, radius)) { // Top left mCornerActionId = config.getCornerActionLeftTop(); } else if (MathUtils.isInCircle(x, y, -width, 0, radius)) { // Top right mCornerActionId = config.getCornerActionRightTop(); } else if (MathUtils.isInCircle(x, y, 0, -height, radius)) { // Bottom left mCornerActionId = config.getCornerActionLeftBottom(); } else if (MathUtils.isInCircle(x, y, -width, -height, radius)) { // Bottom right mCornerActionId = config.getCornerActionRightBottom(); } else { // The default action is unlocking. mCornerActionId = Config.CORNER_UNLOCK; } // Update colors and icon drawable. boolean needsColorReset = updateIcon(); setInnerColor(getColor(config.getCircleInnerColor()), needsColorReset); setOuterColor(getColor(config.getCircleOuterColor())); // Initialize circle mRadiusTargetAimed = false; mRadiusMaxPeak = 0; mPoint[0] = x; mPoint[1] = y; mCanceled = false; if (mHandler.hasMessages(ACTION_UNLOCK)) { // Cancel unlocking process. mHandler.sendEmptyMessage(ACTION_UNLOCK_CANCEL); } mHandler.removeCallbacksAndMessages(null); mHandler.sendEmptyMessageDelayed(MSG_CANCEL, 1000); mHandler.sendEmptyMessage(ACTION_START); break; case MotionEvent.ACTION_MOVE: setRadius(x, y); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mRadiusTargetAimed || action == MotionEvent.ACTION_CANCEL) { cancelCircle(); break; } startUnlock(); break; } return true; }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. *//*from w ww . 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:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java
@SuppressWarnings("deprecation") // FILL_PARENT still required for API level 7 (Android 2.1) @Override//from w ww. j a va 2 s .co 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); }