android开机动画切换
新建一個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
簡單的流程就這么多。
總結
以上是生活随笔為你收集整理的android开机动画切换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7下docker配置加速器
- 下一篇: 使用Navicat快速复制所有表的表名或