是否为Android(不锁定屏幕)编程屏幕保护程序是否可行?在Android中创建屏幕保护程序
我正在寻找关于编程屏幕保护程序的教程。屏幕保护程序将激活,因为用户什么都不做。如果用户触摸屏幕,屏幕保护程序将消失。这可能吗?
是否为Android(不锁定屏幕)编程屏幕保护程序是否可行?在Android中创建屏幕保护程序
我正在寻找关于编程屏幕保护程序的教程。屏幕保护程序将激活,因为用户什么都不做。如果用户触摸屏幕,屏幕保护程序将消失。这可能吗?
你可以在你的应用程序获得ACTION_SCREEN_OFF
与BroadcastReceiver
。在这个广播接收器的onReceive
方法,启动活动为screensaver
。而你可以注册一个听众touch events
,当这个事件发生时,完成你的应用程序。
Android Screen Saver Sample Code
首先尝试搜索答案要求的东西之前
我给屏幕保护程序摘录:评论将解释它。
requestWindowFeature(Window.FEATURE_NO_TITLE); ().WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN; Point res = new Point(); 。getWindowManager()getDefaultDisplay()的getSize(RES)。
DotsView myView = new DotsView(this,res.x,res.y);
setContentView(myView);
}
class DotsView extends View
{
int i = 0;Bitmap bmp;Canvas cnv;Rect bounds;Paint p;Random rnd;int width,height;
public DotsView(Context context ,int width ,int height)
{
super(context);
this.width = width;
this.height = height;
bmp = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
cnv = new Canvas(bmp);
bounds = new Rect(0 , 0, width,height);
p = new Paint();
rnd = new Random();
p.setColor(Color.RED);
p.setStyle(Paint.Style.FILL_AND_STROKE);
p.setDither(false);
p.setStrokeWidth(3);
p.setAntiAlias(true);
p.setColor(Color.parseColor("#CD5C5C"));
p.setStrokeWidth(15);
p.setStrokeJoin(Paint.Join.ROUND);
p.setStrokeCap(Paint.Cap.ROUND);
}
@Override
protected void onDraw(Canvas c)
{//Canvas c gets recycled , so drawing on it will keep erasing previous causing animation...we dont want that.
p.setColor(Color.argb(255, rnd.nextInt(255),rnd.nextInt(255), rnd.nextInt(255)));
//cnv is outside object canvas, so drawing on it will append, no recycle, we want that.
cnv.drawPoint(rnd.nextInt(width), rnd.nextInt(height), p);
//drawing on cnv canvas, draws on bitmap bmp
//c.drawBitmap(bmp,src_rect,dest_rect,paint):-
// crop as per src_rect(null means full), and scale to dest_rect, draw using paint object-null for 'as it is'.
c.drawBitmap(bmp, null, bounds , null);
//make onDraw() recursive but dont make blocking-loop & not indefinite condition
if(i<1000) { i++;invalidate(); }
要查看完整的代码在这里看到: - Code-Example-Screen-Saver-Colorful-Dots
感谢。我也找到了这个答案,但它不一样。他们在谈论锁屏,这对我的问题并没有什么帮助。 – goojr