@Override public void onClick(View v) { v.setActivated(!v.isActivated()); if (popupWindow.isFocusable()) { // isClick = false; img_Menu.setImageResource(R.drawable.cancel_icon); } else { // isClick = true; img_Menu.setImageResource(R.drawable.menu_icon); } popupWindow.showAsDropDown(v, -5, 0); }
@OnClick({ R.id.view_article_menu_bar_bookmark, R.id.view_article_menu_bar_share, R.id.view_article_menu_bar_navigate }) public void onClick(View view) { switch (view.getId()) { case R.id.view_article_menu_bar_bookmark: view.setActivated(!view.isActivated()); callback.onBookmarkClick(view.isActivated()); break; case R.id.view_article_menu_bar_share: callback.onShareClick(); break; case R.id.view_article_menu_bar_navigate: callback.onNavigateClick(); break; default: L.w("Unknown id=" + StringUtil.intToHexStr(view.getId())); break; } }
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) return false; final View parent = (View) getParent(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { // only start tracking when in sweet spot final boolean acceptDrag; final boolean acceptLabel; if (mFollowAxis == VERTICAL) { acceptDrag = event.getX() > getWidth() - (mSweepPadding.right * 8); acceptLabel = mLabelLayout != null ? event.getX() < mLabelLayout.getWidth() : false; } else { acceptDrag = event.getY() > getHeight() - (mSweepPadding.bottom * 8); acceptLabel = mLabelLayout != null ? event.getY() < mLabelLayout.getHeight() : false; } final MotionEvent eventInParent = event.copy(); eventInParent.offsetLocation(getLeft(), getTop()); // ignore event when closer to a neighbor for (ChartSweepView neighbor : mNeighbors) { if (isTouchCloserTo(eventInParent, neighbor)) { return false; } } if (acceptDrag) { if (mFollowAxis == VERTICAL) { mTrackingStart = getTop() - mMargins.top; } else { mTrackingStart = getLeft() - mMargins.left; } mTracking = event.copy(); mTouchMode = MODE_DRAG; // starting drag should activate entire chart if (!parent.isActivated()) { parent.setActivated(true); } return true; } else if (acceptLabel) { mTouchMode = MODE_LABEL; return true; } else { mTouchMode = MODE_NONE; return false; } } case MotionEvent.ACTION_MOVE: { if (mTouchMode == MODE_LABEL) { return true; } getParent().requestDisallowInterceptTouchEvent(true); // content area of parent final Rect parentContent = getParentContentRect(); final Rect clampRect = computeClampRect(parentContent); if (clampRect.isEmpty()) return true; long value; if (mFollowAxis == VERTICAL) { final float currentTargetY = getTop() - mMargins.top; final float requestedTargetY = mTrackingStart + (event.getRawY() - mTracking.getRawY()); final float clampedTargetY = MathUtils.constrain(requestedTargetY, clampRect.top, clampRect.bottom); setTranslationY(clampedTargetY - currentTargetY); value = mAxis.convertToValue(clampedTargetY - parentContent.top); } else { final float currentTargetX = getLeft() - mMargins.left; final float requestedTargetX = mTrackingStart + (event.getRawX() - mTracking.getRawX()); final float clampedTargetX = MathUtils.constrain(requestedTargetX, clampRect.left, clampRect.right); setTranslationX(clampedTargetX - currentTargetX); value = mAxis.convertToValue(clampedTargetX - parentContent.left); } // round value from drag to nearest increment value -= value % mDragInterval; setValue(value); dispatchOnSweep(false); return true; } case MotionEvent.ACTION_UP: { if (mTouchMode == MODE_LABEL) { performClick(); } else if (mTouchMode == MODE_DRAG) { mTrackingStart = 0; mTracking = null; mValue = mLabelValue; dispatchOnSweep(true); setTranslationX(0); setTranslationY(0); requestLayout(); } mTouchMode = MODE_NONE; return true; } default: { return false; } } }