碎纸机for android

作者: ldoublem | 来源:发表于2016-07-19 14:19 被阅读547次

点子出自dribbble
swift版本
android版本
以下是效果展示

shot.png shot1.gif shot2.gif shot3.gif

纸条模式的代码

private void drawPaperSlip(Canvas canvas) {
        Path PaperSlip = new Path();
        float paperSlipwidth = rectFPaper.width() / paperSlipCount;
        float paperSlipspace = paperSlipwidth / 7f;

        float animatedValue = mAnimatedValue;
        mPaint.setColor(paperColor);
        for (int i = 0; i < randomQuadHighs.size(); i++) {
            PaperSlip.reset();
            PaperSlip.moveTo(rectFPaper.left + i * paperSlipwidth + paperSlipspace,
                    rectFPaper.bottom
            );
            PaperSlip.lineTo(rectFPaper.left + (i + 1) * paperSlipwidth - paperSlipspace,
                    rectFPaper.bottom
            );

            float paperSlipHigh = rectFPaper.height() * 2 / 3f
                    + rectFPaper.height() / 3f * randomHighs.get(i);
            float randomQuadWidth = this.randomQuadWidths.get(i) * paperSlipspace * 2.5f * animatedValue;

            if (i % 2 == 0) {
                randomQuadWidth = randomQuadWidth * -1;

            }
            float randomQuadHigh = this.randomQuadHighs.get(i) * paperSlipHigh * animatedValue;


            PaperSlip.quadTo(
                    rectFPaper.left + (i + 1) * paperSlipwidth - paperSlipspace -
                            randomQuadWidth,
                    rectFPaper.bottom + randomQuadHigh,

                    rectFPaper.left + (i + 1) * paperSlipwidth - paperSlipspace,
                    rectFPaper.bottom + paperSlipHigh
            );


            PaperSlip.lineTo(rectFPaper.left + (i) * paperSlipwidth + paperSlipspace,
                    rectFPaper.bottom + paperSlipHigh
            );
            PaperSlip.quadTo(
                    rectFPaper.left + i * paperSlipwidth + paperSlipspace -
                            randomQuadWidth,
                    rectFPaper.bottom + randomQuadHigh,


                    rectFPaper.left + i * paperSlipwidth + paperSlipspace,
                    rectFPaper.bottom
            );
            PaperSlip.close();
            canvas.drawPath(PaperSlip, mPaint);

        }

    }

纸片模式

 private void drawPaperPiece(Canvas canvas) {


        if (mAnimatedValue == 0)
            return;


        float paperPiecewidth = rectFPaper.width() / paperSlipCount;

        Path paperPiece = new Path();


        for (int i = 0; i < PaperPiecerandAngle.size(); i++) {

            int angle = (int) (PaperPiecerandAngle.get(i) * 360);

            angle = (int) (angle + 180 * mAnimatedValue);
            float radius = paperPiecewidth * 0.8f;
            if (PaperPiecerandRadius.get(i) < 0.3f) {
                PaperPiecerandRadius.set(i,0.3f);

            }
            radius = radius * PaperPiecerandRadius.get(i);

            float centerX = mPaddingLR * 3 + (getMeasuredWidth() - 6 * mPaddingLR) * PaperPiecerandX.get(i);
            float centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                    + mAnimatedValue * getMeasuredHeight() / 3;
            if (PaperPiecerandRadius.get(i) >= 0.3f && PaperPiecerandRadius.get(i) <= 0.4f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.8f;
            } else if (PaperPiecerandRadius.get(i) > 0.4f && PaperPiecerandRadius.get(i) <= 0.5f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.6f;
            } else if (PaperPiecerandRadius.get(i) > 0.5f && PaperPiecerandRadius.get(i) <= 0.6f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.4f;
            } else if (PaperPiecerandRadius.get(i) > 0.6f && PaperPiecerandRadius.get(i) <= 0.7f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.2f;
            } else if (PaperPiecerandRadius.get(i) > 0.7f && PaperPiecerandRadius.get(i) <= 0.8f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.4f;
            } else if (PaperPiecerandRadius.get(i) > 0.8f && PaperPiecerandRadius.get(i) <= 0.9f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.6f;
            } else if (PaperPiecerandRadius.get(i) > 0.9f) {
                centerY = getMeasuredHeight() / 3 * PaperPiecerandY.get(i) + getMeasuredHeight() / 3

                        + mAnimatedValue * getMeasuredHeight() / 3 * 2.8f;
            }


            float x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            float y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));

            paperPiece.reset();
            paperPiece.moveTo(centerX - x,
                    centerY - y

            );


            int angleBig = 0;
            if (PaperPiecerandX.get(i) > 0.7f) {
                angleBig = (int) (180 * 0.7f);
            } else if (PaperPiecerandX.get(i) < 0.3f) {
                angleBig = (int) (180 * 0.3f);
            } else {
                angleBig = (int) (180 * PaperPiecerandX.get(i));
            }
            int angleSmall = 180 - angleBig;

            angle = angle + angleBig;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );


            angle = angle + angleSmall;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );

            angle = angle + angleBig;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );
            angle = angle + angleSmall;
            x = (float) ((radius) * Math.cos(angle * Math.PI / 180f));
            y = (float) ((radius) * Math.sin(angle * Math.PI / 180f));
            paperPiece.lineTo(centerX - x,
                    centerY - y

            );




            paperPiece.close();

            int color = (Integer) evaluator.evaluate(PaperPiecerandRadius.get(i),
                    Color.rgb(180, 180, 180), paperColor
            );

            mPaint.setColor(color);
            canvas.drawPath(paperPiece, mPaint);


        }
        mPaint.setColor(paperColor);
    }

