2016-10-17 21:22:00 weixin_30258027 阅读数 26

文件路径:frameworks\base\services\core\java\com\android\server\power\ShutdownThread.java

在beginShutdownSequence()方法中:

 1 private static void beginShutdownSequence(Context context) {
 2     ...... 3     // throw up an indeterminate system dialog to indicate radio is
 4     // shutting down.
 5     //***********************  系统默认的Dialog   ***********************
 6     /*ProgressDialog pd = new ProgressDialog(context);
 7     pd.setTitle(context.getText(com.android.internal.R.string.power_off));
 8     pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
 9     pd.setIndeterminate(true);
10     pd.setCancelable(false);
11     pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
12     pd.show();*/
13     //***********************  替换为自定义的全屏Dialog   ***********************
14     Point outSize = new Point();
15     Dialog dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
16     IndeterminateProgressBar view = new IndeterminateProgressBar(context);
17     dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
18     dialog.getWindow().getWindowManager().getDefaultDisplay().getSize(outSize);  //获取屏幕宽高
19     dialog.setContentView(view, new LayoutParams(outSize.x, outSize.y));         //设置自定义view宽高为全屏
20     dialog.show();
21     
22     ......
23 }
 
注意:必须要设置 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); 之前忘了加导致什么都不显示
 
替换的自定义View:
 
  1 class IndeterminateProgressBar extends View {
  2     static final String TAG = "ProgressBar";
  3     private int delayMillis = 30;
  4     private Handler mHandler;
  5     private ArrayList<Entity> entities;
  6     private int width = 0;
  7     // private int height = 0;
  8     private int r = 15;
  9     private int shift = 20;
 10     private int radius = 3;
 11     private int color = Color.WHITE;
 12     private long time = 0;
 13     private boolean started = false;
 14     public IndeterminateProgressBar(Context context) {
 15         super(context);
 16         init();
 17     }
 18     @Override
 19     protected void onLayout(boolean changed, int left, int top, int right,
 20             int bottom) {
 21         super.onLayout(changed, left, top, right, bottom);
 22         width = getLayoutParams().width / 2;
 23         // height = getLayoutParams().height;
 24         if (width > 0) {
 25             radius = width / 20;
 26             r = 2 * width / 5;
 27             //shift = width / 2;
 28             shift = width / 1;
 29         }
 30     }
 31     private void init() {
 32         setBackgroundResource(android.R.color.transparent);
 33         mHandler = new Handler(new Handler.Callback() {
 34             @Override
 35             public boolean handleMessage(Message msg) {
 36                 for (Entity e : entities) {
 37                     e.update();
 38                 }
 39                 invalidate();
 40                 mHandler.sendEmptyMessageDelayed(0, delayMillis);
 41                 time += delayMillis;
 42                 return false;
 43             }
 44         });
 45     }
 46     public void setColor(int color) {
 47         this.color = color;
 48     }
 49     public void stop() {
 50         mHandler.removeMessages(0);
 51         started = false;
 52         invalidate();
 53     }
 54     public boolean isStart() {
 55         return started;
 56     }
 57     public void start() {
 58         if (started)
 59             return;
 60         started = true;
 61         time = 0;
 62         entities = new ArrayList<IndeterminateProgressBar.Entity>();
 63         float s = .25f;
 64         entities.add(new Entity(0, color, 0));
 65         entities.add(new Entity(1 * s, color, delayMillis * 4));
 66         entities.add(new Entity(2 * s, color, delayMillis * 8));
 67         entities.add(new Entity(3 * s, color, delayMillis * 12));
 68         entities.add(new Entity(4 * s, color, delayMillis * 16));
 69         // entities.add(new Entity(5 * s, color, delayMillis * 20));
 70             if (mHandler != null)
 71                 mHandler.sendEmptyMessage(0);
 72         }
 73         @Override
 74         protected void onDraw(Canvas canvas) {
 75             if (entities != null && entities.size() > 0) {
 76                 for (Entity e : entities) {
 77                     e.draw(canvas);
 78                 }
 79             }
 80             super.onDraw(canvas);
 81         }
 82         class Entity {
 83             private float x;
 84             private float y;
 85             private int color;
 86             private Paint paint;
 87             private double sp = 0;
 88             private long delay;
 89             private int sec = 0;
 90             private float pec = 0;
 91             boolean visiable = true;
 92             public float getInterpolation(float input) {
 93                 return (float) (Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
 94             }
 95             public Entity(float sp, int color, int delay) {
 96                 paint = new Paint();
 97                 paint.setAntiAlias(true);
 98                 paint.setStyle(Paint.Style.FILL);
 99                 this.color = color;
100                 this.sp = sp;
101                 this.delay = delay;
102                 paint.setColor(this.color);
103             }
104             public void update() {
105                 if (time < delay)
106                     return;
107                 visiable = true;
108                 pec += 0.03;
109                 if (pec > 1) {
110                     pec = 0;
111                     sec = ++sec == 3 ? 0 : sec;
112                     delay = sec == 0 ? time + delayMillis * 22 : time + delayMillis
113                             * 3;
114                     visiable = sec == 0 ? false : true;
115                 }
116                 double θ = Math.PI
117                         * .5
118                         + (sec == 0 ? 0 : sec * Math.PI / sec)
119                         - (sec == 0 ? 0 : sp)
120                         + (Math.PI * (sec == 1 ? 2 : 1) - (sec == 0 ? sp : 0) + (sec == 2 ? sp
121                                 : 0)) * getInterpolation(pec);
122                 x = (float) (r / 2 * Math.cos(θ)) + shift / 2;
123                 y = (float) (r / 2 * Math.sin(θ)) + shift / 2;
124             }
125             public void draw(Canvas canvas) {
126                 if (!visiable || x == 0 || y == 0)
127                     return;
128                 canvas.save();
129                 canvas.translate(x, y);
130                 canvas.drawCircle(x, y, radius, paint);
131                 canvas.restore();
132             }
133         }
134         @Override
135         protected void onAttachedToWindow() {
136             super.onAttachedToWindow();
137             if (getVisibility() == View.VISIBLE) {
138                 start();
139             }
140         }
141         @Override
142         protected void onDetachedFromWindow() {
143             super.onDetachedFromWindow();
144             stop();
145         }
146         public void setDelayMillis(int delayMillis) {
147             this.delayMillis = delayMillis;
148         }
149 }

效果图:

转载于:https://www.cnblogs.com/kerray/p/5971219.html

2017-09-04 17:27:13 qsw15923 阅读数 389

Android自定义开机和关机动画

Android在开机的过程中,会经历三张图片,关于静态图的修改在我的这篇文章中有介绍到:

        Android开机图片替换


        现在要介绍的是怎么用动画替换静态图片。开/关机的动画其实就像帧动画一样,快速播放多张图片形成的,在开/关机动画中要将这些图片打包进一个zip中,再进行适当的配置,就可以实现动画播放。


一、开/关机动画zip文件路径

在源码中找到这个文件:frameworks/base/cmds/bootanimation/BootAnimation.cpp

其中有这些定义:这些宏定义就是开/关机过程中动画文件的位置,看名字应该就知道,bootanimation.zip是开机动画,shutanimation .zip是关机动画

		#define OEM_BOOTANIMATION_FILE "/oem/media/bootanimation.zip"
		#define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"
		#define CUSTOM_BOOTANIMATION_FILE "/custom/media/bootanimation.zip"
		#define USER_BOOTANIMATION_FILE   "/data/local/bootanimation.zip"
		#define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip"
		#define EXIT_PROP_NAME "service.bootanim.exit"

		#define SYSTEM_SHUTANIMATION_FILE "/system/media/shutanimation.zip"
		#define CUSTOM_SHUTANIMATION_FILE "/custom/media/shutanimation.zip"
		#define USER_SHUTANIMATION_FILE   "/data/local/shutanimation.zip"

二、开机动画


    1、新建目录part0,将需要显示的jpg拷贝进去。


    2、新建目录part1,将需要显示的jpg拷贝进去。


    *** ***可以根据需求添加文件夹个数


    3、新建空文本文件desc.txt,内容如下:

        1080 1920 15

        p   1   2 part0

        p   0   2 part1


        1080 1920 12 (1080,1920是分辨率,12是帧数)

        p 1 2 part0(p是标识符,1代表该文件夹循环1次,2代表两次循环之间间隔2张图片的时间(例:2/15秒),part0代表要显示的文件夹)

        p 0 2 part1(p是标识符,0代表无限循环,2代表两次循环之间间隔2张图片的时间(例:2/15秒),part1代表要显示的文件夹)

        如果配置有更多的文件夹,则按照以上两个的例子添加配置即可 


    4、将这三个文件以存储方式打包成bootanimation.zip(注意:一定要以“存储”的模式打包,压缩时默认是“标准”必须改为“存储”,非存储方式无法识别)。

        存储在对应目录下。例:

        /system/media/bootanimation.zip

    5、在该文件中添加(不一定必须在embedded.mk中,其它文件也可以,只要可以确保添加的PRODUCT_COPY_FILES能被执行到):

        /build/target/product/embedded.mk

        前边是源码中文件位置,后边是复制到out后文件位置

        PRODUCT_COPY_FILES += \

                system/media/bootanimation.zip:system/media/bootanimation.zip


三、关机动画


    1、新建目录part1,将需要显示的jpg拷贝进去。

    2、新建目录part2,放入最后一张jpg

    3、新建空文本文件desc.txt,内容如下:

        1080 1920 9

        p   1   2 part1

        p   0   2 part2

       

        1080 1920 9 (1080,1920是分辨率,9是帧数)

        p 1 2 part1(p是标识符,1代表该文件夹循环1次,2代表两次循环之间间隔2张图片的时间(例:2/9秒),part1代表要显示的文件夹);

        p 0 2 part2(p是标识符,0代表无限循环,2代表两次循环之间间隔2张图片的时间(例:2/9秒),part2代表要显示的文件夹)。

    4、将这三个文件以存储方式打包成shutanimation.zip(注意:一定要以“存储”的模式打包,压缩时默认是“标准”必须改为“存储”,非存储方式无法识别)。

        存储在对应目录下。例:

        /system/media/shutanimation.zip

    5、在该文件中添加(不一定必须在embedded.mk中,其它文件也可以,只要可以确保添加的PRODUCT_COPY_FILES能被执行到):

        /build/target/product/embedded.mk

        前边是源码中文件位置,后边是复制到out后文件位置

        PRODUCT_COPY_FILES += \

                system/media/shutanimation.zip:system/media/shutanimation.zipp


然后重新编译源码,刷机即可

2016-07-12 08:47:21 u014379571 阅读数 5598

最近一直在修改关机充电动画的问题,我就把一些需要修改的东西,分享给大家

lk-cust_display.h这个文件是修改动画位置,下面以480*800为例


/*

// new animation parameters example:WVGA (480*800)
// A , start point of first number rectangle
// B , left_top point of battery_capacity fill_in rectangle
// c , left_bottom point of battery_capacity fill_in rectangle

// battery capacity rectangle
#define CAPACITY_LEFT                (172) // CAPACITY_LEFT = B.x = 172
#define CAPACITY_TOP                 (330) // CAPACITY_TOP = B.y = 330
#define CAPACITY_RIGHT               (307) // CAPACITY_RIGHT = B.x + fill_line.w = 172 + 135
#define CAPACITY_BOTTOM              (546) // CAPACITY_BOTTOM  = C.y = 546

// first number rectangle
#define NUMBER_LEFT                  (178) // NUMBER_LEFT = A.x
#define NUMBER_TOP                   (190) // NUMBER_TOP  = A.y
#define NUMBER_RIGHT                 (216) // NUMBER_RIGHT = A.x + num.w = 178 + 38
#define NUMBER_BOTTOM                (244) // NUMBER_BOTTOM = A.y + num.h = 190 + 54

// %  rectangle
#define PERCENT_LEFT                 (254) // PERCENT_LEFT = A.x + 2*num.w = 178 + 2*38
#define PERCENT_TOP                  (190) // PERCENT_TOP  = A.y
#define PERCENT_RIGHT                (302) // PERCENT_LEFT = A.x + 2*num.w +(%).w 
#define PERCENT_BOTTOM               (244) // PERCENT_BOTTOM = A.y + (%).h = 190 + 54

// top animation part
#define TOP_ANIMATION_LEFT           (172) // TOP_ANIMATION_LEFT = B.x
#define TOP_ANIMATION_TOP            (100) // 100 
#define TOP_ANIMATION_RIGHT          (307) // TOP_ANIMATION_LEFT = B.x + fill_line.w = 172 + 135
#define TOP_ANIMATION_BOTTOM         (124) // TOP_ANIMATION_BOTTOM = TOP_ANIMATION_TOP + fill_line.h = 100 + 24

*/


#ifndef __CUST_DISPLAY_H__
#define __CUST_DISPLAY_H__

// color
#define BAR_OCCUPIED_COLOR  (0x07E0)    // Green
#define BAR_EMPTY_COLOR     (0xFFFF)    // White
#define BAR_BG_COLOR        (0x0000)    // Black

// LOGO number
#define ANIM_V0_LOGO_NUM   5            // version 0: show 4 recatangle growing animation without battery number
#define ANIM_V1_LOGO_NUM   39           // version 1: show wave animation with  battery number 
#define ANIM_V2_LOGO_NUM   86           // version 2: show wireless charging animation      

// Common LOGO index
#define BOOT_LOGO_INDEX   0 
#define KERNEL_LOGO_INDEX   38 

#define ANIM_V0_BACKGROUND_INDEX   1 
#define ANIM_V1_BACKGROUND_INDEX   35
 
 
#define LOW_BATTERY_INDEX   2 
#define CHARGER_OV_INDEX   3 
#define FULL_BATTERY_INDEX   37 

// version 1: show wave animation with  battery number 

// NUMBER LOGO INDEX
#define NUMBER_PIC_START_0   4 
#define NUMBER_PIC_PERCENT   14 

// DYNAMIC ANIMATION LOGO INDEX
#define BAT_ANIM_START_0   15 

// LOW BATTERY(0~10%) ANIMATION LOGO
#define LOW_BAT_ANIM_START_0    25 

#define ANIM_LINE_INDEX   36 


// version 2: show wireless charging animation logo index

#define V2_NUM_START_0_INDEX  57  
#define V2_NUM_PERCENT_INDEX  67 
 
#define V2_BAT_0_10_START_INDEX     68  
#define V2_BAT_10_40_START_INDEX    72 
#define V2_BAT_40_80_START_INDEX    76 
#define V2_BAT_80_100_START_NDEX   80

#define V2_BAT_0_INDEX   84
#define V2_BAT_100_INDEX   85

// show fast charging animation logo index

#define FAST_CHARGING_BAT_100_INDEX   39
#define FAST_CHARGING_BAT_START_0_INDEX   40

#define FAST_CHARGING_NUM_START_0_INDEX   46
#define FAST_CHARGING_NUM_PERCENT_INDEX   56

#if defined(FHD) || defined(CU_FHD) || defined(CMCC_FHD) || defined(CT_FHD)
	// fhd 1080*1920
	
	// battery capacity rectangle
	#define CAPACITY_LEFT                (387) // battery capacity center
	#define CAPACITY_TOP                 (802)
	#define CAPACITY_RIGHT               (691)
	#define CAPACITY_BOTTOM              (1292)

	// first number rectangle
	#define NUMBER_LEFT                  (351+84) // number
	#define NUMBER_TOP                   (479)
	#define NUMBER_RIGHT                 (435+84)
	#define NUMBER_BOTTOM                (600)

	// %  rectangle
	#define PERCENT_LEFT                 (519+84) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (479)
	#define PERCENT_RIGHT                (627+84)
	#define PERCENT_BOTTOM               (600)

	// top animation part
	#define TOP_ANIMATION_LEFT           (387) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (691)
	#define TOP_ANIMATION_BOTTOM         (152)

	// for old animation
	#define BAR_LEFT            (470)
	#define BAR_TOP             (356)
	#define BAR_RIGHT           (610)
	#define BAR_BOTTOM          (678)

#elif defined(WQHD) || defined(CU_WQHD) || defined(CMCC_WQHD) || defined(CT_WQHD)
	// hd720 720*1280

	// battery capacity rectangle
	#define CAPACITY_LEFT                (393) // battery capacity center
	#define CAPACITY_TOP                 (786)
	#define CAPACITY_RIGHT               (623)
	#define CAPACITY_BOTTOM              (1155)

	// first number rectangle
	#define NUMBER_LEFT                  (410) // number
	#define NUMBER_TOP                   (546)
	#define NUMBER_RIGHT                 (474)
	#define NUMBER_BOTTOM                (636)

	// %  rectangle
	#define PERCENT_LEFT                 (537) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (546)
	#define PERCENT_RIGHT                (618)
	#define PERCENT_BOTTOM               (636)

	// top animation part
	#define TOP_ANIMATION_LEFT           (393) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (624)
	#define TOP_ANIMATION_BOTTOM         (182)

	// for old animation
	#define BAR_LEFT            (443)
	#define BAR_TOP             (337)
	#define BAR_RIGHT           (574)
	#define BAR_BOTTOM          (641)

#elif defined(HD720) || defined(CU_HD720) || defined(CMCC_HD720) || defined(CT_HD720)
	// hd720 720*1280

	// battery capacity rectangle
	#define CAPACITY_LEFT                (278) // battery capacity center
	#define CAPACITY_TOP                 (556)
	#define CAPACITY_RIGHT               (441)
	#define CAPACITY_BOTTOM              (817)

	// first number rectangle
	#define NUMBER_LEFT                  (290) // number
	#define NUMBER_TOP                   (386)
	#define NUMBER_RIGHT                 (335)
	#define NUMBER_BOTTOM                (450)

	// %  rectangle
	#define PERCENT_LEFT                 (380) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (386)
	#define PERCENT_RIGHT                (437)
	#define PERCENT_BOTTOM               (450)

	// top animation part
	#define TOP_ANIMATION_LEFT           (278) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (441)
	#define TOP_ANIMATION_BOTTOM         (129)

	// for old animation
	#define BAR_LEFT            (313)
	#define BAR_TOP             (238)
	#define BAR_RIGHT           (406)
	#define BAR_BOTTOM          (453)

#elif defined(FWVGA) || defined(CU_FWVGA) || defined(CMCC_FWVGA) || defined(CT_FWVGA)
	// fwvga 480*854

	// battery capacity rectangle
	#define CAPACITY_LEFT                (172) // battery capacity center
	#define CAPACITY_TOP                 (357)
	#define CAPACITY_RIGHT               (307)
	#define CAPACITY_BOTTOM              (573)

	// first number rectangle
	#define NUMBER_LEFT                  (172) // number
	#define NUMBER_TOP                   (213)
	#define NUMBER_RIGHT                 (210)
	#define NUMBER_BOTTOM                (267)

	// %  rectangle
	#define PERCENT_LEFT                 (248) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (213)
	#define PERCENT_RIGHT                (296)
	#define PERCENT_BOTTOM               (267)

	// top animation part
	#define TOP_ANIMATION_LEFT           (172) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (307)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (184)
	#define BAR_TOP             (227)
	#define BAR_RIGHT           (294)
	#define BAR_BOTTOM          (437)

#elif defined(QHD) || defined(CU_QHD) || defined(CMCC_QHD) || defined(CT_QHD)
	// qhd 540*960

	// battery capacity rectangle
	#define CAPACITY_LEFT                (202) // battery capacity center
	#define CAPACITY_TOP                 (410)
	#define CAPACITY_RIGHT               (337)
	#define CAPACITY_BOTTOM              (626)

	// first number rectangle
	#define NUMBER_LEFT                  (202) // number
	#define NUMBER_TOP                   (266)
	#define NUMBER_RIGHT                 (240)
	#define NUMBER_BOTTOM                (320)

	// %  rectangle
	#define PERCENT_LEFT                 (278) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (266)
	#define PERCENT_RIGHT                (326)
	#define PERCENT_BOTTOM               (320)

	// top animation part
	#define TOP_ANIMATION_LEFT           (202) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (337)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (235)
	#define BAR_TOP             (179)
	#define BAR_RIGHT           (305)
	#define BAR_BOTTOM          (340)

#elif defined(WVGA) || defined(CU_WVGA) || defined(CMCC_WVGA) || defined(CT_WVGA)
	// default wvga 480*800

	// battery capacity rectangle
	#define CAPACITY_LEFT                (172) // battery capacity center
	#define CAPACITY_TOP                 (330)
	#define CAPACITY_RIGHT               (307)
	#define CAPACITY_BOTTOM              (546)

	// first number rectangle
	#define NUMBER_LEFT                  (178) // number
	#define NUMBER_TOP                   (190)
	#define NUMBER_RIGHT                 (216)
	#define NUMBER_BOTTOM                (244)

	// %  rectangle
	#define PERCENT_LEFT                 (254) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (190)
	#define PERCENT_RIGHT                (302)
	#define PERCENT_BOTTOM               (244)

	// top animation part
	#define TOP_ANIMATION_LEFT           (172) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (307)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (209)
	#define BAR_TOP             (149)
	#define BAR_RIGHT           (271)
	#define BAR_BOTTOM          (282)

#elif defined(HVGA) || defined(CU_HVGA) || defined(CMCC_HVGA) || defined(CT_HVGA)

	// hvga 320*480

	// battery capacity rectangle
	#define CAPACITY_LEFT                (109) // battery capacity center
	#define CAPACITY_TOP                 (189)
	#define CAPACITY_RIGHT               (211)
	#define CAPACITY_BOTTOM              (350)

	// first number rectangle
	#define NUMBER_LEFT                  (126) // number
	#define NUMBER_TOP                   (95)
	#define NUMBER_RIGHT                 (153)
	#define NUMBER_BOTTOM                (131)

	// %  rectangle
	#define PERCENT_LEFT                 (180) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (95)
	#define PERCENT_RIGHT                (212)
	#define PERCENT_BOTTOM               (131)

	// top animation part
	#define TOP_ANIMATION_LEFT           (109) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (211)
	#define TOP_ANIMATION_BOTTOM         (118)

	// for old animation
	#define BAR_LEFT            (129)
	#define BAR_TOP             (128)
	#define BAR_RIGHT           (190)
	#define BAR_BOTTOM          (245)
#elif defined(QVGA) || defined(CU_QVGA) || defined(CMCC_QVGA) || defined(CT_QVGA)

	// hvga 320*480

	// battery capacity rectangle
	#define CAPACITY_LEFT                (82) // battery capacity center
	#define CAPACITY_TOP                 (124)
	#define CAPACITY_RIGHT               (158)
	#define CAPACITY_BOTTOM              (241)

	// first number rectangle
	#define NUMBER_LEFT                  (93) // number
	#define NUMBER_TOP                   (50)
	#define NUMBER_RIGHT                 (109)
	#define NUMBER_BOTTOM                (73)

	// %  rectangle
	#define PERCENT_LEFT                 (125) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (50)
	#define PERCENT_RIGHT                (145)
	#define PERCENT_BOTTOM               (73)

	// top animation part
	#define TOP_ANIMATION_LEFT           (82) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (158)
	#define TOP_ANIMATION_BOTTOM         (113)

	// for old animation
	#define BAR_LEFT            (97)
	#define BAR_TOP             (96)
	#define BAR_RIGHT           (140)
	#define BAR_BOTTOM          (184)
	
#elif defined(WSVGA)
	// wsvga 600*1024

	// battery capacity rectangle
	#define CAPACITY_LEFT                (232) // battery capacity center
	#define CAPACITY_TOP                 (442)
	#define CAPACITY_RIGHT               (367)
	#define CAPACITY_BOTTOM              (658)

	// first number rectangle
	#define NUMBER_LEFT                  (250) // number
	#define NUMBER_TOP                   (300)
	#define NUMBER_RIGHT                 (288)
	#define NUMBER_BOTTOM                (354)

	// %  rectangle
	#define PERCENT_LEFT                 (326) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (300)
	#define PERCENT_RIGHT                (374)
	#define PERCENT_BOTTOM               (354)

	// top animation part
	#define TOP_ANIMATION_LEFT           (232) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (367)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (260)
	#define BAR_TOP             (190)
	#define BAR_RIGHT           (338)
	#define BAR_BOTTOM          (360)

#elif defined(WSVGANL)
	// wsvganl 1024*600

	// battery capacity rectangle
	#define CAPACITY_LEFT                (444) // battery capacity center
	#define CAPACITY_TOP                 (230)
	#define CAPACITY_RIGHT               (579) // 444 + 135
	#define CAPACITY_BOTTOM              (446)

	// first number rectangle
	#define NUMBER_LEFT                  (466) // number
	#define NUMBER_TOP                   (90)
	#define NUMBER_RIGHT                 (504) // 466 + 38
	#define NUMBER_BOTTOM                (144) // 90 + 54

	// %  rectangle
	#define PERCENT_LEFT                 (542) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (90)
	#define PERCENT_RIGHT                (590)
	#define PERCENT_BOTTOM               (144)

	// top animation part
	#define TOP_ANIMATION_LEFT           (444) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (579)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (414)
	#define BAR_TOP             (186)
	#define BAR_RIGHT           (608)
	#define BAR_BOTTOM          (477)

#elif defined(WXGANL)
	// wxganl 1280*800

	// battery capacity rectangle
	#define CAPACITY_LEFT                (558) // battery capacity center
	#define CAPACITY_TOP                 (265)
	#define CAPACITY_RIGHT               (721) //558+163
	#define CAPACITY_BOTTOM              (525)

	#define NUMBER_LEFT                  (585) // number
	#define NUMBER_TOP                   (95)
	#define NUMBER_RIGHT                 (630)//585+45
	#define NUMBER_BOTTOM                (159) //95+64

	#define PERCENT_LEFT                 (675) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (95)
	#define PERCENT_RIGHT                (732) //675+57
	#define PERCENT_BOTTOM               (159)

	#define TOP_ANIMATION_LEFT           (558) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (721)
	#define TOP_ANIMATION_BOTTOM         (129)

	// for old animation
	#define BAR_LEFT            (525)
	#define BAR_TOP             (250)
	#define BAR_RIGHT           (755)
	#define BAR_BOTTOM          (640)
	
#elif defined(WXGA)
	// wxga 800*1280

	// battery capacity rectangle
	#define CAPACITY_LEFT                (318) // battery capacity center
	#define CAPACITY_TOP                 (556)
	#define CAPACITY_RIGHT               (481) //318+163
	#define CAPACITY_BOTTOM              (815)

	#define NUMBER_LEFT                  (345) // number
	#define NUMBER_TOP                   (385)
	#define NUMBER_RIGHT                 (390) //345+45
	#define NUMBER_BOTTOM                (449) //385+64

	#define PERCENT_LEFT                 (435) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (385)
	#define PERCENT_RIGHT                (492) //435+57
	#define PERCENT_BOTTOM               (449)

	#define TOP_ANIMATION_LEFT           (318) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (481)
	#define TOP_ANIMATION_BOTTOM         (129)

	// for old animation
	#define BAR_LEFT            (348)
	#define BAR_TOP             (238)
	#define BAR_RIGHT           (453)
	#define BAR_BOTTOM          (452)
	
#elif defined(WUXGANL)
	// wuxganl 1920*1200

	// battery capacity rectangle
	#define CAPACITY_LEFT                (806) // battery capacity center
	#define CAPACITY_TOP                 (443)
	#define CAPACITY_RIGHT               (1110)
	#define CAPACITY_BOTTOM              (929)

	#define NUMBER_LEFT                  (855) // number
	#define NUMBER_TOP                   (124)
	#define NUMBER_RIGHT                 (939) //855+84
	#define NUMBER_BOTTOM                (245)

	#define PERCENT_LEFT                 (1023) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (124)
	#define PERCENT_RIGHT                (1131) //1023+108
	#define PERCENT_BOTTOM               (245)  //124+121

	#define TOP_ANIMATION_LEFT           (806) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (1110) //806+304
	#define TOP_ANIMATION_BOTTOM         (152)

	// for old animation
	#define BAR_LEFT            (890)
	#define BAR_TOP             (357)
	#define BAR_RIGHT           (1030)
	#define BAR_BOTTOM          (678)
	
#elif defined(WUXGA) || defined(CU_WUXGA)
	// wuxga 1200*1920

	// battery capacity rectangle
	#define CAPACITY_LEFT                (447) // battery capacity center
	#define CAPACITY_TOP                 (803)
	#define CAPACITY_RIGHT               (751)
	#define CAPACITY_BOTTOM              (1289)

	#define NUMBER_LEFT                  (494) // number
	#define NUMBER_TOP                   (481)
	#define NUMBER_RIGHT                 (578)//494+84
	#define NUMBER_BOTTOM                (602) //481+121

	#define PERCENT_LEFT                 (662) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (481)
	#define PERCENT_RIGHT                (770) //662+108
	#define PERCENT_BOTTOM               (602) //481+121

	#define TOP_ANIMATION_LEFT           (447) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (751)
	#define TOP_ANIMATION_BOTTOM         (152)

	// for old animation
	#define BAR_LEFT            (529)
	#define BAR_TOP             (357)
	#define BAR_RIGHT           (672)
	#define BAR_BOTTOM          (680)
	
#elif defined(XGA)
	// xga 768*1024

	// battery capacity rectangle
	#define CAPACITY_LEFT                (316) // battery capacity center
	#define CAPACITY_TOP                 (442)
	#define CAPACITY_RIGHT               (451)
	#define CAPACITY_BOTTOM              (658)

	#define NUMBER_LEFT                  (338) // number
	#define NUMBER_TOP                   (300)
	#define NUMBER_RIGHT                 (376)
	#define NUMBER_BOTTOM                (354)

	#define PERCENT_LEFT                 (414) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (300)
	#define PERCENT_RIGHT                (462)
	#define PERCENT_BOTTOM               (354)

	#define TOP_ANIMATION_LEFT           (316) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (451)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (334)
	#define BAR_TOP             (243)
	#define BAR_RIGHT           (434)
	#define BAR_BOTTOM          (463)
	
#elif defined(XGANL)
	// xganl 1024*768

	// battery capacity rectangle
	#define CAPACITY_LEFT                (444) // battery capacity center
	#define CAPACITY_TOP                 (314)	
	#define CAPACITY_RIGHT               (579)
	#define CAPACITY_BOTTOM              (530)

	#define NUMBER_LEFT                  (467) // number
	#define NUMBER_TOP                   (170)
	#define NUMBER_RIGHT                 (505)
	#define NUMBER_BOTTOM                (224)

	#define PERCENT_LEFT                 (543) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (170)
	#define PERCENT_RIGHT                (591)
	#define PERCENT_BOTTOM               (224)

	#define TOP_ANIMATION_LEFT           (444) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (579)
	#define TOP_ANIMATION_BOTTOM         (124)

	// for old animation
	#define BAR_LEFT            (486)
	#define BAR_TOP             (292)
	#define BAR_RIGHT           (590)
	#define BAR_BOTTOM          (506) 

#elif defined(QXGA)
	// qxga 1536x2048
	
		// battery capacity rectangle
	#define CAPACITY_LEFT                (605) // battery capacity center
	#define CAPACITY_TOP                 (857)	
	#define CAPACITY_RIGHT               (929)
	#define CAPACITY_BOTTOM              (1375)

	#define NUMBER_LEFT                  (662) // number
	#define NUMBER_TOP                   (517)
	#define NUMBER_RIGHT                 (756)
	#define NUMBER_BOTTOM                (647)

	#define PERCENT_LEFT                 (850) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (517)
	#define PERCENT_RIGHT                (968)
	#define PERCENT_BOTTOM               (647)

	#define TOP_ANIMATION_LEFT           (605) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (929)
	#define TOP_ANIMATION_BOTTOM         (155)

	// for old animation
	#define BAR_LEFT            (693)
	#define BAR_TOP             (381)
	#define BAR_RIGHT           (844)
	#define BAR_BOTTOM          (725) 

#else 

	// default wvga 480*800

	// battery capacity rectangle背景范围
	#define CAPACITY_LEFT                (0)//155//(172) // battery capacity center
	#define CAPACITY_TOP                 (0)//154//(330)
	#define CAPACITY_RIGHT               (400)//245//(307)
	#define CAPACITY_BOTTOM              (400)//299//(546)

	// first number rectangle数字
	#define NUMBER_LEFT                  (168)//(178) // number
	#define NUMBER_TOP                   (56)//(190)
	#define NUMBER_RIGHT                 (196)//(216)
	#define NUMBER_BOTTOM              (93)  //(244)

	// %  rectangle百分比
	#define PERCENT_LEFT                (224)// (254) // percent number_left + 2*number_width
	#define PERCENT_TOP                  (56)//(190)
	#define PERCENT_RIGHT                (252)//(302)
	#define PERCENT_BOTTOM              (93)// (244)

	// top animation part动画更新部分
	#define TOP_ANIMATION_LEFT           (0)//155//(172) // top animation
	#define TOP_ANIMATION_TOP            (100)
	#define TOP_ANIMATION_RIGHT          (400)//245//(307)
	#define TOP_ANIMATION_BOTTOM         (145)//116

	// for old animation
	#define BAR_LEFT            (176)	
	#define BAR_TOP             (128)
	#define BAR_RIGHT           (224)
	#define BAR_BOTTOM          (244)

#endif

/* The option of new charging animation */
#define ANIMATION_NEW

#endif // __CUST_DISPLAY_H__

mediatek\external\libshowlogo\show_animation_common.c这个文件是具体实现的文件,它有分为几个方法,下面以fill_animation_battery_ver_1()为例

/* Copyright Statement:
 *
 * This software/firmware and related documentation ("MediaTek Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to MediaTek Inc. and/or its licensors. Without
 * the prior written permission of MediaTek inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of MediaTek Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * MediaTek Inc. (C) 2010. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
 * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
 * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
 *
 * The following software/firmware and/or related documentation ("MediaTek
 * Software") have been modified by MediaTek Inc. All revisions are subject to
 * any receiver's applicable license agreements with MediaTek Inc.
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "show_animation_common.h"
#include "show_logo_log.h"
#include "fast_charging_common.h"
  
static int charging_low_index = 0;
static int charging_animation_index = 0;


#define CHECK_LOGO_BIN_OK  0
#define CHECK_LOGO_BIN_ERROR  -1


static unsigned short  number_pic_addr[(NUMBER_RIGHT - NUMBER_LEFT)*(NUMBER_BOTTOM - NUMBER_TOP)*2] = {0x0}; //addr
static unsigned short  line_pic_addr[(TOP_ANIMATION_RIGHT - TOP_ANIMATION_LEFT)*2] = {0x0};
static unsigned short  percent_pic_addr[(PERCENT_RIGHT - PERCENT_LEFT)*(PERCENT_BOTTOM - PERCENT_TOP)*2] = {0x0};
static unsigned short  top_animation_addr[(TOP_ANIMATION_RIGHT - TOP_ANIMATION_LEFT)*(TOP_ANIMATION_BOTTOM - TOP_ANIMATION_TOP)*2] = {0x0};



/*
 * Check logo.bin address if valid, and get logo related info
 *
 */ 
int check_logo_index_valid(unsigned int index, void * logo_addr, LOGO_PARA_T * logo_info)
{  
    unsigned int *pinfo = (unsigned int*)logo_addr;
    logo_info->logonum = pinfo[0];
    
    LOG_ANIM("[show_animation_common: %s %d]logonum =%d, index =%d\n", __FUNCTION__,__LINE__,logo_info->logonum, index);
    if (index >= logo_info->logonum)
    {
        LOG_ANIM("[show_animation_common: %s %d]unsupported logo, index =%d\n", __FUNCTION__,__LINE__, index);
        return CHECK_LOGO_BIN_ERROR;
    
    }   
   // LOG_ANIM("show_animation_common, pinfo[1]=%d,  pinfo[2+index]=%d, pinfo[3+index]=%d, pinfo[3+index] - pinfo[2+index]= %d, pinfo[1] - pinfo[2+index] =%d \n", 
   //            pinfo[1],pinfo[2+index],pinfo[3+index], pinfo[3+index] - pinfo[2+index],pinfo[1] - pinfo[2+index]); 
    
    if(index < logo_info->logonum - 1)
		logo_info->logolen = pinfo[3+index] - pinfo[2+index];
	else
		logo_info->logolen = pinfo[1] - pinfo[2+index];

    logo_info->inaddr = (unsigned int)logo_addr + pinfo[2+index];
    LOG_ANIM("show_animation_common, in_addr=0x%08x,  logolen=%d\n", 
                logo_info->inaddr,  logo_info->logolen);

    return CHECK_LOGO_BIN_OK;                
}


/*
 * Fill a screen size buffer with logo content 
 *
 */ 
void fill_animation_logo(unsigned int index, void *fill_addr, void * dec_logo_addr, void * logo_addr, LCM_SCREEN_T phical_screen)
{
    LOGO_PARA_T logo_info;
    int logo_width;
    int logo_height;
    if(check_logo_index_valid(index, logo_addr, &logo_info) != CHECK_LOGO_BIN_OK)
        return; 
              
    decompress_logo((void*)logo_info.inaddr, dec_logo_addr, logo_info.logolen, phical_screen.fb_size);
    //RECT_REGION_T rect = {0, 0, phical_screen.width, phical_screen.height};   
    logo_width =phical_screen.width;
    logo_height = phical_screen.height;
    if (phical_screen.rotation == 270 || phical_screen.rotation == 90) {
        logo_width =phical_screen.height;
        logo_height = phical_screen.width;
    }
    RECT_REGION_T rect = {0, 0, logo_width, logo_height};   
    
    fill_rect_with_content(fill_addr, rect, (unsigned short *)dec_logo_addr, phical_screen);

    
}

/*
 * Fill a rectangle size address with special color 
 *
 */ 
void fill_animation_prog_bar(RECT_REGION_T rect_bar,
                       unsigned int fgColor, 
                       unsigned int start_div, unsigned int occupied_div,
                       void *fill_addr, LCM_SCREEN_T phical_screen)
{
    unsigned int div_size  = (rect_bar.bottom - rect_bar.top) / (ANIM_V0_REGIONS);
    unsigned int draw_size = div_size - (ANIM_V0_SPACE_AFTER_REGION);
    
    unsigned int i;
    
    for (i = start_div; i < start_div + occupied_div; ++ i)
    {
        unsigned int draw_bottom = rect_bar.bottom - div_size * i - (ANIM_V0_SPACE_AFTER_REGION);
        unsigned int draw_top    = draw_bottom - draw_size;
        
        RECT_REGION_T rect = {rect_bar.left, draw_top, rect_bar.right, draw_bottom};

        fill_rect_with_color(fill_addr, rect, fgColor, phical_screen);

    }
}


/*
 * Fill a rectangle with logo content 
 *
 */ 
void fill_animation_dynamic(unsigned int index, RECT_REGION_T rect, void *fill_addr, void * dec_logo_addr, void * logo_addr, LCM_SCREEN_T phical_screen)
{
    LOGO_PARA_T logo_info;
    if(check_logo_index_valid(index, logo_addr, &logo_info) != CHECK_LOGO_BIN_OK)
        return; 
                    
    decompress_logo((void*)logo_info.inaddr, (void*)dec_logo_addr, logo_info.logolen, (rect.right-rect.left)*(rect.bottom-rect.top)*2);
    fill_rect_with_content(fill_addr, rect, (unsigned short *)dec_logo_addr, phical_screen);            
}


/*
 * Fill a rectangle  with number logo content 
 *
 * number_position: 0~1st number, 1~2nd number 
 */
void fill_animation_number(unsigned int index, unsigned int number_position, void *fill_addr,  void * logo_addr, LCM_SCREEN_T phical_screen)
{
    LOG_ANIM("[show_animation_common: %s %d]index= %d, number_position = %d\n",__FUNCTION__,__LINE__, index, number_position);

    LOGO_PARA_T logo_info;
    if(check_logo_index_valid(index, logo_addr, &logo_info) != CHECK_LOGO_BIN_OK)
        return;                 

    // draw default number rect,
    decompress_logo((void*)logo_info.inaddr, (void*)number_pic_addr, logo_info.logolen, number_pic_size);

    //static RECT_REGION_T number_location_rect = {NUMBER_LEFT,NUMBER_TOP,NUMBER_RIGHT,NUMBER_BOTTOM};    
    RECT_REGION_T battery_number_rect = {NUMBER_LEFT + (NUMBER_RIGHT - NUMBER_LEFT)*number_position,
                            NUMBER_TOP,
                            NUMBER_RIGHT + (NUMBER_RIGHT - NUMBER_LEFT)*number_position,
                            NUMBER_BOTTOM};   
                                                     
    fill_rect_with_content(fill_addr, battery_number_rect, (unsigned short *)number_pic_addr,phical_screen);            
}

/*
 * Fill a line with special color 
 *
 */ 
void fill_animation_line(unsigned int index, unsigned int capacity_grids, void *fill_addr,  void * logo_addr, LCM_SCREEN_T phical_screen)
{    
    LOGO_PARA_T logo_info;
    if(check_logo_index_valid(index, logo_addr, &logo_info) != CHECK_LOGO_BIN_OK)
        return; 
                
    decompress_logo((void*)logo_info.inaddr, (void*)line_pic_addr, logo_info.logolen, line_pic_size);

    RECT_REGION_T rect = {CAPACITY_LEFT, CAPACITY_TOP, CAPACITY_RIGHT, CAPACITY_BOTTOM}; 
    int i = capacity_grids;
    for(; i < CAPACITY_BOTTOM; i++)
    {      
        rect.top = i;
        rect.bottom = i+1;                                             
        fill_rect_with_content(fill_addr, rect, (unsigned short *)line_pic_addr, phical_screen);

    }
}



/*
 * Show charging animation version 0
 *
 */
void fill_animation_battery_ver_0(unsigned int capacity,  void *fill_addr, void * dec_logo_addr, void * logo_addr,
                       LCM_SCREEN_T phical_screen)
{

    unsigned int capacity_grids = 0;

    if (capacity > 100) capacity = 100;

    capacity_grids = (capacity * (ANIM_V0_REGIONS)) / 100;
    
    LOG_ANIM("[show_animation_common: %s %d]capacity =%d, capacity_grids = %d\n",__FUNCTION__,__LINE__, capacity, capacity_grids);
    

    //show_logo(1);
    fill_animation_logo(ANIM_V0_BACKGROUND_INDEX, fill_addr, dec_logo_addr, logo_addr,phical_screen);
    // Fill Occupied Color

    //RECT_REGION_T bar_rect = {BAR_LEFT, BAR_TOP, BAR_RIGHT, BAR_BOTTOM};    
    RECT_REGION_T rect_bar = {bar_rect.left + 1, bar_rect.top + 1, bar_rect.right, bar_rect.bottom};
    
//    RECT_REGION_T rect_bar = {BAR_LEFT + 1, BAR_TOP + 1,BAR_RIGHT, BAR_BOTTOM};
    
    fill_animation_prog_bar(rect_bar,
                       (unsigned int)(BAR_OCCUPIED_COLOR), 
                       0,  capacity_grids,
                       fill_addr, phical_screen);                              

    fill_animation_prog_bar(rect_bar,
                      (unsigned int)(BAR_EMPTY_COLOR),
                      capacity_grids, ANIM_V0_REGIONS - capacity_grids,
                      fill_addr, phical_screen); 

}

/*
 * Show charging animation version 1
 *
 */
void fill_animation_battery_ver_1(unsigned int capacity, void *fill_addr, void * dec_logo_addr, void * logo_addr, LCM_SCREEN_T phical_screen)
{
    LOG_ANIM("[show_animation_common: %s %d]capacity : %d\n",__FUNCTION__,__LINE__, capacity);
    
    if (capacity >= 100) {
        //show_logo(37); // battery 100
        fill_animation_logo(FULL_BATTERY_INDEX, fill_addr, dec_logo_addr, logo_addr,phical_screen);
     
    } else if (capacity < 10) {
        LOG_ANIM("[show_animation_common: %s %d]charging_low_index = %d\n",__FUNCTION__,__LINE__, charging_low_index);  
        charging_low_index ++ ;
                
        fill_animation_logo(LOW_BAT_ANIM_START_0 + charging_low_index, fill_addr, dec_logo_addr, logo_addr,phical_screen);
        fill_animation_number(NUMBER_PIC_START_0 + capacity, 1, fill_addr, logo_addr, phical_screen);
        fill_animation_dynamic(NUMBER_PIC_PERCENT, percent_location_rect, fill_addr, percent_pic_addr, logo_addr, phical_screen);
        
        if (charging_low_index >= 9) charging_low_index = 0;

    } else {

        unsigned int capacity_grids = 0;
        //static RECT_REGION_T battery_rect = {CAPACITY_LEFT,CAPACITY_TOP,CAPACITY_RIGHT,CAPACITY_BOTTOM};
        capacity_grids = CAPACITY_BOTTOM /*- (CAPACITY_BOTTOM - CAPACITY_TOP) * (capacity - 10) / 90*/;
        LOG_ANIM("[show_animation_common: %s %d]capacity_grids : %d,charging_animation_index = %d\n",__FUNCTION__,__LINE__, capacity_grids,charging_animation_index);   

        //background 
        fill_animation_logo(ANIM_V1_BACKGROUND_INDEX, fill_addr, dec_logo_addr, logo_addr,phical_screen);
        
        //fill_animation_line(ANIM_LINE_INDEX, capacity_grids, fill_addr,  logo_addr, phical_screen);
        //fill_animation_number(NUMBER_PIC_START_0 + (capacity/10), 0, fill_addr, logo_addr, phical_screen);
        //fill_animation_number(NUMBER_PIC_START_0 + (capacity%10), 1, fill_addr, logo_addr, phical_screen);
        //fill_animation_dynamic(NUMBER_PIC_PERCENT, percent_location_rect, fill_addr, dec_logo_addr, logo_addr, phical_screen);                
        
        
        // if (capacity <= 90)
         //{//动画范围
            RECT_REGION_T top_animation_rect = {TOP_ANIMATION_LEFT, /*capacity_grids - (TOP_ANIMATION_BOTTOM - TOP_ANIMATION_TOP)*/0, TOP_ANIMATION_RIGHT, capacity_grids};
            //top_animation_rect.bottom = capacity_grids;
            //top_animation_rect.top = capacity_grids - top_animation_height;
            charging_animation_index++;        
            //show_animation_dynamic(15 + charging_animation_index, top_animation_rect, top_animation_addr);
			//动画
		   fill_animation_dynamic(BAT_ANIM_START_0 + charging_animation_index, top_animation_rect, fill_addr, dec_logo_addr, logo_addr, phical_screen);
			//十位数字
			fill_animation_number(NUMBER_PIC_START_0 + (capacity/10), 0, fill_addr, logo_addr, phical_screen);
			//个位数字
			fill_animation_number(NUMBER_PIC_START_0 + (capacity%10), 1, fill_addr, logo_addr, phical_screen);
			//%
			fill_animation_dynamic(NUMBER_PIC_PERCENT, percent_location_rect, fill_addr, dec_logo_addr, logo_addr, phical_screen); 
            if (charging_animation_index >= 9) charging_animation_index = 0;
         //}
    }

}

/*
 * Show charging animation version 2:wireless ui
 * total 29 logo:from 39 ~ 68 
 * less(0<10): 50-53 , low(<30):54-57 ,middle(<60):58-61 , high():62-75 , o:66, full:67,num (0-9):39-48, %:49
 *
 */

 void fill_animation_battery_ver_2(unsigned int capacity, void *fill_addr, void * dec_logo_addr, void * logo_addr, LCM_SCREEN_T phical_screen)
{
    LOG_ANIM("[show_animation_common: %s %d]capacity : %d\n",__FUNCTION__,__LINE__, capacity);
//    RECT_REGION_T wireless_bgd_rect = {0, 0, phical_screen.width, phical_screen.height};
    
    charging_low_index >= 3? charging_low_index = 0:charging_low_index++;
    LOG_ANIM("[show_animation_common: %s %d]charging_low_index = %d\n",__FUNCTION__,__LINE__, charging_low_index); 
    
    if (capacity >= 100) {
         // battery 100
        fill_animation_logo(V2_BAT_100_INDEX, fill_addr, dec_logo_addr, logo_addr,phical_screen);
    } else if (capacity <= 0) {
        fill_animation_logo(V2_BAT_0_INDEX, fill_addr, dec_logo_addr, logo_addr,phical_screen);
    } else {
        int bg_index = V2_BAT_0_10_START_INDEX; //capacity > 0 && capacity < 10
        if (capacity >= 10 && capacity < 40) {
            bg_index = V2_BAT_10_40_START_INDEX;               
        } else if (capacity >= 40 && capacity < 80) {            
            bg_index = V2_BAT_40_80_START_INDEX;
        } else if (capacity >= 80 && capacity < 100) {      
            bg_index = V2_BAT_80_100_START_NDEX;
        }        
        fill_animation_logo(bg_index + charging_low_index, fill_addr, dec_logo_addr, logo_addr,phical_screen);    
        RECT_REGION_T tmp_rect = {(int)phical_screen.width * 4/10, 
                        (int) phical_screen.height * 1/6,
                        (int)phical_screen.width* 5/10,
                        (int)phical_screen.height*16/60};  
        unsigned short tmp_num_addr[(int)phical_screen.width * phical_screen.height/100]; //addr
                                     
        if (capacity >= 10) {
            LOG_ANIM("[show_animation_common: %s %d]tmp_rect left = %d, right = %d,top = %d,bottom = %d,\n",__FUNCTION__,__LINE__, 
                        tmp_rect.left,tmp_rect.right,tmp_rect.top,tmp_rect.bottom);                         
            fill_animation_dynamic(V2_NUM_START_0_INDEX + (capacity/10), tmp_rect, fill_addr, tmp_num_addr, logo_addr, phical_screen);
            tmp_rect.left += (int)phical_screen.width /10;
            tmp_rect.right += (int)phical_screen.width /10;
        }
        
        LOG_ANIM("[show_animation_common: %s %d]tmp_rect left = %d, right = %d,top = %d,bottom = %d,\n",__FUNCTION__,__LINE__, 
                tmp_rect.left,tmp_rect.right,tmp_rect.top,tmp_rect.bottom);                  
        fill_animation_dynamic(V2_NUM_START_0_INDEX + (capacity%10), tmp_rect, fill_addr, tmp_num_addr, logo_addr, phical_screen);                   
        
        tmp_rect.left += (int)phical_screen.width /10;
        tmp_rect.right += (int)phical_screen.width /10;

        LOG_ANIM("[show_animation_common: %s %d]tmp_rect left = %d, right = %d,top = %d,bottom = %d,\n",__FUNCTION__,__LINE__, 
                        tmp_rect.left,tmp_rect.right,tmp_rect.top,tmp_rect.bottom);                                         
        fill_animation_dynamic(V2_NUM_PERCENT_INDEX, tmp_rect, fill_addr, tmp_num_addr, logo_addr, phical_screen);  
        
    }
}

/*
 * Pump charging aniamtion 
 * index 39: 100%, 40~45 : animation logo, 46~55: number logo, 56: % logo
 *
 */
void fill_animation_battery_fast_charging(unsigned int capacity, void *fill_addr, void * dec_logo_addr, void * logo_addr, LCM_SCREEN_T phical_screen)
{
    int display_width = phical_screen.width;
    int display_height = phical_screen.height;
    int curr_left = 0;
    int num_width = 0;
    int num_height = 0;
    int top_margin_height = 0;
    if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2) ||
        0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
        display_width = phical_screen.height;
        display_height = phical_screen.width;
    }
    num_width = LOGO_NUM_WIDTH(display_width);
    num_height = LOGO_NUM_HEIGHT(display_height);
    top_margin_height = LOGO_TOP_MARGIN(display_height);
    LOG_ANIM("[show_animation_common: %s %d]capacity : %d, num_width:%d, num_height:%d, top_margin_height:%d\n", __FUNCTION__,__LINE__, capacity, num_width, num_height, top_margin_height);

    charging_low_index >= 5? charging_low_index = 0:charging_low_index++;
    LOG_ANIM("[show_animation_common: %s %d]charging_low_index = %d\n",__FUNCTION__,__LINE__, charging_low_index);

    LOG_ANIM("[show_animation_common: %s %d]capacity : %d\n",__FUNCTION__,__LINE__, capacity);
    if (capacity <= 0) {
        return;
    } else if (capacity >= 100) {
        fill_animation_logo(FAST_CHARGING_BAT_100_INDEX, fill_addr, dec_logo_addr, logo_addr, phical_screen);
    } else {
        fill_animation_logo(FAST_CHARGING_BAT_START_0_INDEX + charging_low_index, fill_addr, dec_logo_addr, logo_addr, phical_screen);

        curr_left = (display_width - num_width * 2) >> 1;
        unsigned short tmp_num_addr[(int)phical_screen.width * phical_screen.height/50];
		
        if (capacity > 10) {
            curr_left = (display_width - num_width * 3) >> 1;
            RECT_REGION_T tmp_rect_1 = {curr_left, top_margin_height, curr_left + num_width, top_margin_height + num_height};
            LOG_ANIM("[show_animation_common: %s %d]capacity = %d, show 1nd num : %d\n",__FUNCTION__,__LINE__, capacity, capacity/10);
            fill_animation_dynamic(FAST_CHARGING_NUM_START_0_INDEX + (capacity/10), tmp_rect_1, fill_addr, tmp_num_addr, logo_addr, phical_screen);
            curr_left += num_width;
        }
        RECT_REGION_T tmp_rect_2 = {curr_left, top_margin_height, curr_left + num_width, top_margin_height + num_height};
        LOG_ANIM("[show_animation_common: %s %d]capacity = %d, show 2st num : %d\n",__FUNCTION__,__LINE__, capacity, capacity%10);
        fill_animation_dynamic(FAST_CHARGING_NUM_START_0_INDEX + (capacity%10), tmp_rect_2, fill_addr, tmp_num_addr, logo_addr, phical_screen);

        curr_left += num_width;
        RECT_REGION_T tmp_rect_3 = {curr_left, top_margin_height, curr_left + num_width, top_margin_height + num_height};
        LOG_ANIM("[show_animation_common: %s %d]show percent \n",__FUNCTION__,__LINE__);
        fill_animation_dynamic(FAST_CHARGING_NUM_PERCENT_INDEX, tmp_rect_3, fill_addr, tmp_num_addr, logo_addr, phical_screen);
    }
	
}

/*
 * Show charging animation by version
 *
 */
void fill_animation_battery_by_ver(unsigned int capacity,void *fill_addr, void * dec_logo_addr, void * logo_addr,
                        LCM_SCREEN_T phical_screen, int version)
{
    LOG_ANIM("[show_animation_common: %s %d]version : %d\n",__FUNCTION__,__LINE__, version);
    switch (version)
    {
        case 0:
            fill_animation_battery_ver_0(capacity, fill_addr, dec_logo_addr, logo_addr, phical_screen);
            
            break;
        case 1:
            fill_animation_battery_ver_1(capacity, fill_addr, dec_logo_addr, logo_addr, phical_screen);
            
            break;
        case WIRELESS_CHARGING_ANIM_VER:
            fill_animation_battery_ver_2(capacity, fill_addr, dec_logo_addr, logo_addr, phical_screen);
            
            break;            
        default:
            fill_animation_battery_ver_0(capacity, fill_addr, dec_logo_addr, logo_addr, phical_screen);
            
            break;   
    }                     
}                       
现在知道在哪里具体实现了,那在哪里调用呢?下面是具体文件及方法
mediatek\external\ipod\bootlogo.cpp

 show_battery_capacity(capacity);


2018-10-17 16:37:47 the_Sunshine_of_King 阅读数 1047

开机画面,按照国际惯例,一般是分为2屏,当然也有3屏的说法,不管怎样,我这里说得就是最后的一屏,按照bootanimation的字面意思翻译,大概也就是开机动画的意思,那这就不说第几屏了,直接用“开机动画”这词。

首先,开机动画的地址:system\media\bootanimation.zip。。。要修改开机动画就是修改bootanimation这个文件。如果说你的手机里没有这个文件,那就是说明你用的是官方原始版本的rom,开机动画没有被修改过,但这不碍事,没有就放一个进去,到时候想换回最原始的开机画面,也可以把bootanimation这个文件删了。官方最原始的开机动画在system\ framework\framework-res.apk\assets\images里面,里面主要是2张图片,高手面可以去研究一下,说不定通过这个文件可以用代码实现动画的过程。

接下来,说说bootanimation.zip这个文件的结构。bootanimation里面主要包含一个desc.txt以及N个文件夹。而文件夹里面放着的就是你要的开机动画的图片。decs.txt的作用就是指导系统如何去执行你的开机画面。


1 . 下面继续说说desc.txt这个文档要怎么写。


先看例子,如果我的开机动画要用到2个文件夹,分别是part1和part2,。。。。我希望开机的时候,先把part1里面的图片都播放一遍,然后再循环播放part2里面的文件,直到进入系统。那么decs.txt文档的内容应该如下:
302 480 5
p 1 0 part1
p 0 0 part2

就这么多,现在解释一下这些命令吧。
第一行,320 480是代表你屏幕的分辨率,因为我们的胖6是320*480的,这就不多说了。后面的5是说,5帧每秒,不懂的可以这么理解,5是代表一秒钟播放5张图片。就这么简单。
第二行,p 1 0 part1。p应该是play吧,也就是播放的意思。1是播放一次。0是空指令,就是什么都不做。part1就是说,这条指令是针对part1这个文件夹的。整条指令的意思就是,播放part1里面的图片1次,然后什么都不做,马上进入下一条指令。
第三行,p 0 0 part2。p依然是播放。第一个0这里是代表循环播放,第二个0和上面第二条指令一样,代表什么也不做。part2也就不多说了。
至于为什么第一个0为什么是代表循环,只能这么说,这事国际惯例,就像用迅雷的时候,0代表不限制速度一样,系统规定的,你知道就好,别纠结。

总结公式如下
第一条指令:屏幕的分辨率(空格)播放频率
第二条指令:p(空格)播放次数(空格)后续操作(空格)作用文件夹
第三条指令:同上
第N条指令:同上
屏幕分辨率的格式是:宽(空格)高,胖6的就是320 480。。。播放频率,上面已经说清楚了,至于到底要用多大的数字,视你开机动画的张数而定,比如说,一共有100张图片,开机时间是20秒,那么100/20就是5。
播放次数,1是代表一次,0代表循环播放。如果要播放2次的话,就是就是打个2上去,应该是这样吧,反正我是没试过,只试过0和1.
后续操作,0代表什么都不做,直接进入下一条指令。10是代表稍作停顿。

