Android11.0(R) 华为充电动画

简介: Android11.0(R) 华为充电动画

根据系统原有的无线充电动画流程,新增有线充电气泡动画。


效果图

hU8zcD.png

修改文件清单

  vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
  vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/wired_charging_layout.xml
  vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/charging/BubbleBean.java
  vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/charging/BubbleViscosity.java
  vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/charging/WiredChargingAnimation.java

具体实现


新增布局


vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/wired_charging_layout.xml


<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/shcy_charge_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#99000000">
    <com.android.systemui.charging.BubbleViscosity
        android:id="@+id/shcy_bubble_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</FrameLayout>

新增气泡 bean

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/charging/BubbleBean.java

package com.android.systemui.charging;
public class BubbleBean {
  private float randomY = 3;
  private float x;
  private float y;
  private int index;
  public BubbleBean(float x, float y, float randomY, int index) {
    this.x = x;
    this.y = y;
    this.randomY = randomY;
    this.index = index;
  }
  public void set(float x, float y, float randomY, int index) {
    this.x = x;
    this.y = y;
    this.randomY = randomY;
    this.index = index;
  }
  public void setMove(int screenHeight, int maxDistance) {
    if (y - maxDistance < 110) {
      this.y -= 2;
      return;
    }
    if (maxDistance <= y && screenHeight - y > 110) {
      this.y -= randomY;
    } else {
      this.y -= 0.6;
    }
    if (index == 0) {
      this.x -= 0.4;
    } else if (index == 2) {
      this.x += 0.4;
    }
  }
  public int getIndex() {
    return index;
  }
  public float getX() {
    return x;
  }
  public void setX(float x) {
    this.x = x;
  }
  public float getY() {
    return y;
  }
  public void setY(float y) {
    this.y = y;
  }
}


新增充电动画自定义 view

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/charging/BubbleViscosity.java


package com.android.systemui.charging;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class BubbleViscosity extends SurfaceView implements
    SurfaceHolder.Callback, Runnable {
  private static ScheduledExecutorService scheduledThreadPool;
  private Context context;
  private String paintColor = "#25DA29";
  private String centreColor = "#00000000";
  private String minCentreColor = "#9025DA29";
  private int screenHeight;
  private int screenWidth;
  private float lastRadius;
  private float rate = 0.32f;
  private float rate2 = 0.45f;
  private PointF lastCurveStrat = new PointF();
  private PointF lastCurveEnd = new PointF();
  private PointF centreCirclePoint = new PointF();
  private float centreRadius;
  private float bubbleRadius;
  private PointF[] arcPointStrat = new PointF[8];
  private PointF[] arcPointEnd = new PointF[8];
  private PointF[] control = new PointF[8];
  private PointF arcStrat = new PointF();
  private PointF arcEnd = new PointF();
  private PointF controlP = new PointF();
  List<PointF> bubbleList = new ArrayList<>();
  List<BubbleBean> bubbleBeans = new ArrayList<>();
  private int rotateAngle = 0;
  private float controlrate = 1.66f;
  private float controlrateS = 1.3f;
  private int i = 0;
  private SurfaceHolder mHolder;
  private float scale = 0;
  private Paint arcPaint;
  private Paint minCentrePaint;
  private Paint bubblePaint;
  private Paint centrePaint;
  private Paint lastPaint;
  private Path lastPath;
  private Random random;
  private Paint textPaint;
  private String text = "78 %";
  private Rect rect;
  public BubbleViscosity(Context context) {
    this(context, null);
  }
  public BubbleViscosity(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }
  public BubbleViscosity(Context context, AttributeSet attrs,
      int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.context = context;
    initTool();
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    screenHeight = getMeasuredHeight();
    screenWidth = getMeasuredWidth();
  }
  private void initTool() {
    rect = new Rect();
    mHolder = getHolder();
    mHolder.addCallback(this);
    setFocusable(true);
    mHolder.setFormat(PixelFormat.TRANSPARENT);
    setZOrderOnTop(true);
    lastRadius = dip2Dimension(40f, context);
    centreRadius = dip2Dimension(100f, context);
    bubbleRadius = dip2Dimension(15f, context);
    random = new Random();
    lastPaint = new Paint();
    lastPaint.setAntiAlias(true);
    lastPaint.setStyle(Paint.Style.FILL);
    lastPaint.setColor(Color.parseColor(paintColor));
    lastPaint.setStrokeWidth(2);
    lastPath = new Path();
    centrePaint = new Paint();
    centrePaint.setAntiAlias(true);
    centrePaint.setStyle(Paint.Style.FILL);
    centrePaint.setStrokeWidth(2);
    centrePaint
        .setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
    centrePaint.setColor(Color.parseColor(centreColor));
    arcPaint = new Paint();
    arcPaint.setAntiAlias(true);
    arcPaint.setStyle(Paint.Style.FILL);
    arcPaint.setColor(Color.parseColor(paintColor));
    arcPaint.setStrokeWidth(2);
    minCentrePaint = new Paint();
    minCentrePaint.setAntiAlias(true);
    minCentrePaint.setStyle(Paint.Style.FILL);
    minCentrePaint.setColor(Color.parseColor(minCentreColor));
    minCentrePaint.setStrokeWidth(2);
    bubblePaint = new Paint();
    bubblePaint.setAntiAlias(true);
    bubblePaint.setStyle(Paint.Style.FILL);
    bubblePaint.setColor(Color.parseColor(minCentreColor));
    bubblePaint.setStrokeWidth(2);
    textPaint = new Paint();
    textPaint.setAntiAlias(true);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setColor(Color.parseColor("#FFFFFF"));
    textPaint.setStrokeWidth(2);
    textPaint.setTextSize(dip2Dimension(40f, context));
  }
  private void onMDraw() {
    Canvas canvas = mHolder.lockCanvas();
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    bubbleDraw(canvas);
    lastCircleDraw(canvas);
    centreCircleDraw(canvas);
    textPaint.getTextBounds(text, 0, text.length(), rect);
    canvas.drawText(text, centreCirclePoint.x - rect.width() / 2,
        centreCirclePoint.y + rect.height() / 2, textPaint);
    mHolder.unlockCanvasAndPost(canvas);
  }
  public void setBatteryLevel(String level){
    this.text=level+"%";
    postInvalidate();
  }
  private void centreCircleDraw(Canvas canvas) {
    centreCirclePoint.set(screenWidth / 2, screenHeight / 2);
    circleInCoordinateDraw(canvas);
    canvas.drawCircle(centreCirclePoint.x, centreCirclePoint.y,
        centreRadius, centrePaint);
  }
  private void lastCircleDraw(Canvas canvas) {
    lastCurveStrat.set(screenWidth / 2 - lastRadius, screenHeight);
    lastCurveEnd.set((screenWidth / 2), screenHeight);
    float k = (lastRadius / 2) / lastRadius;
    float aX = lastRadius - lastRadius * rate2;
    float aY = lastCurveStrat.y - aX * k;
    float bX = lastRadius - lastRadius * rate;
    float bY = lastCurveEnd.y - bX * k;
    lastPath.rewind();
    lastPath.moveTo(lastCurveStrat.x, lastCurveStrat.y);
    lastPath.cubicTo(lastCurveStrat.x + aX, aY, lastCurveEnd.x - bX, bY,
        lastCurveEnd.x, lastCurveEnd.y - lastRadius / 2);
    lastPath.cubicTo(lastCurveEnd.x + bX, bY, lastCurveEnd.x + lastRadius
        - aX, aY, lastCurveEnd.x + lastRadius, lastCurveEnd.y);
    lastPath.lineTo(lastCurveStrat.x, lastCurveStrat.y);
    canvas.drawPath(lastPath, lastPaint);
  }
  private int bubbleIndex = 0;
  private void bubbleDraw(Canvas canvas) {
    for (int i = 0; i < bubbleBeans.size(); i++) {
      if (bubbleBeans.get(i).getY() <= (int) (screenHeight / 2 + centreRadius)) {
        bubblePaint.setAlpha(000);
        canvas.drawCircle(bubbleBeans.get(i).getX(), bubbleBeans.get(i)
            .getY(), bubbleRadius, bubblePaint);
      } else {
        bubblePaint.setAlpha(150);
        canvas.drawCircle(bubbleBeans.get(i).getX(), bubbleBeans.get(i)
            .getY(), bubbleRadius, bubblePaint);
      }
    }
  }
  /**
   * @param dip
   * @param context
   * @return
   */
  public float dip2Dimension(float dip, Context context) {
    DisplayMetrics displayMetrics = context.getResources()
        .getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip,
        displayMetrics);
  }
  /**
   * @param canvas
   */
  public void circleInCoordinateDraw(Canvas canvas) {
    int angle;
    for (int i = 0; i < arcPointStrat.length; i++) {
      if (i > 3 && i < 6) {
        if (i == 4) {
          angle = rotateAngle + i * 60;
        } else {
          angle = rotateAngle + i * 64;
        }
      } else if (i > 5) {
        if (i == 6) {
          angle = rotateAngle + i * 25;
        } else {
          angle = rotateAngle + i * 48;
        }
      } else {
        angle = rotateAngle + i * 90;
      }
      float radian = (float) Math.toRadians(angle);
      float adjacent = (float) Math.cos(radian) * centreRadius;
      float right = (float) Math.sin(radian) * centreRadius;
      float radianControl = (float) Math.toRadians(90 - (45 + angle));
      float xStrat = (float) Math.cos(radianControl) * centreRadius;
      float yEnd = (float) Math.sin(radianControl) * centreRadius;
      if (i == 0 || i == 1) {
        if (i == 1) {
          arcStrat.set(centreCirclePoint.x + adjacent - scale,
              centreCirclePoint.y + right + scale);
          arcEnd.set(centreCirclePoint.x - right, centreCirclePoint.y
              + adjacent);
        } else {
          arcStrat.set(centreCirclePoint.x + adjacent,
              centreCirclePoint.y + right);
          arcEnd.set(centreCirclePoint.x - right - scale,
              centreCirclePoint.y + adjacent + scale);
        }
        controlP.set(centreCirclePoint.x + yEnd * controlrate,
            centreCirclePoint.y + xStrat * controlrate);
      } else {
        arcStrat.set(centreCirclePoint.x + adjacent,
            centreCirclePoint.y + right);
        arcEnd.set(centreCirclePoint.x - right, centreCirclePoint.y
            + adjacent);
        if (i > 5) {
          controlP.set(centreCirclePoint.x + yEnd * controlrateS,
              centreCirclePoint.y + xStrat * controlrateS);
        } else {
          controlP.set(centreCirclePoint.x + yEnd * controlrate,
              centreCirclePoint.y + xStrat * controlrate);
        }
      }
      arcPointStrat[i] = arcStrat;
      arcPointEnd[i] = arcEnd;
      control[i] = controlP;
      lastPath.rewind();
      lastPath.moveTo(arcPointStrat[i].x, arcPointStrat[i].y);
      lastPath.quadTo(control[i].x, control[i].y, arcPointEnd[i].x,
          arcPointEnd[i].y);
      if (i > 3 && i < 6) {
        canvas.drawPath(lastPath, minCentrePaint);
      } else {
        canvas.drawPath(lastPath, arcPaint);
      }
      lastPath.rewind();
    }
  }
  private void setAnimation() {
    setScheduleWithFixedDelay(this, 0, 5);
    setScheduleWithFixedDelay(new Runnable() {
      @Override
      public void run() {
        if (bubbleIndex > 2)
          bubbleIndex = 0;
        if (bubbleBeans.size() < 8) {
          bubbleBeans.add(new BubbleBean(
              bubbleList.get(bubbleIndex).x, bubbleList
                  .get(bubbleIndex).y, random.nextInt(4) + 2,
              bubbleIndex));
        } else {
          for (int i = 0; i < bubbleBeans.size(); i++) {
            if (bubbleBeans.get(i).getY() <= (int) (screenHeight / 2 + centreRadius)) {
              bubbleBeans.get(i).set(
                  bubbleList.get(bubbleIndex).x,
                  bubbleList.get(bubbleIndex).y,
                  random.nextInt(4) + 2, bubbleIndex);
              if (random.nextInt(bubbleBeans.size()) + 3 == 3 ? true
                  : false) {
              } else {
                break;
              }
            }
          }
        }
        bubbleIndex++;
      }
    }, 0, 300);
  }
  private static ScheduledExecutorService getInstence() {
    if (scheduledThreadPool == null) {
      synchronized (BubbleViscosity.class) {
        if (scheduledThreadPool == null) {
          scheduledThreadPool = Executors
              .newSingleThreadScheduledExecutor();
        }
      }
    }
    return scheduledThreadPool;
  }
  private static void setScheduleWithFixedDelay(Runnable var1, long var2,
      long var4) {
    getInstence().scheduleWithFixedDelay(var1, var2, var4,
        TimeUnit.MILLISECONDS);
  }
  public static void onDestroyThread() {
    getInstence().shutdownNow();
    if (scheduledThreadPool != null) {
      scheduledThreadPool = null;
    }
  }
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    bubbleList.clear();
    setBubbleList();
    startBubbleRunnable();
    setAnimation();
  }
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width,
      int height) {
  }
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    onDestroyThread();
  }
  @Override
  public void run() {
    i++;
    rotateAngle = i;
    if (i > 90 && i < 180) {
      scale += 0.25;
      if (controlrateS < 1.66)
        controlrateS += 0.005;
    } else if (i >= 180) {
      scale -= 0.12;
      if (i > 300)
        controlrateS -= 0.01;
    }
    onMDraw();
    if (i == 360) {
      i = 0;
      rotateAngle = 0;
      controlrate = 1.66f;
      controlrateS = 1.3f;
      scale = 0;
    }
  }
  public void setBubbleList() {
    float radian = (float) Math.toRadians(35);
    float adjacent = (float) Math.cos(radian) * lastRadius / 3;
    float right = (float) Math.sin(radian) * lastRadius / 3;
    if (!bubbleList.isEmpty())
      return;
    bubbleList.add(new PointF(screenWidth / 2 - adjacent, screenHeight
        - right));
    bubbleList.add(new PointF(screenWidth / 2, screenHeight - lastRadius
        / 4));
    bubbleList.add(new PointF(screenWidth / 2 + adjacent, screenHeight
        - right));
    startBubbleRunnable();
  }
  public void startBubbleRunnable(){
    setScheduleWithFixedDelay(new Runnable() {
      @Override
      public void run() {
        for (int i = 0; i < bubbleBeans.size(); i++) {
          bubbleBeans.get(i).setMove(screenHeight,
              (int) (screenHeight / 2 + centreRadius));
        }
      }
    }, 0, 4);
  }
}

