返回顶部
首页 > 资讯 > 精选 >Android仿苹果关机界面实现代码
  • 261
分享到

Android仿苹果关机界面实现代码

android关机界面roi 2023-05-30 20:05:17 261人浏览 八月长安
摘要

本文实例为大家分享了Android仿苹果关机界面的具体代码,供大家参考,具体内容如下主class 用来控制viewdialog的显示package com.android.server.policy; import android.ap

本文实例为大家分享了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;     }              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;     }   }   } 

--结束END--

本文标题: Android仿苹果关机界面实现代码

本文链接: https://lsjlt.com/news/221020.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作