Exemple #1
0
        private void init(android.content.Context context)
        {
            // Get both the scrollbar states drawables
            android.content.res.TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS
                                                                                          );
            useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
            mTrackDrawable        = ta.getDrawable(TRACK_DRAWABLE);
            mOverlayDrawableLeft  = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
            mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
            mOverlayPosition      = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);
            mScrollCompleted      = true;
            getSectionsFromIndexer();
            mOverlaySize = context.getResources().getDimensionPixelSize([email protected]
                                                                        .fastscroll_overlay_size);
            mOverlayPos = new android.graphics.RectF();
            mScrollFade = new android.widget.FastScroller.ScrollFade(this);
            mPaint      = new android.graphics.Paint();
            mPaint.setAntiAlias(true);
            mPaint.setTextAlign(android.graphics.Paint.Align.CENTER);
            mPaint.setTextSize(mOverlaySize / 2);
            android.content.res.ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
            int textColorNormal = textColor.getDefaultColor();

            mPaint.setColor(textColorNormal);
            mPaint.setStyle(android.graphics.Paint.Style.FILL_AND_STROKE);
            // to show mOverlayDrawable properly
            if (mList.getWidth() > 0 && mList.getHeight() > 0)
            {
                onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
            }
            mState = STATE_NONE;
            refreshDrawableState();
            ta.recycle();
            mScaledTouchSlop = android.view.ViewConfiguration.get(context).getScaledTouchSlop
                                   ();
            mMatchDragPosition = context.getApplicationInfo().targetSdkVersion >= android.os.Build
                                 .VERSION_CODES.HONEYCOMB;
            setScrollbarPosition(mList.getVerticalScrollbarPosition());
        }
