-
-
Save liluxdev/4495358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
package="sample.test" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="17" /> | |
<application | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" | |
android:allowBackup="false"> | |
<service android:name="SampleDreamService"> | |
<intent-filter> | |
<action android:name="android.service.dreams.DreamService" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> | |
<meta-data android:name="android.service.dream" android:resource="@xml/dream" /> | |
</service> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dream xmlns:android="https://schemas.android.com/apk/res/android" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.test; | |
import android.service.dreams.DreamService; | |
public class SampleDreamService extends DreamService { | |
@Override | |
public void onAttachedToWindow() { | |
super.onAttachedToWindow(); | |
setInteractive(false); | |
setFullscreen(true); | |
setContentView(new SampleView(this)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.test; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.util.Log; | |
import android.view.SurfaceHolder; | |
import android.view.SurfaceView; | |
public class SampleView extends SurfaceView implements SurfaceHolder.Callback { | |
private static final String TAG = "SampleView"; | |
private static final int[] colors = new int[]{ | |
Color.RED, | |
Color.WHITE, | |
Color.BLUE, | |
Color.GREEN, | |
Color.YELLOW | |
}; | |
private int width; | |
private int height; | |
private SurfaceHolder holder; | |
public SampleView(Context ctx) { | |
super(ctx); | |
holder = getHolder(); | |
holder.addCallback(this); | |
} | |
@Override | |
public void surfaceCreated(SurfaceHolder holder2) { | |
Log.v(TAG, "surfaceCreated"); | |
new Thread() { | |
@Override | |
public void run() { | |
Paint paint = new Paint(); | |
paint.setAntiAlias(true); | |
Canvas c = null; | |
while (true) { | |
c = holder.lockCanvas(); | |
if (c == null) { | |
break; | |
} | |
float x = (float)(Math.random() * width); | |
float y = (float)(Math.random() * height); | |
paint.setColor(getColor()); | |
c.drawCircle(x, y, 5f, paint); | |
holder.unlockCanvasAndPost(c); | |
} | |
} | |
}.start(); | |
} | |
@Override | |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { | |
Log.v(TAG, "surfaceChanged"); | |
this.width = width; | |
this.height = height; | |
} | |
@Override | |
public void surfaceDestroyed(SurfaceHolder holder) { | |
Log.v(TAG, "surfaceDestroyed"); | |
} | |
private int getColor() { | |
int color = (int)(Math.random() * colors.length); | |
return colors[color]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment