Android Studio实现华为手机的充电动画效果

目录
  • 效果图
  • 修改文件清单
  • 具体实现

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

效果图

修改文件清单

	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
            }
        });

到此这篇关于Android Studio实现华为手机的充电动画效果的文章就介绍到这了,更多相关Android 充电动画内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Android 自定义view和属性动画实现充电进度条效果

    近期项目中需要使用到一种类似手机电池充电进度的动画效果,以前没学属性动画的时候,是用图片+定时器的方式来完成的,最近一直在学习动画这一块,再加上复习一下自定义view的相关知识点,所以打算用属性动画和自定义view的方式来完成这个功能,将它开源出来,供有需要的人了解一下相关的内容. 本次实现的功能类似下面的效果: 接下来便详细解析一下如何完成这个功能,了解其中的原理,这样就能举一反三,实现其他类似的动画效果了. 详细代码请看大屏幕 https://github.com/crazyandcoder

  • Android中检查、监听电量和充电状态的方法

    当你在更改后台更新频率来减少这些更新对电池寿命的影响时,检查当前电量和充电状态是一个好的开始. 电池寿命通过剩余电量和充电状态来影响应用更新的执行.当用交流电充电时,执行更新操作对设备的影响是微不足道的,所以在大多数案例里,你可以把更新频率调到最快.如果设备不在充电,降低更新频率可以帮助延长电池寿命. 类似的,你可以检查电池剩余电量级别,在电量低时,应该降低更新频率甚至停止更新. 注:此处的更新,指的是类似发送心跳包的动作,或者定时更新内容.并非仅仅指更新应用版本.如果是用户动作,比如翻页刷新,

  • Android 开机充电图标和充电动画效果

    首先驱动需要先获取到2个power supply kernel\msm-3.18\drivers\usb\phy\phy-msm-usb.c motg->usb_psy.name = "usb"; motg->usb_psy.type = POWER_SUPPLY_TYPE_USB; motg->usb_psy.supplied_to = otg_pm_power_supplied_to; motg->usb_psy.num_supplicants = ARRA

  • Android实现侦听电池状态显示、电量及充电动态显示的方法

    本文实例讲述了Android实现侦听电池状态显示.电量及充电动态显示的方法,是Android应用程序开发中非常常用的重要功能.分享给大家供大家参考之用.具体方法如下: 使用android系统的电池侦听和系统的电池图片如下: 引入源代码中的两个xml文件(这里我在android2.2的jar包中找不到,所以才引入,源代码路径:C:\android-sdk-windows\platforms\android-8\data\res\drawable),之后会发现stat_sys_battery.xml

  • Android Studio实现华为手机的充电动画效果

    目录 效果图 修改文件清单 具体实现 根据系统原有的无线充电动画流程,新增有线充电气泡动画. 效果图 修改文件清单 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.x

  • Android仿ViVO X6 极速闪充动画效果

    一直都在看自定义View,经过一个星期的坚持,基本上能够写出一些比较实用的控件效果了,今天天气太热,就待在家里玩手机,然后手机没电了,在充电的时候,看到了手机的充电动画,觉得挺酷,然后自己我就仔细的分析了一下这里的动画内容,就觉得,这个我也能写出来,所以就有了这篇博客.纯属原创. 先看看效果,因为图片的原因,只能看到静态的. 这个就是效果图了.当然了,这么看好像不怎么样,但是配上了动画,还是挺好看的. 自定义控件的话,其实做的多了,运用的多了,就会觉得自定义View,跟在Photo shop 里

  • Android高级UI特效仿直播点赞动画效果

    本文给大家分享高级UI特效仿直播点赞效果-一个优美炫酷的点赞动画,具体实现代码大家参考本文. 效果图如下: 攻克难点: 心形图片的路径等走向 心形图片的控制范围 部分代码如下: 通过AbstractPathAnimator定义飘心动画控制器 @Override public void start(final View child, final ViewGroup parent) { parent.addView(child, new ViewGroup.LayoutParams(mConfig.

  • Android仿支付宝中余额宝的数字动画效果

    实现效果图: 下面是具体代码,可直接复制: package com.lcw.rabbit.widget; import android.animation.ObjectAnimator; import android.content.Context; import android.text.TextUtils; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpola

  • Android中ViewFlipper的使用及设置动画效果实例详解

    本文实例讲述了Android中ViewFlipper的使用及设置动画效果.分享给大家供大家参考,具体如下: 说到左右滑动,其实实现左右滑动的方式很多,有ViewPaer,自定义实现Viewgroup,gallery等都可以达到这种效果.这里做下ViewFliper实现左右滑动的效果. 会用到以下的技术: 1.ViewFlipper 2.GestureDetector 3.Animation 主要是这三个类在起作用. ViewFlipper,不妨把它看做一个容器吧,你可以把许多的View放在这个容

  • Android xml实现animation的4种动画效果实例代码

    animation有四种动画类型:分别为alpha(透明的渐变).rotate(旋转).scale(尺寸伸缩).translate(移动),二实现的分发有两种,一种是javaCode,另外一种是XML,而我今天要说的是XML实现的方法,个人感觉javaCode的实现方法比xml要简单,所以有需要的可以自己去找找资料看看. 先给大家展示下效果图,如果大家感觉还不错,请继续往下阅读. 下面是我的四个xml文件,分别代表这四种动画类型. alpha.xml COde: <?xml version=&quo

  • Android编程实现RotateAnimation设置中心点旋转动画效果

    本文实例讲述了Android编程实现RotateAnimation设置中心点旋转动画效果.分享给大家供大家参考,具体如下: 在xml设置: <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="800" // 设置动画

  • Android Studio 全屏沉浸式透明状态栏效果的实现

    如何实现?1.)首先实现全屏 第一种:继承主题特定主题 在Android API 19以上可以使用****.TranslucentDecor***有关的主题,自带相应半透明效果,Theme.Holo.NoActionBar.TranslucentDecor和Theme.Holo.Light.NoActionBar.TranslucentDecor两种主题为新增加的,所以要新建values-v19文件夹并创建styles文件添加如下代码 <style name="AppBaseTheme&q

  • Android实现仿微软系统加载动画效果

    效果图: 实现步骤: 初始化五个圆球分别设置中心点,方便画圆 利用ValueAnimator的值变化来获取旋转角度 onDraw来分别画每个圆 具体代码实现: 1.创建Circle对象 package com.sjl.keeplive.track; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; public class Circle { private

随机推荐