使用方式xml

<com.ldoublem.PaperShredderlib.PaperShredderView
        android:layout_width="200dp"
        android:id="@+id/ps_delete2"
        android:layout_height="220dp"
        paper:sherderBgColor="#f4c600"
        paper:sherderText="清理中"
        paper:sherderType="0"
        paper:sherderPaperEnterColor="#56abe4"
        paper:sherderTextShadow="false"
        paper:sherderTextColor="#99101010"
        paper:sherderPaperColor="#dbdbdb"
        paper:sherderProgress="false"
      />

java

       mPaperShredderView.setShrededType(PaperShredderView.SHREDEDTYPE.Piece);//纸片效果和纸条效果
       mPaperShredderView.setSherderProgress(false);
       mPaperShredderView.setTitle("清除数据");
       mPaperShredderView.setTextColor(Color.BLACK);
       mPaperShredderView.setPaperColor(Color.BLACK);
       mPaperShredderView.setBgColor(Color.WHITE);
       mPaperShredderView.setTextShadow(false);
       mPaperShredderView.setPaperEnterColor(Color.BLACK);
       mPaperShredderView.startAnim(1000);
       mPaperShredderView.stopAnim();

如果觉得还不错,去github给我点颗星吧^^
代码下载

相关文章

  • 碎纸机for android

    点子出自dribbbleswift版本android版本以下是效果展示 纸条模式的代码 纸片模式 使用方式xml ...

  • 碎纸机

    今天我做完作业,就开始玩碎纸机。碎纸机的意思是把纸弄碎的机。碎纸机上面是白色的,下面是透明的。

  • 碎纸机

    我有一个碎纸机,它即是我的工作,也是我的秘密。 像往常一样,我机械性地把文件一页一页地扔进去。不知为何...

  • 碎纸机

    它吃纸。吃被这个人间写脏之后,遗弃的纸。细致地嚼烂如竹叶在风中沙沙 他们说话,每天重复地说话从薄唇里吐出小石子把它...

  • 碎纸机

    1 我们的距离越来越远 友谊越来越浅 时间的考验 谈话的间距越来越久 很少提及伤口 生活的碎片 我最近开始失眠 回...

  • 碎纸机

    这个机器默默蹲在墙角,科技灰的颜色,毫不起眼,很难引起人的注意,我长期忽略它的存在。一直以为,多余的材料纸张...

  • 碎纸机

    粉碎的 忘记的 契合了人类破坏的欲望 砸碎玻璃的清脆声 揭破善意的谎言 想从一场正在上演的舞台剧穿插而过 想去赴一...

  • 碎纸机

    马克思说事物的发展是螺旋式上升的。 从一个平面看,是一个又一个的圈。加上时间和空间,是一个看似不断回到终点却也在不...

  • 【e到修技巧】碎纸机常见问题及解决小办法

    【e到修技巧】碎纸机常见问题及解决小办法 相信大家对碎纸机并不陌生啦,毕竟办公室基本都会置办一台。很多重要废旧的文...

  • 一台碎纸机

    ​我们办公室有一台黑色的、椭圆形的碎纸机,放在桌子下面。它看起来笨笨的,肥肥的。 这台碎纸机操作起来很简单,一插上...

网友评论

本文标题:碎纸机for android

本文链接:https://www.haomeiwen.com/subject/kcbmjttx.html