Compare commits

...

6 Commits

Author SHA1 Message Date
Er2 5400a0d42d comment it 2022-02-10 20:45:10 +03:00
Er2 7018143aaf bump version 2022-02-10 19:44:03 +03:00
Er2 3c6274a763 move if not exists 2022-02-10 19:39:53 +03:00
Er2 f040fa9862 make remake ;) 2022-01-15 15:23:41 +00:00
Er2 9bada7a940 reduce APK by 0.3KB 2022-01-14 19:56:04 +00:00
Er2 3e28db45df add screen 2022-01-14 18:57:24 +00:00
9 changed files with 118 additions and 82 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
bin/
gen/ gen/
*.keystore *.keystore
out.apk
*.tmp

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.er2.fireplace" package="org.er2.fireplace"
android:versionCode="1" android:versionCode="2"
android:versionName="1.0" android:versionName="1.01"
> >
<uses-sdk <uses-sdk
@ -10,10 +10,8 @@
android:targetSdkVersion="32" android:targetSdkVersion="32"
/> />
<!-- if want on TV:
android:banner="@drawable/banner"
-->
<application <application
android:banner="@drawable/banner"
android:icon="@drawable/icon" android:icon="@drawable/icon"
android:label="Fireplace" android:label="Fireplace"
> >

109
Makefile
View File

