新建一个app,用于选择开机用那个动画
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/rg_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/rb_anmi_sound_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/animation_sound_sn_1" />
<RadioButton
android:id="@+id/rb_anmi_sound_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/animation_sound_sn_2" />
<RadioButton
android:id="@+id/rb_anmi_sound_3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/animation_sound_sn_3" />
</RadioGroup>
</LinearLayout>
主activity
package com.sprd.bootres;
import android.util.Log;
import android.os.Bundle;
import android.os.SystemProperties;
import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import android.content.Intent;
public class BootResSelectActivity extends Activity {
public static final String TAG = "BootResSelcetActivity";
public static final int KEY_BOOTANIMATION1_VALUE = 0;// 默认启动动画和声音
public static final int KEY_BOOTANIMATION2_VALUE = 1;// 第二套动画和声音
public static final int KEY_BOOTANIMATION3_VALUE = 2;
//add by ouqijiang,2015-04-21 begin
public static final int KEY_BOOTANIMATION4_VALUE = 3;
//add by ouqijiang,2015-04-21 end
public static final byte BOOT_LOG_1 = 1;
public static final byte BOOT_LOG_2 = 2;
public static final byte BOOT_LOG_3 = 3;
//add by ouqijiang,2015-04-21 begin
public static final byte BOOT_LOG_4 = 4;
//add by ouqijiang,2015-04-21 end
private RadioGroup rgSelectStorage = null;
private RadioButton mRadioButton = null;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.xml.main_3);
initComponent();
}
private void writeProductinfo(int logo_choice) {
File logo_choiceFile = new File("/productinfo/", "logo_choice.file");
FileWriter fw = null;
try {
try {
fw = new FileWriter(logo_choiceFile);
fw.write(String.valueOf(logo_choice));
fw.write("");
if (SystemProperties.getBoolean("persist.sys.M7.h.sn",false)) {
Intent intent = new Intent("com.hyst.switch.animal");
getApplicationContext().sendBroadcast(intent);
}
} finally {
fw.close();
}
} catch (Exception e) {
Log.e(TAG, "Exception Occured: Trying to write logo_choice.file "
+ e.toString());
}
}
private void initComponent() {
rgSelectStorage = (RadioGroup) findViewById(R.id.rg_group);
switch (SystemProperties.getInt("persist.sys.bootanimation", 0)) {
case KEY_BOOTANIMATION1_VALUE:
mRadioButton = (RadioButton) findViewById(R.id.rb_anmi_sound_1);
mRadioButton.setChecked(true);
break;
case KEY_BOOTANIMATION2_VALUE:
mRadioButton = (RadioButton) findViewById(R.id.rb_anmi_sound_2);
mRadioButton.setChecked(true);
break;
case KEY_BOOTANIMATION3_VALUE:
mRadioButton = (RadioButton) findViewById(R.id.rb_anmi_sound_3);
mRadioButton.setChecked(true);
break;
case KEY_BOOTANIMATION4_VALUE:
mRadioButton = (RadioButton) findViewById(R.id.rb_anmi_sound_4);
mRadioButton.setChecked(true);
break;
default:
break;
}
rgSelectStorage
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rb_anmi_sound_1:
Log.d(TAG, "use animation "
+ KEY_BOOTANIMATION1_VALUE);
SystemProperties.set("persist.sys.bootanimation",
Integer.toString(KEY_BOOTANIMATION1_VALUE));
writeProductinfo(BOOT_LOG_1);
break;
case R.id.rb_anmi_sound_2:
Log.d(TAG, "use animation "
+ KEY_BOOTANIMATION2_VALUE);
SystemProperties.set("persist.sys.bootanimation",
Integer.toString(KEY_BOOTANIMATION2_VALUE));
writeProductinfo(BOOT_LOG_2);
break;
case R.id.rb_anmi_sound_3:
Log.d(TAG, "use animation "
+ KEY_BOOTANIMATION3_VALUE);
SystemProperties.set("persist.sys.bootanimation",
Integer.toString(KEY_BOOTANIMATION3_VALUE));
writeProductinfo(BOOT_LOG_3);
break;
case R.id.rb_anmi_sound_4:
Log.d(TAG, "use animation "
+ KEY_BOOTANIMATION4_VALUE);
SystemProperties.set("persist.sys.bootanimation",
Integer.toString(KEY_BOOTANIMATION4_VALUE));
writeProductinfo(BOOT_LOG_4);
break;
}
}
});
}
}
下边是开机动画切换的重点代码
在frameworks/base/cmds/bootanimation bootanimation_main.cpp中
if (argc<2){
String8 bootanimation_path;
String8 bootanimation_sound_path;
if (atoi(value1) == 0) {
bootanimation_path = BOOTANIMATION_BOOT_FILM_PATH_DEFAULT;
bootanimation_sound_path = BOOTANIMATION_BOOT_SOUND_PATH_DEFAULT;
} else if (atoi(value1) == 1) {
bootanimation_path = BOOTANIMATION_BOOT_FILM_PATH_DEFAULT_2;
bootanimation_sound_path = BOOTANIMATION_BOOT_SOUND_PATH_DEFAULT_2;
} else if (atoi(value1) == 2) {
bootanimation_path = BOOTANIMATION_BOOT_FILM_PATH_DEFAULT_3;
bootanimation_sound_path = BOOTANIMATION_BOOT_SOUND_PATH_DEFAULT_3;
} else if (atoi(value1) == 3) {
bootanimation_path = BOOTANIMATION_BOOT_FILM_PATH_DEFAULT_4;
bootanimation_sound_path = BOOTANIMATION_BOOT_SOUND_PATH_DEFAULT_4;
}else {
bootanimation_path = BOOTANIMATION_BOOT_FILM_PATH_DEFAULT;
bootanimation_sound_path = BOOTANIMATION_BOOT_SOUND_PATH_DEFAULT;
}
String8 mpath_default(bootanimation_path);
String8 spath_default(bootanimation_sound_path);
boota->setmoviepath_default(mpath_default);
boota->setsoundpath_default(spath_default);
//boota->setdescname_default(descname_default);
boota->setShutdownAnimation(false);
} else {
String8 bootanimation_path;
String8 bootanimation_sound_path;
if (atoi(value1) == 0) {
bootanimation_path = BOOTANIMATION_SHUTDOWN_FILM_PATH_DEFAULT;
bootanimation_sound_path = BOOTANIMATION_SHUTDOWN_SOUND_PATH_DEFAULT;
} else if (atoi(value1) == 1) {
bootanimation_path = BOOTANIMATION_SHUTDOWN_FILM_PATH_DEFAULT_2;
bootanimation_sound_path = BOOTANIMATION_SHUTDOWN_SOUND_PATH_DEFAULT_2;
} else if (atoi(value1) == 2) {
bootanimation_path = BOOTANIMATION_SHUTDOWN_FILM_PATH_DEFAULT_3;
bootanimation_sound_path = BOOTANIMATION_SHUTDOWN_SOUND_PATH_DEFAULT_3;
} else if (atoi(value1) == 3) {
bootanimation_path = BOOTANIMATION_SHUTDOWN_FILM_PATH_DEFAULT_4;
bootanimation_sound_path = BOOTANIMATION_SHUTDOWN_SOUND_PATH_DEFAULT_4;
} else {
bootanimation_path = BOOTANIMATION_SHUTDOWN_FILM_PATH_DEFAULT;
bootanimation_sound_path = BOOTANIMATION_SHUTDOWN_SOUND_PATH_DEFAULT;
}
关机动画同理
切换了开机动画就要切换开机Logo
在u-boot/property normal_emc_mode.c中
_boot_display_logo函数中
//logo choice start
int ret;
ret = boot_logo_choice();
if(ret == 1){
if(!_boot_partition_read(dev, L"logo", 0, size, bmp_img))
{
debugf("%s: read logo partition failed!\n",__FUNCTION__);
goto end;
}
} else if(ret == 2){
if(!_boot_partition_read(dev, L"fbootlogo", 0, size, bmp_img))
{
debugf("%s: read logo partition failed!\n",__FUNCTION__);
goto end;
}
} else if(ret == 3){
if(!_boot_partition_read(dev, L"logo3", 0, size, bmp_img))
{
debugf("%s: read logo partition failed!\n",__FUNCTION__);
goto end;
}
}else if(ret == 4){
if(!_boot_partition_read(dev, L"logo4", 0, size, bmp_img))
{
debugf("%s: read logo partition failed!\n",__FUNCTION__);
goto end;
}
}
//logo choice end
//logo choice start
int boot_logo_choice()
{
char log_choice_buf[8]={0};
int ret = 1;
if ( do_fs_file_read("prodnv","/logo_choice.file",log_choice_buf,8)) {
return 1;
}
if(!strcmp(log_choice_buf, "1")) {
ret = 1;
}else if (!strcmp(log_choice_buf, "2")) {
ret = 2;
}else if (!strcmp(log_choice_buf, "3")) {
ret = 3;
}else if (!strcmp(log_choice_buf, "4")) {
ret = 4;
}
return ret;
}
//logo choice end
简单的流程就这么多。