本文实例为大家分享了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,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,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,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,434,120); canvas.drawRoundRect(rect,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,new int[] { mDefaultcolor,mDefaultcolor,mSlIDecolor,mDefaultcolor },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,new int[] {mSlIDecolor,mSlIDecolor},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仿苹果关机界面实现代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)