你的位置:首页 > 操作系统

[操作系统]修改Android系统关机动画


文件路径: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 + delayMillis113               * 3;114           visiable = sec == 0 ? false : true;115         }116         double θ = Math.PI117             * .5118             + (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 ? sp121                 : 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     @Override135     protected void onAttachedToWindow() {136       super.onAttachedToWindow();137       if (getVisibility() == View.VISIBLE) {138         start();139       }140     }141     @Override142     protected void onDetachedFromWindow() {143       super.onDetachedFromWindow();144       stop();145     }146     public void setDelayMillis(int delayMillis) {147       this.delayMillis = delayMillis;148     }149 }

效果图: