Android Catch Notes 应用程序,如圆形菜单

时间:2023-02-16
本文介绍了Android Catch Notes 应用程序,如圆形菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我要开发应用程序,我想创建像 Catch notes 应用

I am going to develop the app and i want to create the menu like Catch notes App

屏幕截图

任何知道我如何实现此功能或是否有可用的库的人.请告诉我.

anybody who know how can i implement this or if any library available for it. please let me know.

谢谢

推荐答案

我最近创建了这个圆形菜单以添加到我最近的项目中.看起来像

I recently created this circular menu to add up in my recent project. It looks like

您需要创建一个新视图并绘制此视图,检查用户输入(他正在触摸的位置),设计一个反馈机制,例如,在我看来,如果用户触摸了 5 个弧中的任何一个,背景颜色变为天蓝色.这是我的视图类代码.

What you need is to create a new View and draw this view, check for the user inputs (where he is touching), design a feedback mechanism, for example, in my view, if user touches any of the 5 arcs, background color changes to skyblue. Here is my code for View Class.

:这次我发布了我所有的视图代码.希望对你有帮助.

: This time I am posting all my code for the view. Hope it might help you.

public class SmallCircleView extends View{

    private Paint smallCircleCore;
    private Paint lineCore;
    private Paint bigArc;
    private Paint bigArcDraw;
    private Paint pencil;
    private Paint middleCircleBody;
    private Paint arcTouchedBack;
    private Paint circlePaint;

    private int initial, midInitial;
    private int finalangle;
    private int middleCircleRadius;
    private int i =0;

    private int centerCircleradius;

    int[] colors = new int[]{0xFF33B5E5,
            0xFFAA66CC,
            0xFF99CC00,
            0xFFFFBB33,
            0xFFFF4444,
            0xFF0099CC,
            0xFFAA66CC,
            0xFF669900,
            0xFFFF8800,
            0xFFCC0000};

    private RectF oval = new RectF();
    private RectF middleOval = new RectF();
    private RectF finalOVal = new RectF();

    private Context context;
    private int px, py;

    private boolean isClicked = true;
    private boolean[] arcTouched= new boolean[]{false, false, false, false, false};

    EmbossMaskFilter emboss;
    EmbossMaskFilter forBig;

    private ArrayList<Bitmap> bitmap = new ArrayList<Bitmap>();

    public SmallCircleView(Context context) {
        super(context);
        this.context = context;
        initSmallCircle();

        // TODO Auto-generated constructor stub
    }

    public SmallCircleView(Context context, AttributeSet attri)
    {
        super(context, attri);
        this.context = context;

        initSmallCircle();
    }

    public SmallCircleView(Context context, AttributeSet attri, int defaultStyle)
    {
        super(context, attri, defaultStyle);
        this.context = context;

        initSmallCircle();
    }

    private void initSmallCircle()
    {
        setFocusable(true);

        smallCircleCore = new Paint(Paint.ANTI_ALIAS_FLAG);
        lineCore = new Paint(Paint.ANTI_ALIAS_FLAG);
        bigArc = new Paint(Paint.ANTI_ALIAS_FLAG);
        pencil = new Paint(Paint.ANTI_ALIAS_FLAG);

        lineCore.setColor(0xFFFFFFFF);
        lineCore.setStyle(Paint.Style.FILL);
        lineCore.setStrokeWidth(4);
        //bigCircleCore.setStrokeWidth(5);

        smallCircleCore.setStyle(Paint.Style.FILL);
        smallCircleCore.setColor(0xFFFFFFFF);

        bigArc.setColor(0xFF424242);
        bigArc.setStyle(Paint.Style.FILL);

        bigArcDraw = new Paint(smallCircleCore);
        bigArcDraw.setStrokeWidth(4);
        bigArcDraw.setColor(0xFF000000);

        pencil.setStrokeWidth(0.5f);
        pencil.setColor(0x80444444);
        pencil.setStyle(Paint.Style.STROKE);

        middleCircleBody = new Paint(bigArc);
        middleCircleBody.setColor(0xFFE6E6E6);

        arcTouchedBack = new Paint(Paint.ANTI_ALIAS_FLAG);
        arcTouchedBack.setColor(0xFF81DAF5);
        arcTouchedBack.setStyle(Paint.Style.FILL);      

        circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        circlePaint.setStyle(Paint.Style.STROKE);
        circlePaint.setStrokeWidth(10);



        float[] direection = new float[]{1,1,1};
        float light = 0.4f;
        float specualr = 6;
        float blur = 3.5f;      

        emboss = new EmbossMaskFilter(direection, light, specualr, blur);
        forBig = new EmbossMaskFilter(direection, 1f, 4, 2.5f);

        bitmap.clear();
        bitmap.add(BitmapFactory.decodeResource(getResources(), R.drawable.tasks));
        bitmap.add(BitmapFactory.decodeResource(getResources(), R.drawable.file_manager));
        bitmap.add(BitmapFactory.decodeResource(getResources(), R.drawable.home));
        bitmap.add(BitmapFactory.decodeResource(getResources(), R.drawable.contacts));      
        bitmap.add(BitmapFactory.decodeResource(getResources(), R.drawable.reminder));


        middleCircleBody.setMaskFilter(forBig);
        bigArc.setMaskFilter(forBig);

        String log="";
        Log.d(log, "Value of px & py " + getMeasuredWidth() + " " + getMeasuredHeight());
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        int measuredWidth = measure(widthMeasureSpec);
        int measuredHeight = measure(heightMeasureSpec);

        int d = Math.min(measuredWidth, measuredHeight);

        setMeasuredDimension(d,d);
    }

