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 】
相关推荐:
Laravel怎么发送邮件_Laravel Mail类SMTP配置教程
什么是javascript作用域_全局和局部作用域有什么区别?
大连 网站制作,大连天途有线官网?
Laravel Eloquent模型如何创建_Laravel ORM基础之Model创建与使用教程
JavaScript常见的五种数组去重的方式
Laravel软删除怎么实现_Laravel Eloquent SoftDeletes功能使用教程
Laravel distinct去重查询_Laravel Eloquent去重方法
深圳防火门网站制作公司,深圳中天明防火门怎么编码?
Laravel如何设置自定义的日志文件名_Laravel根据日期或用户ID生成动态日志【技巧】
详解jQuery停止动画——stop()方法的使用
Laravel如何优雅地处理服务层_在Laravel中使用Service层和Repository层
Laravel怎么多语言本地化设置_Laravel语言包翻译与Locale动态切换【手册】
如何快速搭建高效WAP手机网站?
通义万相免费版怎么用_通义万相免费版使用方法详细指南【教程】
HTML5空格和nbsp有啥关系_nbsp的作用及使用场景【说明】
Claude怎样写约束型提示词_Claude约束提示词写法【教程】
html5如何设置样式_HTML5样式设置方法与CSS应用技巧【教程】
Laravel如何清理系统缓存命令_Laravel清除路由配置及视图缓存的方法【总结】
Laravel怎么集成Log日志记录_Laravel单文件与每日日志配置及自定义通道【详解】
中山网站推广排名,中山信息港登录入口?
laravel怎么配置Redis作为缓存驱动_laravel Redis缓存配置教程
怎么制作网站设计模板图片,有电商商品详情页面的免费模板素材网站推荐吗?
C语言设计一个闪闪的圣诞树
Edge浏览器如何截图和滚动截图_微软Edge网页捕获功能使用教程【技巧】
Laravel怎么做缓存_Laravel Cache系统提升应用速度的策略与技巧
PHP正则匹配日期和时间(时间戳转换)的实例代码
PHP 500报错的快速解决方法
怎样使用JSON进行数据交换_它有什么限制
免费的流程图制作网站有哪些,2025年教师初级职称申报网上流程?
香港服务器租用费用高吗?如何避免常见误区?
Laravel如何实现API版本控制_Laravel版本化API设计方案
Android GridView 滑动条设置一直显示状态(推荐)
Laravel中间件起什么作用_Laravel Middleware请求生命周期与自定义详解
java ZXing生成二维码及条码实例分享
CSS3怎么给轮播图加过渡动画_transition加transform实现【技巧】
图册素材网站设计制作软件,图册的导出方式有几种?
猎豹浏览器开发者工具怎么打开 猎豹浏览器F12调试工具使用【前端必备】
Linux虚拟化技术教程_KVMQEMU虚拟机安装与调优
Laravel如何实现模型的全局作用域?(Global Scope示例)
Laravel如何使用Contracts(契约)进行编程_Laravel契约接口与依赖反转
Laravel Docker环境搭建教程_Laravel Sail使用指南
公司网站制作价格怎么算,公司办个官网需要多少钱?
Laravel如何操作JSON类型的数据库字段?(Eloquent示例)
Laravel如何优化应用性能?(缓存和优化命令)
Laravel storage目录权限问题_Laravel文件写入权限设置
如何在万网ECS上快速搭建专属网站?
Edge浏览器提示“由你的组织管理”怎么解决_去除浏览器托管提示【修复】
Windows10电脑怎么设置虚拟光驱_Win10右键装载ISO镜像文件
如何正确下载安装西数主机建站助手?
HTML透明颜色代码怎么让图片透明_给img元素加透明色的技巧【方法】

