Thursday, December 13, 2012

[android-developers] Re: Android circular seek bar

@sink thank for reply there is problem in my ui i need to have track and thumb image , track is circular and thumb is dial have seen this aswell http://blog.publicobject.com/2010/04/shush-ringer-restorer-update.html but m still struggling to put image in canvas of this view

On Thursday, December 13, 2012 4:37:01 PM UTC+5:30, skink wrote:


On 13 Gru, 10:21, djhacktor <deepanshcri...@gmail.com> wrote:
> have nt worked on it  i started today and lots of ui component are left so
> it will great help if you can provide right resource this is what i need Reference
> :https://lh4.ggpht.com/9qL2sQi6XQYBY2pvgsPyObYS3UM42kRw64ve-GacU3jqW0X...
>
>

you can start with something like this:

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.SeekBar;

public class CSB extends SeekBar {

        public CSB(Context context, AttributeSet attrs) {
                super(context, attrs);
                Drawable d = new CSBDrawable();
                setProgressDrawable(d);
                setProgress(33);
        }

        class CSBDrawable extends Drawable {

                private final static String TAG = "CSB.CSBDrawable";
                private Paint mPaint;
                private RectF mRect;

                public CSBDrawable() {
                        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
                        mPaint.setStyle(Style.STROKE);
                        mPaint.setStrokeWidth(5);
                        mPaint.setColor(0xffeeeeee);
                        mRect = new RectF();
                }

                @Override
                protected void onBoundsChange(Rect bounds) {
                        super.onBoundsChange(bounds);
                        Log.d(TAG, "onBoundsChange " + bounds);
                        mRect.set(bounds);
                        int w2 = bounds.width() / 2;
                        int h2 = bounds.height() / 2;
                        if (w2 > h2) {
                                mRect.inset(w2 - h2, 0);
                        } else {
                                mRect.inset(0, h2 - w2);
                        }
                }

                @Override
                public void draw(Canvas canvas) {
                        float angle = 270 * getLevel() / 10000;
                        canvas.drawArc(mRect, -270 + 45, angle, false, mPaint);

                        canvas.save();
                        Rect b = getBounds();
                        canvas.rotate(angle - 45, b.centerX(), b.centerY());
                        canvas.drawCircle(b.centerX() - mRect.width() / 2, mRect.height() /
2, 10, mPaint);
                        canvas.restore();
                }

                @Override
                public void setAlpha(int alpha) {
                }

                @Override
                public void setColorFilter(ColorFilter cf) {
                }

                @Override
                public int getOpacity() {
                        return PixelFormat.TRANSLUCENT;
                }
        }
}

pskink

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment