关于程序实现修改开机Logo

88 篇文章 1 订阅
74 篇文章 1 订阅
做车机的朋友可能知道,一个项目可能会遇到这种需求:根据客户的车品牌设置开机Logo,比如说大众的车就选择大众的开机Logo图片,凯迪拉克的车就选择凯迪拉克的开机Logo图片,十分方便灵活可以适用所有车品牌,车主可以自己选择自己喜欢的开机Logo,一旦选择之后,重启时开机Logo就变成你之前选择的开机Logo,这并不是简单的替换系统代码misc/目录下的 boot_logo.bmp.gz文件那么简单;这种实现需要底层脚本文件来支持,流程是:将所有可能用到的开机Logo图片放到自己创建的apk中,通过打开这个apk的界面用ListView或者GridView去显示Logo图片,然后点击谁设置谁,点击之后通过代码把图片暂放到内部sdcard/根目录(这部分代码后面会贴出来,先把流程说完),然后调用chlogo.sh脚本服务去设置boot_logo.gz文件到misc分区,要确保chlogo.sh服务被启动调用,可到android\device\actions\s700_cb6\目录下的init.modules.rc文件中去添加如下代码即可:目录请以自己的系统代码目录为准!
service chlogo /system/bin/chlogo.sh
user root
    disabled

    oneshot


chlogo.sh脚本文件的内容如下:

#!/system/bin/sh
mount -o rw,remount /dev/block/MISC
#mkdir /storage/sdcard/bootlogo
#cp /storage/sdcard/boot_logo.bmp /storage/sdcard/bootlogo/boot_logo.bmp
gzip -9 /storage/sdcard/boot_logo.bmp
mv /storage/sdcard/boot_logo.bmp.gz /misc/boot_logo.bmp.gz
mount -o ro,remount /dev/block/MISC

点击列表中图片把图片暂放到内部sdcard/根目录的代码如下:

private void setBootLogo(int resId) {
		
		mBitLogo = ((BitmapDrawable) getResources().getDrawable(resId)).getBitmap();
		
		if(mBitLogo != null) {
			
			saveLogoPic(mBitLogo);
			SystemProperties.set("ctl.start", "chlogo");// �������ýű�chlogo
			//�ȴ�ű����
			int nCount = 0;
			final int nMaxCount = 60;
while("running".equalsIgnoreCase(SystemProperties.get("init.svc.chlogo","stopped")) 
					&& nCount < nMaxCount ){
				nCount++;
				SystemClock.sleep(50);
				String tmp2 =SystemProperties.get("init.svc.chlogo","stopped");
				
			}
			if (nCount<nMaxCount) {
				Toast.makeText(mContext, R.string.alert_set_success, Toast.LENGTH_LONG).show();
				mContext.finish();
			}
else {
				Toast.makeText(mContext, R.string.alert_set_fail, Toast.LENGTH_LONG).show();	
			}
			
		}else {
			
			
		}
		
	}