至于文件夹里面的图片,比较简单,首先,纠正一个说法,之前说必须要是png格式,经过我试验证明,jpg格式的也可以,其他的有待试验,不过只支持静态图片这点应该是真的,动态图片同样有待试验。其次,关于图片的尺寸,是不做要求的,只要在txt文档里写好手机的分辨率即可,开机的时候系统会自动适配。其其次要按播放循序命名,建议用5位数字,比如说,第一张图片是00010,第二张就是00020.。。。。为什么要从00010开始,而不是00001?因为这事预防以后要在第一张和第二张中间再插一张图片进去的话,就可以把插进去的图片命名为00011,在00010之后,00020之前。就这么简单。至于图片那里来嘛,当然是自己网上找啦,也可以下载别人的bootanimation,然后修改一下。

最后就是压缩包了,把需要用到的part文件夹跟decs.txt打包成zip格式,必须是zip,不能是rar,而且打包的时候压缩方式要选择“存储”模式。然后改名成为bootanimation.zip,复制到SD卡里,再通过RE文件管理器复制到system\media\下面,重启。

要注意一下,bootanimation不能太大,大了会卡,一般不要超过3M,。

 

————————————————————————————————————————————————————————————————————————————————————

1. Linux 系统启动,出现Linux小企鹅画面(reboot)(Android 1.5及以上版本已经取消加载图片);
2. Android平台启动初始化,出现"A N D R I O D"文字字样画面;
3. Android平台图形系统启动,出现含闪动的ANDROID字样的动画图片(start)。

