Search in sources :

Example 1 with ScrollBarDrawable

use of android.widget.ScrollBarDrawable in project android_frameworks_base by ResurrectionRemix.

the class View method initializeScrollbarsInternal.

/**
     * <p>
     * Initializes the scrollbars from a given set of styled attributes. This
     * method should be called by subclasses that need scrollbars and when an
     * instance of these subclasses is created programmatically rather than
     * being inflated from XML. This method is automatically called when the XML
     * is inflated.
     * </p>
     *
     * @param a the styled attributes set to initialize the scrollbars from
     * @hide
     */
protected void initializeScrollbarsInternal(TypedArray a) {
    initScrollCache();
    final ScrollabilityCache scrollabilityCache = mScrollCache;
    if (scrollabilityCache.scrollBar == null) {
        scrollabilityCache.scrollBar = new ScrollBarDrawable();
        scrollabilityCache.scrollBar.setState(getDrawableState());
        scrollabilityCache.scrollBar.setCallback(this);
    }
    final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true);
    if (!fadeScrollbars) {
        scrollabilityCache.state = ScrollabilityCache.ON;
    }
    scrollabilityCache.fadeScrollBars = fadeScrollbars;
    scrollabilityCache.scrollBarFadeDuration = a.getInt(R.styleable.View_scrollbarFadeDuration, ViewConfiguration.getScrollBarFadeDuration());
    scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt(R.styleable.View_scrollbarDefaultDelayBeforeFade, ViewConfiguration.getScrollDefaultDelay());
    scrollabilityCache.scrollBarSize = a.getDimensionPixelSize(com.android.internal.R.styleable.View_scrollbarSize, ViewConfiguration.get(mContext).getScaledScrollBarSize());
    Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal);
    scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track);
    Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal);
    if (thumb != null) {
        scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb);
    }
    boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, false);
    if (alwaysDraw) {
        scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true);
    }
    track = a.getDrawable(R.styleable.View_scrollbarTrackVertical);
    scrollabilityCache.scrollBar.setVerticalTrackDrawable(track);
    thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical);
    if (thumb != null) {
        scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb);
    }
    alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, false);
    if (alwaysDraw) {
        scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true);
    }
    // Apply layout direction to the new Drawables if needed
    final int layoutDirection = getLayoutDirection();
    if (track != null) {
        track.setLayoutDirection(layoutDirection);
    }
    if (thumb != null) {
        thumb.setLayoutDirection(layoutDirection);
    }
    // Re-apply user/background padding so that scrollbar(s) get added
    resolvePadding();
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ScrollBarDrawable(android.widget.ScrollBarDrawable) ScrollBarDrawable(android.widget.ScrollBarDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 2 with ScrollBarDrawable

use of android.widget.ScrollBarDrawable in project android_frameworks_base by ParanoidAndroid.

the class View method initializeScrollbars.

/**
     * <p>
     * Initializes the scrollbars from a given set of styled attributes. This
     * method should be called by subclasses that need scrollbars and when an
     * instance of these subclasses is created programmatically rather than
     * being inflated from XML. This method is automatically called when the XML
     * is inflated.
     * </p>
     *
     * @param a the styled attributes set to initialize the scrollbars from
     */
protected void initializeScrollbars(TypedArray a) {
    initScrollCache();
    final ScrollabilityCache scrollabilityCache = mScrollCache;
    if (scrollabilityCache.scrollBar == null) {
        scrollabilityCache.scrollBar = new ScrollBarDrawable();
    }
    final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true);
    if (!fadeScrollbars) {
        scrollabilityCache.state = ScrollabilityCache.ON;
    }
    scrollabilityCache.fadeScrollBars = fadeScrollbars;
    scrollabilityCache.scrollBarFadeDuration = a.getInt(R.styleable.View_scrollbarFadeDuration, ViewConfiguration.getScrollBarFadeDuration());
    scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt(R.styleable.View_scrollbarDefaultDelayBeforeFade, ViewConfiguration.getScrollDefaultDelay());
    scrollabilityCache.scrollBarSize = a.getDimensionPixelSize(com.android.internal.R.styleable.View_scrollbarSize, ViewConfiguration.get(mContext).getScaledScrollBarSize());
    Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal);
    scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track);
    Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal);
    if (thumb != null) {
        scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb);
    }
    boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, false);
    if (alwaysDraw) {
        scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true);
    }
    track = a.getDrawable(R.styleable.View_scrollbarTrackVertical);
    scrollabilityCache.scrollBar.setVerticalTrackDrawable(track);
    thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical);
    if (thumb != null) {
        scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb);
    }
    alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, false);
    if (alwaysDraw) {
        scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true);
    }
    // Apply layout direction to the new Drawables if needed
    final int layoutDirection = getLayoutDirection();
    if (track != null) {
        track.setLayoutDirection(layoutDirection);
    }
    if (thumb != null) {
        thumb.setLayoutDirection(layoutDirection);
    }
    // Re-apply user/background padding so that scrollbar(s) get added
    resolvePadding();
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ScrollBarDrawable(android.widget.ScrollBarDrawable) ScrollBarDrawable(android.widget.ScrollBarDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 3 with ScrollBarDrawable

use of android.widget.ScrollBarDrawable in project android_frameworks_base by ParanoidAndroid.

the class View method awakenScrollBars.

/**
     * <p>
     * Trigger the scrollbars to draw. When invoked this method starts an
     * animation to fade the scrollbars out after a fixed delay. If a subclass
     * provides animated scrolling, the start delay should equal the duration of
     * the scrolling animation.
     * </p>
     *
     * <p>
     * The animation starts only if at least one of the scrollbars is enabled,
     * as specified by {@link #isHorizontalScrollBarEnabled()} and
     * {@link #isVerticalScrollBarEnabled()}. When the animation is started,
     * this method returns true, and false otherwise. If the animation is
     * started, this method calls {@link #invalidate()} if the invalidate parameter
     * is set to true; in that case the caller
     * should not call {@link #invalidate()}.
     * </p>
     *
     * <p>
     * This method should be invoked everytime a subclass directly updates the
     * scroll parameters.
     * </p>
     *
     * @param startDelay the delay, in milliseconds, after which the animation
     *        should start; when the delay is 0, the animation starts
     *        immediately
     *
     * @param invalidate Wheter this method should call invalidate
     *
     * @return true if the animation is played, false otherwise
     *
     * @see #scrollBy(int, int)
     * @see #scrollTo(int, int)
     * @see #isHorizontalScrollBarEnabled()
     * @see #isVerticalScrollBarEnabled()
     * @see #setHorizontalScrollBarEnabled(boolean)
     * @see #setVerticalScrollBarEnabled(boolean)
     */
protected boolean awakenScrollBars(int startDelay, boolean invalidate) {
    final ScrollabilityCache scrollCache = mScrollCache;
    if (scrollCache == null || !scrollCache.fadeScrollBars) {
        return false;
    }
    if (scrollCache.scrollBar == null) {
        scrollCache.scrollBar = new ScrollBarDrawable();
    }
    if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) {
        if (invalidate) {
            // Invalidate to show the scrollbars
            postInvalidateOnAnimation();
        }
        if (scrollCache.state == ScrollabilityCache.OFF) {
            // FIXME: this is copied from WindowManagerService.
            // We should get this value from the system when it
            // is possible to do so.
            final int KEY_REPEAT_FIRST_DELAY = 750;
            startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay);
        }
        // Tell mScrollCache when we should start fading. This may
        // extend the fade start time if one was already scheduled
        long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay;
        scrollCache.fadeStartTime = fadeStartTime;
        scrollCache.state = ScrollabilityCache.ON;
        // Schedule our fader to run, unscheduling any old ones first
        if (mAttachInfo != null) {
            mAttachInfo.mHandler.removeCallbacks(scrollCache);
            mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime);
        }
        return true;
    }
    return false;
}
Also used : ScrollBarDrawable(android.widget.ScrollBarDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 4 with ScrollBarDrawable

use of android.widget.ScrollBarDrawable in project android_frameworks_base by ParanoidAndroid.

the class View method onDrawScrollBars.

/**
     * <p>Request the drawing of the horizontal and the vertical scrollbar. The
     * scrollbars are painted only if they have been awakened first.</p>
     *
     * @param canvas the canvas on which to draw the scrollbars
     *
     * @see #awakenScrollBars(int)
     */
protected final void onDrawScrollBars(Canvas canvas) {
    // scrollbars are drawn only when the animation is running
    final ScrollabilityCache cache = mScrollCache;
    if (cache != null) {
        int state = cache.state;
        if (state == ScrollabilityCache.OFF) {
            return;
        }
        boolean invalidate = false;
        if (state == ScrollabilityCache.FADING) {
            // We're fading -- get our fade interpolation
            if (cache.interpolatorValues == null) {
                cache.interpolatorValues = new float[1];
            }
            float[] values = cache.interpolatorValues;
            // Stops the animation if we're done
            if (cache.scrollBarInterpolator.timeToValues(values) == Interpolator.Result.FREEZE_END) {
                cache.state = ScrollabilityCache.OFF;
            } else {
                cache.scrollBar.setAlpha(Math.round(values[0]));
            }
            // This will make the scroll bars inval themselves after
            // drawing. We only want this when we're fading so that
            // we prevent excessive redraws
            invalidate = true;
        } else {
            // We're just on -- but we may have been fading before so
            // reset alpha
            cache.scrollBar.setAlpha(255);
        }
        final int viewFlags = mViewFlags;
        final boolean drawHorizontalScrollBar = (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL;
        final boolean drawVerticalScrollBar = (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL && !isVerticalScrollBarHidden();
        if (drawVerticalScrollBar || drawHorizontalScrollBar) {
            final int width = mRight - mLeft;
            final int height = mBottom - mTop;
            final ScrollBarDrawable scrollBar = cache.scrollBar;
            final int scrollX = mScrollX;
            final int scrollY = mScrollY;
            final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0;
            int left;
            int top;
            int right;
            int bottom;
            if (drawHorizontalScrollBar) {
                int size = scrollBar.getSize(false);
                if (size <= 0) {
                    size = cache.scrollBarSize;
                }
                scrollBar.setParameters(computeHorizontalScrollRange(), computeHorizontalScrollOffset(), computeHorizontalScrollExtent(), false);
                final int verticalScrollBarGap = drawVerticalScrollBar ? getVerticalScrollbarWidth() : 0;
                top = scrollY + height - size - (mUserPaddingBottom & inside);
                left = scrollX + (mPaddingLeft & inside);
                right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap;
                bottom = top + size;
                onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom);
                if (invalidate) {
                    invalidate(left, top, right, bottom);
                }
            }
            if (drawVerticalScrollBar) {
                int size = scrollBar.getSize(true);
                if (size <= 0) {
                    size = cache.scrollBarSize;
                }
                scrollBar.setParameters(computeVerticalScrollRange(), computeVerticalScrollOffset(), computeVerticalScrollExtent(), true);
                int verticalScrollbarPosition = mVerticalScrollbarPosition;
                if (verticalScrollbarPosition == SCROLLBAR_POSITION_DEFAULT) {
                    verticalScrollbarPosition = isLayoutRtl() ? SCROLLBAR_POSITION_LEFT : SCROLLBAR_POSITION_RIGHT;
                }
                switch(verticalScrollbarPosition) {
                    default:
                    case SCROLLBAR_POSITION_RIGHT:
                        left = scrollX + width - size - (mUserPaddingRight & inside);
                        break;
                    case SCROLLBAR_POSITION_LEFT:
                        left = scrollX + (mUserPaddingLeft & inside);
                        break;
                }
                top = scrollY + (mPaddingTop & inside);
                right = left + size;
                bottom = scrollY + height - (mUserPaddingBottom & inside);
                onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom);
                if (invalidate) {
                    invalidate(left, top, right, bottom);
                }
            }
        }
    }
}
Also used : ScrollBarDrawable(android.widget.ScrollBarDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 5 with ScrollBarDrawable

use of android.widget.ScrollBarDrawable in project XobotOS by xamarin.

the class View method awakenScrollBars.

/**
     * <p>
     * Trigger the scrollbars to draw. When invoked this method starts an
     * animation to fade the scrollbars out after a fixed delay. If a subclass
     * provides animated scrolling, the start delay should equal the duration of
     * the scrolling animation.
     * </p>
     *
     * <p>
     * The animation starts only if at least one of the scrollbars is enabled,
     * as specified by {@link #isHorizontalScrollBarEnabled()} and
     * {@link #isVerticalScrollBarEnabled()}. When the animation is started,
     * this method returns true, and false otherwise. If the animation is
     * started, this method calls {@link #invalidate()} if the invalidate parameter
     * is set to true; in that case the caller
     * should not call {@link #invalidate()}.
     * </p>
     *
     * <p>
     * This method should be invoked everytime a subclass directly updates the
     * scroll parameters.
     * </p>
     *
     * @param startDelay the delay, in milliseconds, after which the animation
     *        should start; when the delay is 0, the animation starts
     *        immediately
     *
     * @param invalidate Wheter this method should call invalidate
     *
     * @return true if the animation is played, false otherwise
     *
     * @see #scrollBy(int, int)
     * @see #scrollTo(int, int)
     * @see #isHorizontalScrollBarEnabled()
     * @see #isVerticalScrollBarEnabled()
     * @see #setHorizontalScrollBarEnabled(boolean)
     * @see #setVerticalScrollBarEnabled(boolean)
     */
protected boolean awakenScrollBars(int startDelay, boolean invalidate) {
    final ScrollabilityCache scrollCache = mScrollCache;
    if (scrollCache == null || !scrollCache.fadeScrollBars) {
        return false;
    }
    if (scrollCache.scrollBar == null) {
        scrollCache.scrollBar = new ScrollBarDrawable();
    }
    if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) {
        if (invalidate) {
            // Invalidate to show the scrollbars
            invalidate(true);
        }
        if (scrollCache.state == ScrollabilityCache.OFF) {
            // FIXME: this is copied from WindowManagerService.
            // We should get this value from the system when it
            // is possible to do so.
            final int KEY_REPEAT_FIRST_DELAY = 750;
            startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay);
        }
        // Tell mScrollCache when we should start fading. This may
        // extend the fade start time if one was already scheduled
        long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay;
        scrollCache.fadeStartTime = fadeStartTime;
        scrollCache.state = ScrollabilityCache.ON;
        // Schedule our fader to run, unscheduling any old ones first
        if (mAttachInfo != null) {
            mAttachInfo.mHandler.removeCallbacks(scrollCache);
            mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime);
        }
        return true;
    }
    return false;
}
Also used : ScrollBarDrawable(android.widget.ScrollBarDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point)

Aggregations

ScrollBarDrawable (android.widget.ScrollBarDrawable)18 Paint (android.graphics.Paint)17 Point (android.graphics.Point)17 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Drawable (android.graphics.drawable.Drawable)6 Rect (android.graphics.Rect)4