IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> 基于Android P,自定义Android开机动画的方法 -> 正文阅读

[移动开发]基于Android P,自定义Android开机动画的方法

1.前言

  • 基于android P(9.0)环境

.
安卓的开机动画是一个ZIP压缩文件,里面包含了脚本文件,以及一系列的PNG图片,脚本文件用于解释如何播放这些PNG图片。

本文,以谷歌原文为基础,详细解释自定义安卓开机动画的方法,基于Android P

2. 基本步骤

  1. 解压一个正常播放的bootanimation.zip文件,采用其结构和目录
  2. 删除其PNG文件和多余的part目录
  3. 将PNG文件按需要分组,存放到各part目录中
  4. 编辑控制播放的脚本文件desc.txt
  5. 重新压缩为bootanimation.zip文件
  6. 部署到开发部或者虚拟机上测试
  7. 修改aosp源码,集成到安卓系统源代码目录中
  8. 编译成系统镜像,确认修改正确

3.bootanimation.zip 自定义方法

3.1 存放路径

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设备的其中一个目录即可。

3.2 文件结构

下面的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

3.3 解释 desc.txt

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次,但需全部图片都播放,不能打断

3.4 谷歌原文:desc.txt

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 配置……省略……

.

3.5 ZIP打包

3.5.1 命令

cd <path-to-pieces>
zip -0qry -i \*.txt \*.png \*.wav @ ../bootanimation.zip *.txt part*

3.5.2 用法举例

  1. 切换到bootanimation目录
  2. 执行zip命令
  3. 在bootanimation的上一级目录,获取bootanimation.zip
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 811 11:07 .
drwxr-xr-x 7 szhou szhou  4096 811 10:14 ..
drwx------ 5 szhou szhou  4096 810 15:26 bootanimation
-rw-rw-r-- 1 szhou szhou 77767 811 11:07 bootanimation.zip --> 在上级目录生成ZIP
drwx------ 3 szhou szhou  4096 811 10:12 R
szhou@bcsrv01:~/bootanimation$ 

最后,将bootanimation.zip复制到U盘上

4. 上机测试

4. 1 部署的路径

下面两个目录都可以用于简单测试,任选其一

  • /system/media/bootanimation.zip
  • /oem/media/bootanimation.zip

我们将部署到oem目录下做测试

4. 2 部署的命令

此处使用串口连接到开发板上
若使用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

4. 3 效果

reboot重启后,即可看到开机动画的效果
在这里插入图片描述

.

5. 集成到AOSP源码中

基于android P,使用的是联发科平台,请根据自己的平台切换对应目录,若不确定,可使用find命令查找下文件名

  1. 将ZIP文件放置于下面目录
    aosp/vendor/mediatek/proprietary_tv/open/product/m7642/preinstall/bootanimation.zip

  2. 修改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 

.

6. 谷歌原文地址

安卓原文:BootAnimationFormat

.

7. 关于 options 参数

本文描述的内容,已基本够用,网络上的文章,大多都提及了上文所述的内容,但还有OPTION部分,很少有人去写,本想研究一下感兴趣的[PROGRESS],但……

WIDTH HEIGHT FPS [PROGRESS]

源码中查找PROGRESS参数的足迹

  • 下面此函数用于解析desc.txt文件
//路径: frameworks\base\cmds\bootanimation\BootAnimation.cpp
bool BootAnimation::parseAnimationDesc(Animation& animation)
{
    String8 desString;

    if (!readFile(animation.zip, "desc.txt", desString)) {
        return false;
    }
  • 但从Animation类的成员变量看,并未提供PROGRESS的解析
    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;
    };

  • 所以,从源码的简单分析看,PROGRESS参数看样子无法使用,在测试中添加相关参数,看样子是被直接忽略掉了。后续有时间再继续分析,有知道的同学,可以备注下~
  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-08-12 16:42:49  更:2021-08-12 16:45:53 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 0:45:19-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码