Compare commits

..

No commits in common. "main" and "d52e43502227b9ef613c346ba5232107580caa43" have entirely different histories.

9 changed files with 82 additions and 118 deletions

3
.gitignore vendored
View file

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

View file

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

109
Makefile
View file

@ -1,68 +1,89 @@
NAME = Fireplace
CLASS= org.er2.fireplace
PROJ = org.er2.fireplace
KEY_PATH = debug.keystore
KEY_NAME = androiddebugkey
KEY_PASS = android
ifeq ($TV,1)
SDK_VER = 24
SDK = 24.0.3
else
SDK_VER = 19
SDK = 19.1.0
endif
SDK_VER = 24
SDK = 24.0.3
SDK_ROOT = ~/Android/Sdk
JAVA_HOME:=$(if $(JAVA_HOME),$(JAVA_HOME),/usr/lib/jvm/java-1.11.0-openjdk-amd64)
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
# Tools
ADB = $(SDK_ROOT)/platform-tools/adb
AAPT = $(SDK_ROOT)/build-tools/$(SDK)/aapt
DX = $(SDK_ROOT)/build-tools/$(SDK)/dx
ZIPALIGN = $(SDK_ROOT)/build-tools/$(SDK)/zipalign
ADB = $(SDK_ROOT)/platform-tools/adb
AAPT = $(SDK_ROOT)/build-tools/$(SDK)/aapt
DX = $(SDK_ROOT)/build-tools/$(SDK)/dx
ZIPALIGN=$(SDK_ROOT)/build-tools/$(SDK)/zipalign
JAVAC = $(JAVA_HOME)/bin/javac
JARSIGNER = $(JAVA_HOME)/bin/jarsigner
SRC = $(shell find src/ -name '*.java')
CLSS= $(SRC:src/%.java=gen/%.class)
PWD=$(shell pwd)
all: build
build: out.apk
OUT=$(PWD)/bin
GEN=$(PWD)/gen
RES=$(PWD)/res
SRC=$(PWD)/src
#ASS=$(PWD)/assets
out.apk: AndroidManifest.xml gen/classes.dex $(KEY_PATH)
@$(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 $@
SRCS=$(shell find $(SRC) -name '*.java')
CLSS=$(SRCS:$(SRC)/%.java=$(GEN)/%.class)
-@if [ ! -r "$@" ]; then mv -f $@.tmp $@; fi
KEY_PATH ?= debug.keystore
KEY_NAME ?= androiddebugkey
KEY_PASS ?= android
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/
all: debug
### Helpers
debug:
@$(MAKE) DEBUG=true -C $(PWD) build
prepare: res/*
-@echo Generating R.java
@mkdir -p gen
@$(AAPT) p -I $(VEDBASE) -fm -M AndroidManifest.xml -J gen -S res
release:
@$(MAKE) -C $(PWD) build
gen/%.class: src/%.java
APK=$(OUT)/$(NAME).apk
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 $@
@$(JAVAC) -classpath $(VEDBASE) -sourcepath 'src/:gen/' -d 'gen/' $< -source 1.7 -target 1.7 > /dev/null 2>&1
@$(JAVAC) $(if $(DEBUG),-g,) -classpath $(VEDBASE) -sourcepath 'src:$(GEN)' -d '$(GEN)' -target 1.7 -source 1.7 $<
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):
@yes | keytool -genkey -v -keystore $(KEY_PATH) -storepass '$(KEY_PASS)' -alias $(KEY_NAME) -keypass $(KEY_PASS) -keyalg RSA -keysize 2048 -validity 10000
### Tools
clean:
rm -rf gen/ classes.dex out.apk out.apk.tmp
@rm -rf $(OUT) $(GEN)
deploy: out.apk
-@$(ADB) uninstall $(CLASS)
@$(ADB) install $<
@$(ADB) shell monkey -p $(CLASS) -c android.intent.category.LAUNCHER 1
run: $(OUT)/$(NAME).apk
-@$(ADB) uninstall $(PROJ)
@$(ADB) install $^
@$(ADB) shell monkey -p $(PROJ) -c android.intent.category.LAUNCHER 1

View file

@ -6,24 +6,3 @@ It was written unoptimized, so it can be benchmark.
Also you can compile it for TV
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 KiB

View file

@ -1,19 +1,12 @@
package org.er2.fireplace;
import android.service.dreams.DreamService;
/* Dream service to show fireplace on device
* instead of just black screen (useful for TVs).
*
* (c) Er2 2022 <er2@dismail.de>
* Zlib License
*/
import android.widget.TextView;
public class Dream extends DreamService {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
setInteractive(false);
setFullscreen(true);
setContentView(R.layout.dream);

View file

@ -3,34 +3,24 @@ package org.er2.fireplace;
import java.util.Random;
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 {
/* Characters and colors to use */
/* (yes I like comments in C style) */
private static String chr = "!\"#$%&*+,./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^_`~ ";
private static int[] cols = {
/* 0x OPACITY hex
Because Android uses opacity before hex
*/
0xFFfdcf58,
0xFFf27d0c,
0xFFf07f13,
0xFF800909,
};
int fsize; /* Font size */
public int w, h, col; /* width, height, columns */
ArrayList<Integer> fire; /* ArrayList is to allow resize */
Random rand; /* Some random :) */
int fsize;
public int w, h, col;
ArrayList<Integer> fire;
Random rand;
int ind, cid, hid; /* column INDex, Color InDex, cHaracter InDex */
int ind;
int cid;
int hid;
/* Pls no comments */
public Fireplace() {
fire = new ArrayList<Integer>();
rand = new Random();

View file

@ -9,17 +9,10 @@ import android.util.AttributeSet;
import android.util.Log;
/* Fireplace frontend
* TODO: Optimize this..
*
* (c) Er2 2022 <er2@dismail.de>
* Zlib License
*/
public class FireplaceView extends View {
Paint paint; /* Android paint */
Fireplace fpl; /* Our backend */
Bitmap bmp; /* Screenshot of previous frame (thing to be optimized) */
Paint paint;
Fireplace fpl;
Bitmap bmp;
public FireplaceView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
@ -29,14 +22,9 @@ public class FireplaceView extends View {
}
public void drawFire(Canvas canv) {
/* draw previous frame and apply transparency
thing to be optimized
*/
canv.drawBitmap(bmp, 0, 0, null);
paint.setColor(0x1E000000);
canv.drawRect(0, 0, getWidth(), getHeight(), paint);
/* going through columns */
for(int i = 0; i < fpl.col; i++) {
fpl.next();
paint.setColor(fpl.getCol());
@ -51,7 +39,6 @@ public class FireplaceView extends View {
@Override
public void onDraw(Canvas c) {
/* TODO: To be optimized */
Bitmap bip = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canv = new Canvas(bip);
drawFire(canv);
@ -62,7 +49,6 @@ public class FireplaceView extends View {
@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
/* Set size directly */
fpl.setSize(w, h);
}
}

View file

@ -3,12 +3,6 @@ package org.er2.fireplace;
import android.app.Activity;
import android.os.Bundle;
/* Typical main activity file
*
* (c) Er2 2022 <er2@dismail.de>
* Zlib License
*/
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {