Modify the Android system shutdown animation and android shutdown Animation

Source: Internet
Author: User

Modify the Android system shutdown animation and android shutdown Animation

File Path: frameworks \ base \ services \ core \ java \ com \ android \ server \ power \ ShutdownThread. java

In the beginShutdownSequence () method:

1 private static void beginShutdownSequence (Context context) {2 ...... 3 // throw up an indeterminate system dialog to indicate radio is 4 // shutting down. 5 ********** * ************ 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 // ************************ with the custom full screen 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 (). getdefadisplay display (). getSize (outSize); // get the screen width and height 19 dialog. setContentView (view, new LayoutParams (outSize. x, outSize. y); // set the width and height of the custom view to 20 dialog in full screen mode. show (); 21 22 ...... 23}
Note: You must set dialog. getWindow (). setType (WindowManager. LayoutParams. TYPE_KEYGUARD_DIALOG). If you forget to add it, you will not display the replaced custom 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 }

:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.