    private int measure(int measureSpec)
    {
        int result = 0;

        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);

        if(specMode == MeasureSpec.UNSPECIFIED)
        {
            result = 200;
        }
        else
        {
            result = specSize;
        }

        return result;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub

        px = getMeasuredWidth()/2;
        py = getMeasuredHeight();


        initial = 144;
        finalangle = 252;

        centerCircleradius  = 30;
        middleCircleRadius = 140;




            int init, fina;
            init = 160;
            fina = 360;
            finalOVal.set(px-middleCircleRadius-4, py-middleCircleRadius-4, px+middleCircleRadius+4, py+middleCircleRadius+4);
            middleOval.set(px-middleCircleRadius, py-middleCircleRadius, px+middleCircleRadius, py+middleCircleRadius);
            while(init<fina)
            {
                circlePaint.setColor(colors[i]);
                canvas.drawArc(finalOVal,init,10,false, circlePaint);
                i++;
                if(i>=colors.length)
                {
                    i=0;
                }
                init = init + 10;

            }
            //Setting Mask Filter


            canvas.drawArc(middleOval, 180, 180, false, pencil);

            midInitial = 180;


            i=0;

            //Creating the first Arc
            if(arcTouched[0])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(0), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;

            if(arcTouched[1])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(1), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;

            if(arcTouched[2])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(2), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;
            //Creatring the second Arc

            if(arcTouched[3])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(3), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;

