Android 修改系统关机动画的实现
程序员文章站
2024-03-05 10:04:48
在android 系统移植做自己的移动设备,肯定会遇到更改开机或者关机画面,配置自己产品logo 这点是必须的,这些都要在...
在android 系统移植做自己的移动设备,肯定会遇到更改开机或者关机画面,配置自己产品logo 这点是必须的,这些都要在源码中修改,然后编译,下面给大家介绍个关机动画修改,一个简单示例!
文件路径:frameworks\base\services\core\java\com\android\server\power\shutdownthread.java
在beginshutdownsequence()方法中:
private static void beginshutdownsequence(context context) { ...... 3 // throw up an indeterminate system dialog to indicate radio is // shutting down. //*********************** 系统默认的dialog *********************** /*progressdialog pd = new progressdialog(context); pd.settitle(context.gettext(com.android.internal.r.string.power_off)); pd.setmessage(context.gettext(com.android.internal.r.string.shutdown_progress)); pd.setindeterminate(true); pd.setcancelable(false); pd.getwindow().settype(windowmanager.layoutparams.type_keyguard_dialog); pd.show();*/ //*********************** 替换为自定义的全屏dialog *********************** point outsize = new point(); dialog dialog = new dialog(context, android.r.style.theme_black_notitlebar_fullscreen); indeterminateprogressbar view = new indeterminateprogressbar(context); dialog.getwindow().settype(windowmanager.layoutparams.type_keyguard_dialog); dialog.getwindow().getwindowmanager().getdefaultdisplay().getsize(outsize); //获取屏幕宽高 dialog.setcontentview(view, new layoutparams(outsize.x, outsize.y)); //设置自定义view宽高为全屏 dialog.show(); ...... }
注意:必须要设置 dialog.getwindow().settype(windowmanager.layoutparams.type_keyguard_dialog); 之前忘了加导致什么都不显示
替换的自定义view:
class indeterminateprogressbar extends view { static final string tag = "progressbar"; private int delaymillis = 30; private handler mhandler; private arraylist<entity> entities; private int width = 0; // private int height = 0; private int r = 15; private int shift = 20; private int radius = 3; private int color = color.white; private long time = 0; private boolean started = false; public indeterminateprogressbar(context context) { super(context); init(); } @override protected void onlayout(boolean changed, int left, int top, int right, int bottom) { super.onlayout(changed, left, top, right, bottom); width = getlayoutparams().width / 2; // height = getlayoutparams().height; if (width > 0) { radius = width / 20; r = 2 * width / 5; //shift = width / 2; shift = width / 1; } } private void init() { setbackgroundresource(android.r.color.transparent); mhandler = new handler(new handler.callback() { @override public boolean handlemessage(message msg) { for (entity e : entities) { e.update(); } invalidate(); mhandler.sendemptymessagedelayed(0, delaymillis); time += delaymillis; return false; } }); } public void setcolor(int color) { this.color = color; } public void stop() { mhandler.removemessages(0); started = false; invalidate(); } public boolean isstart() { return started; } public void start() { if (started) return; started = true; time = 0; entities = new arraylist<indeterminateprogressbar.entity>(); float s = .25f; entities.add(new entity(0, color, 0)); entities.add(new entity(1 * s, color, delaymillis * 4)); entities.add(new entity(2 * s, color, delaymillis * 8)); entities.add(new entity(3 * s, color, delaymillis * 12)); entities.add(new entity(4 * s, color, delaymillis * 16)); // entities.add(new entity(5 * s, color, delaymillis * 20)); if (mhandler != null) mhandler.sendemptymessage(0); } @override protected void ondraw(canvas canvas) { if (entities != null && entities.size() > 0) { for (entity e : entities) { e.draw(canvas); } } super.ondraw(canvas); } class entity { private float x; private float y; private int color; private paint paint; private double sp = 0; private long delay; private int sec = 0; private float pec = 0; boolean visiable = true; public float getinterpolation(float input) { return (float) (math.cos((input + 1) * math.pi) / 2.0f) + 0.5f; } public entity(float sp, int color, int delay) { paint = new paint(); paint.setantialias(true); paint.setstyle(paint.style.fill); this.color = color; this.sp = sp; this.delay = delay; paint.setcolor(this.color); } public void update() { if (time < delay) return; visiable = true; pec += 0.03; if (pec > 1) { pec = 0; sec = ++sec == 3 ? 0 : sec; delay = sec == 0 ? time + delaymillis * 22 : time + delaymillis * 3; visiable = sec == 0 ? false : true; } double θ = math.pi * .5 + (sec == 0 ? 0 : sec * math.pi / sec) - (sec == 0 ? 0 : sp) + (math.pi * (sec == 1 ? 2 : 1) - (sec == 0 ? sp : 0) + (sec == 2 ? sp : 0)) * getinterpolation(pec); x = (float) (r / 2 * math.cos(θ)) + shift / 2; y = (float) (r / 2 * math.sin(θ)) + shift / 2; } public void draw(canvas canvas) { if (!visiable || x == 0 || y == 0) return; canvas.save(); canvas.translate(x, y); canvas.drawcircle(x, y, radius, paint); canvas.restore(); } } @override protected void onattachedtowindow() { super.onattachedtowindow(); if (getvisibility() == view.visible) { start(); } } @override protected void ondetachedfromwindow() { super.ondetachedfromwindow(); stop(); } public void setdelaymillis(int delaymillis) { this.delaymillis = delaymillis; } }
效果图:
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇: ASP.NET线程相关配置
下一篇: 详解Java中的 枚举与泛型