Android仿苹果关机界面实现代码
发布时间 - 2026-01-11 03:20:39 点击率:次本文实例为大家分享了Android仿苹果关机界面的具体代码,供大家参考,具体内容如下

主class 用来控制viewdialog的显示
package com.android.server.policy;
import android.app.AlertDialog;
import android.app.StatusBarManager;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.util.Log;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
//import android.widget.SlideBar;
import com.android.internal.R;
import android.widget.ImageView;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
import android.util.Log;
import android.widget.FrameLayout;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.graphics.drawable.BitmapDrawable;
import android.view.Display;
import android.view.WindowManager;
//import com.android.internal.widget.SlideView;
//import android.view.WindowManagerPolicy.WindowManagerFuncs;
import android.view.WindowManagerPolicy.WindowManagerFuncs;
import android.view.Gravity;
import android.app.WallpaperManager;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
//added by wangchengju for shutdown
public class IphoneShutdownDialog {
private static String TAG = "IphoneShutdownDialog";
private int mStyleId;
private boolean mIsRestore = false;
private View view ;
private StatusBarManager mStatusBar;
private Context mContext;
private final WindowManagerFuncs mWindowManagerFuncs;//added by wangchengju for shutdown
private static final int MESSAGE_DISMISS = 0;
static final String SYSTEM_DIALOG_REASON_KEY = "reason";
static final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
int mdownx,mdowny;
boolean ispowerdown=false;
private WallpaperManager wpm;
private FrameLayout mgradientView;
private WindowManager mWindowManager;
private WindowManager.LayoutParams mFrameLayoutParams;
private FrameLayout mFrameLayout;
public IphoneShutdownDialog(Context context, WindowManagerFuncs windowManagerFuncs)
{
Log.d(TAG,"denghaigui construction");
mContext = context;
mWindowManagerFuncs = windowManagerFuncs;//added by wangchengju for shutdown
mStatusBar = (StatusBarManager)mContext.getSystemService(Context.STATUS_BAR_SERVICE);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_WALLPAPER_CHANGED);
context.registerReceiver(mBroadcastReceiver, filter);
wpm = (WallpaperManager) mContext.getSystemService(mContext.WALLPAPER_SERVICE);
}
public Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
// canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
/* public Drawable getBitmapDrawable(View views){
WindowManager windowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int w = display.getWidth();
int h = display.getHeight();
Bitmap Bmp = Bitmap.createBitmap( w, h, Config.ARGB_8888 );
View decorview = views.getWindow().getDecorView();
decorview.setDrawingCacheEnabled(true);
Bmp = decorview.getDrawingCache();
Drawable drawable =new BitmapDrawable(Bmp);
return drawable;
}*/
private void initWindowsView() {
if (mWindowManager == null)
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mFrameLayoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
mFrameLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;//
mFrameLayoutParams.format = PixelFormat.RGBA_8888;
resetWindowParamsFlags();
mFrameLayoutParams.gravity = Gravity.TOP | Gravity.START;
mFrameLayout = new FrameLayout(mContext);
mFrameLayout.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
mWindowManager.addView(mFrameLayout, mFrameLayoutParams);
}
private void resetWindowParamsFlags() {
mFrameLayoutParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
}
private void removeView(){
mFrameLayout.removeAllViews();
mWindowManager.removeViewImmediate(mFrameLayout);
view=null;
mFrameLayout = null;
mWindowManager = null;
}
public void showDialog(boolean keyguardShowing)
{
Log.d("PhoneShutdownDialog","denghaigui showDialog");
initWindowsView();
//create Dialog
if(view == null){
LayoutInflater inflater = LayoutInflater.from(mContext) ;
view = inflater.inflate(R.layout.iphone_shutdown_dialog, null, false) ;
mFrameLayout.addView(view);
Bitmap image = drawableToBitmap(wpm.getDrawable());
image = Blur.fastblur(mContext, image,25);
BitmapDrawable bt = new BitmapDrawable(image);
Blur.setDrawable(bt);
}else{
Log.d("PhoneShutdownDialog","denghaigui view is not null");
}
Drawable bt = Blur.getDrawable();
if(bt!=null){
view.setBackground(bt);
}
mgradientView = (FrameLayout)view.findViewById(R.id.gradientView_layout);
FrameLayout slide_shutdown = (FrameLayout)view.findViewById(R.id.slide_layout);
SlideView mslideview=new SlideView(mContext);
android.widget.FrameLayout.LayoutParams layoutparams = new android.widget.FrameLayout.LayoutParams(524, 150,Gravity.CENTER);
slide_shutdown.addView(mslideview,0,layoutparams);
final LinearLayout cancelShutdown = (LinearLayout)view.findViewById(R.id.cancelShutdown) ;
Button cancelShutdownBtn = (Button)view.findViewById(R.id.cancelShutdownBtn) ;
cancelShutdownBtn.setPressed(false);
cancelShutdownBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
removeView();
// playCloseAnimation(shutdownTab, cancelShutdown) ;
}
}) ;
//play open animation
// playOpenAnimation(shutdownTab, cancelShutdown) ;
mStatusBar.disable(StatusBarManager.DISABLE_EXPAND);
}
public void dismissDialog()
{
removeView();
mStatusBar.disable(StatusBarManager.DISABLE_NONE);
}
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
|| Intent.ACTION_SCREEN_OFF.equals(action)) {
String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
mHandler.sendEmptyMessage(MESSAGE_DISMISS);
}
}
if(action.equals(Intent.ACTION_WALLPAPER_CHANGED)){
Bitmap image = drawableToBitmap(wpm.getDrawable());
image = Blur.fastblur(context, image,25);
BitmapDrawable bt = new BitmapDrawable(image);
Blur.setDrawable(bt);
}
}
};
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == MESSAGE_DISMISS) {
if (view != null) {
dismissDialog();
}
}
}
};
public class SlideView extends View
{
public float mTouchX;
private Drawable mSlideDrawable;
public float mDownX,mdx;
private boolean isPower=false;
private Context mContext;
public SlideView(Context context, AttributeSet attrs) {
this(context);
}
public SlideView(Context context) {
super(context);
mContext=context;
mSlideDrawable = context.getResources().getDrawable(R.drawable.slide_touch_icon);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(mdx>374)mdx=374;
if(mdx<0)mdx=0;
Paint mPaint=new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.WHITE);
mPaint.setAlpha(200);
canvas.save();
Path path=new Path();
RectF rect=new RectF(mdx, 0, 434, 120);
canvas.drawRoundRect(rect, 72, 72, mPaint);
canvas.restore();
canvas.drawBitmap(((BitmapDrawable) mSlideDrawable).getBitmap(), mdx+5, 5,null);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
mDownX=ev.getX();
isPower=true;
//mgradientView.setVisibility(8);
break;
case MotionEvent.ACTION_MOVE:
mgradientView.setVisibility(8);
mTouchX = ev.getX();
if(mTouchX <= mDownX)
{
mdx=0;
mgradientView.setVisibility(0);
}
else
mdx=(mTouchX-mDownX);
invalidate();
if(mdx>374)
isPower=false;
else
isPower=true;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if(isPower==true){
mgradientView.setVisibility(0);
mdx=0;
invalidate();
}
else
mWindowManagerFuncs.shutdown(false);
break;
}
return true;
}
}
}
GradientPowerView.java 用来做滑块和写入滑块中的文字显示
package com.android.server.policy;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import com.android.internal.R;
import android.graphics.Typeface;
public class GradientPowerView extends View {
private static final String TAG = "GradientPowerView";
private static final boolean DEBUG = false;
private float mIndex = 0;
private Shader mShader;
private int mTextSize;
private static final int mUpdateStep = 15;
private static final int mMaxWidth = 40 * mUpdateStep; // 26*25
private static final int mMinWidth = 6 * mUpdateStep; // 5*25
int mDefaultColor;
int mSlideColor;
private ValueAnimator animator;
private int mWidth,mHeight;
private String mStringToShow;
private Paint mTextPaint;
private float mTextHeight;
private Drawable mSlideIcon;
private int mSlideIconHeight;
private static final int mSlideIconOffSetTop = 20;
private static final String ANDROID_CLOCK_FONT_FILE = "/system/fonts/ASans.ttf";
private AnimatorUpdateListener mAnimatorUpdateListener = new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mIndex =Float.parseFloat(animation.getAnimatedValue().toString());
// RadialGradient SweepGradient
mShader = new LinearGradient(mIndex - 20 * mUpdateStep, 100,
mIndex, 100, new int[] { mDefaultColor, mDefaultColor, mDefaultColor,mSlideColor,
mSlideColor, mDefaultColor, mDefaultColor, mDefaultColor }, null,
Shader.TileMode.CLAMP);
postInvalidate();
}
};
public GradientPowerView(Context context) {
super(context);
}
public GradientPowerView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GradientView);
mStringToShow = a.getString(R.styleable.GradientView_text) ;
mTextSize = (int)a.getDimension(R.styleable.GradientView_textSize, 40);
mDefaultColor = a.getColor(R.styleable.GradientView_textColor, Color.GRAY);
mSlideColor = a.getColor(R.styleable.GradientView_SlideColor, Color.WHITE);
mSlideIcon = context.getResources().getDrawable(R.drawable.slide_icon);
mSlideIconHeight = mSlideIcon.getMinimumHeight();
a.recycle();
animator = ValueAnimator.ofFloat(mMinWidth,mMaxWidth);
animator.setDuration(1800);
animator.addUpdateListener(mAnimatorUpdateListener);
animator.setRepeatCount(Animation.INFINITE);//repeat animation
animator.start();
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setColor(mSlideColor);
mTextPaint.setTextSize(mTextSize);
mTextPaint.setTextAlign(Paint.Align.CENTER);
// mTextPaint.setTypeface(Typeface.createFromFile(ANDROID_CLOCK_FONT_FILE));
mTextHeight = mTextPaint.ascent();
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
if(DEBUG)
Log.w(TAG, "b onDraw()");
mTextPaint.setShader(mShader);
Log.i("denghaigui","mWidth is: "+mWidth +"Height is: "+mHeight+ "mTextHeight: "+mTextHeight);
canvas.drawText(mStringToShow, (mWidth+30)/2, mHeight / 2 - mTextHeight
/ 2 - mSlideIconOffSetTop, mTextPaint); // slide_unlock
}
public void stopAnimatorAndChangeColor() {
//if(DEBUG)
Log.w(TAG, "stopGradient");
animator.cancel();
//reset
mShader = new LinearGradient(0, 100, mIndex, 100,
new int[] {mSlideColor, mSlideColor},
null, Shader.TileMode.CLAMP);
invalidate();
}
public void startAnimator() {
if(DEBUG)
Log.w(TAG, "startGradient");
animator.start();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mWidth = MeasureSpec.getSize(widthMeasureSpec);
mHeight = MeasureSpec.getSize(heightMeasureSpec);
}
public void resetControl(){
animator.start();
this.setX(0);
invalidate();
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# Android仿苹果关机界面
# Android关机界面
# Android苹果关机界面
# android实现短按电源键关机的实现代码
# Android平台预置GMS包后关机闹钟失效问题及解决方法
# Android实现关机后数据不会丢失问题
# Android 6.0开发实现关机菜单添加重启按钮的方法
# Android开发实现长按返回键弹出关机框功能
# Android 修改系统关机动画的实现
# Android下的CMD命令之关机重启及重启recovery
# Android实现关机与重启的几种方式(推荐)
# Android系统关机的全流程解析
# Android 实现关机的多种方式
# 滑块
# 大家分享
# 具体内容
# 大家多多
# OPAQUE
# canvas
# getOpacity
# bitmap
# drawableToBitmap
# createBitmap
# getIntrinsicHeight
# getIntrinsicWidth
# WINDOW_SERVICE
# windowManager
# display
# getWidth
# getDefaultDisplay
# views
# setBounds
# setBitmap
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
微信小程序 HTTPS报错整理常见问题及解决方案
Laravel如何创建自定义中间件?(Middleware代码示例)
Laravel如何使用Gate和Policy进行授权?(权限控制)
Win11应用商店下载慢怎么办 Win11更改DNS提速下载【修复】
胶州企业网站制作公司,青岛石头网络科技有限公司怎么样?
Laravel怎么在Blade中安全地输出原始HTML内容
制作无缝贴图网站有哪些,3dmax无缝贴图怎么调?
Laravel怎么配置自定义表前缀_Laravel数据库迁移与Eloquent表名映射【步骤】
佛山网站制作系统,佛山企业变更地址网上办理步骤?
Laravel如何与Vue.js集成_Laravel + Vue前后端分离项目搭建指南
Laravel如何获取当前用户信息_Laravel Auth门面获取用户ID
如何在万网主机上快速搭建网站?
如何在宝塔面板中修改默认建站目录?
Laravel用户认证怎么做_Laravel Breeze脚手架快速实现登录注册功能
今日头条微视频如何找选题 今日头条微视频找选题技巧【指南】
HTML5空格和nbsp有啥关系_nbsp的作用及使用场景【说明】
Zeus浏览器网页版官网入口 宙斯浏览器官网在线通道
怎样使用JSON进行数据交换_它有什么限制
Laravel Session怎么存储_Laravel Session驱动配置详解
详解一款开源免费的.NET文档操作组件DocX(.NET组件介绍之一)
php做exe能调用系统命令吗_执行cmd指令实现方式【详解】
Laravel怎么使用Session存储数据_Laravel会话管理与自定义驱动配置【详解】
Laravel如何集成第三方登录_Laravel Socialite实现微信QQ微博登录
如何续费美橙建站之星域名及服务?
如何快速搭建高效服务器建站系统?
Python函数文档自动校验_规范解析【教程】
php增删改查怎么学_零基础入门php数据库操作必知基础【教程】
Edge浏览器怎么启用睡眠标签页_节省电脑内存占用优化技巧
香港服务器选型指南:免备案配置与高效建站方案解析
高端云建站费用究竟需要多少预算?
如何在香港免费服务器上快速搭建网站?
微信小程序 canvas开发实例及注意事项
JavaScript如何实现路由_前端路由原理是什么
Laravel如何使用Livewire构建动态组件?(入门代码)
laravel服务容器和依赖注入怎么理解_laravel服务容器与依赖注入解析
Laravel如何生成API文档?(Swagger/OpenAPI教程)
微信小程序 input输入框控件详解及实例(多种示例)
免费的流程图制作网站有哪些,2025年教师初级职称申报网上流程?
Laravel如何使用Collections进行数据处理?(实用方法示例)
如何实现javascript表单验证_正则表达式有哪些实用技巧
网站设计制作书签怎么做,怎样将网页添加到书签/主页书签/桌面?
Laravel Eloquent:优雅地将关联模型字段扁平化到主模型中
详解Huffman编码算法之Java实现
网站制作免费,什么网站能看正片电影?
PHP怎么接收前端传的文件路径_处理文件路径参数接收方法【汇总】
如何在 React 中条件性地遍历数组并渲染元素
Java Adapter 适配器模式(类适配器,对象适配器)优缺点对比
Laravel如何设置定时任务(Cron Job)_Laravel调度器与任务计划配置
Laravel如何实现密码重置功能_Laravel密码找回与重置流程
Java遍历集合的三种方式

