|
@@ -0,0 +1,168 @@
|
|
|
|
|
+package cn.fmode.app;
|
|
|
|
|
+
|
|
|
|
|
+import android.animation.Animator;
|
|
|
|
|
+import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
+import android.animation.ValueAnimator;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.graphics.Canvas;
|
|
|
|
|
+import android.graphics.DashPathEffect;
|
|
|
|
|
+import android.graphics.LinearGradient;
|
|
|
|
|
+import android.graphics.Matrix;
|
|
|
|
|
+import android.graphics.Paint;
|
|
|
|
|
+import android.graphics.Path;
|
|
|
|
|
+import android.graphics.PathMeasure;
|
|
|
|
|
+import android.graphics.RectF;
|
|
|
|
|
+import android.graphics.Shader;
|
|
|
|
|
+import android.util.AttributeSet;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.animation.LinearInterpolator;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 开屏动画视图(2026-11-23 定稿):**纯代码绘制,不用视频、不用图片资源**。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 轮廓与配色取自 resources/logo-mark.png(一次性用 OpenCV 提取归一化,
|
|
|
|
|
+ * 提取方法见 docs/00-tracking/2026-11-23-修改留痕-开屏动画视频接入.md)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 时序(总长 2.1s):
|
|
|
|
|
+ * 0.00–0.80s 三笔轮廓「生长」出来(PathMeasure dash 描边,先快后稳)
|
|
|
|
|
+ * 0.63–1.50s 品牌渐变(左下粉 → 右上青)沿对角线扫入填充,描边淡出
|
|
|
|
|
+ * 1.50–2.10s 定格保持,随后回调 MainActivity 淡出遮罩
|
|
|
|
|
+ */
|
|
|
|
|
+public class SplashAnimView extends View {
|
|
|
|
|
+
|
|
|
|
|
+ /** 动画播完回调(遮罩由 MainActivity 负责淡出移除) */
|
|
|
|
|
+ public interface OnEndListener { void onEnd(); }
|
|
|
|
|
+
|
|
|
|
|
+ private static final long DURATION_MS = 2100;
|
|
|
|
|
+ // 阶段边界(0..1)
|
|
|
|
|
+ private static final float DRAW_END = 0.38f; // 描边生长完成
|
|
|
|
|
+ private static final float FILL_START = 0.30f; // 填充开始出现
|
|
|
|
|
+ private static final float FILL_FULL = 0.55f; // 填充不再透明
|
|
|
|
|
+ private static final float SWEEP_END = 0.72f; // 渐变扫到位 & 描边完全淡出
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 轮廓点:从 logo-mark.png(512×512 带透明通道)提取的 4 个外轮廓,
|
|
|
|
|
+ * 已归一化到 0..1(x,y 交替)。形状依次为:
|
|
|
|
|
+ * 0 顶部大翼(含左侧下探的一笔)、1 左下翼、2 右下翼、3 底部小点
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final float[] CONTOUR_0 = { 0.9766f, 0.0957f, 0.9668f, 0.0938f, 0.9473f, 0.1172f, 0.9062f, 0.1367f, 0.3281f, 0.1426f, 0.2637f, 0.1621f, 0.1895f, 0.2012f, 0.1289f, 0.2520f, 0.0703f, 0.3262f, 0.0254f, 0.4395f, 0.0195f, 0.5703f, 0.0586f, 0.6953f, 0.0684f, 0.6953f, 0.0742f, 0.6113f, 0.0996f, 0.5488f, 0.1660f, 0.4746f, 0.2246f, 0.4414f, 0.2656f, 0.4297f, 0.6641f, 0.4297f, 0.7578f, 0.4102f, 0.8125f, 0.3848f, 0.8652f, 0.3457f, 0.9316f, 0.2656f, 0.9707f, 0.1621f };
|
|
|
|
|
+ private static final float[] CONTOUR_1 = { 0.4316f, 0.4395f, 0.2949f, 0.4395f, 0.2852f, 0.4453f, 0.2598f, 0.4453f, 0.2500f, 0.4531f, 0.2363f, 0.4531f, 0.2168f, 0.4648f, 0.2070f, 0.4648f, 0.1699f, 0.4902f, 0.1348f, 0.5254f, 0.1094f, 0.5605f, 0.0977f, 0.5977f, 0.0898f, 0.6074f, 0.0898f, 0.6250f, 0.0840f, 0.6309f, 0.0840f, 0.7109f, 0.0898f, 0.7188f, 0.0898f, 0.7363f, 0.1152f, 0.7695f, 0.1758f, 0.8262f, 0.2207f, 0.8555f, 0.2520f, 0.8672f, 0.2598f, 0.8750f, 0.2695f, 0.8750f, 0.2734f, 0.8809f, 0.3105f, 0.8867f, 0.3164f, 0.8926f, 0.3398f, 0.8926f, 0.3516f, 0.9004f, 0.3652f, 0.8926f, 0.3789f, 0.8926f, 0.3848f, 0.8867f, 0.3984f, 0.8867f, 0.4062f, 0.8770f, 0.3633f, 0.8379f, 0.3379f, 0.8047f, 0.3125f, 0.7500f, 0.2988f, 0.6699f, 0.3125f, 0.5918f, 0.3184f, 0.5879f, 0.3184f, 0.5781f, 0.3438f, 0.5293f, 0.3906f, 0.4805f, 0.4141f, 0.4609f, 0.4316f, 0.4531f, 0.4355f, 0.4473f };
|
|
|
|
|
+ private static final float[] CONTOUR_2 = { 0.7891f, 0.4355f, 0.5273f, 0.4336f, 0.5215f, 0.4395f, 0.4961f, 0.4395f, 0.4883f, 0.4453f, 0.4766f, 0.4453f, 0.4688f, 0.4531f, 0.4453f, 0.4590f, 0.4297f, 0.4727f, 0.4062f, 0.4844f, 0.3672f, 0.5234f, 0.3555f, 0.5449f, 0.3477f, 0.5508f, 0.3359f, 0.5742f, 0.3359f, 0.5840f, 0.3281f, 0.5918f, 0.3281f, 0.6035f, 0.3223f, 0.6094f, 0.3223f, 0.6309f, 0.3164f, 0.6406f, 0.3164f, 0.7051f, 0.3223f, 0.7129f, 0.3223f, 0.7324f, 0.3281f, 0.7402f, 0.3301f, 0.7559f, 0.3418f, 0.7676f, 0.3438f, 0.7383f, 0.3516f, 0.7285f, 0.3516f, 0.7129f, 0.3711f, 0.6758f, 0.4121f, 0.6348f, 0.4336f, 0.6230f, 0.4707f, 0.6152f, 0.4785f, 0.6094f, 0.6582f, 0.6094f, 0.6660f, 0.6035f, 0.6836f, 0.6035f, 0.6875f, 0.5977f, 0.6992f, 0.5957f, 0.7012f, 0.5898f, 0.7109f, 0.5898f, 0.7578f, 0.5488f, 0.7695f, 0.5312f, 0.7695f, 0.5215f, 0.7773f, 0.5156f, 0.7773f, 0.5078f, 0.7832f, 0.5020f, 0.7832f, 0.4863f, 0.7891f, 0.4805f };
|
|
|
|
|
+ private static final float[] CONTOUR_3 = { 0.3965f, 0.9004f, 0.3965f, 0.9043f, 0.3984f, 0.9043f, 0.4004f, 0.9062f, 0.4590f, 0.9062f, 0.4609f, 0.9043f, 0.4609f, 0.9004f, 0.4570f, 0.8965f, 0.4551f, 0.8965f, 0.4531f, 0.8945f, 0.4531f, 0.8926f, 0.4512f, 0.8906f, 0.4434f, 0.8906f, 0.4414f, 0.8887f, 0.4414f, 0.8867f, 0.4395f, 0.8848f, 0.4277f, 0.8848f, 0.4258f, 0.8867f, 0.4258f, 0.8887f, 0.4238f, 0.8906f, 0.4160f, 0.8906f, 0.4102f, 0.8965f, 0.4023f, 0.8965f, 0.3984f, 0.9004f };
|
|
|
|
|
+ private static final float[][] CONTOURS = { CONTOUR_0, CONTOUR_1, CONTOUR_2, CONTOUR_3 };
|
|
|
|
|
+
|
|
|
|
|
+ /** 品牌渐变(沿标志主轴采样):左下粉 → 右上青 */
|
|
|
|
|
+ private static final int[] GRADIENT_COLORS = { 0xFFDC55A9, 0xFF916BB8, 0xFF5583C7, 0xFF34AEE2, 0xFF55DFFC };
|
|
|
|
|
+ private static final float[] GRADIENT_POS = { 0f, 0.25f, 0.5f, 0.75f, 1f };
|
|
|
|
|
+ private static final int STROKE_COLOR = 0xFF34AEE2;
|
|
|
|
|
+
|
|
|
|
|
+ private final Path[] paths = new Path[CONTOURS.length];
|
|
|
|
|
+ private final float[] lengths = new float[CONTOURS.length];
|
|
|
|
|
+ private final Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
|
+ private final Paint fillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
|
+ private final RectF bounds = new RectF();
|
|
|
|
|
+ private final Matrix gradMatrix = new Matrix();
|
|
|
|
|
+ private LinearGradient gradient;
|
|
|
|
|
+ private float progress;
|
|
|
|
|
+ private ValueAnimator animator;
|
|
|
|
|
+ private OnEndListener endListener;
|
|
|
|
|
+
|
|
|
|
|
+ public SplashAnimView(Context context) { this(context, null); }
|
|
|
|
|
+
|
|
|
|
|
+ public SplashAnimView(Context context, AttributeSet attrs) {
|
|
|
|
|
+ super(context, attrs);
|
|
|
|
|
+ strokePaint.setStyle(Paint.Style.STROKE);
|
|
|
|
|
+ strokePaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
|
|
+ strokePaint.setStrokeJoin(Paint.Join.ROUND);
|
|
|
|
|
+ strokePaint.setColor(STROKE_COLOR);
|
|
|
|
|
+ fillPaint.setStyle(Paint.Style.FILL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setOnEndListener(OnEndListener listener) { this.endListener = listener; }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
|
|
|
+ // 标志占短边 56%,中心略偏上(与 splash 设计一致:纵向 44% 处)
|
|
|
|
|
+ float s = Math.min(w, h) * 0.56f;
|
|
|
|
|
+ float dx = (w - s) / 2f;
|
|
|
|
|
+ float dy = h * 0.44f - s / 2f;
|
|
|
|
|
+ bounds.set(dx, dy, dx + s, dy + s);
|
|
|
|
|
+ for (int i = 0; i < CONTOURS.length; i++) {
|
|
|
|
|
+ float[] pts = CONTOURS[i];
|
|
|
|
|
+ Path p = new Path();
|
|
|
|
|
+ p.moveTo(dx + pts[0] * s, dy + pts[1] * s);
|
|
|
|
|
+ for (int j = 2; j + 1 < pts.length; j += 2) {
|
|
|
|
|
+ p.lineTo(dx + pts[j] * s, dy + pts[j + 1] * s);
|
|
|
|
|
+ }
|
|
|
|
|
+ p.close();
|
|
|
|
|
+ paths[i] = p;
|
|
|
|
|
+ lengths[i] = new PathMeasure(p, false).getLength();
|
|
|
|
|
+ }
|
|
|
|
|
+ strokePaint.setStrokeWidth(s * 0.012f);
|
|
|
|
|
+ gradient = new LinearGradient(bounds.left, bounds.bottom, bounds.right, bounds.top,
|
|
|
|
|
+ GRADIENT_COLORS, GRADIENT_POS, Shader.TileMode.CLAMP);
|
|
|
|
|
+ fillPaint.setShader(gradient);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onAttachedToWindow() {
|
|
|
|
|
+ super.onAttachedToWindow();
|
|
|
|
|
+ animator = ValueAnimator.ofFloat(0f, 1f);
|
|
|
|
|
+ animator.setDuration(DURATION_MS);
|
|
|
|
|
+ animator.setInterpolator(new LinearInterpolator());
|
|
|
|
|
+ animator.addUpdateListener(a -> {
|
|
|
|
|
+ progress = (float) a.getAnimatedValue();
|
|
|
|
|
+ invalidate();
|
|
|
|
|
+ });
|
|
|
|
|
+ animator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onAnimationEnd(Animator animation) {
|
|
|
|
|
+ if (endListener != null) post(() -> endListener.onEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ animator.start();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onDetachedFromWindow() {
|
|
|
|
|
+ if (animator != null) animator.cancel();
|
|
|
|
|
+ super.onDetachedFromWindow();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onDraw(Canvas canvas) {
|
|
|
|
|
+ float t = progress;
|
|
|
|
|
+ // ① 描边生长(ease-out:起笔快、收笔稳)
|
|
|
|
|
+ float drawT = easeOut(clamp(t / DRAW_END));
|
|
|
|
|
+ // ② 填充:透明度过渡 + 渐变沿对角线扫入
|
|
|
|
|
+ float fillT = clamp((t - FILL_START) / (FILL_FULL - FILL_START));
|
|
|
|
|
+ float sweepT = clamp((t - FILL_START) / (SWEEP_END - FILL_START));
|
|
|
|
|
+ // ③ 描边在填充成型后淡出
|
|
|
|
|
+ float strokeAlpha = 1f - clamp((t - FILL_FULL) / (SWEEP_END - FILL_FULL));
|
|
|
|
|
+
|
|
|
|
|
+ if (fillT > 0f && gradient != null) {
|
|
|
|
|
+ gradMatrix.setTranslate(
|
|
|
|
|
+ -bounds.width() * (1f - sweepT) * 0.6f,
|
|
|
|
|
+ bounds.height() * (1f - sweepT) * 0.6f);
|
|
|
|
|
+ gradient.setLocalMatrix(gradMatrix);
|
|
|
|
|
+ fillPaint.setAlpha((int) (255 * fillT));
|
|
|
|
|
+ for (Path p : paths) {
|
|
|
|
|
+ if (p != null) canvas.drawPath(p, fillPaint);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (strokeAlpha > 0f) {
|
|
|
|
|
+ strokePaint.setAlpha((int) (255 * strokeAlpha));
|
|
|
|
|
+ for (int i = 0; i < paths.length; i++) {
|
|
|
|
|
+ if (paths[i] == null) continue;
|
|
|
|
|
+ float len = lengths[i];
|
|
|
|
|
+ strokePaint.setPathEffect(new DashPathEffect(new float[]{ len, len }, len * (1f - drawT)));
|
|
|
|
|
+ canvas.drawPath(paths[i], strokePaint);
|
|
|
|
|
+ }
|
|
|
|
|
+ strokePaint.setPathEffect(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static float clamp(float v) { return v < 0f ? 0f : Math.min(v, 1f); }
|
|
|
|
|
+
|
|
|
|
|
+ private static float easeOut(float x) { return 1f - (1f - x) * (1f - x); }
|
|
|
|
|
+}
|