Exemple #2
0
        public virtual void draw(android.graphics.Canvas canvas)
        {
            if (mState == STATE_NONE)
            {
                // No need to draw anything
                return;
            }
            int y         = mThumbY;
            int viewWidth = mList.getWidth();

            android.widget.FastScroller.ScrollFade scrollFade = mScrollFade;
            int alpha = -1;

            if (mState == STATE_EXIT)
            {
                alpha = scrollFade.getAlpha();
                if (alpha < android.widget.FastScroller.ScrollFade.ALPHA_MAX / 2)
                {
                    mThumbDrawable.setAlpha(alpha * 2);
                }
                int left = 0;
                switch (mPosition)
                {
                case android.view.View.SCROLLBAR_POSITION_DEFAULT:
                case android.view.View.SCROLLBAR_POSITION_RIGHT:
                {
                    left = viewWidth - (mThumbW * alpha) / android.widget.FastScroller.ScrollFade.ALPHA_MAX;
                    break;
                }

                case android.view.View.SCROLLBAR_POSITION_LEFT:
                {
                    left = -mThumbW + (mThumbW * alpha) / android.widget.FastScroller.ScrollFade.ALPHA_MAX;
                    break;
                }
                }
                mThumbDrawable.setBounds(left, 0, left + mThumbW, mThumbH);
                mChangedBounds = true;
            }
            if (mTrackDrawable != null)
            {
                android.graphics.Rect thumbBounds = mThumbDrawable.getBounds();
                int left            = thumbBounds.left;
                int halfThumbHeight = (thumbBounds.bottom - thumbBounds.top) / 2;
                int trackWidth      = mTrackDrawable.getIntrinsicWidth();
                int trackLeft       = (left + mThumbW / 2) - trackWidth / 2;
                mTrackDrawable.setBounds(trackLeft, halfThumbHeight, trackLeft + trackWidth, mList
                                         .getHeight() - halfThumbHeight);
                mTrackDrawable.draw(canvas);
            }
            canvas.translate(0, y);
            mThumbDrawable.draw(canvas);
            canvas.translate(0, -y);
            // If user is dragging the scroll bar, draw the alphabet overlay
            if (mState == STATE_DRAGGING && mDrawOverlay)
            {
                if (mOverlayPosition == OVERLAY_AT_THUMB)
                {
                    int left = 0;
                    switch (mPosition)
                    {
                    case android.view.View.SCROLLBAR_POSITION_DEFAULT:
                    case android.view.View.SCROLLBAR_POSITION_RIGHT:
                    default:
                    {
                        left = System.Math.Max(0, mThumbDrawable.getBounds().left - mThumbW - mOverlaySize
                                               );
                        break;
                    }

                    case android.view.View.SCROLLBAR_POSITION_LEFT:
                    {
                        left = System.Math.Min(mThumbDrawable.getBounds().right + mThumbW, mList.getWidth
                                                   () - mOverlaySize);
                        break;
                    }
                    }
                    int top = System.Math.Max(0, System.Math.Min(y + (mThumbH - mOverlaySize) / 2, mList
                                                                 .getHeight() - mOverlaySize));
                    android.graphics.RectF pos = mOverlayPos;
                    pos.left   = left;
                    pos.right  = pos.left + mOverlaySize;
                    pos.top    = top;
                    pos.bottom = pos.top + mOverlaySize;
                    if (mOverlayDrawable != null)
                    {
                        mOverlayDrawable.setBounds((int)pos.left, (int)pos.top, (int)pos.right, (int)pos.
                                                   bottom);
                    }
                }
                mOverlayDrawable.draw(canvas);
                android.graphics.Paint paint = mPaint;
                float descent = paint.descent();
                android.graphics.RectF rectF   = mOverlayPos;
                android.graphics.Rect  tmpRect = mTmpRect;
                mOverlayDrawable.getPadding(tmpRect);
                int hOff = (tmpRect.right - tmpRect.left) / 2;
                int vOff = (tmpRect.bottom - tmpRect.top) / 2;
                canvas.drawText(mSectionText, (int)(rectF.left + rectF.right) / 2 - hOff, (int)(rectF
                                                                                                .bottom + rectF.top) / 2 + mOverlaySize / 4 - descent - vOff, paint);
            }
            else
            {
                if (mState == STATE_EXIT)
                {
                    if (alpha == 0)
                    {
                        // Done with exit
                        setState(STATE_NONE);
                    }
                    else
                    {
                        if (mTrackDrawable != null)
                        {
                            mList.invalidate(viewWidth - mThumbW, 0, viewWidth, mList.getHeight());
                        }
                        else
                        {
                            mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH);
                        }
                    }
                }
            }
        }
Exemple #3
0
		private void init(android.content.Context context)
		{
			// Get both the scrollbar states drawables
			android.content.res.TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS
				);
			useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
			mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);
			mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
			mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
			mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);
			mScrollCompleted = true;
			getSectionsFromIndexer();
			mOverlaySize = context.getResources().getDimensionPixelSize([email protected]
				.fastscroll_overlay_size);
			mOverlayPos = new android.graphics.RectF();
			mScrollFade = new android.widget.FastScroller.ScrollFade(this);
			mPaint = new android.graphics.Paint();
			mPaint.setAntiAlias(true);
			mPaint.setTextAlign(android.graphics.Paint.Align.CENTER);
			mPaint.setTextSize(mOverlaySize / 2);
			android.content.res.ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
			int textColorNormal = textColor.getDefaultColor();
			mPaint.setColor(textColorNormal);
			mPaint.setStyle(android.graphics.Paint.Style.FILL_AND_STROKE);
			// to show mOverlayDrawable properly
			if (mList.getWidth() > 0 && mList.getHeight() > 0)
			{
				onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
			}
			mState = STATE_NONE;
			refreshDrawableState();
			ta.recycle();
			mScaledTouchSlop = android.view.ViewConfiguration.get(context).getScaledTouchSlop
				();
			mMatchDragPosition = context.getApplicationInfo().targetSdkVersion >= android.os.Build
				.VERSION_CODES.HONEYCOMB;
			setScrollbarPosition(mList.getVerticalScrollbarPosition());
		}