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.undatech.opaque.RemoteCanvasActivity.java
/** * Initializes the on-screen keys for meta keys and arrow keys. *///from w w w. j a va 2 s .c om private void initializeOnScreenKeys() { layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys); keyStow = (ImageButton) findViewById(R.id.keyStow); setKeyStowDrawableAndVisibility(); keyStow.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (layoutKeys.getVisibility() == View.VISIBLE) { extraKeysHidden = true; setExtraKeysVisibility(View.GONE, false); } else { extraKeysHidden = false; setExtraKeysVisibility(View.VISIBLE, true); } layoutKeys.offsetTopAndBottom(prevBottomOffset); setKeyStowDrawableAndVisibility(); } }); // Define action of tab key and meta keys. keyTab = (ImageButton) findViewById(R.id.keyTab); keyTab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_TAB; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyTab.setImageResource(R.drawable.tabon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyTab.setImageResource(R.drawable.taboff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyEsc = (ImageButton) findViewById(R.id.keyEsc); keyEsc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = 111; /* KEYCODE_ESCAPE */ if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyEsc.setImageResource(R.drawable.escon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyEsc.setImageResource(R.drawable.escoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyCtrl = (ImageButton) findViewById(R.id.keyCtrl); keyCtrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = false; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); } }); keyCtrl.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = true; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); return true; } }); keySuper = (ImageButton) findViewById(R.id.keySuper); keySuper.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = false; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); } }); keySuper.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = true; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); return true; } }); keyAlt = (ImageButton) findViewById(R.id.keyAlt); keyAlt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = false; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); } }); keyAlt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = true; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); return true; } }); keyShift = (ImageButton) findViewById(R.id.keyShift); keyShift.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = false; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); } }); keyShift.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = true; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); return true; } }); // Define action of arrow keys. keyUp = (ImageButton) findViewById(R.id.keyUpArrow); keyUp.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_UP; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyUp.setImageResource(R.drawable.upon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyUp.setImageResource(R.drawable.upoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyDown = (ImageButton) findViewById(R.id.keyDownArrow); keyDown.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_DOWN; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyDown.setImageResource(R.drawable.downon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyDown.setImageResource(R.drawable.downoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow); keyLeft.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_LEFT; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyLeft.setImageResource(R.drawable.lefton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyLeft.setImageResource(R.drawable.leftoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyRight = (ImageButton) findViewById(R.id.keyRightArrow); keyRight.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_RIGHT; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyRight.setImageResource(R.drawable.righton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyRight.setImageResource(R.drawable.rightoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); }
From source file:com.android.mail.browse.ConversationContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mTouchIsDown = false;// w w w . j a va 2s .c o m } else if (!mTouchIsDown && (action == MotionEvent.ACTION_MOVE || action == MotionEvent.ACTION_POINTER_DOWN)) { forwardFakeMotionEvent(ev, MotionEvent.ACTION_DOWN); if (mMissedPointerDown) { forwardFakeMotionEvent(ev, MotionEvent.ACTION_POINTER_DOWN); mMissedPointerDown = false; } mTouchIsDown = true; } final boolean webViewResult = mWebView.onTouchEvent(ev); // LogUtils.v(TAG, "in Container.OnTouch. action=%d x/y=%f/%f pointers=%d", // ev.getActionMasked(), ev.getX(), ev.getY(), ev.getPointerCount()); return webViewResult; }
From source file:com.gizwits.framework.activity.BaseActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { // ?ViewEditText View v = getCurrentFocus(); if (isShouldHideInput(v, ev)) { hideSoftInput(v.getWindowToken()); }/*from w w w . j a v a 2 s . c o m*/ } return super.dispatchTouchEvent(ev); }
From source file:com.cloverstudio.spika.CameraCropActivity.java
@Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: savedMatrix.set(matrix);//w w w .ja va 2 s . c o m start.set(event.getX(), event.getY()); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(mid, event); mode = ZOOM; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { // ... matrix.set(savedMatrix); matrix.postTranslate(event.getX() - start.x, event.getY() - start.y); start_x = event.getX() - start.x; start_y = event.getY() - start.y; } else if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; mAspect = scale; matrix.postScale(scale, scale, mid.x, mid.y); } } break; } view.setImageMatrix(matrix); view.invalidate(); return true; }
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 *//*ww w. j a va 2 s . c o 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(); }
From source file:com.android.backups.BackupStaggeredGridView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from ww w. ja v a 2 s.c om*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; setTouchMode(mTouchMode); return true; } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; setTouchMode(mTouchMode); return true; } } } return false; }
From source file:com.aincc.libtest.activity.flip.FlipViewGroup.java
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int tempCurrentViewId = currentItem; if (event.getY() < getHeight() / 2) { if (tempCurrentViewId > 0) { tempCurrentViewId--;/*from ww w. j ava 2 s . co m*/ } renderer.getCards().handleTouchEventDown(true, tempCurrentViewId, getPrevPrevView()); } else { if (tempCurrentViewId < adapter.getCount() - 1) { tempCurrentViewId++; } renderer.getCards().handleTouchEventDown(false, tempCurrentViewId, getNextNextView()); } } return renderer.getCards().handleTouchEvent(event); }
From source file:cn.iterlog.myapplication.widget.overscroll.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from ww w . j av a2 s.com final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && mAdapter != null && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } updateSelectorState(); } break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; invalidate(); } else { mTouchMode = TOUCH_MODE_IDLE; } if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; } return true; } else if (!mDataChanged && mAdapter != null && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.androtex.viewpagerindicator.TitlePageIndicator.java
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; if ((mCurrentPage > 0) && (event.getX() < halfWidth - sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } else if ((mCurrentPage < count - 1) && (event.getX() > halfWidth + sixthWidth)) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; }// w w w. j a va 2 s. c o m } return super.onTouchEvent(event); }
From source file:com.netease.qa.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. *///from ww w. jav a 2 s. c om 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() - statusBarHeight; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchStartX = event.getX(); mTouchStartY = event.getY(); break; case MotionEvent.ACTION_MOVE: updateViewPosition(); break; case MotionEvent.ACTION_UP: updateViewPosition(); 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.open_wifi); if (buttonText.equals(wifiText)) { wifiManager.setWifiEnabled(true); btnWifi.setText(R.string.close_wifi); } else { wifiManager.setWifiEnabled(false); btnWifi.setText(R.string.open_wifi); } } catch (Exception e) { Toast.makeText(viFloatingWindow.getContext(), getString(R.string.wifi_fail_toast), Toast.LENGTH_LONG).show(); Log.e(LOG_TAG, e.toString()); } } }); }