现在我们说的是第三种方式(基于模拟器):

2. 修改开机动画

android开机动画叫源码位于frameworks/base/cmds/bootanimation下,这个程序会将/data/local/bootanimation.zip或/system/media/bootanimation.zip里面的png图片以动画的形式播放出来。

首先,我们先来分析一下源码:

frameworks/base/cmds/bootanimation/BootAnimation.cpp

首先看一下定义的常量:

1

2

3

4

#define USER_BOOTANIMATION_FILE "/data/local/bootanimation.zip"

 

#define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"

#define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip"

BootAnimation::readyToRun()

进入一个if判断语句

1

2

3

4

5

6

7

8

9

10

11

if ((encryptedAnimation &&

            (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0) &&

            (mZip.open(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE) == NO_ERROR)) ||

 

            ((access(USER_BOOTANIMATION_FILE, R_OK) == 0) &&

            (mZip.open(USER_BOOTANIMATION_FILE) == NO_ERROR)) ||

 

            ((access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) &&

            (mZip.open(SYSTEM_BOOTANIMATION_FILE) == NO_ERROR))) {

        mAndroidAnimation = false;

    }

BootAnimation::threadLoop()

1

2

3

4

5

if (mAndroidAnimation) {

 r = Android(); // 执行android字体闪动的图片

 } else {

 r = movie(); // 执行bootanimation.zip中提供的动画图片

 }