@ -1,89 +1,68 @@
NAME = Fireplace NAME = Fireplace
PROJ = org.er2.fireplace CLASS= org.er2.fireplace
ifeq ($TV,1) KEY_PATH = debug.keystore
SDK_VER = 24 KEY_NAME = androiddebugkey
SDK = 24.0.3 KEY_PASS = android
else
SDK_VER = 19
SDK = 19.1.0
endif
SDK_ROOT = ~/Android/Sdk SDK_VER = 24
JAVA_HOME:=$(if $(JAVA_HOME),$(JAVA_HOME),/usr/lib/jvm/java-1.11.0-openjdk-amd64) SDK = 24.0.3
SDK_ROOT = ~/Android/Sdk
JAVA_HOME = /usr/lib/jvm/java-1.11.0-openjdk-amd64
# Android framework, DO NOT REMOVE!
VEDBASE = $(SDK_ROOT)/platforms/android-$(SDK_VER)/android.jar VEDBASE = $(SDK_ROOT)/platforms/android-$(SDK_VER)/android.jar
ADB = $(SDK_ROOT)/platform-tools/adb # Tools
AAPT = $(SDK_ROOT)/build-tools/$(SDK)/aapt ADB = $(SDK_ROOT)/platform-tools/adb
DX = $(SDK_ROOT)/build-tools/$(SDK)/dx AAPT = $(SDK_ROOT)/build-tools/$(SDK)/aapt
ZIPALIGN=$(SDK_ROOT)/build-tools/$(SDK)/zipalign DX = $(SDK_ROOT)/build-tools/$(SDK)/dx
ZIPALIGN = $(SDK_ROOT)/build-tools/$(SDK)/zipalign
JAVAC = $(JAVA_HOME)/bin/javac JAVAC = $(JAVA_HOME)/bin/javac
JARSIGNER = $(JAVA_HOME)/bin/jarsigner JARSIGNER = $(JAVA_HOME)/bin/jarsigner
PWD=$(shell pwd) SRC = $(shell find src/ -name '*.java')
CLSS= $(SRC:src/%.java=gen/%.class)
OUT=$(PWD)/bin all: build
GEN=$(PWD)/gen build: out.apk
RES=$(PWD)/res
SRC=$(PWD)/src
#ASS=$(PWD)/assets
SRCS=$(shell find $(SRC) -name '*.java') out.apk: AndroidManifest.xml gen/classes.dex $(KEY_PATH)
CLSS=$(SRCS:$(SRC)/%.java=$(GEN)/%.class) @$(AAPT) p -I $(VEDBASE) -fM AndroidManifest.xml -S res/ -F $@.tmp
@cp gen/classes.dex . && $(AAPT) a $@.tmp classes.dex && rm -f classes.dex
@$(JARSIGNER) -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' $@.tmp $(KEY_NAME)
@$(ZIPALIGN) -f 4 $@.tmp $@
KEY_PATH ?= debug.keystore -@if [ ! -r "$@" ]; then mv -f $@.tmp $@; fi
KEY_NAME ?= androiddebugkey
KEY_PASS ?= android
all: debug gen/classes.dex: prepare $(CLSS)
-@echo removing R classes to economy some space
@find gen/ -name 'R.class' -exec rm {} \;
@find gen/ -name 'R$$*.class' -exec rm {} \;
@$(DX) --dex --output=$@ gen/
debug: ### Helpers
@$(MAKE) DEBUG=true -C $(PWD) build
release: prepare: res/*
@$(MAKE) -C $(PWD) build -@echo Generating R.java
@mkdir -p gen
@$(AAPT) p -I $(VEDBASE) -fm -M AndroidManifest.xml -J gen -S res
APK=$(OUT)/$(NAME).apk gen/%.class: src/%.java
CDX=$(OUT)/classes.dex
build: $(APK)
$(APK): $(CDX) package sign zip
@if [ ! -f "$(APK)" ]; then mv $(OUT)/$(NAME).ap_ $(APK); fi
@$(RM) $(OUT)/$(NAME).ap_
prepare: clean
@mkdir -p $(OUT) $(GEN)
@$(AAPT) > /dev/null 2>&1; if ! [ $$? -ne 0 ]; then echo YOU NEED TO install lib32stdc++6 lib32z1; exit 1; fi
@$(AAPT) p $(if $(DEBUG),--debug-mode,) -I $(VEDBASE) -fm -M $(PWD)/AndroidManifest.xml -J $(GEN) -S $(RES)
$(CDX):
# dependencies is here to not re-build on every make
@make -C $(PWD) prepare $(CLSS)
@$(DX) --dex --output=$@ $(GEN)
$(GEN)/%.class: $(SRC)/%.java
-@echo Recompiling $@ -@echo Recompiling $@
@$(JAVAC) $(if $(DEBUG),-g,) -classpath $(VEDBASE) -sourcepath 'src:$(GEN)' -d '$(GEN)' -target 1.7 -source 1.7 $< @$(JAVAC) -classpath $(VEDBASE) -sourcepath 'src/:gen/' -d 'gen/' $< -source 1.7 -target 1.7 > /dev/null 2>&1
package: $(CDX) AndroidManifest.xml
@$(AAPT) p $(if $(DEBUG),--debug-mode,) -I $(VEDBASE) -f -M $(PWD)/AndroidManifest.xml -S $(RES) -F $(OUT)/$(NAME).ap_ # -A $(ASS)
@cd $(OUT) && $(AAPT) a $(NAME).ap_ classes.dex
sign: package $(KEY_PATH)
@$(JARSIGNER) -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' $(OUT)/$(NAME).ap_ $(KEY_NAME)
zip: package
@$(ZIPALIGN) -f 4 $(OUT)/$(NAME).ap_ $(APK)
$(KEY_PATH): $(KEY_PATH):
@yes | keytool -genkey -v -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' -alias $(KEY_NAME) -keypass $(KEY_PASS) -keyalg RSA -keysize 2048 -validity 10000 @yes | keytool -genkey -v -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' -alias $(KEY_NAME) -keypass $(KEY_PASS) -keyalg RSA -keysize 2048 -validity 10000
### Tools
clean: clean:
@rm -rf $(OUT) $(GEN) rm -rf gen/ classes.dex out.apk out.apk.tmp
run: $(OUT)/$(NAME).apk deploy: out.apk
-@$(ADB) uninstall $(PROJ) -@$(ADB) uninstall $(CLASS)
@$(ADB) install $^ @$(ADB) install $<
@$(ADB) shell monkey -p $(PROJ) -c android.intent.category.LAUNCHER 1 @$(ADB) shell monkey -p $(CLASS) -c android.intent.category.LAUNCHER 1

View File

@ -6,3 +6,24 @@ It was written unoptimized, so it can be benchmark.
Also you can compile it for TV Also you can compile it for TV
and even use as screensaver! and even use as screensaver!
#+caption: Screensaver or /Daydream/ on TV
[[./scr.jpg]]
* Make this
To make an APK file, you need:
- Android SDK 24.0.3
- OpenJDK (or other Java) JDK (full, not just JRE)
- GNU Make (as on Linux, no installed on macOS or other *BSD)
You maybe need to change some values in Makefile,
but on Debian no changes needed.
To build, just run ~make~.
If you need to install, connect your Android device
and run ~make deploy~.

BIN
scr.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

View File

@ -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);

View File

@ -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();

View File

@ -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);
} }
} }

View File

@ -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) {