新增动画管理类

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/charging/WiredChargingAnimation.java

package com.android.systemui.charging;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.util.Slog;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.LayoutInflater;
import com.android.systemui.R;
public class WiredChargingAnimation {
    public static final long DURATION = 3333;
    private static final String TAG = "WiredChargingAnimation";
    private static final boolean DEBUG = true || Log.isLoggable(TAG, Log.DEBUG);
    private final WiredChargingView mCurrentWirelessChargingView;
    private static WiredChargingView mPreviousWirelessChargingView;
    private static boolean mShowingWiredChargingAnimation;
    public static boolean isShowingWiredChargingAnimation(){
        return mShowingWiredChargingAnimation;
    }
    public WiredChargingAnimation(@NonNull Context context, @Nullable Looper looper, int
            batteryLevel,  boolean isDozing) {
        mCurrentWirelessChargingView = new WiredChargingView(context, looper,
                batteryLevel, isDozing);
    }
    public static WiredChargingAnimation makeWiredChargingAnimation(@NonNull Context context,
            @Nullable Looper looper, int batteryLevel, boolean isDozing) {
        mShowingWiredChargingAnimation = true;
        android.util.Log.d(TAG,"makeWiredChargingAnimation batteryLevel="+batteryLevel);
        return new WiredChargingAnimation(context, looper, batteryLevel, isDozing);
    }
    /**
     * Show the view for the specified duration.
     */
    public void show() {
        if (mCurrentWirelessChargingView == null ||
                mCurrentWirelessChargingView.mNextView == null) {
            throw new RuntimeException("setView must have been called");
        }
        /*if (mPreviousWirelessChargingView != null) {
            mPreviousWirelessChargingView.hide(0);
        }*/
        mPreviousWirelessChargingView = mCurrentWirelessChargingView;
        mCurrentWirelessChargingView.show();
        mCurrentWirelessChargingView.hide(DURATION);
    }
    private static class WiredChargingView {
        private static final int SHOW = 0;
        private static final int HIDE = 1;
        private final WindowManager.LayoutParams mParams = new WindowManager.LayoutParams();
        private final Handler mHandler;
        private int mGravity;
        private View mView;
        private View mNextView;
        private WindowManager mWM;
        public WiredChargingView(Context context, @Nullable Looper looper, int batteryLevel, boolean isDozing) {
            //mNextView = new WirelessChargingLayout(context, batteryLevel, isDozing);
            mNextView = LayoutInflater.from(context).inflate(R.layout.wired_charging_layout, null, false);
            BubbleViscosity shcyBubbleViscosity = mNextView.findViewById(R.id.shcy_bubble_view);
            shcyBubbleViscosity.setBatteryLevel(batteryLevel+"");
            mGravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER;
            final WindowManager.LayoutParams params = mParams;
            params.height = WindowManager.LayoutParams.MATCH_PARENT;
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.format = PixelFormat.TRANSLUCENT;
            params.type = WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
            params.setTitle("Charging Animation");
            params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_DIM_BEHIND;
            params.dimAmount = .3f;
            if (looper == null) {
                // Use Looper.myLooper() if looper is not specified.
                looper = Looper.myLooper();
                if (looper == null) {
                    throw new RuntimeException(
                            "Can't display wireless animation on a thread that has not called "
                                    + "Looper.prepare()");
                }
            }
            mHandler = new Handler(looper, null) {
                @Override
                public void handleMessage(Message msg) {
                    switch (msg.what) {
                        case SHOW: {
                            handleShow();
                            break;
                        }
                        case HIDE: {
                            handleHide();
                            // Don't do this in handleHide() because it is also invoked by
                            // handleShow()
                            mNextView = null;
                            mShowingWiredChargingAnimation = false;
                            break;
                        }
                    }
                }
            };
        }
        public void show() {
            if (DEBUG) Slog.d(TAG, "SHOW: " + this);
            mHandler.obtainMessage(SHOW).sendToTarget();
        }
        public void hide(long duration) {
            mHandler.removeMessages(HIDE);
            if (DEBUG) Slog.d(TAG, "HIDE: " + this);
            mHandler.sendMessageDelayed(Message.obtain(mHandler, HIDE), duration);
        }
        private void handleShow() {
            if (DEBUG) {
                Slog.d(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView="
                        + mNextView);
            }
            if (mView != mNextView) {
                // remove the old view if necessary
                handleHide();
                mView = mNextView;
                Context context = mView.getContext().getApplicationContext();
                String packageName = mView.getContext().getOpPackageName();
                if (context == null) {
                    context = mView.getContext();
                }
                mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                mParams.packageName = packageName;
                mParams.hideTimeoutMilliseconds = DURATION;
                if (mView.getParent() != null) {
                    if (DEBUG) Slog.d(TAG, "REMOVE! " + mView + " in " + this);
                    mWM.removeView(mView);
                }
                if (DEBUG) Slog.d(TAG, "ADD! " + mView + " in " + this);
                try {
                    mWM.addView(mView, mParams);
                } catch (WindowManager.BadTokenException e) {
                    Slog.d(TAG, "Unable to add wireless charging view. " + e);
                }
            }
        }
        private void handleHide() {
            if (DEBUG) Slog.d(TAG, "HANDLE HIDE: " + this + " mView=" + mView);
            if (mView != null) {
                if (mView.getParent() != null) {
                    if (DEBUG) Slog.d(TAG, "REMOVE! " + mView + " in " + this);
                    mWM.removeViewImmediate(mView);
                }
                mView = null;
            }
        }
    }
}

