This commit is contained in:
Er2 2022-01-13 21:38:35 +00:00
commit a1de0cbb5b
12 changed files with 326 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
bin/
gen/
*.keystore

46
AndroidManifest.xml Normal file
View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.er2.fireplace"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="32"
/>
<!-- if want on TV:
android:banner="@drawable/banner"
-->
<application
android:icon="@drawable/icon"
android:label="Fireplace"
>
<activity android:hardwareAccelerated="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:name=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".Dream"
android:exported="true"
android:permission="android.permission.BIND_DREAM_SERVICE"
>
<intent-filter>
<action android:name="android.service.dreams.DreamService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
</manifest>

89
Makefile Normal file
View File

@ -0,0 +1,89 @@
NAME = Fireplace
PROJ = org.er2.fireplace
ifeq ($TV,1)
SDK_VER = 24
SDK = 24.0.3
else
SDK_VER = 19
SDK = 19.1.0
endif
SDK_ROOT = ~/Android/Sdk
JAVA_HOME:=$(if $(JAVA_HOME),$(JAVA_HOME),/usr/lib/jvm/java-1.11.0-openjdk-amd64)
VEDBASE = $(SDK_ROOT)/platforms/android-$(SDK_VER)/android.jar
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
PWD=$(shell pwd)
OUT=$(PWD)/bin
GEN=$(PWD)/gen
RES=$(PWD)/res
SRC=$(PWD)/src
#ASS=$(PWD)/assets
SRCS=$(shell find $(SRC) -name '*.java')
CLSS=$(SRCS:$(SRC)/%.java=$(GEN)/%.class)
KEY_PATH ?= debug.keystore
KEY_NAME ?= androiddebugkey
KEY_PASS ?= android
all: debug
debug:
@$(MAKE) DEBUG=true -C $(PWD) build
release:
@$(MAKE) -C $(PWD) build
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) $(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
clean:
@rm -rf $(OUT) $(GEN)
run: $(OUT)/$(NAME).apk
-@$(ADB) uninstall $(PROJ)
@$(ADB) install $^
@$(ADB) shell monkey -p $(PROJ) -c android.intent.category.LAUNCHER 1

8
readme.org Normal file
View File

@ -0,0 +1,8 @@
* Fireplace
This is a matrix-like fireplace for Android!
It was written unoptimized, so it can be benchmark.
Also you can compile it for TV
and even use as screensaver!

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
res/drawable-xhdpi/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

23
res/layout/dream.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<org.er2.fireplace.FireplaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- Yes clock only for dream -->
<TextClock
android:textSize="32sp"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:layout_marginEnd="32dp"
android:layout_marginTop="32dp"
/>
</FrameLayout>

6
res/layout/main.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<org.er2.fireplace.FireplaceView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

View File

@ -0,0 +1,14 @@
package org.er2.fireplace;
import android.service.dreams.DreamService;
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

@ -0,0 +1,70 @@
package org.er2.fireplace;
import java.util.Random;
import java.util.ArrayList;
public class Fireplace {
private static String chr = "!\"#$%&*+,./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^_`~ ";
private static int[] cols = {
0xFFfdcf58,
0xFFf27d0c,
0xFFf07f13,
0xFF800909,
};
int fsize;
public int w, h, col;
ArrayList<Integer> fire;
Random rand;
int ind;
int cid;
int hid;
public Fireplace() {
fire = new ArrayList<Integer>();
rand = new Random();
ind = -1;
cid = 0;
hid = 0;
fire.add(0);
}
public void row() {
ind = -1;
next();
}
public void next() {
if(ind + 1 >= fire.size()) return;
ind++;
if(fire.get(ind) * fsize > h / 7
&& rand.nextInt(6) == 2)
fire.set(ind, 0);
else fire.set(ind, fire.get(ind) + 1);
cid = rand.nextInt(cols.length);
hid = rand.nextInt(chr.length());
}
public int[] getXY() {
int[] c = new int[2];
c[0] = ind * fsize;
c[1] = h - fire.get(ind) * fsize;
return c;
}
public int getCol() {
return cols[cid];
}
public char getChr() {
return chr.charAt(hid);
}
public void setSize(int w, int h) {
this.w = w;
this.h = h;
fsize = Math.min(w, h) / 32;
col = w / fsize + 1;
for(int i = 0; i < col; i++)
if(i >= fire.size()) fire.add(0);
}
}

View File

@ -0,0 +1,55 @@
package org.er2.fireplace;
import android.view.View;
import android.graphics.Canvas;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
public class FireplaceView extends View {
Paint paint;
Fireplace fpl;
Bitmap bmp;
public FireplaceView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
paint = new Paint();
fpl = new Fireplace();
bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);
}
public void drawFire(Canvas canv) {
canv.drawBitmap(bmp, 0, 0, null);
paint.setColor(0x1E000000);
canv.drawRect(0, 0, getWidth(), getHeight(), paint);
for(int i = 0; i < fpl.col; i++) {
fpl.next();
paint.setColor(fpl.getCol());
int[] xy = fpl.getXY();
canv.drawText("" + fpl.getChr(),
xy[0], xy[1], paint);
}
fpl.row();
//postInvalidateDelayed(60);
invalidate();
}
@Override
public void onDraw(Canvas c) {
Bitmap bip = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canv = new Canvas(bip);
drawFire(canv);
bmp.recycle();
bmp = bip;
c.drawBitmap(bmp, 0, 0, null);
}
@Override
protected void onSizeChanged(int w, int h, int ow, int oh) {
fpl.setSize(w, h);
}
}

View File

@ -0,0 +1,12 @@
package org.er2.fireplace;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}