android开机动画修改实战(bootanimation)

8 篇文章 0 订阅
5 篇文章 0 订阅

1. android开机动画修改

1.1 底层代码中的信息

bootanimation.zip在平台上的位置
在底层源代码中的
/source PATH/frameworks/base/cmds/bootanimation/BootAnimation.cpp,可以找到
/system/media/bootanimation.zip


namespace android {

static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip";
static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";

1.2 在硬件系统中确定

通过usb连接硬件,adb shell进去系统,可以看到bootanimation.zip的位置
在这里插入图片描述

2. 修改bootanimation.zip

2.1 下载bootanimation.zip

adb pull来下载原来的bootanimation.zip
解压bootanimation.zip,可以看到里面有两个文件:

在这里插入图片描述

2.2 修改图片

打开文件夹part0,图片的格式是.png,存入的格式也应该是.png。
图片的分辨率,根据显示屏的分辨率,不能大于显示屏分辨率。
我用的显示屏是10802340
所以,图片宽不大于1080,长不大于2340。
我选用的1080
607的图片
在这里插入图片描述

2.3 修改desc.txt

打开文件如下:
在这里插入图片描述

2.3.1 格式说明:

第一行,1080 607是图片的分辨率,10是10帧每秒.
第二行,c 1 10 part4
c :有些是p,有些是c,后面说明。
c后面第1个参数:1是播放一次, 0表示无限循环直至开机完成。
c后面第2个参数: 数字表示阶段间隔时间,0表示没有间隔时间
c后面第3个参数:为对应的步骤文件夹。
p或c引领每个步骤,几行几步

第三行,回车(一定要有)

2.3.2 p或c说明:

通常animation都是P参数开头的,偶尔也会有C开头的参数,如下:
Android5.1以上,加入了“c”,若是"c", 即使exitPending()返回值为true,也会继续显示。
BootAnimation.cpp中,
函数bool BootAnimation::parseAnimationDesc(Animation& animation),解析desc.txt
函数bool BootAnimation::movie(),播放动画,释放动画。
movie()中playAnimation(),操作Animation。

bool BootAnimation::parseAnimationDesc(Animation& animation)
{
    String8 desString;

    if (!readFile(animation.zip, "desc.txt", desString)) {
        return false;
    }
    char const* s = desString.string();

    // Parse the description file
    for (;;) {
        const char* endl = strstr(s, "\n");
        if (endl == NULL) break;           //这两行说明最后一行一定是回车\n
        String8 line(s, endl - s);         
        const char* l = line.string();
        int fps = 0;
        int width = 0;
        int height = 0;
        int count = 0;
        int pause = 0;
        char path[ANIM_ENTRY_NAME_MAX];     //
        char color[7] = "000000"; // default to black if unspecified
        char clockPos1[TEXT_POS_LEN_MAX + 1] = "";
        char clockPos2[TEXT_POS_LEN_MAX + 1] = "";

        char pathType;
        if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {//若某一行是3个参数,第一个是宽,第2个是长,第3个是每秒显示帧数
            // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps);
            animation.width = width;
            animation.height = height;
            animation.fps = fps;
        } else if (sscanf(l, " %c %d %d %s #%6s %16s %16s",
                          &pathType, &count, &pause, path, color, clockPos1, clockPos2) >= 4) {//若某一行参数大于等于4个,第1个是类型"c",第2个是count重复次数,第3个是pause间隔时间
            //ALOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPos1=%s, clockPos2=%s",
            //    pathType, count, pause, path, color, clockPos1, clockPos2);
            Animation::Part part;
            part.playUntilComplete = pathType == 'c';     //英文直译:画面播放直到完成
            part.count = count;                           //
            part.pause = pause;
            part.path = path;
            part.audioData = NULL;
            part.animation = NULL;
            if (!parseColor(color, part.backgroundColor)) {
                ALOGE("> invalid color '#%s'", color);
                part.backgroundColor[0] = 0.0f;
                part.backgroundColor[1] = 0.0f;
                part.backgroundColor[2] = 0.0f;
            }
            parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY);
            animation.parts.add(part);
        }
... ...
... ...
}

bool BootAnimation::movie()
{
... ...
... ...

    playAnimation(*animation);                  //播放Animation

    if (mTimeCheckThread != nullptr) {
        mTimeCheckThread->requestExit();
        mTimeCheckThread = nullptr;
    }

    releaseAnimation(animation);

    if (clockFontInitialized) {
        glDeleteTextures(1, &animation->clockFont.texture.name);
    }

    return false;
}
bool BootAnimation::playAnimation(const Animation& animation)
{
    const size_t pcount = animation.parts.size();  //part数量,即part有多少行。
    nsecs_t frameDuration = s2ns(1) / animation.fps;  //s2ns:s转ns;                        
    const int animationX = (mWidth - animation.width) / 2;   
    const int animationY = (mHeight - animation.height) / 2;   

    ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
            elapsedRealtime());
    for (size_t i=0 ; i<pcount ; i++) {             //pcount:c打头代码行数
        const Animation::Part& part(animation.parts[i]);//i:按顺序播放
        const size_t fcount = part.frames.size();//fcount:part文件中png图片的数量
... ...
... ...

        for (int r=0 ; !part.count || r<part.count ; r++) {//The number of times this part should repeat, 0 for infinite;本次part重复次数
            // Exit any non playuntil complete parts immediately
... ...
... ...

            for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) {//fcount:part文件中png图片的
                const Animation::Frame& frame(part.frames[j]);
                nsecs_t lastFrame = systemTime();
... ...
... ...
            }
        }
    }
... ...
... ...
}

2.4 打包bootanimation.zip

2.4.1 打包文件选择方法

一定不要先建一个bootanimation文件夹,再压缩。
要先选择要压缩的文件,包括part*文件夹和desc.txt,再右键添加到压缩文件夹,生成bootanimation.zip。
1). 若是先建文件夹,再压缩,查看bootanimation.zip,会看到总文件夹数是>=2。
请添加图片描述
2). 若选择要压缩的文件夹,直接点击右键进行压缩,查看属性:
总文件夹=1。
总长度和大小一样:4,112,818字节
请添加图片描述

2.4.2 打包格式

一定是zip,压缩方式一定是存储请添加图片描述

3. 传送bootanimation.zip到系统

3.1 adb push送到系统中的/system/media

直接adb push,若出现以下error:

adb: error: failed to copy 'C:\Users\Desktop\bootanimation.zip' to '/system/media/bootanimation.zip': remote couldn't create file: Read-only file system

因为没有root权限。以下步骤可以解决:

  1. adb root
  2. adb remount
  3. adb push …

重新开机,可以看到开机画面变化。

参考文献:
[1]: https://blog.csdn.net/wd229047557/article/details/81916915

  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值