Browse Source

Initial commit

main
meutraa 1 year ago
commit
6ed8711e57
Signed by: meutraa GPG Key ID: 82664A5F8DAC3400
  1. 26
      AndroidManifest.xml
  2. 241
      MainActivity.java
  3. 44
      build.sh
  4. BIN
      macros.apk
  5. 37
      proguard.txt
  6. BIN
      r8-1.6.84.jar
  7. BIN
      release.keystore

26
AndroidManifest.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="host.lost.macros"
android:versionCode="1"
android:versionName="0.1">
<uses-sdk android:minSdkVersion="29"
android:targetSdkVersion="29"
android:maxSdkVersion="29" />
<!--android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"-->
<application android:label="Macros">
<activity
android:name=".MainActivity"
android:theme="@android:style/Theme.Material.Light.NoActionBar"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

241
MainActivity.java

@ -0,0 +1,241 @@
package host.lost.macros;
import android.app.Activity;
import android.os.Bundle;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.lang.Runnable;
import android.graphics.Paint;
import android.graphics.Canvas;
import android.text.TextPaint;
import android.view.View;
import android.view.Gravity;
import android.view.ViewGroup;
import android.content.Context;
import android.content.ContentValues;
import android.widget.TextView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.BaseAdapter;
import android.database.DataSetObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class MainActivity extends Activity {
private class FoodEntry {
long id;
String name;
float calories;
float fat;
float protein;
float carb;
float saturated;
float sugar;
float fibre;
String time;
}
private static class FoodView extends View {
private static TextPaint paint;
private static TextPaint endPaint;
private FoodEntry f;
FoodView(Context context, ExecutorService ex) {
super(context);
if (null == paint) {
paint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
paint.setTextSize(22);
endPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
endPaint.setTextAlign(Paint.Align.RIGHT);
endPaint.setTextSize(22);
}
}
void setFoodEntry(FoodEntry entry) {
f = entry;
postInvalidate();
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText(f.name, 32, 32, paint);
canvas.drawText(String.valueOf(f.carb), 32, 76, paint);
canvas.drawText(f.time, getWidth() - 32, 32, endPaint);
canvas.drawText(String.valueOf(f.calories), getWidth() - 32, 76, endPaint);
}
}
private class FoodAdapter extends BaseAdapter {
List<FoodEntry> entries = new ArrayList<>();
@Override
public View getView(int position, View cv, ViewGroup container) {
var entry = (FoodEntry) getItem(position);
if (null != cv) {
var v = (FoodView) cv;
v.setFoodEntry(entry);
return v;
} else {
var v = new FoodView(container.getContext(), ex);
v.setLayoutParams(new FrameLayout.LayoutParams(-1, 100));
v.setFoodEntry(entry);
return v;
}
}
public void setItems(List<FoodEntry> e) {
entries.clear();
entries.addAll(e);
notifyDataSetChanged();
};
public void addItem(FoodEntry e) {
entries.add(e);
notifyDataSetChanged();
};
@Override
public int getCount() {
return entries.size();
}
@Override
public long getItemId(int p) {
return p;
}
@Override
public Object getItem(int p) {
return entries.get(p);
}
@Override
public boolean hasStableIds() {
return true;
}
}
public class FoodDbHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 3;
public FoodDbHelper(Context context) {
super(context, "foods.db", null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE foods (" +
"id INTEGER PRIMARY KEY," +
"name TEXT NOT NULL," +
"calories REAL NOT NULL," +
"fat REAL NOT NULL," +
"carb REAL NOT NULL," +
"saturated REAL NOT NULL," +
"sugar REAL NOT NULL," +
"fibre REAL NOT NULL," +
"time INTEGER NOT NULL," +
"protein REAL NOT NULL)"
);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS foods");
onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}
FoodAdapter adapter;
ListView list;
Button button;
FoodDbHelper helper;
ExecutorService ex = Executors.newWorkStealingPool();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
var frame = new FrameLayout(this);
var bp = new FrameLayout.LayoutParams(-2, -2, Gravity.BOTTOM | Gravity.END);
list = new ListView(this);
button = new Button(this);
button.setText("Add Item");
button.setLayoutParams(bp);
frame.addView(list);
frame.addView(button);
setContentView(frame);
}
@Override
protected void onStart() {
super.onStart();
helper = new FoodDbHelper(this);
adapter = new FoodAdapter();
list.setAdapter(adapter);
button.setOnClickListener(view -> {
ex.execute(() -> {
var db = helper.getWritableDatabase();
var v = new ContentValues();
v.put("name", "Test Name");
v.put("calories", 100.5f);
v.put("fat", 32.2f);
v.put("protein", 16.7f);
v.put("fibre", 16.7f);
v.put("carb", 16.7f);
v.put("saturated", 16.7f);
v.put("sugar", 16.7f);
v.put("time", System.currentTimeMillis());
var id = db.insert("foods", null, v);
var e = new FoodEntry();
e.id = id;
e.name = "Test Name";
e.carb = 100.5f;
e.fat = 32.2f;
e.saturated = 16.7f;
e.protein = 16.7f;
e.sugar = 16.7f;
e.fibre = 16.7f;
e.calories = 16.7f;
e.time = (new Date()).toString();
runOnUiThread(() -> adapter.addItem(e));
});
});
ex.execute(() -> {
var db = helper.getReadableDatabase();
var c = db.query("foods", null, null, null, null, null, "id DESC");
var entries = new ArrayList<FoodEntry>(c.getCount());
while(c.moveToNext()) {
var e = new FoodEntry();
e.id = c.getInt(c.getColumnIndex("id"));
e.name = c.getString(c.getColumnIndex("name"));
e.calories = c.getFloat(c.getColumnIndex("calories"));
e.fat = c.getFloat(c.getColumnIndex("fat"));
e.protein = c.getFloat(c.getColumnIndex("protein"));
e.fibre = c.getFloat(c.getColumnIndex("fibre"));
e.sugar = c.getFloat(c.getColumnIndex("sugar"));
e.saturated = c.getFloat(c.getColumnIndex("saturated"));
e.carb = c.getFloat(c.getColumnIndex("carb"));
e.time = new Date(c.getLong(c.getColumnIndex("time"))).toString();
entries.add(e);
}
c.close();
runOnUiThread(() -> adapter.setItems(entries));
});
}
}