1

  

==> BootAnimation::Android()会加载"images/android-logo-mask.png"和"images/android-logo-shine.png"
==> BootAnimation::movie()会加载bootanimation.zip中的内容

我们下载的源码里默认是没有那些个.zip动画的,所以总会跳到android字体闪动的画面

所以如果你系那个用.zip的动画那么把你做好的动画拷贝到编译好对应的目录下即可,然后执行make snod整合进img包就可以看到效果了

如果你想修改android闪动的那两张图片的话,最简单的方法是直接替换图片,如果你懂openGL的话也可以自己做酷炫的动画

那两张图片放在./frameworks/base/core/res/assets/images  目录下,一张镂空的android图,一张发光效果,动画效果就是下面那张发光的效果图不断左右移动。

我是用Photoshop直接修改的

修改完后直接替换,然后再 mmm frameworks/base  , make snod 即可

以下是我修改后的效果图:

image

 

看样子还想那么回事

3. 接下来我们给系统添加开机声音

由于动画是在BootAnimation播放的,所以我们的声音肯定也在这个类中做,照猫画虎

首先在BootAnimation.h添加方法的声明和头文件的引用

1

2

#include <media/AudioSystem.h>

#include <media/mediaplayer.h>

image

 

添加方法 void bootMusic();

image

然后在BootAnimation.cpp中实现这个方法:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

void BootAnimation::bootMusic()

{

    int index;

    MediaPlayer* mp = new MediaPlayer();

    if (mp->setDataSource("/system/etc/poweron.wav", NULL) == NO_ERROR) {

        mp->setAudioStreamType(AUDIO_STREAM_ENFORCED_AUDIBLE);

        mp->prepare();

    }

    AudioSystem::getStreamVolumeIndex(AUDIO_STREAM_ENFORCED_AUDIBLE, &index);

    if (index != 0) {

        mp->seekTo(0);

        mp->start();

    }

 

}

请注意这个目录setDataSource("/system/etc/poweron.wav", NULL)

其实这个目录是随便写的,你想从哪个目录读这个文件就从哪个目录读好了,但是你要把这个文件放在对应的目录下

比如,这个目录是system/etc (这个目录是android系统的目录,不是源码的目录),这个文件夹是只有读权限而没有写权限的,所有你不用试adb shell了,没用的

其实system/etc这个目录对应的是我们编译后out文件夹下的xxx,然后在system/etc,所以你把poweron.wav放到这里就行了,当然如果你这时再emulaor 也同样是看不到效果的,因为你修改完还没有编译,和上面修改图片一样,make snod一下

image

然后和图上一样,你就会生成新的system.img,当然你之前添加的poweron.wav也会自动被编译进去了

image

 

然后再修改bootanimation_main.cpp这个文件,因为方法也申明了,也实现了,就是还没有调用,所以调用就在这里调

 

1

2

3

//play boot music -yp

        BootAnimation *animation = new BootAnimation();

        animation->bootMusic();

 

image

修改完这写以后还需要修改Android.mk文件

因为播放声音还需要引入库

LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
libbinder \
    libui \
     libskia \
    libEGL \
    libGLESv1_CM \
    libgui \
    libmedia

 

请注意,libmedia是新添加的;

完事后就ok了,当然还是需要编译的

mmm  frameworks/base/cmds/bootanimation/

make snod

 

大功告成,这样你就成功的添加了开机音乐

也许有人会问,那android系统自带的那些音乐和铃声在什么地方呢?

源码目录在framworks/base/data/sounds

至于编译完成后放到什么地方了那是Android.mk文件上配置的

不过这里叫AllAudio.mk

image

我们可以看到他又包含了很多mk文件,在同一目录下就可以找到,上图中就可以,我们随便打开一个看看

image

 

这下你们顿时明白了吧,这些资源编译后都去了神马地方

 

所以,在刚才添加poweron.wav的时候,其实可以直接把声音资源丢到framworks/base/data/sounds这个目录下

然后再mk文件中这样修改:

$(LOCAL_PATH)/poweron.wav:system/etc/poweron.wav \

 

不用我说,当然是执行mmm还有make snod命令了

 

其实还有一种办法,如果你不想这么麻烦,你可以之际把poweron.wav 文件丢到./frameworks/base/core/res/assets/sounds下,用的时候怎么用呢?

加载的时候路径是什么呢?我们看看源码

我们可以看到之前我们修改的那两张图片是怎么被加载进来的

image

而这个方法的两个参数是:

image

是不是顿时又明白了?

原来精髓所在是有个Asset可以使用,这个和上层开发中是一样的,这个文件夹中的东西是不编译的。

1

2

3

4

5

6

7

8

Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);

    if (!asset)

        return NO_INIT;

    SkBitmap bitmap;

    SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),

            &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);

    asset->close();

    delete asset;

 

所以按照这个方法就可以找到poweron.wav 这个文件了,然后修改下bootMusic的代码就可以了。

 

——————————————————————————————————————————————————————————————————————————————————

原创文章,转载请注明出处,谢谢。

系统通常默认支持开机动画,开机关机铃声服务倒是预先定义了,不过使用时需要在/sysytem/media/下添加相应的音频文件。长按Power键弹出关键选项,关机时也只是显示进度条,而不是我们期望的关机动画同时伴有关机铃声,当然在做二次开发的时候,这些都是可以定制的。下面将逐步分析如何实现这些定制化的需求。

 

一.    制作开机动画

开机画面是保存在/system/media的bootanimation.zip,下面分析系统开机画面的构成
文件名为bootanimation.zip 一定是这个不能修改,里面包含part1 part2文件夹 和desc.txt,part 文件夹里面放的是动画拆分的图片,格式为png, desc.txt里面是播放的设置。
格式是这样的

480 800 15
p 1 0 part0
p 0 0 part1
480 800是指显示的分辨率 宽 高
15是一秒的帧数
p后面的数字是指播放次数 0为循环,N为播放N次
后面那位数字 一般为0(空指令), 表示播放一遍后稍作停顿的时间
part0,part1 为文件夹名
一般我们只使用part0目录

图片准备好了,desc.txt里面的命令也准备好了,就可以把他们一起打包压缩成zip格式了。记住,是zip格式,而不是rar格式。另外压缩的时候注意一点,压缩的时候压缩方式要选择存储,否则开机时手机会不认的。当然不至于变砖,只是开机的时候会黑着没动画一直到进入桌面为止。

 

开机动画的替换也很简单,我们把做好的bootanimation.zip替换掉原来的/system/media/bootanimation.zip文件即可。关机动画其实和开机动画的制作一样,我们命名为shutdownanimation.zip,和bootanimation.zip放在同一目录下。

 

 

 

二. 开关机动画实现原理

Android系统在init.rc中定义了很多Servic,具体定义格式可以参考《Android Platform Developer’s Guide》中的“Android Init Language”。Init.rc中定义的Service将会被Init进程创建,其中已经定义的服务就包含了开机动画,但没有关机动画的定义

service bootsound /system/bin/mplayer /system/media/bootsound

    user media

    group audio

    oneshot

//开机铃声服务 /system/media/startupsound是铃声文件

service startupsound /system/bin/mplayer /system/media/startupsound

    user media

    group audio

    disabled

    oneshot

//关机铃声服务 /system/media/shutdownsound是关机铃声

service shutdownsound /system/bin/mplayer /system/media/shutdownsound

    user media

    group audio

    disabled

    oneshot

//定义了一个bootanim的服务,对应执行/system/bin/bootanimation

//disabled 表示init进程创建只是创建它,但不立刻执行

//oneshot 表示该服务只执行一次

service bootanim /system/bin/bootanimation

    user graphics

    group graphics

    disabled

oneshot

 

 

当android系统boot时,开始加载动画和开机铃声,其代码位于

//源文件SurfaceFlinger.cpp

status_t SurfaceFlinger::readyToRun() {

    

    // start boot animation service

    property_set("ctl.start", "bootanim");//

    {

        char value[PROPERTY_VALUE_MAX];

        property_get("persist.sys.profile.silent", value, "0");

        if (atoi(value)== 0){

            LOGI("start:persist.sys.profile.silent is soundable");

            // start startupsound service

            property_set("ctl.start","startupsound");//

         } else {

            LOGI("start:persist.sys.profile.silent is silent");

         }

    }

    return NO_ERROR;

}

 

当Android完成boot后,关闭动画和开机铃声,代码位于

//源文件SurfaceFlinger.cpp

void SurfaceFlinger::bootFinished() {

   const nsecs_t now = systemTime();

   const nsecs_t duration = now - mBootTime;

   LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );

   mBootFinished = true;

   //stop bootanim service

   property_set("ctl.stop", "bootanim");

   char value[PROPERTY_VALUE_MAX];

   property_get("persist.sys.profile.silent", value, "0");

   if (atoi(value)== 0){

       LOGI("stop:persist.sys.profile.silent is soundable");

       //stop startupsound service

       property_set("ctl.stop","startupsound");

   } else {

       LOGI("stop:persist.sys.profile.silent is silent");

   }

}

 

如何理解ctr.start和ctr.stop系统属性?

