add fancynew finished
This commit is contained in:
27
fancynew/src/main/config.json
Normal file
27
fancynew/src/main/config.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.xcl.fancynew",
|
||||
"vendor": "tzx",
|
||||
"version": {
|
||||
"code": 1830,
|
||||
"name": "1.2.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {
|
||||
},
|
||||
"module": {
|
||||
"package": "com.xcl.fancynew",
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"tv",
|
||||
"wearable",
|
||||
"car"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "fancynew",
|
||||
"moduleType": "har"
|
||||
}
|
||||
}
|
||||
}
|
||||
37
fancynew/src/main/java/com/xcl/fancynew/BitmapUtils.java
Normal file
37
fancynew/src/main/java/com/xcl/fancynew/BitmapUtils.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
import ohos.agp.components.element.PixelMapElement;
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.render.Texture;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* github wongzy
|
||||
* wongzhenyu96@gmail.com
|
||||
* 2020-04-29
|
||||
*/
|
||||
public class BitmapUtils {
|
||||
private BitmapUtils() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Drawable to bitmap pixel map.
|
||||
*
|
||||
* @param drawable the drawable
|
||||
* @return the pixel map
|
||||
*/
|
||||
public static PixelMap drawableToBitmap(PixelMapElement drawable) {
|
||||
|
||||
int w = drawable.getWidth();
|
||||
int h = drawable.getHeight();
|
||||
|
||||
PixelMap pixelMap = drawable.getPixelMap();
|
||||
|
||||
Canvas canvas = new Canvas(new Texture(pixelMap));
|
||||
drawable.setBounds(0, 0, w, h);
|
||||
drawable.drawToCanvas(canvas);
|
||||
|
||||
return pixelMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
/**
|
||||
* The interface Delegate recycle view.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
interface DelegateRecycleView {
|
||||
/**
|
||||
* 释放动画view内存的接口
|
||||
*/
|
||||
void finishAnimation();
|
||||
}
|
||||
51
fancynew/src/main/java/com/xcl/fancynew/DrawStrategy.java
Normal file
51
fancynew/src/main/java/com/xcl/fancynew/DrawStrategy.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The interface Draw strategy.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public interface DrawStrategy {
|
||||
|
||||
/**
|
||||
* 绘制app名称文字
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param fraction 完成时间百分比
|
||||
* @param name 文字
|
||||
* @param colorOfAppName 字体颜色
|
||||
* @param widthAndHeightOfView view的宽和高
|
||||
*/
|
||||
void drawAppName(Canvas canvas, float fraction, String name, int colorOfAppName,
|
||||
WidthAndHeightOfView widthAndHeightOfView);
|
||||
|
||||
/**
|
||||
* 绘制app图标
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param fraction 完成时间百分比
|
||||
* @param icon 图标
|
||||
* @param colorOfIcon 绘制图标颜色
|
||||
* @param widthAndHeightOfView view的宽和高
|
||||
*/
|
||||
void drawAppIcon(Canvas canvas, float fraction, PixelMap icon, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView);
|
||||
|
||||
/**
|
||||
* 绘制app一句话描述
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param fraction 完成时间百分比
|
||||
* @param statement 一句话描述
|
||||
* @param colorOfStatement 字体颜色
|
||||
* @param widthAndHeightOfView view的宽和高
|
||||
*/
|
||||
void drawAppStatement(Canvas canvas, float fraction, String statement, int colorOfStatement,
|
||||
WidthAndHeightOfView widthAndHeightOfView);
|
||||
}
|
||||
152
fancynew/src/main/java/com/xcl/fancynew/LineDrawStrategy.java
Normal file
152
fancynew/src/main/java/com/xcl/fancynew/LineDrawStrategy.java
Normal file
@@ -0,0 +1,152 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.components.element.PixelMapElement;
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.render.Paint;
|
||||
import ohos.agp.render.Path;
|
||||
import ohos.agp.render.PixelMapHolder;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.agp.utils.Matrix;
|
||||
import ohos.agp.utils.RectFloat;
|
||||
import ohos.agp.utils.TextAlignment;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Line draw strategy.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public class LineDrawStrategy implements DrawStrategy {
|
||||
|
||||
/**
|
||||
* Instantiates a new Line draw strategy.
|
||||
*/
|
||||
public LineDrawStrategy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppName(Canvas canvas, float fraction, String name, int colorOfAppName,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfAppName));
|
||||
paint.setStyle(Paint.Style.STROKE_STYLE);
|
||||
paint.setStrokeWidth(5);
|
||||
paint.setTextSize(50);
|
||||
paint.setStrokeJoin(Paint.Join.ROUND_JOIN);
|
||||
paint.setTextAlign(TextAlignment.LEFT);
|
||||
float x = widthAndHeightOfView.getWidth() >> 1;
|
||||
int centerY = widthAndHeightOfView.getHeight() / 2;
|
||||
float y = centerY - 275;
|
||||
Path path = new Path();
|
||||
path.moveTo(x, y);
|
||||
if (fraction <= 0.50) {
|
||||
path.lineTo(x, y + (25 + name.length() + 250) * (fraction / 0.50f));
|
||||
canvas.drawPath(path, paint);
|
||||
} else {
|
||||
path.lineTo(x, y + (25 + name.length() + 250) * ((1 - fraction) / 0.50f));
|
||||
canvas.drawPath(path, paint);
|
||||
paint.setStyle(Paint.Style.FILL_STYLE);
|
||||
canvas.drawText(paint, name, x + 20, y + 150);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppIcon(Canvas canvas, float fraction, PixelMap icon, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
int centerX = widthAndHeightOfView.getWidth() / 2;
|
||||
int centerY = widthAndHeightOfView.getHeight() / 2;
|
||||
PixelMap bitmap = BitmapUtils.drawableToBitmap(new PixelMapElement(icon));
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfIcon));
|
||||
paint.setStrokeWidth(3);
|
||||
paint.setStrokeJoin(Paint.Join.ROUND_JOIN);
|
||||
paint.setStyle(Paint.Style.STROKE_STYLE);
|
||||
float bitmapLeft = centerX - 250;
|
||||
float bitmapRight = bitmapLeft + bitmap.getImageInfo().size.width * 1.7f;
|
||||
float bitmapTop = centerY - 250;
|
||||
float bitmapBottom = bitmapTop + bitmap.getImageInfo().size.height * 1.7f;
|
||||
canvas.save();
|
||||
if (fraction <= 0.75) {
|
||||
float newfraction = fraction / 0.75f;
|
||||
if (newfraction <= 0.25) {
|
||||
canvas.drawLine(bitmapLeft, bitmapBottom, bitmapLeft,
|
||||
bitmapBottom - (bitmapBottom - bitmapTop) * (newfraction / 0.25f), paint);
|
||||
} else {
|
||||
canvas.drawLine(bitmapLeft, bitmapBottom, bitmapLeft, bitmapTop, paint);
|
||||
}
|
||||
if (newfraction > 0.25) {
|
||||
if (newfraction <= 0.50) {
|
||||
canvas.drawLine(bitmapLeft, bitmapTop,
|
||||
bitmapLeft + (bitmapRight - bitmapLeft) * ((newfraction - 0.25f) / 0.25f),
|
||||
bitmapTop, paint);
|
||||
} else {
|
||||
canvas.drawLine(bitmapLeft, bitmapTop, bitmapRight, bitmapTop, paint);
|
||||
}
|
||||
}
|
||||
if (newfraction > 0.50) {
|
||||
if (newfraction <= 0.75) {
|
||||
canvas.drawLine(bitmapRight, bitmapTop, bitmapRight,
|
||||
bitmapTop + (bitmapBottom - bitmapTop) * ((newfraction - 0.50f) / 0.25f),
|
||||
paint);
|
||||
} else {
|
||||
canvas.drawLine(bitmapRight, bitmapTop, bitmapRight, bitmapBottom, paint);
|
||||
}
|
||||
}
|
||||
if (newfraction > 0.75) {
|
||||
if (newfraction <= 1) {
|
||||
canvas.drawLine(bitmapRight, bitmapBottom, bitmapRight - (bitmapRight - bitmapLeft) * ((newfraction - 0.75f) / 0.25f),
|
||||
bitmapBottom, paint);
|
||||
} else {
|
||||
canvas.drawLine(bitmapRight, bitmapBottom, bitmapLeft, bitmapBottom, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
canvas.restore();
|
||||
canvas.save();
|
||||
if (fraction > 0.75) {
|
||||
canvas.clipRect(bitmapLeft + (bitmap.getImageInfo().size.width / 2f) * ((1 - fraction) / 0.25f),
|
||||
bitmapTop + (bitmap.getImageInfo().size.height / 2f) * ((1 - fraction) / 0.25f),
|
||||
bitmapRight - (bitmap.getImageInfo().size.width / 2f) * ((1 - fraction) / 0.25f),
|
||||
bitmapBottom - (bitmap.getImageInfo().size.height / 2f) * ((1 - fraction) / 0.25f));
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.7f, 1.7f, (bitmapLeft + bitmapRight) * 0.5f,
|
||||
(bitmapTop + bitmapBottom) * 0.5f);
|
||||
canvas.concat(matrix);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(bitmap), (bitmapLeft + bitmapRight) / 2 - (bitmap.getImageInfo().size.width >> 1),
|
||||
(bitmapTop + bitmapBottom) / 2 - (bitmap.getImageInfo().size.height >> 1), paint);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppStatement(Canvas canvas, float fraction, String statement, int colorOfStatement,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfStatement));
|
||||
paint.setStyle(Paint.Style.STROKE_STYLE);
|
||||
paint.setTextSize(45);
|
||||
paint.horizontalTilt(-0.2f);
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
RectFloat rectF = new RectFloat((width >> 2) - statement.length(), height * 7 >> 3,
|
||||
width * 3, height);
|
||||
if (fraction <= 0.60f) {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40 * fraction * 1.67f);
|
||||
canvas.drawPath(path, paint);
|
||||
} else {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40);
|
||||
canvas.drawPath(path, paint);
|
||||
canvas.drawTextOnPath(paint, statement, path, 0, 0);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
102
fancynew/src/main/java/com/xcl/fancynew/NormalDrawStrategy.java
Normal file
102
fancynew/src/main/java/com/xcl/fancynew/NormalDrawStrategy.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.components.element.PixelMapElement;
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.render.Paint;
|
||||
import ohos.agp.render.Path;
|
||||
import ohos.agp.render.PixelMapHolder;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.agp.utils.Matrix;
|
||||
import ohos.agp.utils.RectFloat;
|
||||
import ohos.agp.utils.TextAlignment;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Normal draw strategy.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public class NormalDrawStrategy implements DrawStrategy {
|
||||
|
||||
/**
|
||||
* Instantiates a new Normal draw strategy.
|
||||
*/
|
||||
public NormalDrawStrategy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppName(Canvas canvas, float fraction, String name, int colorOfAppName,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfAppName));
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
paint.setTextSize(50);
|
||||
canvas.drawText(paint, name, width >> 1, (height >> 1) + 50);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppIcon(Canvas canvas, float fraction, PixelMap icon, int colorOfIcon, WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
PixelMap bitmap = BitmapUtils.drawableToBitmap(new PixelMapElement(icon));
|
||||
|
||||
int bitmapWidth = bitmap.getImageInfo().size.width;
|
||||
int bitmapHeight = bitmap.getImageInfo().size.height;
|
||||
int radius = bitmapWidth * 3 / 2;
|
||||
int centerX = width / 2 + bitmapWidth / 2;
|
||||
int centerY = height / 2 - 100;
|
||||
if (fraction <= 0.60) {
|
||||
Path path = new Path();
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.2f, 1.2f, centerX - (bitmapWidth >> 1), centerY - (bitmapHeight >> 1));
|
||||
path.addCircle(centerX, centerY, radius * (fraction - 0.1f) * 2, Path.Direction.CLOCK_WISE);
|
||||
canvas.concat(matrix);
|
||||
canvas.clipPath(path, Canvas.ClipOp.INTERSECT);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(bitmap), centerX - bitmapWidth, centerY - bitmapHeight, paint);
|
||||
} else {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.2f + (0.5f) * (fraction - 0.6f) * 2.5f,
|
||||
1.2f + (0.5f) * (fraction - 0.6f) * 2.5f,
|
||||
centerX - (bitmapWidth >> 1), centerY - (bitmapHeight >> 1));
|
||||
canvas.concat(matrix);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(bitmap), centerX - bitmapWidth, centerY - bitmapHeight, paint);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppStatement(Canvas canvas, float fraction, String statement, int colorOfStatement,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfStatement));
|
||||
paint.setStyle(Paint.Style.STROKE_STYLE);
|
||||
paint.setTextSize(45);
|
||||
paint.horizontalTilt(-0.2f);
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
RectFloat rectF = new RectFloat((width >> 2) - statement.length(), height * 7 / 8,
|
||||
width * 3, height);
|
||||
if (fraction <= 0.60f) {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40 * fraction * 1.67f);
|
||||
canvas.drawPath(path, paint);
|
||||
} else {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40);
|
||||
canvas.drawPath(path, paint);
|
||||
canvas.drawTextOnPath(paint, statement, path, 0, 0);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
import ohos.aafwk.ability.Ability;
|
||||
import ohos.agp.animation.Animator;
|
||||
import ohos.agp.animation.AnimatorValue;
|
||||
import ohos.agp.components.Component;
|
||||
import ohos.agp.components.StackLayout;
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.agp.window.dialog.CommonDialog;
|
||||
import ohos.app.Context;
|
||||
import ohos.eventhandler.EventHandler;
|
||||
import ohos.eventhandler.EventRunner;
|
||||
import ohos.eventhandler.InnerEvent;
|
||||
import ohos.global.configuration.Configuration;
|
||||
import ohos.global.resource.NotExistException;
|
||||
import ohos.media.image.ImageSource;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;
|
||||
|
||||
/**
|
||||
* The type Opening start animation.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public class OpeningStartAnimation extends Component implements Component.DrawTask {
|
||||
private static final int FINISHANIMATION = 1;
|
||||
private final WidthAndHeightOfView mWidthAndHeightOfView;
|
||||
/**
|
||||
* The Device.
|
||||
*/
|
||||
int device = 0;
|
||||
private long animationInterval = 1500;
|
||||
private long animationFinishTime = 350;
|
||||
private int colorOfBackground = 0;
|
||||
private float fraction;
|
||||
private PixelMap mDrawable = null;
|
||||
private int colorOfAppIcon = Color.getIntColor("#FF4BF3E2");
|
||||
private String appName = "";
|
||||
private int colorOfAppName = Color.getIntColor("#FF86AEAA");
|
||||
private String appStatement = "";
|
||||
private int colorOfAppStatement = Color.getIntColor("#FF8E6FFD");
|
||||
private DelegateRecycleView mDelegateRecycleView;
|
||||
private DrawStrategy mDrawStrategy = new NormalDrawStrategy();
|
||||
|
||||
{
|
||||
StackLayout.LayoutConfig layoutParams;
|
||||
layoutParams = new StackLayout.LayoutConfig(MATCH_PARENT,
|
||||
MATCH_PARENT);
|
||||
this.setLayoutConfig(layoutParams);
|
||||
mWidthAndHeightOfView = new WidthAndHeightOfView();
|
||||
}
|
||||
|
||||
private OpeningStartAnimation(Context context, int iconId, int dev) {
|
||||
super(context);
|
||||
int colorMode = new Configuration().getSystemColorMode();
|
||||
if (colorMode == Configuration.DARK_MODE) {
|
||||
colorOfBackground = Color.BLACK.getValue();
|
||||
} else {
|
||||
colorOfBackground = Color.WHITE.getValue();
|
||||
}
|
||||
device = dev;
|
||||
appName = "示例APP名字";
|
||||
appStatement = "示例一句话";
|
||||
mDrawable = getPixelMapFromResource(context, iconId);
|
||||
addDrawTask(this);
|
||||
}
|
||||
|
||||
private OpeningStartAnimation(Context context, int iconId) {
|
||||
super(context);
|
||||
int colorMode = new Configuration().getSystemColorMode();
|
||||
if (colorMode == Configuration.DARK_MODE) {
|
||||
colorOfBackground = Color.BLACK.getValue();
|
||||
} else {
|
||||
colorOfBackground = Color.WHITE.getValue();
|
||||
}
|
||||
device = 0;
|
||||
appName = "示例APP名字";
|
||||
appStatement = "示例一句话";
|
||||
mDrawable = getPixelMapFromResource(context, iconId);
|
||||
addDrawTask(this);
|
||||
}
|
||||
|
||||
private PixelMap getPixelMapFromResource(Context context, int resourceId) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
// 创建图像数据源ImageSource对象
|
||||
inputStream = context.getResourceManager().getResource(resourceId);
|
||||
ImageSource.SourceOptions srcOpts = new ImageSource.SourceOptions();
|
||||
srcOpts.formatHint = "image/png";
|
||||
ImageSource imageSource = ImageSource.create(inputStream, srcOpts);
|
||||
// 设置图片参数
|
||||
ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
|
||||
return imageSource.createPixelmap(decodingOptions);
|
||||
} catch (IOException | NotExistException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置完成的百分比
|
||||
*
|
||||
* @param fraction 百分比
|
||||
*/
|
||||
private void setFraction(float fraction) {
|
||||
this.fraction = fraction;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Component component, Canvas canvas) {
|
||||
canvas.drawColor(colorOfBackground, Canvas.PorterDuffMode.SRC_OVER); //绘制背景色
|
||||
mWidthAndHeightOfView.setHeight(getHeight());
|
||||
mWidthAndHeightOfView.setWidth(getWidth());
|
||||
if (device == 0 || device == 3) {
|
||||
mDrawStrategy.drawAppIcon(canvas, fraction, mDrawable, colorOfAppIcon,
|
||||
mWidthAndHeightOfView);
|
||||
mDrawStrategy.drawAppName(canvas, fraction, appName, colorOfAppName,
|
||||
mWidthAndHeightOfView);
|
||||
mDrawStrategy.drawAppStatement(canvas, fraction, appStatement, colorOfAppStatement,
|
||||
mWidthAndHeightOfView);
|
||||
} else if (device == 2) {
|
||||
mDrawStrategy.drawAppIcon(canvas, fraction, mDrawable, colorOfAppIcon,
|
||||
mWidthAndHeightOfView);
|
||||
mDrawStrategy.drawAppName(canvas, fraction, appName, colorOfAppName,
|
||||
mWidthAndHeightOfView);
|
||||
} else if (device == 1) {
|
||||
mDrawStrategy.drawAppIcon(canvas, fraction, mDrawable, colorOfAppIcon,
|
||||
mWidthAndHeightOfView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示动画
|
||||
*
|
||||
* @param mactivity 显示动画的界面
|
||||
*/
|
||||
public void show(Ability mactivity) {
|
||||
SoftReference<Ability> softReference = new SoftReference<>(mactivity);
|
||||
final Ability activity = softReference.get();
|
||||
CommonDialog dialog = new CommonDialog(activity.getContext());
|
||||
dialog.setContentCustomComponent(this);
|
||||
dialog.show();
|
||||
AnimatorValue animatorValue = new AnimatorValue();
|
||||
animatorValue.setDuration(animationInterval - 50);
|
||||
animatorValue.setDelay(100);
|
||||
animatorValue.setLoopedCount(0);
|
||||
animatorValue.setCurveType(Animator.CurveType.LINEAR);
|
||||
animatorValue.setValueUpdateListener((animatorValue1, value) -> {
|
||||
setFraction(value);
|
||||
});
|
||||
animatorValue.start();
|
||||
//处理动画定时
|
||||
EventHandler handler = new EventHandler(EventRunner.getMainEventRunner()) {
|
||||
@Override
|
||||
protected void processEvent(InnerEvent event) {
|
||||
super.processEvent(event);
|
||||
if (event.eventId == FINISHANIMATION) {
|
||||
moveAnimation(activity);
|
||||
dialog.hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
//动画定时器
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
InnerEvent message = InnerEvent.get();
|
||||
message.eventId = FINISHANIMATION;
|
||||
handler.sendEvent(message);
|
||||
}
|
||||
}, animationInterval + 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏动画view
|
||||
*
|
||||
* @param activity 当前活动
|
||||
*/
|
||||
private void moveAnimation(Ability activity) {
|
||||
this.createAnimatorProperty()
|
||||
.scaleX(0)
|
||||
.scaleY(0)
|
||||
.alpha(0)
|
||||
.setDuration(animationFinishTime);
|
||||
mDelegateRecycleView.finishAnimation();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Builder模式创建对象
|
||||
*/
|
||||
public static final class Builder implements DelegateRecycleView {
|
||||
/**
|
||||
* The constant mDrawStrategy.
|
||||
*/
|
||||
public static DrawStrategy mDrawStrategy;
|
||||
/**
|
||||
* The M opening start animation.
|
||||
*/
|
||||
OpeningStartAnimation mOpeningStartAnimation;
|
||||
|
||||
/**
|
||||
* Instantiates a new Builder.
|
||||
*
|
||||
* @param context the context
|
||||
* @param iconId the icon id
|
||||
* @param dev the dev
|
||||
*/
|
||||
public Builder(Context context, int iconId, int dev) {
|
||||
mOpeningStartAnimation = new OpeningStartAnimation(context, iconId, dev);
|
||||
mOpeningStartAnimation.mDelegateRecycleView = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Builder.
|
||||
*
|
||||
* @param context the context
|
||||
* @param iconId the icon id
|
||||
*/
|
||||
public Builder(Context context, int iconId) {
|
||||
mOpeningStartAnimation = new OpeningStartAnimation(context, iconId);
|
||||
mOpeningStartAnimation.mDelegateRecycleView = this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置动画时间的方法
|
||||
*
|
||||
* @param animationInterval 动画时间
|
||||
* @return Builder对象 animation interval
|
||||
*/
|
||||
public Builder setAnimationInterval(long animationInterval) {
|
||||
mOpeningStartAnimation.animationInterval = animationInterval;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动画消失的时间
|
||||
*
|
||||
* @param animationFinishTime 动画消失的时间
|
||||
* @return Builder对象 animation finish time
|
||||
*/
|
||||
public Builder setAnimationFinishTime(long animationFinishTime) {
|
||||
mOpeningStartAnimation.animationFinishTime = animationFinishTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动画图标
|
||||
*
|
||||
* @param drawable 动画图标
|
||||
* @return Builder对象 app icon
|
||||
*/
|
||||
public Builder setAppIcon(PixelMap drawable) {
|
||||
mOpeningStartAnimation.mDrawable = drawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图标绘制辅助颜色
|
||||
*
|
||||
* @param colorOfAppIcon 辅助颜色
|
||||
* @return Builder对象 color of app icon
|
||||
*/
|
||||
public Builder setColorOfAppIcon(int colorOfAppIcon) {
|
||||
mOpeningStartAnimation.colorOfAppIcon = colorOfAppIcon;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置要绘制的app名称
|
||||
*
|
||||
* @param appName app名称
|
||||
* @return Builder对象 app name
|
||||
*/
|
||||
public Builder setAppName(String appName) {
|
||||
mOpeningStartAnimation.appName = appName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置app名称的颜色
|
||||
*
|
||||
* @param colorOfAppName app名称颜色
|
||||
* @return Builder对象 color of app name
|
||||
*/
|
||||
public Builder setColorOfAppName(int colorOfAppName) {
|
||||
mOpeningStartAnimation.colorOfAppName = colorOfAppName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置app一句话描述
|
||||
*
|
||||
* @param appStatement app一句话描述
|
||||
* @return Builder对象 app statement
|
||||
*/
|
||||
public Builder setAppStatement(String appStatement) {
|
||||
mOpeningStartAnimation.appStatement = appStatement;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置一句话描述的字体颜色
|
||||
*
|
||||
* @param colorOfAppStatement 字体颜色
|
||||
* @return Builder对象 color of app statement
|
||||
*/
|
||||
public Builder setColorOfAppStatement(int colorOfAppStatement) {
|
||||
mOpeningStartAnimation.colorOfAppStatement = colorOfAppStatement;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色
|
||||
*
|
||||
* @param colorOfBackground 背景颜色对应的int值
|
||||
* @return Builder对象 color of background
|
||||
*/
|
||||
public Builder setColorOfBackground(int colorOfBackground) {
|
||||
mOpeningStartAnimation.colorOfBackground = colorOfBackground;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开放绘制策略接口,可由用户自行定义
|
||||
*
|
||||
* @param drawStrategy 绘制接口
|
||||
* @return Builder对象 draw stategy
|
||||
*/
|
||||
public Builder setDrawStategy(DrawStrategy drawStrategy) {
|
||||
mOpeningStartAnimation.mDrawStrategy = drawStrategy;
|
||||
mDrawStrategy = drawStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建开屏动画
|
||||
*
|
||||
* @return 创建出的开屏动画 opening start animation
|
||||
*/
|
||||
public OpeningStartAnimation create() {
|
||||
return mOpeningStartAnimation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishAnimation() {
|
||||
mOpeningStartAnimation = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Ryb draw strategy state controller.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
class RYBDrawStrategyStateController {
|
||||
|
||||
private final RYBDrawStrategyStateOne mRYBDrawStrategyStateOne = new RYBDrawStrategyStateOne();
|
||||
private final RYBDrawStrategyStateTwo mRYBDrawStrategyStateTwo = new RYBDrawStrategyStateTwo();
|
||||
private RYBDrawStrategyStateInterface mRYBDrawStrategyStateInterface;
|
||||
|
||||
/**
|
||||
* Instantiates a new Ryb draw strategy state controller.
|
||||
*/
|
||||
RYBDrawStrategyStateController() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
*
|
||||
* @param rybDrawStrategyStateInterface 状态接口
|
||||
*/
|
||||
private void setState(RYBDrawStrategyStateInterface rybDrawStrategyStateInterface) {
|
||||
mRYBDrawStrategyStateInterface = rybDrawStrategyStateInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择合适的状态来执行操作
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param fraction 完成时间百分比
|
||||
* @param icon 图标
|
||||
* @param colorOfIcon 绘制颜色
|
||||
* @param widthAndHeightOfView view的宽高
|
||||
*/
|
||||
void choseStateDrawIcon(Canvas canvas, float fraction, PixelMap icon, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
if (fraction <= 0.65f) {
|
||||
setState(mRYBDrawStrategyStateOne);
|
||||
} else if (fraction > 0.65f) {
|
||||
setState(mRYBDrawStrategyStateTwo);
|
||||
}
|
||||
mRYBDrawStrategyStateInterface.drawIcon(canvas, fraction, icon, colorOfIcon, widthAndHeightOfView);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The interface Ryb draw strategy state interface.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
interface RYBDrawStrategyStateInterface {
|
||||
|
||||
/**
|
||||
* 绘制图标
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param fraction 完成时间
|
||||
* @param drawable 图标素材
|
||||
* @param colorOfIcon 绘制颜色
|
||||
* @param widthAndHeightOfView view的宽高
|
||||
*/
|
||||
void drawIcon(Canvas canvas, float fraction, PixelMap drawable, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.render.Paint;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Ryb draw strategy state one.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
class RYBDrawStrategyStateOne implements RYBDrawStrategyStateInterface {
|
||||
@Override
|
||||
public void drawIcon(Canvas canvas, float fraction, PixelMap drawable, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
float newFraction = fraction / 0.65f;
|
||||
int centerX = widthAndHeightOfView.getWidth() / 2;
|
||||
int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
|
||||
Paint paint = new Paint();
|
||||
canvas.save();
|
||||
paint.setColor(new Color(Color.getIntColor("#FFFF0500")));//RED
|
||||
if (newFraction <= 0.33f) {
|
||||
canvas.drawCircle(centerX, centerY - 50, 100 * (newFraction / 0.33f), paint);
|
||||
} else {
|
||||
canvas.drawCircle(centerX, centerY - 50, 100, paint);
|
||||
}
|
||||
if (newFraction > 0.33f) {
|
||||
paint.setColor(new Color(Color.getIntColor("#FFFFD100")));//YELLOW
|
||||
if (newFraction <= 0.66f)
|
||||
canvas.drawCircle(centerX - 35, centerY + 35, 100 * ((newFraction - 0.33f) / 0.33f), paint);
|
||||
else
|
||||
canvas.drawCircle(centerX - 35, centerY + 35, 100, paint);
|
||||
}
|
||||
if (newFraction > 0.66f) {
|
||||
paint.setColor(new Color(Color.getIntColor("#FF008BFF")));//BLUE
|
||||
if (newFraction <= 1f)
|
||||
canvas.drawCircle(centerX + 35, centerY + 35, 100 * ((newFraction - 0.66f) / 0.34f), paint);
|
||||
else
|
||||
canvas.drawCircle(centerX + 35, centerY + 35, 100, paint);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.components.element.PixelMapElement;
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.render.Paint;
|
||||
import ohos.agp.render.Path;
|
||||
import ohos.agp.render.PixelMapHolder;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.agp.utils.Matrix;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Ryb draw strategy state two.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
class RYBDrawStrategyStateTwo implements RYBDrawStrategyStateInterface {
|
||||
@Override
|
||||
public void drawIcon(Canvas canvas, float fraction, PixelMap drawable, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
int centerX = widthAndHeightOfView.getWidth() / 2;
|
||||
int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
|
||||
canvas.save();
|
||||
Paint paint = new Paint();
|
||||
float newFraction = (fraction - 0.65f) / 0.35f;
|
||||
paint.setColor(new Color(Color.getIntColor("#FFFF0500")));//RED
|
||||
canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint);
|
||||
paint.setColor(new Color(Color.getIntColor("#FFFFD100")));//YELLOW
|
||||
canvas.drawCircle(centerX - 35, centerY + 35, 100 * (1 - newFraction), paint);
|
||||
paint.setColor(new Color(Color.getIntColor("#FF008BFF")));//BLUE
|
||||
canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint);
|
||||
canvas.restore();
|
||||
canvas.save();
|
||||
Path path = new Path();
|
||||
PixelMap bitmap = BitmapUtils.drawableToBitmap(new PixelMapElement(drawable));
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.7f, 1.7f, centerX, centerY);
|
||||
canvas.concat(matrix);
|
||||
path.addCircle(centerX, centerY, bitmap.getImageInfo().size.height * 1.5f * newFraction, Path.Direction.CLOCK_WISE);
|
||||
canvas.clipPath(path, Canvas.ClipOp.INTERSECT);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(bitmap), centerX - (bitmap.getImageInfo().size.width >> 1), centerY - bitmap.getImageInfo().size.height / 2, paint);
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
|
||||
import ohos.agp.render.Canvas;
|
||||
import ohos.agp.render.Paint;
|
||||
import ohos.agp.render.Path;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.agp.utils.RectFloat;
|
||||
import ohos.agp.utils.TextAlignment;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Red yellow blue draw strategy.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public class RedYellowBlueDrawStrategy implements DrawStrategy {
|
||||
private final RYBDrawStrategyStateController mRYBDrawStrategyStateController;
|
||||
|
||||
/**
|
||||
* Instantiates a new Red yellow blue draw strategy.
|
||||
*/
|
||||
public RedYellowBlueDrawStrategy() {
|
||||
mRYBDrawStrategyStateController = new RYBDrawStrategyStateController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppName(Canvas canvas, float fraction, String name, int colorOfAppName,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfAppName));
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
paint.setTextSize(50);
|
||||
canvas.drawText(paint, name, width >> 1, (height >> 1) + 50);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppIcon(Canvas canvas, float fraction, PixelMap icon, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
mRYBDrawStrategyStateController.choseStateDrawIcon(canvas, fraction, icon, colorOfIcon, widthAndHeightOfView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppStatement(Canvas canvas, float fraction, String statement, int colorOfStatement,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfStatement));
|
||||
paint.setStyle(Paint.Style.STROKE_STYLE);
|
||||
paint.setTextSize(45);
|
||||
paint.horizontalTilt(-0.2f);
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
RectFloat rectF = new RectFloat((width >> 2) - statement.length(), height * 7 >> 3,
|
||||
width * 3, height);
|
||||
if (fraction <= 0.60f) {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40 * fraction * 1.67f);
|
||||
canvas.drawPath(path, paint);
|
||||
} else {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40);
|
||||
canvas.drawPath(path, paint);
|
||||
canvas.drawTextOnPath(paint, statement, path, 0, 0);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
import ohos.agp.render.*;
|
||||
import ohos.agp.utils.Color;
|
||||
import ohos.agp.utils.Matrix;
|
||||
import ohos.agp.utils.RectFloat;
|
||||
import ohos.agp.utils.TextAlignment;
|
||||
import ohos.media.image.PixelMap;
|
||||
|
||||
/**
|
||||
* The type Rotation draw strategy.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public class RotationDrawStrategy implements DrawStrategy {
|
||||
/**
|
||||
* Instantiates a new Rotation draw strategy.
|
||||
*/
|
||||
public RotationDrawStrategy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppName(Canvas canvas, float fraction, String name, int colorOfAppName,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
canvas.clipRect((width >> 1) - 150, (height >> 1) - 80,
|
||||
(width >> 1) + 150 * fraction, (height >> 1) + 65 * fraction);
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfAppName));
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
paint.setTextSize(50);
|
||||
canvas.drawText(paint, name, width >> 1, (height >> 1) + 50);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppIcon(Canvas canvas, float fraction, PixelMap icon, int colorOfIcon,
|
||||
WidthAndHeightOfView widthAndHeightOfView) {
|
||||
drawIcon(canvas, (int) (fraction * 540), icon,
|
||||
widthAndHeightOfView.getWidth(), widthAndHeightOfView.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawAppStatement(Canvas canvas, float fraction, String statement,
|
||||
int colorOfStatement, WidthAndHeightOfView widthAndHeightOfView) {
|
||||
canvas.save();
|
||||
int width = widthAndHeightOfView.getWidth();
|
||||
int height = widthAndHeightOfView.getHeight();
|
||||
Paint paint = new Paint();
|
||||
paint.setColor(new Color(colorOfStatement));
|
||||
paint.setStyle(Paint.Style.STROKE_STYLE);
|
||||
paint.setTextSize(45);
|
||||
paint.horizontalTilt(-0.2f);
|
||||
paint.setTextAlign(TextAlignment.CENTER);
|
||||
RectFloat rectF = new RectFloat((width >> 2) - statement.length(), height * 7 >> 3,
|
||||
width * 3, height);
|
||||
if (fraction <= 0.60f) {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40 * fraction * 1.67f);
|
||||
canvas.drawPath(path, paint);
|
||||
} else {
|
||||
Path path = new Path();
|
||||
path.addArc(rectF, 193, 40);
|
||||
canvas.drawPath(path, paint);
|
||||
canvas.drawTextOnPath(paint, statement, path, 0, 0);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角度绘制图标的类
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param degree 角度
|
||||
* @param icon 图标
|
||||
* @param width view宽度
|
||||
* @param height view高度
|
||||
*/
|
||||
private void drawIcon(Canvas canvas, int degree, PixelMap icon, int width, int height) {
|
||||
if (degree <= 180) {
|
||||
drawIconOne(canvas, degree / 180f, icon, width, height);
|
||||
}
|
||||
if (degree > 180 && degree <= 360) {
|
||||
drawIconTwo(canvas, degree - 180, icon, width, height);
|
||||
}
|
||||
if (degree > 360 && degree <= 540) {
|
||||
drawIconThree(canvas, degree - 360, icon, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角度绘制图标的类
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param fraction 完成时间百分比
|
||||
* @param icon 图标
|
||||
* @param width view宽度
|
||||
* @param height view高度
|
||||
*/
|
||||
private void drawIconOne(Canvas canvas, float fraction, PixelMap icon, int width, int height) {
|
||||
ThreeDimView camera = new ThreeDimView();
|
||||
Paint paint = new Paint();
|
||||
canvas.save();
|
||||
int centerX = width / 2;
|
||||
int centerY = height / 2 - 200;
|
||||
int x = centerX - icon.getImageInfo().size.width / 2;
|
||||
int y = centerY - icon.getImageInfo().size.height / 2;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.7f, 1.7f, centerX, centerY);
|
||||
canvas.concat(matrix);
|
||||
canvas.clipRect(x, y, x + icon.getImageInfo().size.width * fraction * 0.5f, y + icon.getImageInfo().size.height * fraction * 0.5f);
|
||||
canvas.translate(centerX, centerY);
|
||||
camera.rotateX(180);
|
||||
camera.rotateY(-180);
|
||||
camera.applyToCanvas(canvas);
|
||||
canvas.translate(-centerX, -centerY);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(icon), x, y, paint);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角度绘制图标的类
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param degree 角度
|
||||
* @param icon 图标
|
||||
* @param width view宽度
|
||||
* @param height view高度
|
||||
*/
|
||||
private void drawIconTwo(Canvas canvas, int degree, PixelMap icon, int width, int height) {
|
||||
ThreeDimView camera = new ThreeDimView();
|
||||
Paint paint = new Paint();
|
||||
int centerX = width / 2;
|
||||
int centerY = height / 2 - 200;
|
||||
int x = centerX - icon.getImageInfo().size.width / 2;
|
||||
int y = centerY - icon.getImageInfo().size.height / 2;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.7f, 1.7f, centerX, centerY);
|
||||
//绘制左半部分
|
||||
canvas.save();
|
||||
canvas.concat(matrix);
|
||||
canvas.clipRect(x, y, x + icon.getImageInfo().size.width / 2, y + (icon.getImageInfo().size.height >> 1));
|
||||
canvas.translate(centerX, centerY);
|
||||
camera.rotateX(180);
|
||||
camera.applyToCanvas(canvas);
|
||||
canvas.translate(-centerX, -centerY);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(icon), x, y, paint);
|
||||
canvas.restore();
|
||||
|
||||
//绘制右半部分
|
||||
canvas.save();
|
||||
canvas.concat(matrix);
|
||||
if (degree <= 90)
|
||||
canvas.clipRect(x, y, x + icon.getImageInfo().size.width / 2, y + (icon.getImageInfo().size.height >> 1));
|
||||
else
|
||||
canvas.clipRect(x + icon.getImageInfo().size.width / 2, y, x + icon.getImageInfo().size.width, y + icon.getImageInfo().size.height / 2);
|
||||
canvas.translate(centerX, centerY);
|
||||
camera.rotateX(180);
|
||||
camera.rotateY(180 - degree);
|
||||
camera.applyToCanvas(canvas);
|
||||
canvas.translate(-centerX, -centerY);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(icon), x, y, paint);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角度绘制图标的类
|
||||
*
|
||||
* @param canvas 画布
|
||||
* @param degree 角度
|
||||
* @param icon 图标
|
||||
* @param width view宽度
|
||||
* @param height view高度
|
||||
*/
|
||||
private void drawIconThree(Canvas canvas, int degree, PixelMap icon, int width, int height) {
|
||||
ThreeDimView camera = new ThreeDimView();
|
||||
Paint paint = new Paint();
|
||||
int centerX = width / 2;
|
||||
int centerY = height / 2 - 200;
|
||||
int x = centerX - icon.getImageInfo().size.width / 2;
|
||||
int y = centerY - icon.getImageInfo().size.height / 2;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(1.7f, 1.7f, centerX, centerY);
|
||||
//绘制上半部分
|
||||
canvas.save();
|
||||
canvas.concat(matrix);
|
||||
canvas.clipRect(x, y, x + icon.getImageInfo().size.width, y + (icon.getImageInfo().size.height >> 1));
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(icon), x, y, paint);
|
||||
canvas.restore();
|
||||
|
||||
//绘制下半部分
|
||||
canvas.save();
|
||||
canvas.concat(matrix);
|
||||
if (degree <= 90)
|
||||
canvas.clipRect(x, y, x + icon.getImageInfo().size.width, y + (icon.getImageInfo().size.height >> 1));
|
||||
else
|
||||
canvas.clipRect(x, y + icon.getImageInfo().size.height / 2, x + icon.getImageInfo().size.width, y + icon.getImageInfo().size.height);
|
||||
canvas.translate(centerX, centerY);
|
||||
camera.rotateX(180 - degree);
|
||||
camera.applyToCanvas(canvas);
|
||||
canvas.translate(-centerX, -centerY);
|
||||
canvas.drawPixelMapHolder(new PixelMapHolder(icon), x, y, paint);
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
/**
|
||||
* The type Width and height of view.
|
||||
*
|
||||
* @author Xcl
|
||||
* @version 1.2
|
||||
* @package com.xcl.fancynew
|
||||
*/
|
||||
public class WidthAndHeightOfView {
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
/**
|
||||
* Instantiates a new Width and height of view.
|
||||
*/
|
||||
WidthAndHeightOfView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets width.
|
||||
*
|
||||
* @return the width
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets width.
|
||||
*
|
||||
* @param width the width
|
||||
*/
|
||||
void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets height.
|
||||
*
|
||||
* @return the height
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets height.
|
||||
*
|
||||
* @param height the height
|
||||
*/
|
||||
void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
8
fancynew/src/main/resources/base/element/string.json
Normal file
8
fancynew/src/main/resources/base/element/string.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "fancynew_library",
|
||||
"value": "fancynew"
|
||||
}
|
||||
]
|
||||
}
|
||||
9
fancynew/src/test/java/com/xcl/fancynew/ExampleTest.java
Normal file
9
fancynew/src/test/java/com/xcl/fancynew/ExampleTest.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.xcl.fancynew;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExampleTest {
|
||||
@Test
|
||||
public void onStart() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user