Android 系统充电动画

  • 效果
    在这里插入图片描述

Android获取电池充电状态是否为快充可参考.

Android_source/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

    private int lastBatteryStatus;private final BroadcastReceiver mBatteryChangedReceiver= new BroadcastReceiver(){@Overridepublic void onReceive(Context context, Intent intent) {int status=intent.getIntExtra(BatteryManager.EXTRA_STATUS,BatteryManager.BATTERY_STATUS_UNKNOWN);BatteryManager batteryManager = context.getSystemService(BatteryManager.class);int level = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);batteryStatus = com.android.settingslib.Utils.getBatteryStatus(context, intent);Log.d(TAG, "battery status="+status+" level="+level + "  batteryStatus = " + batteryStatus);if (status==BatteryManager.BATTERY_STATUS_CHARGING&& lastBatteryStatus!=status){showWirelessChargingAnimation(level);}if (status==BatteryManager.BATTERY_STATUS_DISCHARGING&& lastBatteryStatus!=status){hideWirelessChargingAnimation();}lastBatteryStatus=status;}};@Overridepublic void showWirelessChargingAnimation(int batteryLevel) {if(!mKeyguardManager.isKeyguardLocked() && !isHome(mContext)){return;}if (mDozing || mKeyguardManager.isKeyguardLocked()) {// on ambient or lockscreen, hide notification panelwirelessChargingAnimation =  WirelessChargingAnimation.makeWirelessChargingAnimation(mContext, null,batteryLevel, new WirelessChargingAnimation.Callback() {@Overridepublic void onAnimationStarting() {CrossFadeHelper.fadeOut(mNotificationPanelViewController.getView(), 1);}@Overridepublic void onAnimationEnded() {CrossFadeHelper.fadeIn(mNotificationPanelViewController.getView());}}, mDozing, batteryStatus);wirelessChargingAnimation.show();} else {// workspacewirelessChargingAnimation =  WirelessChargingAnimation.makeWirelessChargingAnimation(mContext, null,batteryLevel, null, false, batteryStatus);wirelessChargingAnimation.show();}}public void hideWirelessChargingAnimation(){try{if(wirelessChargingAnimation != null  && wirelessChargingAnimation.isShown()){wirelessChargingAnimation.hide();}}catch(RuntimeException e){}}

Android_source/frameworks/base/packages/SystemUI/src/com/android/systemui/charing/WirelessChargingAnimation.java

/** Copyright (C) 2018 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package com.android.systemui.charing;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.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.provider.Settings;
import android.os.Build;
import android.content.pm.ActivityInfo;import androidx.annotation.NonNull;
import androidx.annotation.Nullable;import com.android.chargeanim.R;/*** A WirelessChargingAnimation is a view containing view + animation for wireless charging.* @hide*/
public class WirelessChargingAnimation {public static final long DURATION = 15133;private static final String TAG = "WirelessChargingView";private final WirelessChargingView mCurrentWirelessChargingView;private static WirelessChargingView mPreviousWirelessChargingView;public interface Callback {void onAnimationStarting();void onAnimationEnded();}/*** Constructs an empty WirelessChargingAnimation object.  If looper is null,* Looper.myLooper() is used.  Must set* {@link WirelessChargingAnimation#mCurrentWirelessChargingView}* before calling {@link #show} - can be done through {@link #makeWirelessChargingAnimation}.* @hide*/public WirelessChargingAnimation(@NonNull Context context, @Nullable Looper looper, intbatteryLevel, Callback callback, boolean isDozing, String batteryStatus) {mCurrentWirelessChargingView = new WirelessChargingView(context, looper,batteryLevel, callback, isDozing, batteryStatus);}/*** Creates a wireless charging animation object populated with next view.* @hide*/public static WirelessChargingAnimation makeWirelessChargingAnimation(@NonNull Context context,@Nullable Looper looper, int batteryLevel, Callback callback, boolean isDozing, String batteryStatus) {return new WirelessChargingAnimation(context, looper, batteryLevel, callback, isDozing, batteryStatus);}/*** 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);}public void hide(){if (mCurrentWirelessChargingView == null ||mCurrentWirelessChargingView.mNextView == null) {throw new RuntimeException("setView must have been called");}if (mPreviousWirelessChargingView != null) {mPreviousWirelessChargingView.hide(0);}}private static class WirelessChargingView {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;private Callback mCallback;private Context mContext;public WirelessChargingView(Context context, @Nullable Looper looper, int batteryLevel,Callback callback, boolean isDozing, String batteryStatus) {mContext = context;mCallback = callback;mNextView = LayoutInflater.from(context).inflate(R.layout.activity_main , null, false);BubbleView syberBubbleView = mNextView.findViewById(R.id.syber_bubble_view);syberBubbleView.setBatteryLevel(batteryLevel);
//            syberBubbleView.setBatteryStatus(batteryStatus);syberBubbleView.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View view, MotionEvent motionEvent) {Log.d(TAG, "onTouch: " + motionEvent.getAction());return true;}});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_WALLPAPER ;params.setTitle("Charging Animation");if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;}if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;}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) {@Overridepublic 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;break;}}}};}public void show() {Log.d(TAG, "SHOW: " + this);mHandler.obtainMessage(SHOW).sendToTarget();}public void hide(long duration) {mHandler.removeMessages(HIDE);Log.d(TAG, "HIDE: " + this);mHandler.sendMessageDelayed(Message.obtain(mHandler, HIDE), duration);}private void handleShow() {
//            Settings.System.putInt(mContext.getContentResolver(), "show_battery_ui", 1);{Log.d(TAG, "HANDLE SHOW: " + this + " mView=" + mView + " mNextView="+ mNextView);}if (mView != mNextView) {// remove the old view if necessaryhandleHide();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) {Log.d(TAG, "REMOVE! " + mView + " in " + this);mWM.removeView(mView);}Log.d(TAG, "ADD! " + mView + " in " + this);try {if (mCallback != null) {mCallback.onAnimationStarting();}int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_FULLSCREEN;mParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;mView.setSystemUiVisibility(visibility);mView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Log.d("sgq", "onTouch:    handleHide();" );handleHide();}});mWM.addView(mView, mParams);} catch (WindowManager.BadTokenException e) {Log.d(TAG, "Unable to add wireless charging view. " + e);}}}private void handleHide() {if (mView != null) {if (mView.getParent() != null) {if (mCallback != null) {mCallback.onAnimationEnded();}mWM.removeViewImmediate(mView);}mView = null;}}}
}

资源文件可参考充电动画Demo.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/2945.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

杰发科技AC7840——CAN通信简介(6)_监听模式

参考:http://t.csdnimg.cn/AFFPC 0. 简介 7840支持4种扩展模式,其中监听模式。 监听模式概念 作用: 这里写的用于诊断,实际上我还没有用到,不太理解为啥可以用作诊断。 我的理解是,在多个总线下,使用监听…

BUUCTF-MISC-10.LSB1

10.LSB1 题目:lsb隐写,stegsolve可以看到包含了一个PNG图片 使用stegsolve打开这个图片 由PNG文件头可以看出隐写内容为PNG文件,按save Bin键保存为PNG文件。 得到一张二维码图片,使用CQR扫一下

PostgreSQL中的临时表与永久表的区别,以及它们的最佳使用场景?

文章目录 临时表与永久表的区别临时表永久表区别总结 最佳使用场景临时表的使用场景永久表的使用场景 解决方案及示例代码临时表示例创建临时表插入数据查询数据 永久表示例创建永久表插入数据查询数据 总结 在PostgreSQL中,临时表和永久表都是用于存储数据的表结构…

Tensorflow小技巧01:检测本地Tensorflow的版本

前言: 以Pycharm为例,Windwos10系统,检测本地环境的Tensorflow的版本: 1 打开Pycharm窗口 2 在窗口中输入: pythonPython 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win…

智慧文旅:引领旅游产业智慧升级的创新模式

一、智慧文旅是什么? 智慧文旅是指以当地特色文化为核心,借助现代科技手段,实现旅游景区全面智慧升级的旅游模式。在智慧文旅中,新一代信息网络技术和装备得到充分运用,文化旅游基础设施得到新建和改善,特…

【唯美情侣爱情表白纪念HTML单页】

唯美情侣爱情表白纪念HTML单页 效果图部分代码领取代码下期更新预报 效果图 整图 背景图 部分代码 index.html <!DOCTYPE html> <html lang"en"><head><meta http-equiv"Content-Type" content"text/html; charsetUTF-8"…

valgrind,memcheck的使用

一&#xff0c;valgrind介绍 ​ valgrind是一个开源的&#xff0c;检测内存泄漏的工具&#xff0c;通常在linux下使用&#xff0c;除此之外&#xff0c;他还能检测内存管理错误&#xff0c;线程bug等错误。粗浅的来讲&#xff0c;valgrind由两部分构成&#xff0c;一部分用来模…

爬虫学习笔记-数美验证

测试网址&#xff1a;智能验证码体验_图片验证码_数美科技数美科技智能验证码在线体验&#xff0c;智能识别风险用户级别&#xff0c;自行切换智能验证码难度及类型&#xff0c;提供滑动、拼图、点选、数字、动态等多种智能验证码服务&#xff0c;精准拦截机器行为。https://ww…

R语言详解二

一&#xff0c;列表详解 创建一个列表 > myList<-list(id2,name"张三",age20) > myList $id [1] 2$name [1] "张三"$age [1] 20 获取第一个元素 > myList[[2]] [1] "张三" 获取第一个子列表 > myList[2] $name [1] "张…

20240309web前端_第四次作业_完成随机点名程序

要求 一、结合抽奖案例完成随机点名程序&#xff0c;要求如下: 1.点击点名按钮&#xff0c;名字界面随机显示&#xff0c;按钮文字由点名变为停止 2.再次点击点名按钮&#xff0c;显示当前被点名学生姓名&#xff0c;按钮文字由停止变为点名 3.样式请参考css及html自由发挥完成…

解读宁波IATF16949认证:开启成功之门的钥匙️

&#x1f449;解读宁波IATF16949认证&#xff1a;&#x1f970;开启成功之门的钥匙&#x1f5dd;️ &#x1f432;在风起云涌的&#x1f4fa;商业浪潮中&#xff0c;&#x1f6b6;每一个追求卓越的&#x1f685;企业都渴望找到一把&#x1f511;开启成功之门的钥匙。&#x1f3…

Vscode配置C/C++编程环境@配置C和CPP的运行和调试环境@配置过程的相关问题@中文文件名乱码@build和debug方案组合配置

文章目录 abstractgcc/g文档和用法常见用例 目录.vscode中的相关文件说明tasks.jsonlaunch.jsonc_cpp_properties.json IDE或编辑器配置vscode配置相关指令和快捷键默认task配置和取消默认 配置文件C/C共用一组tasks.json/launch.json文件?关于注释内容示例&#x1f47a;tasks…

linux安装MySQL8.0,密码修改权限配置等常规操作详解

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…

面试二十一、红黑树

性质&#xff1a; 插入&#xff1a; 旋转&#xff1a;

公司网页制作需要多少钱

公司网页制作需要多少钱&#xff1f;这是一个非常常见的问题。答案取决于您需要的功能和设计。一些小型企业网站可能只需要一些基本的功能&#xff0c;花费可能低至几百美元&#xff0c;而一些大型企业网站可能需要高级功能和设计&#xff0c;可能需要几万美元。 以下是一些考虑…

阿里云盘小白羊版3.24.33113

网盘下载 里云盘小白羊版是一款在官方客户端基础上进行二次开发制作而成的第三方客户端&#xff0c;它拥有完善的云盘客户端功能&#xff0c;支持文件的列出、移动、重命名、在线预览、下载文件、创建点连接等等一系列功能&#xff0c;官方客户端所拥有的的功能它都有&#xf…

matlab 对数坐标画图,及在曲线上加竖直线

matlab 对数坐标画图 方法一&#xff1a;直接对x、y值取对数&#xff0c;然后画图 plot(log(x), log(y), m, LineWidth,1, Marker,.);% ,Color,#EDB120 方法二&#xff1a;将x、y轴刻度改为对数形式 plot(x, y, r, LineWidth,1, Marker,); ax gca();% 获取当前坐标句柄 ax…

.NET/C#汇总 —— 数据库SQL查询(附建表语句)

1.⽤⼀条SQL 语句 查询出每⻔课都⼤于80 分的学⽣姓名 建表语句: create table tableA ( name varchar(10), kecheng varchar(10), fenshu int(11) )DEFAULT CHARSET = utf8;插⼊数据 insert into tableA values (张三,语⽂,81); insert into tableA values (张三,数学,75)…

spring boot3单模块项目工程搭建-下(个人开发模板)

⛰️个人主页: 蒾酒 &#x1f525;系列专栏&#xff1a;《spring boot实战》 &#x1f30a;山高路远&#xff0c;行路漫漫&#xff0c;终有归途 目录 写在前面 上文衔接 常用依赖介绍以及整合 web组件 测试组件 样板代码生成 数据库连接器 常用工具包 面向切面编…

覆盖完整产业链“2024长三角消费电子产业展会”11月在南京召开

2024长三角消费电子产业展览会将与11月份在南京国际博览中心盛大开幕。作为一场集智慧生活、智慧健康、人工智能、雷达技术、智能机器人、5G通信和自动驾驶等众多领域于一体的消费电子产业盛会&#xff0c;本届展会不仅全面覆盖了消费电子产业链的各个环节&#xff0c;更致力于…