每一项服务必须在/init.rc中定义.Android系统启动时,init守护进程将解析init.rc和启动属性服务,属性“ ctl.start ”和“ ctl.stop ”是用来启动和停止服务的。一旦收到设置“ ctrl.start ”属性的请求,属性服务将使用该属性值作为服务名找到该服务,启动该服务。这项服务的启动结果将会放入“ init.svc.<服务名>“属性中 。客户端应用程序可以轮询那个属性值,以确定结果。想更深入了解Android property系统可以参考博文《(翻译)Android属性系统》

 

property_set("ctl.start",ServiceName);就是启动ServiceName服务(在init.rc中定义)

property_set("ctl.stop",ServiceName)相对的是关闭ServiceName服务。

 

 

 A启动动画服务

由于开机动画和关机动画除了播放的动画文件不同,其他的完全一致,这里重复利用/system/bin/bootanimation代码, 仿照开机动画服务,我们新定义关机动画

service shutdownanim /system/bin/bootanimation -shutdown

    user graphics

    group graphics

    disabled

    oneshot

唯一要注意的是关机动画使用的/system/bin/bootanimation带了-shutdown参数,这个参数用来区分加载的动画文件为开机还是关机动画。当bootanimation服务启动时,进入/frameworks/base/cmds/bootanimation/bootanimation_main.cpp主函数main

int main(int argc, char** argv)

{

#if defined(HAVE_PTHREADS)

    setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);

#endif

 

    char value[PROPERTY_VALUE_MAX];

    property_get("debug.sf.nobootanimation", value, "0");

    int noBootAnimation = atoi(value);

    LOGI_IF(noBootAnimation,  "boot animation disabled");

    if (!noBootAnimation) {

 

        sp<ProcessState> proc(ProcessState::self());

        ProcessState::self()->startThreadPool();

 

        // create the animation object

        sp<BootAnimation> boot = new BootAnimation();

        //根据是否有参数,来设置动画对象的isShutdown属性

        if (argc > 1) {

            if (strcmp(argv[1], "-shutdown")==0) {

                boot->isShutdown(true);

            }

        }

 

        IPCThreadState::self()->joinThreadPool();

 

    }

    return 0;

}

new BootAnimation();时,如果有参数-shutdown, 则boot->isShutdown(true);方法isShutdown和isShutdown使我们新加的,所以先要在frameworks/base/cmds/bootanimation/bootanimation/BootAnimation.h头文件中申明为public,如下:

class BootAnimation : public Thread, public IBinder::DeathRecipient

{

public:

                BootAnimation();

    virtual     ~BootAnimation();

 

    sp<SurfaceComposerClient> session() const;

    bool        mShutdown;

void        isShutdown(bool shutdown);

…………………………………………….

}

 

之后修改BootAnimation.cpp

//源码位于frameworks/base/cmds/bootanimation/bootanimation/BootAnimation.cpp

首先在构造函数中初始化mShutdown = false;表示默认是开机标志

BootAnimation::BootAnimation() : Thread(false)

{

    mSession = new SurfaceComposerClient();

    mShutdown = false;

}

实现isShutdown(bool shutdown);方法

void BootAnimation::isShutdown(bool shutdown)

{

    mShutdown = shutdown;

}

修改status_t BootAnimation::readyToRun() 方法来根据mShutdown值加载动画文件,如

status_t BootAnimation::readyToRun() {

……………………………………

mAndroidAnimation = false;

if (!mShutdown) {

    status_t err = mZip.open("/data/local/bootanimation.zip");

    if (err != NO_ERROR) {

        err = mZip.open("/system/media/bootanimation.zip");

        if (err != NO_ERROR) {

            mAndroidAnimation = true;

        }

    }

} else {

    status_t err = mZip.open("/data/local/shutdownanimation.zip");

    if (err != NO_ERROR) {

        err = mZip.open("/system/media/shutdownanimation.zip");

        if (err != NO_ERROR) {

            mAndroidAnimation = true;

        }

    }

    mShutdown = false;

}

return NO_ERROR;

}

以上是动画定制化C代码部分的全部修改。

 

 

 

B启动开机铃声服务

startupsound开机铃声服务,shutdownsound关机铃声服务

init.rc定义,service startupsound /system/bin/mplayer /system/media/startupsound

相当于用/system/bin/mplayer对象播放媒体文件/system/media/startupsound,

init.rc定义,service shutdownsound /system/bin/mplayer /system/media/shutdownsound

相当于用/system/bin/mplayer对象播放媒体文件/system/media/ shutdownsound.

 

 

到这里,开机动画和开机铃声是正常的,我们还需要修改的是关机时候的执行流程,因为默认的操作时关机确认后显示进度条。

 

 

 

C定制Android关机过程

在Android系统中,长按Power键默认会弹出对话框让你选择“飞行模式”,“静音”,“关机”等功能。

     我的目标是长按Power键,将会关机,弹出“设备将要关机”选择对话框。如果可以选择“是”关机,和“否”返回系统。

 

弹出对话框的代码位于:

frameworks\policies\base\phone\com\android\internal\policy\impl\PhoneWindowManager.java

长按Power键显示对话框的代码如下:

Runnable mPowerLongPress = new Runnable() {

    public void run() {

        mShouldTurnOffOnKeyUp = false;

        performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);

        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);

        showGlobalActionsDialog();

    }

};

调用showGlobalActionsDialog方法将会显示上面提到的显示“飞行模式”,“静音”,“关机”,选项的对话框。

      关机的代码位于:

frameworks\policies\base\phone\com\android\internal\policy\impl\GlobalActions.java

文件的createDialog方法中,有如下代码:

mItems = Lists.newArrayList(

    // silent mode

    mSilentModeToggle,

    // next: airplane mode

    mAirplaneModeOn,

    // last: power off

    new SinglePressAction(

           com.android.internal.R.drawable.ic_lock_power_off,

           R.string.global_action_power_off) {

                public void onPress() {

                    // shutdown by making sure radio and power are handled accordingly.

                    ShutdownThread.shutdown(mContext, true);

                }

 

                public boolean showDuringKeyguard() {

                    return true;

                }

 

                public boolean showBeforeProvisioning() {

                    return true

                }

            });

从代码中我们可以看出,如果选择上述对话框的“关机”选项之后,将会调用ShutdownThread的shutdown方法来关机。shutdown方法的第二个参数标识是否弹出询问对话框。

 

ShutdownThread代码位于

frameworks/base/core/java/com/android/internal/app/ShutdownThread.java

shutdown方法中有如下代码

public static void shutdown(final Context context, boolean confirm) {

    // ensure that only one thread is trying to power down.

    // any additional calls are just returned

    synchronized (sIsStartedGuard){

        if (sIsStarted) {

            Log.d(TAG, "Request to shutdown already running, returning.");

            return;

        }

    }

 

    Log.d(TAG, "Notifying thread to start radio shutdown");

 

    if (confirm) {

        final AlertDialog dialog = new AlertDialog.Builder(context)

               .setIcon(android.R.drawable.ic_dialog_alert)

               .setTitle(com.android.internal.R.string.power_off)

               .setMessage(com.android.internal.R.string.shutdown_confirm)

               .setPositiveButton(com.android.internal.R.string.yes,

new DialogInterface.OnClickListener() {

                           public void onClick(DialogInterface dialog, int which) {

                               beginShutdownSequence(context);

                           }

                    })

                .setNegativeButton(com.android.internal.R.string.no, null)

                .create();

 

dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);

        if (!context.getResources().getBoolean(

             com.android.internal.R.bool.config_sf_slowBlur)) {

dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

        }

        dialog.show();

    } else {

        beginShutdownSequence(context);

    }

}

 

确认关机后开始执行beginShutdownSequence(context),这里就是我们定制关机过程的关键。

 

修改beginShutdownSequence(context)方法,在方法开头打印Log之后增加如下代码:

//我们判断如果有关机动画文件,即显示关机动画,否则显示默认的进度条。

boolean showShutdownAnim = new File("/system/media/shutdownanimation.zip").exists();

    if (showShutdownAnim) {

        Log.d(TAG, "shutdownanim");

        //设置前面说的android系统属性ctr.start即通知属性服务启动关机动画服务

        android.os.SystemProperties.set("ctl.start", "shutdownanim");

    } else {

        // throw up an indeterminate system dialog to indicate radio is

        // shutting down.

        ProgressDialog pd = new ProgressDialog(context);

        pd.setTitle(context.getText(com.android.internal.R.string.power_off));

        pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));

        pd.setIndeterminate(true);

        pd.setCancelable(false);

        pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);

        if (!context.getResources().getBoolean(

            com.android.internal.R.bool.config_sf_slowBlur)) {

            pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

        }

 

        pd.show();

    }

 

    boolean playShutdownSound = new File("/system/media/shutdownsound").exists();

    android.os.SystemProperties.getBoolean("ro.config.enable_shutdownshound", false);

    if (playShutdownSound) {

        // play shutdown sound

        Log.d(TAG, "shutdownsound");

        android.os.SystemProperties.set("ctl.start", "shutdownsound");

}

以上就是定制化实现的所有需要修改的地方,想更深入了解Android property系统可以参考博文《(翻译)Android属性系统

2017-01-16 14:45:15 w815878564 阅读数 1184

  Android系统的开机动画修改主要是修改/system/media/文件夹下面的bootanimation.zip文件。
  解压该文件后,我们会发现里面有一个文件夹,还有一个名为desc.txt的文件。这个文件内容一般如下:
  1920 1080 20
  p 0 0 loading
  第一行中的1920和1080表示图片的分辨率,前面是宽后面是高,20表示刷新帧率,即每秒20帧
  第二行中的第一个0表示重复次数,0表示无限重复;第二个0表示动画完成后多久开始下一次动画;loading是我们放图片的文件夹名称。
  loading文件夹存放的图片一般为png图片,如果有多张图片就按照动画顺序依次命名为1.png 2.png。。。。。等
  最后我们把desc.txt文件和loading文件夹压缩名为bootanimation的zip压缩文件。
  这里需要注意的是,我们在压缩的时候需要选择压缩方式,这里必须选择为存储,否则即使替换了系统中的压缩文件,动画也不会正常显示。
  

Android开关机动画

阅读数 300

没有更多推荐了,返回首页