comment it
This commit is contained in:
parent
7018143aaf
commit
5400a0d42d
|
@ -1,12 +1,19 @@
|
||||||
package org.er2.fireplace;
|
package org.er2.fireplace;
|
||||||
|
|
||||||
import android.service.dreams.DreamService;
|
import android.service.dreams.DreamService;
|
||||||
import android.widget.TextView;
|
|
||||||
|
/* Dream service to show fireplace on device
|
||||||
|
* instead of just black screen (useful for TVs).
|
||||||
|
*
|
||||||
|
* (c) Er2 2022 <er2@dismail.de>
|
||||||
|
* Zlib License
|
||||||
|
*/
|
||||||
|
|
||||||
public class Dream extends DreamService {
|
public class Dream extends DreamService {
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
setInteractive(false);
|
setInteractive(false);
|
||||||
setFullscreen(true);
|
setFullscreen(true);
|
||||||
setContentView(R.layout.dream);
|
setContentView(R.layout.dream);
|
||||||
|
|
|
@ -3,24 +3,34 @@ package org.er2.fireplace;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/* This file is a model and some controller in MVC pattern
|
||||||
|
*
|
||||||
|
* (c) Er2 <er2@dismail.de>
|
||||||
|
* Zlib License
|
||||||
|
*/
|
||||||
|
|
||||||
public class Fireplace {
|
public class Fireplace {
|
||||||
|
/* Characters and colors to use */
|
||||||
|
/* (yes I like comments in C style) */
|
||||||
private static String chr = "!\"#$%&*+,./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^_`~ ";
|
private static String chr = "!\"#$%&*+,./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^_`~ ";
|
||||||
private static int[] cols = {
|
private static int[] cols = {
|
||||||
|
/* 0x OPACITY hex
|
||||||
|
Because Android uses opacity before hex
|
||||||
|
*/
|
||||||
0xFFfdcf58,
|
0xFFfdcf58,
|
||||||
0xFFf27d0c,
|
0xFFf27d0c,
|
||||||
0xFFf07f13,
|
0xFFf07f13,
|
||||||
0xFF800909,
|
0xFF800909,
|
||||||
};
|
};
|
||||||
|
|
||||||
int fsize;
|
int fsize; /* Font size */
|
||||||
public int w, h, col;
|
public int w, h, col; /* width, height, columns */
|
||||||
ArrayList<Integer> fire;
|
ArrayList<Integer> fire; /* ArrayList is to allow resize */
|
||||||
Random rand;
|
Random rand; /* Some random :) */
|
||||||
|
|
||||||
int ind;
|
int ind, cid, hid; /* column INDex, Color InDex, cHaracter InDex */
|
||||||
int cid;
|
|
||||||
int hid;
|
|
||||||
|
|
||||||
|
/* Pls no comments */
|
||||||
public Fireplace() {
|
public Fireplace() {
|
||||||
fire = new ArrayList<Integer>();
|
fire = new ArrayList<Integer>();
|
||||||
rand = new Random();
|
rand = new Random();
|
||||||
|
|
|
@ -9,10 +9,17 @@ import android.util.AttributeSet;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
/* Fireplace frontend
|
||||||
|
* TODO: Optimize this..
|
||||||
|
*
|
||||||
|
* (c) Er2 2022 <er2@dismail.de>
|
||||||
|
* Zlib License
|
||||||
|
*/
|
||||||
|
|
||||||
public class FireplaceView extends View {
|
public class FireplaceView extends View {
|
||||||
Paint paint;
|
Paint paint; /* Android paint */
|
||||||
Fireplace fpl;
|
Fireplace fpl; /* Our backend */
|
||||||
Bitmap bmp;
|
Bitmap bmp; /* Screenshot of previous frame (thing to be optimized) */
|
||||||
|
|
||||||
public FireplaceView(Context ctx, AttributeSet attrs) {
|
public FireplaceView(Context ctx, AttributeSet attrs) {
|
||||||
super(ctx, attrs);
|
super(ctx, attrs);
|
||||||
|
@ -22,9 +29,14 @@ public class FireplaceView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawFire(Canvas canv) {
|
public void drawFire(Canvas canv) {
|
||||||
|
/* draw previous frame and apply transparency
|
||||||
|
thing to be optimized
|
||||||
|
*/
|
||||||
canv.drawBitmap(bmp, 0, 0, null);
|
canv.drawBitmap(bmp, 0, 0, null);
|
||||||
paint.setColor(0x1E000000);
|
paint.setColor(0x1E000000);
|
||||||
canv.drawRect(0, 0, getWidth(), getHeight(), paint);
|
canv.drawRect(0, 0, getWidth(), getHeight(), paint);
|
||||||
|
|
||||||
|
/* going through columns */
|
||||||
for(int i = 0; i < fpl.col; i++) {
|
for(int i = 0; i < fpl.col; i++) {
|
||||||
fpl.next();
|
fpl.next();
|
||||||
paint.setColor(fpl.getCol());
|
paint.setColor(fpl.getCol());
|
||||||
|
@ -39,6 +51,7 @@ public class FireplaceView extends View {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas c) {
|
public void onDraw(Canvas c) {
|
||||||
|
/* TODO: To be optimized */
|
||||||
Bitmap bip = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
|
Bitmap bip = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
Canvas canv = new Canvas(bip);
|
Canvas canv = new Canvas(bip);
|
||||||
drawFire(canv);
|
drawFire(canv);
|
||||||
|
@ -49,6 +62,7 @@ public class FireplaceView extends View {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int ow, int oh) {
|
protected void onSizeChanged(int w, int h, int ow, int oh) {
|
||||||
|
/* Set size directly */
|
||||||
fpl.setSize(w, h);
|
fpl.setSize(w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,12 @@ package org.er2.fireplace;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
/* Typical main activity file
|
||||||
|
*
|
||||||
|
* (c) Er2 2022 <er2@dismail.de>
|
||||||
|
* Zlib License
|
||||||
|
*/
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
Loading…
Reference in New Issue