List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;//from ww w. ja va2s .co m int value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; long millis = SystemClock.uptimeMillis(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the tapTimeout // in case the user moves their finger quickly. tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, tapTimeout); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // tapTimeout in case the user moves their finger quickly. tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, tapTimeout); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= touchSlop && dY <= touchSlop) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }
From source file:com.base.view.slidemenu.SlideMenu.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (MotionEvent.ACTION_UP == ev.getAction()) { requestDisallowInterceptTouchEvent(false); }/* w w w . j a v a 2 s. c o m*/ return super.dispatchTouchEvent(ev); }
From source file:cn.com.zzwfang.view.directionalviewpager.DirectionalViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our // descendants. return false; }/*from w ww .j av a 2 s . c o m*/ if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ completeScroll(); // Remember where the motion event started if (mOrientation == HORIZONTAL) { mLastMotionX = mInitialMotion = ev.getX(); } else { mLastMotionY = mInitialMotion = ev.getY(); } mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; } case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float yDiff = Math.abs(y - mLastMotionY); float primaryDiff; float secondaryDiff; if (mOrientation == HORIZONTAL) { primaryDiff = xDiff; secondaryDiff = yDiff; } else { primaryDiff = yDiff; secondaryDiff = xDiff; } if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (primaryDiff > mTouchSlop && primaryDiff > secondaryDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; if (mOrientation == HORIZONTAL) { mLastMotionX = x; } else { mLastMotionY = y; } setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); } } if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float y = MotionEventCompat.getY(ev, activePointerIndex); int size; float scroll; if (mOrientation == HORIZONTAL) { size = getWidth(); scroll = getScrollX() + (mLastMotionX - x); mLastMotionX = x; } else { size = getHeight(); scroll = getScrollY() + (mLastMotionY - y); mLastMotionY = y; } final float lowerBound = Math.max(0, (mCurItem - 1) * size); final float upperBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * size; if (scroll < lowerBound) { scroll = lowerBound; } else if (scroll > upperBound) { scroll = upperBound; } if (mOrientation == HORIZONTAL) { // Don't lose the rounded component mLastMotionX += scroll - (int) scroll; scrollTo((int) scroll, getScrollY()); } else { // Don't lose the rounded component mLastMotionY += scroll - (int) scroll; scrollTo(getScrollX(), (int) scroll); } if (mOnPageChangeListener != null) { final int position = (int) scroll / size; final int positionOffsetPixels = (int) scroll % size; final float positionOffset = (float) positionOffsetPixels / size; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity; float lastMotion; int sizeOverThree; if (mOrientation == HORIZONTAL) { initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); lastMotion = mLastMotionX; sizeOverThree = getWidth() / 3; } else { initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); lastMotion = mLastMotionY; sizeOverThree = getHeight() / 3; } mPopulatePending = true; if ((Math.abs(initialVelocity) > mMinimumVelocity) || Math.abs(mInitialMotion - lastMotion) >= sizeOverThree) { if (lastMotion > mInitialMotion) { setCurrentItemInternal(mCurItem - 1, true, true); } else { setCurrentItemInternal(mCurItem + 1, true, true); } } else { setCurrentItemInternal(mCurItem, true, true); } mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged) { setCurrentItemInternal(mCurItem, true, true); mActivePointerId = INVALID_POINTER; endDrag(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); if (mOrientation == HORIZONTAL) { mLastMotionX = MotionEventCompat.getX(ev, index); } else { mLastMotionY = MotionEventCompat.getY(ev, index); } mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (mOrientation == HORIZONTAL) { mLastMotionX = MotionEventCompat.getX(ev, index); } else { mLastMotionY = MotionEventCompat.getY(ev, index); } break; } return true; }
From source file:com.andfchat.frontend.activities.ChatScreen.java
/** * Hides the soft keyboard if user is touching anywhere else. *///from ww w .j a va2 s . co m @Override public boolean dispatchTouchEvent(MotionEvent event) { View view = getCurrentFocus(); boolean ret = super.dispatchTouchEvent(event); if (view 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]; if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) { inputFragment.hideKeyboard(); inputFragment.saveEntry(); } } return ret; }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
@Override public boolean onTouchEvent(MotionEvent event) { final int x = (int) (event.getX() + 0.5f); final int y = (int) (event.getY() + 0.5f); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = x;// ww w. ja v a 2 s. co m mDownY = y; mInitialTarget = getDayAtLocation(mDownX, mDownY); if (mInitialTarget < 0) { return false; } if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); break; case MotionEvent.ACTION_MOVE: if (!isStillAClick(x, y)) { if (mPendingCheckForTap != null) { removeCallbacks(mPendingCheckForTap); } mInitialTarget = -1; if (mTouchedItem >= 0) { mTouchedItem = -1; invalidate(); } } break; case MotionEvent.ACTION_UP: onDayClicked(mInitialTarget); // Fall through. case MotionEvent.ACTION_CANCEL: if (mPendingCheckForTap != null) { removeCallbacks(mPendingCheckForTap); } // Reset touched day on stream end. mTouchedItem = -1; mInitialTarget = -1; invalidate(); break; } return true; }
From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;/* w w w . j a v a 2 s . c om*/ int value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; long millis = SystemClock.uptimeMillis(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT // in case the user moves their finger quickly. tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, TAP_TIMEOUT); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // TAP_TIMEOUT in case the user moves their finger quickly. tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, TAP_TIMEOUT); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); final int currentState = mCurrentState; if (STATE_DRAG == currentState || STATE_SCROLL == currentState) { return true; }/*from w w w .j av a 2s . c om*/ switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x; mIsTapContent = isTapContent(x, y); return isOpen() && mIsTapContent; case MotionEvent.ACTION_MOVE: float distance = x - mPressedX; if (Math.abs(distance) >= mTouchSlop && mIsTapContent) { if (!canScroll(this, (int) distance, (int) x, (int) y)) { setCurrentState(STATE_DRAG); return true; } } } return super.onInterceptTouchEvent(ev); }
From source file:cn.kangeqiu.kq.activity.GroupDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ??groupid/* www .j av a 2 s. co m*/ groupId = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(groupId); roomId = getIntent().getStringExtra("roomId"); // we are not supposed to show the group if we don't find the group if (group == null) { finish(); return; } setContentView(R.layout.activity_group_details); shareUtil = new ShareUtils(this); instance = this; st = getResources().getString(R.string.people); clearAllHistory = (RelativeLayout) findViewById(R.id.clear_all_history); userGridview = (ExpandGridView) findViewById(R.id.gridview); loadingPB = (ProgressBar) findViewById(R.id.progressBar); exitBtn = (Button) findViewById(R.id.btn_exit_grp); deleteBtn = (Button) findViewById(R.id.btn_exitdel_grp); blacklistLayout = (RelativeLayout) findViewById(R.id.rl_blacklist); changeGroupNameLayout = (RelativeLayout) findViewById(R.id.rl_change_group_name); rl_switch_block_groupmsg = (RelativeLayout) findViewById(R.id.rl_switch_block_groupmsg); iv_switch_block_groupmsg = (ImageView) findViewById(R.id.iv_switch_block_groupmsg); iv_switch_unblock_groupmsg = (ImageView) findViewById(R.id.iv_switch_unblock_groupmsg); hourse_name = (TextView) findViewById(R.id.hourse_name); invite_number = (TextView) findViewById(R.id.invite_number); match_name = (TextView) findViewById(R.id.match_name); rl_chuiniu = (RelativeLayout) findViewById(R.id.rl_chuiniu); rl_guess = (RelativeLayout) findViewById(R.id.rl_guess); rl_match_name = (RelativeLayout) findViewById(R.id.rl_match_name); member_sum = (TextView) findViewById(R.id.member_sum); rl_chuiniu.setOnClickListener(this); rl_guess.setOnClickListener(this); rl_switch_block_groupmsg.setOnClickListener(this); Drawable referenceDrawable = getResources().getDrawable(R.drawable.smiley_add_btn); referenceWidth = referenceDrawable.getIntrinsicWidth(); referenceHeight = referenceDrawable.getIntrinsicHeight(); if (group.getOwner() == null || "".equals(group.getOwner()) || !group.getOwner().equals(EMChatManager.getInstance().getCurrentUser())) { exitBtn.setVisibility(View.GONE); deleteBtn.setVisibility(View.GONE); blacklistLayout.setVisibility(View.GONE); // changeGroupNameLayout.setVisibility(View.GONE); changeGroupNameLayout.setClickable(false); changeGroupNameLayout.setFocusable(false); findViewById(R.id.hourse_name_right).setVisibility(View.INVISIBLE); } // if (EMChatManager.getInstance().getCurrentUser().equals(group.getOwner())) { exitBtn.setVisibility(View.GONE); deleteBtn.setVisibility(View.VISIBLE); findViewById(R.id.hourse_name_right).setVisibility(View.VISIBLE); findViewById(R.id.match_right).setVisibility(View.VISIBLE); changeGroupNameLayout.setOnClickListener(this); rl_match_name.setOnClickListener(this); } // ((TextView) // findViewById(R.id.group_name)).setText(group.getGroupName() // + "(" + group.getAffiliationsCount() + st); List<String> members = new ArrayList<String>(); members.addAll(group.getMembers()); adapter = new GridAdapter(this, R.layout.grid); userGridview.setAdapter(adapter); // ???group updateGroup(); // OnTouchListener userGridview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (adapter.isInDeleteMode) { adapter.isInDeleteMode = false; adapter.notifyDataSetChanged(); return true; } break; default: break; } return false; } }); clearAllHistory.setOnClickListener(this); blacklistLayout.setOnClickListener(this); initDate(); }
From source file:arun.com.chromer.webheads.ui.views.WebHead.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w ww. j a v a 2 s . co m*/ public boolean onTouchEvent(MotionEvent event) { // Don't react to any touch event and consume it when we are being destroyed, if we are a // a slave or if we are in queue. if (destroyed || !master || inQueue) return true; try { // Reset gesture flag on each event wasFlung = false; wasClicked = false; // Let gesture detector intercept events, needed for fling and click gestureDetector.onTouchEvent(event); if (wasClicked) return true; switch (event.getAction()) { case ACTION_DOWN: handleTouchDown(event); break; case ACTION_MOVE: handleMove(event); break; case ACTION_UP: case ACTION_CANCEL: if (handleTouchUp()) return true; break; default: break; } } catch (NullPointerException e) { destroySelf(true); } return true; }
From source file:com.android.documentsui.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);//ww w. jav a 2 s . c o m final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = getIntent().getType(); final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(getIntent()); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = getIntent().getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }