diff --git a/README.md b/README.md
index 1bcd945..4aa9e81 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,7 @@ I'm always on the quest to make this the best HangoverClock ever.
* The only public method is generateWidget, which returns a Bitmap Image.
* The fonts get dynamically collected from all available resource files
and saved in a static String array within the ClockWidgetProvider class.
+* The resulting bitmap resolution will be calculated to reach the best quality possible on every device.
* The sharedPreference keys are defined in preferencekeys.xml and their defaults in preferencekeydefaults.xml.
* sharedPreferences are saved in the format key and directly appended widget ID.
* If a key is not defined its default value is assumed and only gets saved when not default or when alwayssavepreferences bool is active.
diff --git a/app/build.gradle b/app/build.gradle
index ce6309e..065dc44 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,7 +6,7 @@ android {
applicationId "com.JJ.hangoverclock"
minSdkVersion 14
targetSdkVersion 28
- versionCode 7
+ versionCode 8
versionName "dynamite"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
index 0a79a7b..a3287c9 100644
Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ
diff --git a/app/release/output.json b/app/release/output.json
index 7d65c07..c819b7d 100644
--- a/app/release/output.json
+++ b/app/release/output.json
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":7,"versionName":"dynamite","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":8,"versionName":"dynamite","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6a381c2..b29bda3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -17,13 +17,11 @@
-
-
diff --git a/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java b/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java
index 15172e6..67f4ce2 100644
--- a/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java
+++ b/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java
@@ -86,6 +86,22 @@ public void onClick(View v) {
boolean twelvehours = ((Switch) findViewById(R.id.hourselector)).isChecked();
boolean enabledate = ((Switch) findViewById(R.id.dateselector)).isChecked();
boolean as = context.getResources().getBoolean(R.bool.alwayssavepreference); //wether preferences should always be saved
+ int[] flushkeys = {
+ R.string.keyenableseconds,
+ R.string.keyfont,
+ R.string.keyfontscale,
+ R.string.keyhouroverhang,
+ R.string.keyminuteoverhang,
+ R.string.keysecondoverhang,
+ R.string.keydayoverhang,
+ R.string.keymonthoverhang,
+ R.string.keycolor,
+ R.string.keytwelvehour,
+ R.string.keyenabledate,
+ };
+ for (int key:flushkeys) {
+ editor.remove(context.getResources().getString(key) + appWidgetID);
+ }
if (as | context.getResources().getBoolean(R.bool.defaultenableseconds) != enableseconds)
editor.putBoolean(context.getResources().getString(R.string.keyenableseconds) + appWidgetID, enableseconds);
if (as | !context.getResources().getString(R.string.defaultfonttext).equals(font))
@@ -254,7 +270,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
((Switch) findViewById(R.id.dateselector)).setOnCheckedChangeListener(updatepreviewlistener);
((Switch) findViewById(R.id.secondsselector)).setOnCheckedChangeListener(updatepreviewlistener);
((Switch) findViewById(R.id.autohourselector)).setOnCheckedChangeListener(updatepreviewlistener);
- //TODO: replace spinner with recyclerview (big project ._.)
Spinner fontspinner = findViewById(R.id.fontspinner);
ArrayList rowItems = new ArrayList();
ArrayList fonts = ClockWidgetProvider.fonts;
@@ -349,7 +364,7 @@ private void updatepreview() {
SeekBar seekbaralpha = findViewById(R.id.seekbaralpha);
int color = Color.argb(seekbaralpha.getProgress(), seekbarred.getProgress(), seekbargreen.getProgress(), seekbarblue.getProgress());
SeekBar fontsizedividerseekbar = findViewById(R.id.datefontsizeseekbar);
- float fontsizedivider = context.getResources().getInteger(R.integer.maxfontscale) - (float) (fontsizedividerseekbar.getMax() - fontsizedividerseekbar.getProgress()) / 100;
+ float fontsizedivider = context.getResources().getInteger(R.integer.maxfontscale) - (float) fontsizedividerseekbar.getProgress() / 100;
if (((Switch) findViewById(R.id.dateselector)).isChecked()) {
findViewById(R.id.overhanginputdate).setVisibility(View.VISIBLE);
fontsizedividerseekbar.setVisibility(View.VISIBLE);
@@ -377,15 +392,13 @@ private void updatepreview() {
//Expected if called to early
font = context.getResources().getString(R.string.defaultfonttext);
}
- int fontresolution = context.getResources().getInteger(R.integer.widgetfontresolution);
Bitmap bitmap = WidgetGenerator.generateWidget(
context, Calendar.getInstance().getTimeInMillis(),
secondoverhang, minuteoverhang, houroverhang, dayoverhang, monthoverhang,
twelvehour, withseconds, withdate,
- font, color, fontsizedivider, fontresolution
+ font, color, fontsizedivider
);
bitmap.prepareToDraw();
imageView.setImageBitmap(bitmap);
-
}
}
diff --git a/app/src/main/java/com/JJ/hangoverclock/WidgetGenerator.java b/app/src/main/java/com/JJ/hangoverclock/WidgetGenerator.java
index b2634b7..c0c7786 100644
--- a/app/src/main/java/com/JJ/hangoverclock/WidgetGenerator.java
+++ b/app/src/main/java/com/JJ/hangoverclock/WidgetGenerator.java
@@ -22,11 +22,11 @@ static Bitmap generateWidget(Context context, long timestamp,
int secondoverhang, int minuteoverhang, int houroverhang,
int dayoverhang, int monthoverhang,
boolean twelvehours, boolean withseconds, boolean withdate,
- String font, int color, float fontscale, int fontresolution) {
+ String font, int color, float fontscale) {
if (!withdate) {
return generateBitmap(context,
calculatetime(timestamp, houroverhang, minuteoverhang, secondoverhang, twelvehours, withseconds),
- font, color, fontresolution);
+ font, color);
} else {
String[] hangovertext = combinedcalculate(timestamp,
monthoverhang, dayoverhang,
@@ -34,32 +34,31 @@ static Bitmap generateWidget(Context context, long timestamp,
withseconds, twelvehours);
return generateBitmap(context,
hangovertext[0], hangovertext[1],
- font, color, fontscale, fontresolution);
+ font, color, fontscale);
}
}
- private static Bitmap generateBitmap(Context context, String time, String date, String font, int color, float datefontscale, int fontresolution) {
+ private static Bitmap generateBitmap(Context context, String time, String date, String font, int color, float datefontscale) {
if (date == null) {
- return generateBitmap(context, time, font, color, fontresolution);
+ return generateBitmap(context, time, font, color);
} else {
- return generateBitmap(context, time, font, color, date, font, color, datefontscale, fontresolution);
+ return generateBitmap(context, time, font, color, date, font, color, datefontscale);
}
}
- private static Bitmap generateBitmap(Context context, String time, String timefont, int timecolor, int fontresolution) {
- return generateBitmap(context, false, time, timefont, timecolor, null, null, 0,
- 0, fontresolution);
+ private static Bitmap generateBitmap(Context context, String time, String timefont, int timecolor) {
+ return generateBitmap(context, false, time, timefont, timecolor, null, null, 0, 0);
}
private static Bitmap generateBitmap(Context context, String time, String timefont, int timecolor,
- String date, String datefont, int datecolor, float datefontscale, int fontresolution) {
- return generateBitmap(context, true, time, timefont, timecolor, date, datefont, datecolor, datefontscale, fontresolution);
+ String date, String datefont, int datecolor, float datefontscale) {
+ return generateBitmap(context, true, time, timefont, timecolor, date, datefont, datecolor, datefontscale);
}
private static Bitmap generateBitmap(Context context, boolean withdate,
String time, String timefont, int timecolor,
String date, String datefont, int datecolor,
- float fontscale, int fontresolution) {
+ float fontscale) {
//ah shit .settypeface doesnt exist in remoteviews wth do I do now? guess ill be rendering a bitmap
//solution: https://stackoverflow.com/questions/4318572/how-to-use-a-custom-typeface-in-a-widget
//but i added the date myself
@@ -220,6 +219,7 @@ private static String[] combinedcalculate(long timestamp,
private static int calculatefontsize(Context context, String text, String font) {
String TAG = "calculatefontsize";
+ int cap = 5000; //max iterations cap to preventto crash rather then ANR
Typeface typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
font = font.replace(" ", "_");
if (!context.getString(R.string.defaultfonttext).equals(font)) {
@@ -251,16 +251,40 @@ private static int calculatefontsize(Context context, String text, String font)
while (currentbytes < maxbytes) {
fontsize++;
count++;
- if ((float)currentbytes/maxbytes<1) fontsize*=(1-(float)currentbytes/maxbytes)/2+1;
- paint.setTextSize(fontsize);
+ //i wasted so many days just to find out that my first formula works best :(
+ if ((float)currentbytes/maxbytes<1) fontsize*=(1-(float)currentbytes/maxbytes)/2+1; //works in about 18 iterations
+ //if ((float)currentbytes/maxbytes<1) fontsize = fontsize * (int)(0+((1*(Math.exp(-currentbytes+(maxbytes/2)))+maxbytes)/maxbytes)-0); //not working at all, hits the cap
+ //if ((float)currentbytes/maxbytes<1) fontsize = ((Math.log((y-e)/a))/1)-0; //unfinished
+ //if ((float)currentbytes/maxbytes<1) fontsize = (int)(fontsize * (1/((float)currentbytes/maxbytes))); //big overshoot
+ //if ((float)currentbytes/maxbytes<1) fontsize = (int)(fontsize * (5*Math.exp(-9*((float)currentbytes/maxbytes))+1)); //its alright
+ paint.setTextSize(fontsize);
int pad = (fontsize / 9);
int textWidth = (int) (paint.measureText(text) + pad * 2);
int height = (int) (fontsize / 0.7);
currentbytes = (textWidth * height * 4);
//Log.d(TAG, "calculatefontsize: itaration "+count+", fontsize "+fontsize+", size is "+currentbytes+", that is "+((float)currentbytes/maxbytes));
+ if (count>cap) break;
}
- //Log.d(TAG, "calculatefontsize: using "+currentbytes+" of "+maxbytes);
fontsize--;
+ paint.setTextSize(fontsize);
+ {
+ int pad = (fontsize / 9);
+ int textWidth = (int) (paint.measureText(text) + pad * 2);
+ int height = (int) (fontsize / 0.7);
+ currentbytes = (textWidth * height * 4);
+ }
+ while (currentbytes > maxbytes) {
+ fontsize--;
+ count++;
+ paint.setTextSize(fontsize);
+ int pad = (fontsize / 9);
+ int textWidth = (int) (paint.measureText(text) + pad * 2);
+ int height = (int) (fontsize / 0.7);
+ currentbytes = (textWidth * height * 4);
+ //Log.d(TAG, "calculatefontsize: subtratcting itaration "+count+", fontsize "+fontsize+", size is "+currentbytes+", that is "+((float)currentbytes/maxbytes));
+ if (count>cap*2) break;
+ }
+ //Log.d(TAG, "calculatefontsize: using "+currentbytes+" of "+maxbytes+", that is "+((float)currentbytes/maxbytes));
//Log.d(TAG, "calculatefontsize: calculated font size is "+fontsize);
return fontsize;
}
diff --git a/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java b/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java
index db0c559..f04d2be 100644
--- a/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java
+++ b/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java
@@ -22,6 +22,7 @@
public class ClockWidgetProvider extends AppWidgetProvider {
+ //TODO: automatischer Farbwechsel
static final String TAG = "ClockWidgetProvider";
public static ArrayList fonts = new ArrayList() {{
add("default");
@@ -146,13 +147,12 @@ public void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
String font = sharedPreferences.getString(context.getResources().getString(R.string.keyfont) + appWidgetId, context.getResources().getString(R.string.defaultfonttext));
float fontscale = sharedPreferences.getFloat(context.getResources().getString(R.string.keyfontscale) + appWidgetId, context.getResources().getInteger(R.integer.defaultdatefontscale));
int color = sharedPreferences.getInt(context.getResources().getString(R.string.keycolor) + appWidgetId, context.getResources().getColor(R.color.defaultWidgetColor));
- int fontresolution = context.getResources().getInteger(R.integer.widgetfontresolution);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteViews.setImageViewBitmap(R.id.clock,
WidgetGenerator.generateWidget(
context, Calendar.getInstance().getTimeInMillis(),
secondoverhang, minuteoverhang, houroverhang, dayoverhang, monthoverhang,
- twelvehour, enableseconds, enabledate, font, color, fontscale, fontresolution)
+ twelvehour, enableseconds, enabledate, font, color, fontscale)
);
try {
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml
index 1f77311..d02d2e2 100644
--- a/app/src/main/res/layout/widget.xml
+++ b/app/src/main/res/layout/widget.xml
@@ -11,6 +11,6 @@
android:id="@+id/clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:src="@mipmap/clock" />
+ android:src="@drawable/clock" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_configure.xml b/app/src/main/res/layout/widget_configure.xml
index da4b6cb..b41a355 100644
--- a/app/src/main/res/layout/widget_configure.xml
+++ b/app/src/main/res/layout/widget_configure.xml
@@ -111,6 +111,14 @@
android:layout_height="2dp"
android:background="?android:attr/listDivider" />
+
+
+
+
+
+
Datum aktivieren
Tage
Systemzeitformat benutzen
- Overhang:
+ Overhang
Stunden
Monate
+ Farben
+ Schriftart
+ Einstellungen
\ No newline at end of file
diff --git a/app/src/main/res/values/font_certs.xml b/app/src/main/res/values/font_certs.xml
deleted file mode 100644
index d2226ac..0000000
--- a/app/src/main/res/values/font_certs.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- - @array/com_google_android_gms_fonts_certs_dev
- - @array/com_google_android_gms_fonts_certs_prod
-
-
- -
- MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wP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6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
-
-
-
diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml
index 506fa11..93b5424 100644
--- a/app/src/main/res/values/integers.xml
+++ b/app/src/main/res/values/integers.xml
@@ -1,6 +1,5 @@
- 150
- 5
5
+ 5
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 47fd960..24343e3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -4,13 +4,16 @@
Create Widget
minutes
Use 12h format
- system default
+ default
Enable seconds
Using seconds is a big system load and is not recommended!
Enable Date
days
Use system timeformat
- Overhang:
+ Overhang
hours
months
+ Colors
+ Settings
+ Fonts
diff --git a/build.gradle b/build.gradle
index f5fb2cc..48947c3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.0'
+ classpath 'com.android.tools.build:gradle:3.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files