使圆角矩形围绕路径旋转

时间:2019-12-22 18:14:26

标签: android live-wallpaper

我正在为Android开发动态壁纸应用,我需要实现this

这是我代码的重要部分:

 private void makePath(WallpaperSettings wallpaperSettings){
        float f;
        float f2;
        float f3 = (float) wallpaperSettings.getRadiusTop();
        float f4 = (float) wallpaperSettings.getRadiusBottom();
        float f5 = (float) wallpaperSettings.getNotchBottomFull() * 2;
        float f6 = (float) (this.surfaceWidth + 2);
        float f7 = (float) (this.surfaceHeight + 2);
        float f8 = f6 - (f3 + f3);
        this.path = new Path();
        this.path.moveTo(f6 - 1.0f, -1.0f + f3);
        float f9 = -f3;
        this.path.rQuadTo(0.0f, f9, f9, f9);
        if (!wallpaperSettings.isNotch()) {
            f = f6;
            f2 = 0.0f;
            this.path.rLineTo(-f8, 0.0f);
        } else {
            float f10 = (float) wallpaperSettings.getNotchHeight();
            float f11 = (float)wallpaperSettings.getNotchWidth();
            float f12 = (((float) wallpaperSettings.getNotchTop()) / 100.0f) * f11;
            float f13 = f10 * 0.0f;
            float f14 = (((float) wallpaperSettings.getNotchBottom()) / 100.0f) * f11;
            float f15 = -((f8 - ((f11 * 2.0f) + f5)) / 2.0f);
            this.path.rLineTo(f15, 0.0f);
            float f16 = -f13;
            f = f6;
            float f17 = -f11;
            this.path.rCubicTo(-f12, f13, f14 - f11, f16 + f10, f17, f10);
            this.path.rLineTo(-f5, 0.0f);
            this.path.rCubicTo(-f14, f16, f12 - f11, f13 - f10, f17, -f10);
            f2 = 0.0f;
            this.path.rLineTo(f15, 0.0f);
        }
        this.path.rQuadTo(f9, f2, f9, f3);
        float f21 = f7 - (f3 + f4);
        this.path.rLineTo(f2, f21);
        this.path.rQuadTo(f2, f4, f4, f4);
        this.path.rLineTo(f - (f4 + f4), f2);
        this.path.rQuadTo(f4, f2, f4, -f4);
        this.path.rLineTo(f2, -f21);
        this.path.close();
    }

(效果很好,给了我一条路)

 private void circuitLighting(WallpaperSettings settings, Canvas lockHardwareCanvas, int nanoTime, float interpolation){
        circuit(settings);
        float pow = (float) (((double) nanoTime) / Math.pow((double) (settings.getBorderSpeed() >= 90 ? 10 : 100F - ((float) settings.getBorderSpeed())), 1.3d));
        Matrix matrix2 = new Matrix();

        matrix2.preRotate(pow, ((float) this.surfaceWidth) / 2.0f, ((float) this.surfaceHeight) / 2.0f);
        this.borderPaint.setAlpha(255);

        this.grad.setLocalMatrix(matrix2);
        this.borderPaint.setStrokeWidth(interpolation);

        lockHardwareCanvas.drawPath(path, this.borderPaint);
        try {
            this.holder.getSurface().unlockCanvasAndPost(lockHardwareCanvas);
        }catch (Exception ignored){

        }
    }

    private void circuit(WallpaperSettings settings){
        long time = 5000L - (settings.getBorderSpeed() * 5);
        if(System.currentTimeMillis() - last < time){
            return;
        }

        int[] colorArray = MainActivity.getMainActivity().getSettings().getColors();
        if(index > colorArray.length - 1){
            index = 0;
        }

        int[] colors = new int[500];
        colors[0] = colorArray[index];
        for (int x = 1; x < 9; x++){
            colors[x] = ColorUtils.getDarkerShade(shade, colorArray[index]);
            shade += 0.1;
        }

        shade = 0.1F;

        int next = index + 1 > colorArray.length - 1 ? 0 : index + 1;
        colors[10] = colorArray[next];
        for (int x = 11; x < 20; x++){
            colors[x] = ColorUtils.getDarkerShade(shade, colorArray[next]);
            shade += 0.1;
        }

        for (int x = 21; x < 500; x++){
            colors[x] = Color.TRANSPARENT;
        }

        this.grad = new SweepGradient(((float) this.surfaceWidth) / 2.0f, ((float) this.surfaceHeight) / 2.0f, colors, null);
        this.borderPaint.setShader(grad);
        borderPaint.setAlpha(255);

        index++;
        last = System.currentTimeMillis();
    }

另一方面,该部分不起作用,我尝试使大部分边框透明,同时使一部分颜色发生变化,但它的尺寸不正确(并非总是相同),并且错误形状。有人知道吗?

0 个答案:

没有答案