小米水墨锁屏代码
来源:互联网 发布:数学软件那些好 编辑:程序博客网 时间:2024/04/27 14:33
效果图:
Ink_LockActivity.java
package com.aiai.www;import android.app.Activity;import android.app.KeyguardManager;import android.app.KeyguardManager.KeyguardLock;import android.content.Context;import android.content.Intent;import android.os.Bundle;public class Ink_LockActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);startService(new Intent(this, Ink_LockScreenService.class));EnableSystemKeyguard(false);}void EnableSystemKeyguard(boolean bEnable) {KeyguardManager mKeyguardManager = null;KeyguardLock mKeyguardLock = null;mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);mKeyguardLock = mKeyguardManager.newKeyguardLock("");if (bEnable)mKeyguardLock.reenableKeyguard();elsemKeyguardLock.disableKeyguard();}}
Ink_LockScreenActivity.java
package com.aiai.www;import com.aiai.www.Ink_LockScreenView.OnCompleteListener;import android.app.Activity;import android.content.BroadcastReceiver;import android.content.ComponentName;import android.content.ContentResolver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.os.Bundle;import android.provider.ContactsContract;import android.view.KeyEvent;import android.view.View;import android.view.Window;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Toast;public class Ink_LockScreenActivity extends Activity {private Ink_LockScreenView mInkView;private final String ACT_TIME_TICK = "android.intent.action.TIME_TICK";@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.requestWindowFeature(Window.FEATURE_NO_TITLE);// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,// WindowManager.LayoutParams.FLAG_FULLSCREEN);System.out.println("Ink_LockScreenActivity onCreate");//Ink_LockScreenView.istime24_flag = istime24();mInkView = new Ink_LockScreenView(this);//mInkView.setParentActivity(this);setContentView(mInkView);mInkView.setOnCompleteListener(new OnCompleteListener(){@Overridepublic void onComplete(){ Ink_LockScreenActivity.this.finish();/*Intent mIntent = new Intent( ); ComponentName comp = new ComponentName("com.android.mms", "ç±»å"); mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); startActivity(mIntent);*/}@Overridepublic void onEnterContact() {// TODO Auto-generated method stubInk_LockScreenActivity.this.finish();Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);startActivity(intent);}@Overridepublic void onEnterMms() {// TODO Auto-generated method stubInk_LockScreenActivity.this.finish();Intent intent = new Intent();intent = getPackageManager().getLaunchIntentForPackage("com.android.mms");startActivity(intent);}});}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubSystem.out.println("*************lockscreenviewactivity*********onKeyDown keyCode:"+keyCode);return true;//super.onKeyDown(keyCode, event);} @Overridepublic void onAttachedToWindow() {// TODO Auto-generated method stub//ç¦ç¨homeæé® this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);super.onAttachedToWindow();}@Overrideprotected void onStart() {// TODO Auto-generated method stubsuper.onStart();IntentFilter intentFilter = new IntentFilter(ACT_TIME_TICK);registerReceiver(mTimeUpdateBCR, intentFilter);}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();unregisterReceiver(mTimeUpdateBCR);}private BroadcastReceiver mTimeUpdateBCR = new BroadcastReceiver() {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stub System.out.println("time update in activity act:"+intent.getAction());if(intent.getAction().equals(ACT_TIME_TICK)){mInkView.invalidate();//mUpdateTimeListener.updateTime();} }};/*private boolean istime24() {ContentResolver cv = this.getContentResolver();String strTimeFormat = android.provider.Settings.System.getString(cv,android.provider.Settings.System.TIME_12_24);if (strTimeFormat.equals("24"))return true;elsereturn false;}*/}
Ink_LockScreenService.java
package com.aiai.www;import java.util.List; import android.app.ActivityManager;import android.app.Service;import android.content.BroadcastReceiver;import android.content.ComponentName;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.os.IBinder;import android.util.Log;public class Ink_LockScreenService extends Service {private final String ACT_SCREEN_OFF = "android.intent.action.SCREEN_OFF";//private final String ACT_SCREEN_ON = "android.intent.action.SCREEN_ON";//private final String ACT_TIME_TICK = "android.intent.action.TIME_TICK";@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generated method stub return null;}@Overridepublic void onCreate() {// TODO Auto-generated method stubsuper.onCreate();// register Broadcast IntentFilter intentFilter = new IntentFilter(ACT_SCREEN_OFF);registerReceiver(mScreenBCR, intentFilter);/*IntentFilter intentFilter2 = new IntentFilter(ACT_TIME_TICK);registerReceiver(mScreenBCR, intentFilter2);*/}@Overridepublic void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();unregisterReceiver(mScreenBCR);}private BroadcastReceiver mScreenBCR = new BroadcastReceiver() {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stub System.out.println("onReceive receive intent:"+intent);System.out.println("act:"+intent.getAction());if(intent.getAction().equals(ACT_SCREEN_OFF)){System.out.println("aa");try {Intent i = new Intent();i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setClass(context, Ink_LockScreenActivity.class);context.startActivity(i);} catch (Exception e) {// TODO: handle exception }}//else if(intent.getAction().equals(ACT_TIME_TICK)){System.out.println("bb");//mUpdateTimeListener.updateTime();} }};/*private UpdateTimeListener mUpdateTimeListener;public interface UpdateTimeListener{public void updateTime(); }*/}
Ink_LockScreenView.java
package com.aiai.www;import java.util.Calendar;import java.util.Date; import android.app.Activity;import android.content.ComponentName;import android.content.ContentResolver;import android.content.Context;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Rect;import android.graphics.drawable.BitmapDrawable;import android.text.format.DateFormat;import android.util.Log;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;public class Ink_LockScreenView extends View {private Bitmap Ink_bg, Ink_bar;private Bitmap Ink_time0, Ink_time1, Ink_time2, Ink_time3, Ink_time4, Ink_time5, Ink_time6, Ink_time7, Ink_time8, Ink_time9, Ink_timedot;private int hour=0;private int minute=0;//public static boolean istime24_flag=false; public Canvas mCanvas;private Paint mPaint;private int INK_BG_X = 0;private int INK_BG_Y = -20;private int INK_BAR_X = 0;private int INK_BAR_Y = 290;private int INK_BAR_TOUCH_AREA_Y1 = 340;private int INK_BAR_TOUCH_AREA_Y2 = 420;private int INK_BAR_UNLOCK_Y = 448;private int INK_TIME_X = 80;private int INK_TIME_Y = 360;private int INK_UNLOCK_AREA_X1 = 80;private int INK_UNLOCK_AREA_X2 = 254;private boolean isInited = false; enum BarState { STATE_NORMAL, STATE_PRESS, STATE_MOVE, STATE_UNLOCK, } private BarState mBarState = BarState.STATE_NORMAL; private float moveX = 0,moveY=0; private float premoveX = 0,premoveY=0; private float tmpX = 0,tmpY=0; private float movedX = 0,movedY=0;Activity mParentActivity;public Ink_LockScreenView(Context context) {super(context);// TODO Auto-generated constructor stub Ink_bg = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_bg);Ink_bar = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_bar);Ink_time0 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_0);Ink_time1 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_1);Ink_time2 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_2);Ink_time3 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_3);Ink_time4 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_4);Ink_time5 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_5);Ink_time6 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_6);Ink_time7 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_7);Ink_time8 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_8);Ink_time9 = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_9);Ink_timedot = BitmapFactory.decodeResource(this.getResources(), R.drawable.ink_time_dot);mPaint = new Paint(); /*mCanvas = new Canvas(Ink_bg);*/ }@Overrideprotected void onDraw(Canvas canvas) {// TODO Auto-generated method stubsuper.onDraw(canvas);System.out.println("onDraw isInited:"+isInited);if(!isInited){initDraw(canvas);}else{// draw background//canvas.drawColor(Color.BLUE);//canvas.drawBitmap(Ink_bg, INK_BG_X, INK_BG_Y, mPaint);if(mBarState == BarState.STATE_MOVE){canvas.drawBitmap(Ink_bg, INK_BG_X, INK_BG_Y, mPaint);canvas.drawBitmap(Ink_bar, INK_BAR_X, INK_BAR_Y+movedY, mPaint);timeDraw(canvas);}else //if(mBarState == BarState.STATE_NORMAL){canvas.drawBitmap(Ink_bg, INK_BG_X, INK_BG_Y, mPaint);canvas.drawBitmap(Ink_bar, INK_BAR_X, INK_BAR_Y, mPaint);timeinitDraw(canvas);}}}private void initDraw(Canvas canvas) {// TODO Auto-generated method stubcanvas.drawBitmap(Ink_bg, INK_BG_X, INK_BG_Y, mPaint);canvas.drawBitmap(Ink_bar, INK_BAR_X, INK_BAR_Y, mPaint);timeinitDraw(canvas);isInited = true;}private void timeGet() {Calendar c = Calendar.getInstance(); hour = c.get(Calendar.HOUR_OF_DAY); minute = c.get(Calendar.MINUTE); System.out.println("hour:"+hour+",minute:"+minute);}private void timeDraw(Canvas canvas) {timeGet();int tmpWidth=0;Bitmap[] timearr={Ink_time0,Ink_time1,Ink_time2,Ink_time3,Ink_time4,Ink_time5,Ink_time6,Ink_time7,Ink_time8,Ink_time9}; System.out.println("timeDraw"); int tmphour1 = hour/10; int tmphour2 = hour%10; int tmpmin1 = minute/10; int tmpmin2 = minute%10; //draw hourcanvas.drawBitmap(timearr[tmphour1], INK_TIME_X, INK_TIME_Y+movedY, mPaint);tmpWidth = timearr[tmphour1].getWidth();canvas.drawBitmap(timearr[tmphour2], INK_TIME_X+tmpWidth, INK_TIME_Y+movedY, mPaint);tmpWidth += timearr[tmphour2].getWidth();//draw dotcanvas.drawBitmap(Ink_timedot, INK_TIME_X+tmpWidth, INK_TIME_Y+movedY, mPaint);tmpWidth += timearr[tmphour2].getWidth();//draw minutecanvas.drawBitmap(timearr[tmpmin1], INK_TIME_X+tmpWidth, INK_TIME_Y+movedY, mPaint);tmpWidth += timearr[tmpmin1].getWidth();canvas.drawBitmap(timearr[tmpmin2], INK_TIME_X+tmpWidth, INK_TIME_Y+movedY, mPaint);//tmpWidth = timearr[tmphour2].getWidth(); }private void timeinitDraw(Canvas canvas) {timeGet();int tmpWidth=0;Bitmap[] timearr={Ink_time0,Ink_time1,Ink_time2,Ink_time3,Ink_time4,Ink_time5,Ink_time6,Ink_time7,Ink_time8,Ink_time9}; System.out.println("timeDraw"); int tmphour1 = hour/10; int tmphour2 = hour%10; int tmpmin1 = minute/10; int tmpmin2 = minute%10; //draw hourcanvas.drawBitmap(timearr[tmphour1], INK_TIME_X, INK_TIME_Y, mPaint);tmpWidth = timearr[tmphour1].getWidth();canvas.drawBitmap(timearr[tmphour2], INK_TIME_X+tmpWidth, INK_TIME_Y, mPaint);tmpWidth += timearr[tmphour2].getWidth();//draw dotcanvas.drawBitmap(Ink_timedot, INK_TIME_X+tmpWidth, INK_TIME_Y, mPaint);tmpWidth += timearr[tmphour2].getWidth();//draw minutecanvas.drawBitmap(timearr[tmpmin1], INK_TIME_X+tmpWidth, INK_TIME_Y, mPaint);tmpWidth += timearr[tmpmin1].getWidth();canvas.drawBitmap(timearr[tmpmin2], INK_TIME_X+tmpWidth, INK_TIME_Y, mPaint);//tmpWidth = timearr[tmphour2].getWidth();/*if(istime24_flag){}else{}*/}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stubSystem.out.println("*************lockscreenview*********onKeyDown keyCode:"+keyCode);return super.onKeyDown(keyCode, event);}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stubSystem.out.println("onTouchEvent");float ex = event.getX();float ey = event.getY();System.out.println("onTouchEvent ex="+ex+",ey="+ey);moveX = ex;moveY = ey; switch (event.getAction()){case MotionEvent.ACTION_DOWN: System.out.println("onTouchEvent ACTION_DOWN"); if(ey>=INK_BAR_TOUCH_AREA_Y1 && ey<=INK_BAR_TOUCH_AREA_Y2)mBarState = BarState.STATE_PRESS;break;case MotionEvent.ACTION_MOVE:System.out.println("onTouchEvent ACTION_MOVE");if (ey >= INK_BAR_TOUCH_AREA_Y1 && movedY >= 0){tmpX = moveX - premoveX;tmpY = moveY - premoveY;movedX = movedX + tmpX;movedY = movedY + tmpY;} if(ey>=INK_BAR_TOUCH_AREA_Y1&& movedY > 0){mBarState = BarState.STATE_MOVE;}else{mBarState = BarState.STATE_NORMAL;}break;case MotionEvent.ACTION_UP:movedX = 0;movedY = 0;premoveX = 0;premoveY = 0;if(ey>= INK_BAR_UNLOCK_Y){mBarState = BarState.STATE_UNLOCK;if (ex<INK_UNLOCK_AREA_X1&& ex>0){mCompleteListener.onEnterContact();}else if(ex<INK_UNLOCK_AREA_X2&& ex>INK_UNLOCK_AREA_X1){mCompleteListener.onComplete();}else{mCompleteListener.onEnterMms();}//mParentActivity.finish();/*Intent mIntent = new Intent( ); ComponentName comp = new ComponentName("å å", "ç±»å"); mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); startActivity(mIntent);*/return true;}else{mBarState = BarState.STATE_NORMAL;}System.out.println("onTouchEvent ACTION_UP");break;}premoveX = ex;premoveY = ey;this.postInvalidate(); super.onTouchEvent(event); return true;}/*public void setParentActivity(Activity parentAct) {// TODO Auto-generated method stubmParentActivity = parentAct;}*/private OnCompleteListener mCompleteListener;public void setOnCompleteListener(OnCompleteListener mCompleteListener){this.mCompleteListener = mCompleteListener;}public interface OnCompleteListener{public void onComplete();public void onEnterContact();public void onEnterMms();} }
androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.aiai.www" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.DISABLE_KEYGUARD" > </uses-permission> <uses-permission android:name="android.permission.WAKE_LOCK" > </uses-permission> <uses-permission android:name="android.permission.GET_TASKS" > </uses-permission> <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".Ink_LockActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".Ink_LockScreenService" > <intent-filter> <action android:name="android.intent.action.SCREEN_OFF" /> <!-- <action android:name="android.intent.action.TIME_TICK" /> --> </intent-filter> </service> <activity android:name=".Ink_LockScreenActivity" > <intent-filter> <action android:name="android.intent.action.TIME_TICK" /> </intent-filter> </activity> </application></manifest>
- 小米水墨锁屏代码
- 电子水墨屏-原理
- 水墨江南
- 水墨江南
- 关于小米的代码门
- 小米手机删除屏锁密码
- 水墨渲染初探
- 实时水墨渲染探究
- PS水墨字教程
- 《水墨青花》----徐志摩
- 花开倾城,水墨竹韵
- 小米整屏移动,小米2S
- 小米
- 小米手机保护套自动锁屏功能
- Android 仿小米锁屏实现九宫格解锁
- 中国传统风格水墨实时渲染
- flash 水墨表现(转)
- 水墨画布(InkCanvas)的使用
- 善者不辩 辩者不善
- java加密解密研究9、其他消息摘要算法
- Could not find method android.app.Activity.on.AttachedToWindow...
- 几种常见的排序算法---插入排序
- 面试记录
- 小米水墨锁屏代码
- 关于java的String的探讨
- linux系统下opencv中IplImage转换成QT中QImage并在label上显示
- Windows Azure
- 计算两个时间的相差天数。。
- 给UIImageview 添加边框 或者设置成圆角
- 从开发到测试
- uva 10916 - Factstone Benchmark
- 封装远程注入类CreateRemoteThreadEx