Code example for EditText

Methods: EditText.invalidate, getScrollX, getScrollY, getWidth, invalidate

0
 
    public void setState(int state) {
        switch (state) {
            case STATE_NONE:
                mHandler.removeCallbacks(mScrollFade);
                mList.invalidate();
                break; 
            case STATE_VISIBLE:
                if (mState != STATE_VISIBLE) { // Optimization
                    resetThumbPos(); 
                } 
                // Fall through 
            case STATE_DRAGGING:
                mHandler.removeCallbacks(mScrollFade);
                break; 
            case STATE_EXIT:
                int viewWidth = mList.getWidth();
                mList.invalidate(viewWidth - mThumbW, mThumbY, viewWidth, mThumbY + mThumbH);
                break; 
        } 
        mState = state;
    } 
 
    public int getState() { 
        return mState;
    } 
 
    private void resetThumbPos() { 
        final int viewWidth = mList.getWidth();
        // Bounds are always top right. Y coordinate get's translated during draw 
        //Log.v(TAG, "setBounds resetThumbPos left:"+String.valueOf(viewWidth - mThumbW)+" right:"+String.valueOf(viewWidth)+" button:"+String.valueOf(mThumbH)); 
        mThumbDrawable.setBounds(viewWidth - mThumbW, 0, viewWidth, mThumbH);
        mThumbDrawable.setAlpha(ScrollFade.ALPHA_MAX);
    } 
    private void useThumbDrawable(Context context, Drawable drawable) {
        mThumbDrawable = drawable;
        /*mThumbW = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
                48, context.getResources().getDisplayMetrics()); 
        mThumbH = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
                52, context.getResources().getDisplayMetrics());*/ 
        mThumbW = context.getResources().getDimensionPixelSize(
                R.dimen.fastscroll_thumb_width); 
        mThumbH = context.getResources().getDimensionPixelSize(
                R.dimen.fastscroll_thumb_height); 
        mChangedBounds = true;
    } 
 
    private void init(Context context) {
        // Get both the scrollbar states drawables 
        final Resources res = context.getResources();
        useThumbDrawable(context, res.getDrawable(
                R.drawable.scrollbar_handle_accelerated_anim2)); 
        //mScrollCompleted = true; 
 
        getSectionsFromIndexer(); 
 
        mScrollFade = new ScrollFade();
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setTextAlign(Paint.Align.CENTER);
        TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] {
                android.R.attr.textColorPrimary });
        ColorStateList textColor = ta.getColorStateList(ta.getIndex(0));
        int textColorNormal = textColor.getDefaultColor();
        mPaint.setColor(textColorNormal);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
 
        mState = STATE_NONE;
    } 
 
    void stop() { 
        setState(STATE_NONE);
    } 
 
    boolean isVisible() { 
        return !(mState == STATE_NONE);
    } 
 
    public void draw(Canvas canvas) {
        //Log.v(TAG, "draw status "+String.valueOf(mState)); 
        if (mState == STATE_NONE) {
            // No need to draw anything 
            return; 
        } 
 
        final int y = mThumbY + mList.getScrollY();
        final int viewWidth = mList.getWidth();
        final FastScroller.ScrollFade scrollFade = mScrollFade;
        final int x = mList.getScrollX();
 
        int alpha = -1;
        if (mState == STATE_EXIT) {
            alpha = scrollFade.getAlpha();
            if (alpha < ScrollFade.ALPHA_MAX / 2) {
                mThumbDrawable.setAlpha(alpha * 2);
            } 
            int left = viewWidth - (mThumbW * alpha) / ScrollFade.ALPHA_MAX;
            //Log.v(TAG, "setBounds draw left:"+String.valueOf(left)+" right:"+String.valueOf(viewWidth)+" button:"+String.valueOf(mThumbH)); 
            mThumbDrawable.setBounds(left, 0, viewWidth, mThumbH);
            mChangedBounds = true;
        } 
        //Log.v(TAG, "setBounds draw x:"+String.valueOf(x)+" y:"+String.valueOf(y)); 
        canvas.translate(x, y);
        mThumbDrawable.draw(canvas);
        canvas.translate(-x, -y);
 
        // If user is dragging the scroll bar, draw the alphabet overlay 
        if (alpha == 0) { // Done with exit
            setState(STATE_NONE);
        } else { 
            mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH);
        } 
    } 
 
    void onSizeChanged(int w, int h, int oldw, int oldh) {
        if (mThumbDrawable != null) {