public void saveLogoPic(Bitmap bitmap) {

		if (bitmap != null) {
			int w = bitmap.getWidth(), h = bitmap.getHeight();	
			int[] pixels = new int[w * h];
			bitmap.getPixels(pixels, 0, w, 0, 0, w, h);

			byte[] rgb = addBMP_RGB_888(pixels, w, h);
			byte[] header = addBMPImageHeader(rgb.length);
			byte[] infos = addBMPImageInfosHeader(w, h);
byte[] buffer = new byte[54 + rgb.length];
			System.arraycopy(header, 0, buffer, 0, header.length);
			System.arraycopy(infos, 0, buffer, 14, infos.length);
			System.arraycopy(rgb, 0, buffer, 54, rgb.length);

			File f = new File(LOGO_ROOT_PATH + LogoPicName_bmp);
			if (f.exists()) {
				f.delete();
			}
try {
				FileOutputStream fos = new FileOutputStream(f);
				fos.write(buffer);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//util.runtimeCommand("gzip -9 " + LOGO_ROOT_PATH + LogoPicName);
		//savePNG();//����png add by 66126
		
	}

private static byte[] addBMPImageHeader(int size) {
			byte[] buffer = new byte[14];
			// magic number 'BM'
			buffer[0] = 0x42;
			buffer[1] = 0x4D;
			// ��¼��С
			buffer[2] = (byte) (size >> 0);
			buffer[3] = (byte) (size >> 8);
			buffer[4] = (byte) (size >> 16);
			buffer[5] = (byte) (size >> 24);
buffer[6] = 0x00;
			buffer[7] = 0x00;
			buffer[8] = 0x00;
			buffer[9] = 0x00;
			buffer[10] = 0x36;
			buffer[11] = 0x00;
			buffer[12] = 0x00;
			buffer[13] = 0x00;
			return buffer;
		}


private byte[] addBMP_RGB_888(int[] b, int w, int h) {
			int len = b.length;
			System.out.println(b.length);
			byte[] buffer = new byte[w * h * 3];
			int offset = 0;
			for (int i = len - 1; i >= w; i -= w) {
				// DIB�ļ���ʽ���һ��Ϊ��һ�У�ÿ�а�������˳��
				int end = i, start = i - w + 1;
for (int j = start; j <= end; j++) {
					buffer[offset] = (byte) (b[j] >> 0);
					buffer[offset + 1] = (byte) (b[j] >> 8);
					buffer[offset + 2] = (byte) (b[j] >> 16);
					offset += 3;
				}
			}
			return buffer;
		}

private static byte[] addBMPImageInfosHeader(int w, int h) {
			byte[] buffer = new byte[40];
			// ����ǹ̶��� BMP ��ϢͷҪ40���ֽ�
			buffer[0] = 0x28;
			buffer[1] = 0x00;
			buffer[2] = 0x00;
			buffer[3] = 0x00;
			// ��� ��λ�������ǰ��λ�� ��λ������ź��λ��
			buffer[4] = (byte) (w >> 0);
			buffer[5] = (byte) (w >> 8);
			buffer[6] = (byte) (w >> 16);
			buffer[7] = (byte) (w >> 24);
// ���� ͬ��
			buffer[8] = (byte) (h >> 0);
			buffer[9] = (byte) (h >> 8);
			buffer[10] = (byte) (h >> 16);
			buffer[11] = (byte) (h >> 24);
			// ���DZ�����Ϊ1
			buffer[12] = 0x01;
			buffer[13] = 0x00;
			// ������ ���� 32λ����һ������ �����ͬ�ķ�ʽ(ARGB 32λ RGB24λ��ͬ��!!!!)
			buffer[14] = 0x18;
			buffer[15] = 0x00;
			// 0-��ѹ�� 1-8bitλͼ
			// 2-4bitλͼ 3-16/32λͼ
			// 4 jpeg 5 png
buffer[16] = 0x00;
			buffer[17] = 0x00;
			buffer[18] = 0x00;
			buffer[19] = 0x00;
			// ˵��ͼ���С
			buffer[20] = 0x00;
			buffer[21] = 0x00;
			buffer[22] = 0x00;
			buffer[23] = 0x00;
			// ˮƽ�ֱ���
			buffer[24] = (byte) 0xc3;
			buffer[25] = 0x0e;
			buffer[26] = 0x00;
			buffer[27] = 0x00;
// ��ֱ�ֱ���
			buffer[28] = (byte) 0xc3;
			buffer[29] = 0x0e;
			buffer[30] = 0x00;
			buffer[31] = 0x00;
			// 0 ʹ�����еĵ�ɫ����
			buffer[32] = 0x00;
			buffer[33] = 0x00;
			buffer[34] = 0x00;
			buffer[35] = 0x00;
// ������ɫ����
			buffer[36] = 0x00;
			buffer[37] = 0x00;
			buffer[38] = 0x00;
			buffer[39] = 0x00;
			return buffer;
		}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值