电源插入时且在锁屏下显示气泡动画

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

//cczheng add for hw charge start 
import com.android.systemui.charging.WiredChargingAnimation;
//cczheng add for hw charge end
    mBatteryController.addCallback(new BatteryStateChangeCallback() {
            @Override
            public void onPowerSaveChanged(boolean isPowerSave) {
                mHandler.post(mCheckBarModes);
                if (mDozeServiceHost != null) {
                    mDozeServiceHost.firePowerSaveChanged(isPowerSave);
                }
            }
            @Override
            public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
                // noop
                 //cczheng add for hw charge start    
                boolean isShowing = WiredChargingAnimation.isShowingWiredChargingAnimation();
                android.util.Log.d("WiredChargingAnimation","level="+level+" charging="+charging+" isShowing="+isShowing);
                if (!isShowing && charging && mState == StatusBarState.KEYGUARD) {
                    WiredChargingAnimation.makeWiredChargingAnimation(mContext, null,
                            level, false).show();
                }
                //cczheng add for hw charge end
            }
        });


目录
相关文章
|
5月前
|
Android开发 开发者
Android利用SVG实现动画效果
本文介绍了如何在Android中利用SVG实现动画效果。首先通过定义`pathData`参数(如M、L、Z等)绘制一个简单的三角形SVG图形,然后借助`objectAnimator`实现动态的线条绘制动画。文章详细讲解了从配置`build.gradle`支持VectorDrawable,到创建动画文件、关联SVG与动画,最后在Activity中启动动画的完整流程。此外,还提供了SVG绘制原理及工具推荐,帮助开发者更好地理解和应用SVG动画技术。
250 30
|
5月前
|
Android开发 UED 计算机视觉
Android自定义view之线条等待动画(灵感来源:金铲铲之战)
本文介绍了一款受游戏“金铲铲之战”启发的Android自定义View——线条等待动画的实现过程。通过将布局分为10份,利用`onSizeChanged`测量最小长度,并借助画笔绘制动态线条,实现渐变伸缩效果。动画逻辑通过四个变量控制线条的增长与回退,最终形成流畅的等待动画。代码中详细展示了画笔初始化、线条绘制及动画更新的核心步骤,并提供完整源码供参考。此动画适用于加载场景,提升用户体验。
490 5
Android自定义view之线条等待动画(灵感来源:金铲铲之战)
|
5月前
|
API Android开发 开发者
Android颜色渐变动画效果的实现
本文介绍了在Android中实现颜色渐变动画效果的方法,重点讲解了插值器(TypeEvaluator)的使用与自定义。通过Android自带的颜色插值器ArgbEvaluator,可以轻松实现背景色的渐变动画。文章详细分析了ArgbEvaluator的核心代码,并演示了如何利用Color.colorToHSV和Color.HSVToColor方法自定义颜色插值器MyColorEvaluator。最后提供了完整的源码示例,包括ColorGradient视图类和MyColorEvaluator类,帮助开发者更好地理解和应用颜色渐变动画技术。
167 3
|
5月前
|
Android开发 开发者
Android SVG动画详细例子
本文详细讲解了在Android中利用SVG实现动画效果的方法,通过具体例子帮助开发者更好地理解和应用SVG动画。文章首先展示了动画的实现效果,接着回顾了之前的文章链接及常见问题(如属性名大小写错误)。核心内容包括:1) 使用阿里图库获取SVG图形;2) 借助工具将SVG转换为VectorDrawable;3) 为每个路径添加动画绑定属性;4) 创建动画文件并关联SVG;5) 在ImageView中引用动画文件;6) 在Activity中启动动画。文末还提供了完整的代码示例和源码下载链接,方便读者实践操作。
308 65
|
5月前
|
XML Java Maven
Android线条等待动画JMWorkProgress(可添加依赖直接使用)
这是一篇关于Android线条等待动画JMWorkProgress的教程文章,作者计蒙将其代码开源至GitHub,提升可读性。文章介绍了如何通过添加依赖库使用该动画,并详细讲解了XML与Java中的配置方法,包括改变线条颜色、宽度、添加文字等自定义属性。项目已支持直接依赖集成(`implementation &#39;com.github.Yufseven:JMWorkProgress:v1.0&#39;`),开发者可以快速上手实现炫酷的等待动画效果。文末附有GitHub项目地址,欢迎访问并点赞支持!
157 26
|
5月前
|
XML Android开发 数据格式
Android中SlidingDrawer利用透明动画提示效果
本文介绍了在Android中使用`SlidingDrawer`实现带有透明动画提示效果的方法。通过XML布局配置`SlidingDrawer`的把手(handle)和内容(content),结合Activity中的代码实现动态动画效果。最终实现了交互性强、视觉效果良好的滑动抽屉功能。
Android中SlidingDrawer利用透明动画提示效果
|
5月前
|
XML Java Android开发
Android 动画之帧动画 + 补间动画 + 属性动画
本文介绍了Android开发中的三种动画类型:帧动画、补间动画和属性动画。帧动画通过依次播放一系列静态图片实现动态效果,支持Java代码与XML两种实现方式。补间动画基于起始和结束位置自动生成过渡效果,涵盖透明度、位移、旋转、缩放及组合动画等多种形式,并可搭配插值器优化动画过程。属性动画则通过改变对象属性实现动画,支持透明度、位移、旋转、缩放及组合动画,灵活性更高且适用于更复杂的场景。文中提供了详细的代码示例,帮助开发者快速上手。
314 15
|
5月前
|
Android开发 开发者
Android自定义view之围棋动画(化繁为简)
本文介绍了Android自定义View的动画实现,通过两个案例拓展动态效果。第一个案例基于`drawArc`方法实现单次动画,借助布尔值控制动画流程。第二个案例以围棋动画为例,从简单的小球直线运动到双向变速运动,最终实现循环动画效果。代码结构清晰,逻辑简明,展示了如何化繁为简实现复杂动画,帮助读者拓展动态效果设计思路。文末提供完整源码,适合初学者和进阶开发者学习参考。
Android自定义view之围棋动画(化繁为简)
|
5月前
|
Java Android开发 开发者
Android自定义view之围棋动画
本文详细介绍了在Android中自定义View实现围棋动画的过程。从测量宽高、绘制棋盘背景,到创建固定棋子及动态棋子,最后通过属性动画实现棋子的移动效果。文章还讲解了如何通过自定义属性调整棋子和棋盘的颜色及动画时长,并优化视觉效果,如添加渐变色让白子更明显。最终效果既可作为围棋动画展示,也可用作加载等待动画。代码完整,适合进阶开发者学习参考。
124 0
|
5月前
|
XML Java API
Android翻转动画(卡片翻转效果)
本文介绍了如何实现卡片翻转动画效果,通过Android中的ObjectAnimator结合不同插值器(LinearInterpolator、AccelerateInterpolator、DecelerateInterpolator)完成平滑过渡。示例中以按钮点击触发动画,核心逻辑包括判断视图可见性、设置旋转角度及处理初始Bug(如第一次点击异常)。最终提供完整代码(Java与XML布局),并指出将按钮事件替换为屏幕监听即可满足右滑触发需求。适合初学者学习动画实现原理。
218 0

热门文章

最新文章