Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.cornerofseven.android.lwp.paint;
import android.graphics.Paint;
import android.hardware.SensorManager;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;
/**
* PaintService
* Basic setup to create an Android Live Wallpaper.
* The goal is, by using the orientation sensors, have a wallpaper that paints
* based on the tilt of the phone. X- and Y-axis tilt will control which
* direction the paint moves.
* @author Christopher Kruse <chris@cornerofseven.com>
*
*/
public class PaintService extends WallpaperService {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public Engine onCreateEngine() {
return new PaintEngine();
}
class PaintEngine extends Engine {
private final Paint[] mCardinalPaints = new Paint[4];
private final Runnable mDrawWP = new Runnable(){
public void run() {
drawFrame();
}
};
private SensorManager mSensMgr =
(SensorManager) getSystemService(SENSOR_SERVICE);
PaintEngine(){
super();
setPaintProperties(mCardinalPaints);
}
private void setPaintProperties(Paint[] paints) {
paints[0].setARGB(255, 255, 0, 0);
paints[1].setARGB(255, 0, 0, 255);
paints[2].setARGB(255, 255, 255, 0);
paints[3].setARGB(255, 0, 255, 0);
for(Paint p : paints){
p.setAntiAlias(true);
p.setStrokeWidth(16);
p.setStrokeCap(Paint.Cap.ROUND);
p.setStyle(Paint.Style.FILL);
}
}
protected void drawFrame() {
// TODO Auto-generated method stub
}
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.