            if(arcTouched[4])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(4), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);           
            canvas.drawCircle(px, py-10, 40, pencil);
            canvas.drawCircle(px, py-10, 39, smallCircleCore);

            canvas.drawCircle(px, py-10, 35, bigArc);
            canvas.drawCircle(px, py-10, 20, smallCircleCore);

            canvas.drawCircle(px, py-10, 15, bigArc);
            canvas.drawLine(px-8, py-10, px+8, py-10, lineCore);

        canvas.save();
    }



    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub

        float centerX = px;
        float centerY = (py-centerCircleradius+(centerCircleradius/4));

        switch(event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
                if(isInSideCenterCircle(centerX, centerY, centerCircleradius, event.getX(), event.getY()))
                {
                    return super.onTouchEvent(event);
                }
                if(isInArc(180, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[0] = true;
                    invalidate();
                    return true;
                }

                if(isInArc(216, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[1] = true;
                    invalidate();
                    return true;
                }

                if(isInArc(252, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[2] = true;
                    invalidate();
                    return true;
                }

                if(isInArc(288,36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[3] = true;
                    invalidate();
                    return true;
                }

                if(isInArc(324, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[4] = true;
                    invalidate();
                    return true;
                }
            }
            case MotionEvent.ACTION_UP:
            {


                if(isInSideCenterCircle(centerX, centerY, centerCircleradius, event.getX(), event.getY()))
                {
                    return super.onTouchEvent(event);
                }

                if(isInArc(180, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {
                    Toast.makeText(getContext(), "In the first Arc !!!", Toast.LENGTH_SHORT).show();
                    makeAllFalse();

                    invalidate();
                    return false;
                }

                if(isInArc(216, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {
                    Toast.makeText(getContext(), "In Second Arc", Toast.LENGTH_SHORT).show();
                    makeAllFalse();

                    invalidate();
                    return false;
                }

                if(isInArc(252, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {
                    Toast.makeText(getContext(), "In Third Arc", Toast.LENGTH_SHORT).show();
                    makeAllFalse();

                    invalidate();
                    return false;
                }

                if(isInArc(288,36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {
                    Toast.makeText(getContext(), "In fourth Arc", Toast.LENGTH_SHORT).show();
                    makeAllFalse();

                    invalidate();
                    return false;
                }

                if(isInArc(324, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {
                    Toast.makeText(getContext(), "In Fifth Arc", Toast.LENGTH_SHORT).show();
                    makeAllFalse();

                    invalidate();
                    return false;
                }

                else
                {
                    makeAllFalse();
                    invalidate();
                    return super.onTouchEvent(event);
                }
            }
            case MotionEvent.ACTION_MOVE:
            {
                if(isInSideCenterCircle(centerX, centerY, centerCircleradius, event.getX(), event.getY()))
                {
                    makeAllFalse();
                    invalidate();
                    return super.onTouchEvent(event);
                }

                if(isInArc(180, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[0] = true;
                    invalidate();
                    return false;
                }

                if(isInArc(216, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[1] = true;
                    invalidate();
                    return false;
                }

                if(isInArc(252, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[2] = true;
                    invalidate();
                    return false;
                }

                if(isInArc(288,36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[3] = true;
                    invalidate();
                    return false;
                }

                if(isInArc(324, 36, middleCircleRadius, px, py, event.getX(), event.getY()))
                {

                    makeAllFalse();
                    arcTouched[4] = true;
                    invalidate();
                    return false;
                }

                else
                {
                    makeAllFalse();
                    invalidate();
                    return super.onTouchEvent(event);
                }
            }
        }
        return super.onTouchEvent(event);
    }

    private boolean isInSideCenterCircle(float centerX, float centerY, float radius, float co_ordinateX, float co_ordinateY)
    {       
        return ((Math.pow((centerX-co_ordinateX),2))+(Math.pow((centerY-co_ordinateY),2))-Math.pow(radius, 2))<=0;      
    }

    private void changeIsClicked()
    {
        isClicked =(isClicked?(false):(true));
    }

    private RectF putBitmapTo(int startAngle, int SweepAngle, float radius, float centerX, float centerY)
    {
        float locx = (float) (centerX +((radius/17*11)*Math.cos(Math.toRadians(
                                                         (startAngle+SweepAngle+startAngle)/2
                                                         ))
                                                         ));
        float locy = (float) (centerY + ((radius/17*11)*Math.sin(Math.toRadians(
                                                         (startAngle+SweepAngle+startAngle)/2
                                                         ))
                                                         ));

        return new RectF(locx-20, locy-20, locx+20, locy+20);   

    }

    private boolean isInArc(int startAngle, int SweepAngle, float radius, float centerX, float centerY, float toCheckX, float toCheckY)
    {

        double degree;

        if(
           (Math.pow(centerX - toCheckX, 2) + 
           Math.pow(centerY - toCheckY, 2) -
           Math.pow(radius, 2))<=0)
        {           
            double radian = Math.atan((centerY-toCheckY)/(centerX-toCheckX));
            if(radian<0)                
            {
                degree = Math.toDegrees(radian);
                degree = 360+ degree;                   
            }
            else
            {               
                degree = Math.toDegrees(radian);
                degree = 180 + degree;          
            }           

            if(degree>=startAngle)
            {               
                if(degree<=(startAngle+SweepAngle))
                {                   
                    return true;
                }               
            }           
        }       
        else
        {
            return false;
        }       
        return false;
    }

    private void makeAllFalse()
    {
        for(int i=0;i<arcTouched.length;i++)
        {
            arcTouched[i] = false;
        }
    }

}

我知道这不是最好的方法,也不专业.我根据需要创建了这个菜单.在您更改角度计算之前,它无法以某种方式缩放.

I know this isn't the best way and not professional too. I created this menu as per need. Its not scale able in a way until you change the angle calculations.

这篇关于Android Catch Notes 应用程序,如圆形菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:不存在这样的 acos 函数 下一篇:为什么给 addArcWithCenter 一个 0 度的 startAngle 使它从 90 度开始?

相关文章

最新文章