44
build.sh

@ -0,0 +1,44 @@
#!/usr/bin/env bash
#!/bin/bash
set -e
NAME="macros"
ID="host/lost/macros"
BTV="29.0.3"
PTV="30.0.0"
SV="android-29"
SDK="$HOME/sdk"
AAPT="$SDK/build-tools/$BTV/aapt2"
ZIPALIGN="$SDK/build-tools/$BTV/zipalign"
APKSIGNER="$SDK/build-tools/$BTV/apksigner"
PLATFORM="$SDK/platforms/$SV/android.jar"
mkdir -p obj
rm -f $NAME.unaligned.apk
echo "Compiling java"
javac -d obj -cp $PLATFORM -source 11 -target 11 MainActivity.java
echo "Optimizing with R8"
CLASSES=$(find obj -name "*.class" | tr '\n' ' ')
java -cp r8-1.6.84.jar com.android.tools.r8.R8 --release --output . --pg-conf proguard.txt --min-api 29 --lib "${PLATFORM}" ${CLASSES}
echo "Creating apk"
$AAPT link -o $NAME.unaligned.apk --manifest AndroidManifest.xml -I $PLATFORM
zip -uj $NAME.unaligned.apk classes.dex
advzip -4 -i 256 -z $NAME.unaligned.apk
echo "Aligning and signing apk"
$ZIPALIGN -f 4 $NAME.unaligned.apk $NAME.apk
$APKSIGNER sign --ks release.keystore \
--v1-signing-enabled false \
--v2-signing-enabled false \
--v3-signing-enabled true \
--ks-pass "pass:Toekabee" --key-pass "pass:Toekabee" $NAME.apk
echo "Cleaning..."
rm -rf obj
rm -f $NAME.unaligned.apk
rm -f classes.dex

BIN
macros.apk

37
proguard.txt

@ -0,0 +1,37 @@
-allowaccessmodification
-dontpreverify
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclasseswithmembers class host.lost.** {
*;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**

BIN
r8-1.6.84.jar

BIN
release.keystore

Loading…
Cancel
Save