.
安卓的开机动画是一个ZIP压缩文件,里面包含了脚本文件,以及一系列的PNG图片,脚本文件用于解释如何播放这些PNG图片。
本文,以谷歌原文为基础,详细解释自定义安卓开机动画的方法,基于Android P
Android的开机动画是以bootanimation.zip的形式存储在手机、TV等安卓设备上,安卓启动时候,搜索开机动画的ZIP文件的优先顺序如下,只会播放其中一个:
如果设置prop属性vold.decrypt = 1,则:
(1)/system/media/bootanimation-encrypted.zip (if getprop("vold.decrypt") = '1')
否则:
(2)/system/media/bootanimation.zip
(3)/oem/media/bootanimation.zip
从以上路径可知,在源码集成的时候,只需让Makefile在编译过程中,将bootanimation.zip复制到android设备的其中一个目录即可。
下面的ZIP动画文件,是从Android R中获取的原生文件,即谷歌的androidTV开机动画。
在自定义自己动画的时候,我们只需要将自己的图片,按场景或者自己的意图,分目录存储好,再编辑下动画的脚本文件即可。
szhou@bcsrv01:~/Documents/R$ tree -L 3
.
├── bootanimation
│ ├── desc.txt ---> 控制动画播放的-格式化的-脚本文件
│ ├── part0 ---> part 0 -- part N 用于组织各个场景的图片,同场景的放同目录
│ │ └── 00000.png
│ ├── part1
│ │ ├── 01000.png
│ │ ├── 省略.png
│ │ └── 01033.png
│ ├── part2
│ │ ├── 02000.png
│ │ ├── 省略.png
│ │ └── 03184.png
│ ├── part4
│ │ ├── 04000.png
│ │ ├── 省略.png
│ │ └── 04101.png
│ └── part5
│ ├── 00000.png
│ ├── 省略.png
│ └── 00010.png
└── bootanimation.zip ---> ZIP动画原文件,来自于Android R(11.0)
7 directories, 374 files
szhou@bcsrv01:~/Documents/R$
脚本文件:desc.txt
512 416 60
c 1 0 part0
c 1 15 part1
c 1 0 part2
c 1 0 part3
p 0 0 part4
c 1 0 part5
512 416 60 宽x高=512x416, fps=60帧
c 1 0 part0 part0只播放1次,但需全部图片都播放,不能打断
c 1 15 part1 part1只播放1次,但需全部图片都播放,不能打断,在播放结束时延迟15帧,即15/fps=1/60=1/4秒
c 1 0 part2 part2只播放1次,但需全部图片都播放,不能打断
c 1 0 part3 part3只播放1次,但需全部图片都播放,不能打断
p 0 0 part4 part4循环播放,直到系统启动完成,收到boot completed信号即打断播放
c 1 0 part5 part5只播放1次,但需全部图片都播放,不能打断
The first line defines the general parameters of the animation:
WIDTH HEIGHT FPS [PROGRESS]
WIDTH: animation width (pixels)
HEIGHT: animation height (pixels)
FPS: frames per second, e.g. 60
PROGRESS: whether to show a progress percentage on the last part
The percentage will be displayed with an x-coordinate of ‘c’, and a y-coordinate set to 1/3 of the animation height.
It is followed by a number of rows of the form:
TYPE COUNT PAUSE PATH [FADE [#RGBHEX [CLOCK1 [CLOCK2]]]]
TYPE: a single char indicating what type of animation segment this is:
p -- this part will play unless interrupted by the end of the boot
c -- this part will play to completion, no matter what
f -- same as p but in addition the specified number of frames is being faded out while continue playing. Only the first interrupted f part is faded out, other subsequent f parts are skipped
COUNT: how many times to play the animation, or 0 to loop forever until boot is complete
PAUSE: number of FRAMES to delay after this part ends
PATH: directory in which to find the frames for this part (e.g. part0)
FADE: (ONLY FOR f TYPE) number of frames to fade out when interrupted where 0 means immediately which makes f ... 0 behave like p and doesn't count it as a fading part
…… OPTIONS 配置……省略……
.
cd
zip -0qry -i \*.txt \*.png \*.wav @ ../bootanimation.zip *.txt part*
szhou@bcsrv01:~/bootanimation$ zip -0qry -i \*.txt \*.png \*.wav @ ../bootanimation.zip *.txt part*
szhou@bcsrv01:~/bootanimation$ ls -al ../
total 92
drwx------ 4 szhou szhou 4096 8月 11 11:07 .
drwxr-xr-x 7 szhou szhou 4096 8月 11 10:14 ..
drwx------ 5 szhou szhou 4096 8月 10 15:26 bootanimation
-rw-rw-r-- 1 szhou szhou 77767 8月 11 11:07 bootanimation.zip --> 在上级目录生成ZIP
drwx------ 3 szhou szhou 4096 8月 11 10:12 R
szhou@bcsrv01:~/bootanimation$
最后,将bootanimation.zip复制到U盘上
下面两个目录都可以用于简单测试,任选其一
我们将部署到oem目录下做测试
此处使用串口连接到开发板上
若使用adb,可使用$adb shell获得bash shell环境,即可直接执行下面命令
su
mount -o remount,rw /
mkdir /oem/media
chmod 755 /oem/media
cp /mnt/xxx/bootanimation.zip /oem/media/bootanimation.zip
sync
reboot
.
基于android P,使用的是联发科平台,请根据自己的平台切换对应目录,若不确定,可使用find命令查找下文件名
将ZIP文件放置于下面目录
aosp/vendor/mediatek/proprietary_tv/open/product/m7642/preinstall/bootanimation.zip
修改makefile文件
aosp/vendor/mediatek/proprietary_tv/open/product/m7642/preinstall/preinstall.mk
在编译时候,将ZIP复制到对应的目录下:
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/bootanimation.zip:/system/media/bootanimation.zip
或者
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/bootanimation.zip:/oem/media/bootanimation.zip
.
安卓原文:BootAnimationFormat
.
本文描述的内容,已基本够用,网络上的文章,大多都提及了上文所述的内容,但还有OPTION部分,很少有人去写,本想研究一下感兴趣的[PROGRESS],但……
WIDTH HEIGHT FPS [PROGRESS]
源码中查找PROGRESS参数的足迹
//路径: frameworks\base\cmds\bootanimation\BootAnimation.cpp
bool BootAnimation::parseAnimationDesc(Animation& animation)
{
String8 desString;
if (!readFile(animation.zip, "desc.txt", desString)) {
return false;
}
struct Animation {
struct Frame {
String8 name;
FileMap* map;
int trimX;
int trimY;
int trimWidth;
int trimHeight;
mutable GLuint tid;
bool operator < (const Frame& rhs) const {
return name < rhs.name;
}
};
struct Part {
int count; // The number of times this part should repeat, 0 for infinite
int pause; // The number of frames to pause for at the end of this part
int clockPosX; // The x position of the clock, in pixels. Positive values offset from
// the left of the screen, negative values offset from the right.
int clockPosY; // The y position of the clock, in pixels. Positive values offset from
// the bottom of the screen, negative values offset from the top.
// If either of the above are INT_MIN the clock is disabled, if INT_MAX
// the clock is centred on that axis.
String8 path;
String8 trimData;
SortedVector<Frame> frames;
bool playUntilComplete;
float backgroundColor[3];
uint8_t* audioData;
int audioLength;
Animation* animation;
};
int fps;
int width;
int height;
Vector<Part> parts;
String8 audioConf;
String8 fileName;
ZipFileRO* zip;
Font clockFont;
};