@Override public void onBackPressed() { if (mLayout != null && (mLayout.getPanelState() == PanelState.EXPANDED || mLayout.getPanelState() == PanelState.ANCHORED)) { mLayout.setPanelState(PanelState.COLLAPSED); } else { super.onBackPressed(); } } }
mLayout.addPanelSlideListener(new PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { mLayout.setFadeOnClickListener(new OnClickListener() { @Override public void onClick(View view) {
/** * Set the Drag View after the view is inflated */ @Override protected void onFinishInflate() { super.onFinishInflate(); if (mDragViewResId != -1) { setDragView(findViewById(mDragViewResId)); } if (mScrollableViewResId != -1) { setScrollableView(findViewById(mScrollableViewResId)); } }
/** * Set the draggable view portion. Use to null, to allow the whole panel to be draggable * * @param dragViewResId The resource ID of the new drag view */ public void setDragView(int dragViewResId) { mDragViewResId = dragViewResId; setDragView(findViewById(dragViewResId)); }
@Override public void onClick(View v) { if (!isEnabled() || !isTouchEnabled()) return; if (mSlideState != PanelState.EXPANDED && mSlideState != PanelState.ANCHORED) { if (mAnchorPoint < 1.0f) { setPanelState(PanelState.ANCHORED); } else { setPanelState(PanelState.EXPANDED); } } else { setPanelState(PanelState.COLLAPSED); } } });
@Override public void onClick(View view) { mLayout.setPanelState(PanelState.COLLAPSED); } });
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.demo, menu); MenuItem item = menu.findItem(R.id.action_toggle); if (mLayout != null) { if (mLayout.getPanelState() == PanelState.HIDDEN) { item.setTitle(R.string.action_show); } else { item.setTitle(R.string.action_hide); } } return true; }
/** * Set the collapsed panel height in pixels * * @param val A height in pixels */ public void setPanelHeight(int val) { if (getPanelHeight() == val) { return; } mPanelHeight = val; if (!mFirstLayout) { requestLayout(); } if (getPanelState() == PanelState.COLLAPSED) { smoothToBottom(); invalidate(); return; } }
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int paddingLeft = getPaddingLeft(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); break; case HIDDEN: int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight); mSlideOffset = computeSlideOffset(newTop); break; default: final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); childTop = computePanelTopPosition(mSlideOffset); childTop = computePanelTopPosition(mSlideOffset) + mSlideableView.getMeasuredHeight(); updateObscuredViewVisibility(); applyParallaxForCurrentSlideOffset();
case R.id.action_toggle: { if (mLayout != null) { if (mLayout.getPanelState() != PanelState.HIDDEN) { mLayout.setPanelState(PanelState.HIDDEN); item.setTitle(R.string.action_show); } else { mLayout.setPanelState(PanelState.COLLAPSED); item.setTitle(R.string.action_hide); if (mLayout.getAnchorPoint() == 1.0f) { mLayout.setAnchorPoint(0.7f); mLayout.setPanelState(PanelState.ANCHORED); item.setTitle(R.string.action_anchor_disable); } else { mLayout.setAnchorPoint(1.0f); mLayout.setPanelState(PanelState.COLLAPSED); item.setTitle(R.string.action_anchor_enable);
private void onPanelDragged(int newTop) { if (mSlideState != PanelState.DRAGGING) { mLastNotDraggingSlideState = mSlideState; } setPanelStateInternal(PanelState.DRAGGING); // Recompute the slide offset based on the new top position mSlideOffset = computeSlideOffset(newTop); applyParallaxForCurrentSlideOffset(); // Dispatch the slide event dispatchOnPanelSlide(mSlideableView); // If the slide offset is negative, and overlay is not on, we need to increase the // height of the main content LayoutParams lp = (LayoutParams) mMainView.getLayoutParams(); int defaultHeight = getHeight() - getPaddingBottom() - getPaddingTop() - mPanelHeight; if (mSlideOffset <= 0 && !mOverlayContent) { // expand the main view lp.height = mIsSlidingUp ? (newTop - getPaddingBottom()) : (getHeight() - getPaddingBottom() - mSlideableView.getMeasuredHeight() - newTop); if (lp.height == defaultHeight) { lp.height = LayoutParams.MATCH_PARENT; } mMainView.requestLayout(); } else if (lp.height != LayoutParams.MATCH_PARENT && !mOverlayContent) { lp.height = LayoutParams.MATCH_PARENT; mMainView.requestLayout(); } }
throw new IllegalArgumentException("Panel state cannot be null or DRAGGING."); if (!isEnabled() || (!mFirstLayout && mSlideableView == null) || state == mSlideState setPanelStateInternal(state); } else { if (mSlideState == PanelState.HIDDEN) { mSlideableView.setVisibility(View.VISIBLE); requestLayout(); smoothSlideTo(mAnchorPoint, 0); break; case COLLAPSED: smoothSlideTo(0, 0); break; case EXPANDED: smoothSlideTo(1.0f, 0); break; case HIDDEN: int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight); smoothSlideTo(computeSlideOffset(newTop), 0); break;
@Override public void onBackPressed() { if (findViewById(R.id.context_menu_fragment) == null && mSlidingUpPanelLayout.isEnabled() && (mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED || mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.ANCHORED)) { mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); } else { if (mSlidingUpPanelLayout.getPanelState() != SlidingUpPanelLayout.PanelState.HIDDEN) { AnimationUtils.fade(mPlaybackPanel, AnimationUtils.DURATION_CONTEXTMENU, true); } super.onBackPressed(); } }
final int action = MotionEventCompat.getActionMasked(ev); if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.abort(); return super.dispatchTouchEvent(ev); if (!isViewUnder(mScrollableView, (int) mInitialMotionX, (int) mInitialMotionY)) { return super.dispatchTouchEvent(ev); return this.onTouchEvent(ev); } else if (dy * (mIsSlidingUp ? 1 : -1) < 0) { // Expanding return this.onTouchEvent(ev);
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); mDockViewPager.setAdapter(mDockViewPagerAdapter); mSlidingUpPanelLayout.addPanelSlideListener(this);
/** * Smoothly animate mDraggingPane to the target X position within its range. * * @param slideOffset position to animate to * @param velocity initial velocity in case of fling, or 0. */ boolean smoothSlideTo(float slideOffset, int velocity) { if (!isEnabled() || mSlideableView == null) { // Nothing to do. return false; } int panelTop = computePanelTopPosition(slideOffset); if (mDragHelper.smoothSlideViewTo(mSlideableView, mSlideableView.getLeft(), panelTop)) { setAllChildrenVisible(); ViewCompat.postInvalidateOnAnimation(this); return true; } return false; }
@Override public void onClick(View view) { mLayout.setEnabled(true); mLayout.setClickable(true); mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); } });
slider.addPanelSlideListener(this);
slidingUpPanelLayout.setAnchorPoint(0.5f); slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { slidingUpPanelLayout.setFadeOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled() || !isTouchEnabled()) { return super.onTouchEvent(ev); } try { mDragHelper.processTouchEvent(ev); return true; } catch (Exception ex) { // Ignore the pointer out of range exception return false; } }