Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
programminghoch10 committed Sep 13, 2019
2 parents 669a457 + 4ee3656 commit 0d9ed43
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 326 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ android {
applicationId "com.JJ.hangoverclock"
minSdkVersion 16
targetSdkVersion 28
versionCode 3
versionCode 4
versionName "dynamite"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -20,9 +20,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"dynamite","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"dynamite","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver android:name=".ClockWidgetProvider">
<intent-filter>
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/JJ/hangoverclock/BootReceiver.java

This file was deleted.

9 changes: 3 additions & 6 deletions app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void onClick(View v) {
//Expected error if no value was choosen, just set to default value
monthoverhang = context.getResources().getInteger(R.integer.defaultmonthoverhang);
}
int yearoverhang = context.getResources().getInteger(R.integer.defaultyearoverhang);
String font;
try {
font = ((Spinner) findViewById(R.id.fontspinner)).getSelectedItem().toString().replace(" ", "_");
Expand Down Expand Up @@ -101,8 +100,6 @@ public void onClick(View v) {
editor.putInt(context.getResources().getString(R.string.keydayoverhang) + appWidgetID, dayoverhang);
if (as | context.getResources().getInteger(R.integer.defaultmonthoverhang) != monthoverhang)
editor.putInt(context.getResources().getString(R.string.keymonthoverhang) + appWidgetID, monthoverhang);
if (as | context.getResources().getInteger(R.integer.defaultyearoverhang) != yearoverhang)
editor.putInt(context.getResources().getString(R.string.keyyearoverhang) + appWidgetID, yearoverhang);
if (as | context.getResources().getColor(R.color.defaultWidgetColor) != color)
editor.putInt(context.getResources().getString(R.string.keycolor) + appWidgetID, color);
if (!autotwelvehours)
Expand Down Expand Up @@ -325,7 +322,6 @@ private void updatepreview() {
//Expected error if no value was choosen, just set to default value
monthoverhang = context.getResources().getInteger(R.integer.defaultmonthoverhang);
}
int yearoverhang = context.getResources().getInteger(R.integer.defaultyearoverhang);
boolean withseconds = ((Switch) findViewById(R.id.secondsselector)).isChecked();
SeekBar seekbarred = (SeekBar) findViewById(R.id.seekbarred);
SeekBar seekbargreen = (SeekBar) findViewById(R.id.seekbargreen);
Expand Down Expand Up @@ -361,12 +357,13 @@ private void updatepreview() {
//Expected if called to early
font = context.getResources().getString(R.string.defaultfonttext);
}
int fontresolution = context.getResources().getInteger(R.integer.widgetfontresolution);
imageView.setImageBitmap(
WidgetGenerator.generateWidget(
context, Calendar.getInstance().getTimeInMillis(),
secondoverhang, minuteoverhang, houroverhang, dayoverhang, monthoverhang, yearoverhang,
secondoverhang, minuteoverhang, houroverhang, dayoverhang, monthoverhang,
twelvehour, withseconds, withdate,
font, color, fontsizedivider
font, color, fontsizedivider, fontresolution
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.app.Activity;
import android.graphics.Typeface;
import android.support.v4.content.res.ResourcesCompat;
import androidx.core.content.res.ResourcesCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand Down
46 changes: 20 additions & 26 deletions app/src/main/java/com/JJ/hangoverclock/WidgetGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.support.v4.content.res.ResourcesCompat;
import androidx.core.content.res.ResourcesCompat;
import android.util.TypedValue;

import java.util.Calendar;
Expand All @@ -16,51 +16,50 @@ class WidgetGenerator {

static Bitmap generateWidget(Context context, long timestamp,
int secondoverhang, int minuteoverhang, int houroverhang,
int dayoverhang, int monthoverhang, int yearoverhang,
int dayoverhang, int monthoverhang,
boolean twelvehours, boolean withseconds, boolean withdate,
String font, int color, float fontscale) {
//Calendar calendar = Calendar.getInstance();
//calendar.setTimeInMillis(timestamp);
String font, int color, float fontscale, int fontresolution) {
if (!withdate) {
return generateBitmap(context,
calculatetime(timestamp, houroverhang, minuteoverhang, secondoverhang, twelvehours, withseconds),
font, color);
font, color, fontresolution);
} else {
String[] hangovertext = combinedcalculate(timestamp,
monthoverhang, dayoverhang,
houroverhang, minuteoverhang, secondoverhang,
withseconds, twelvehours);
return generateBitmap(context,
hangovertext[0], hangovertext[1],
font, color, fontscale);
font, color, fontscale, fontresolution);
}
}

private static Bitmap generateBitmap(Context context, String time, String date, String font, int color, float datefontscale) {
private static Bitmap generateBitmap(Context context, String time, String date, String font, int color, float datefontscale, int fontresolution) {
if (date == null) {
return generateBitmap(context, time, font, color);
return generateBitmap(context, time, font, color, fontresolution);
} else {
return generateBitmap(context, time, font, color, date, font, color, datefontscale);
return generateBitmap(context, time, font, color, date, font, color, datefontscale, fontresolution);
}
}

private static Bitmap generateBitmap(Context context, String time, String timefont, int timecolor) {
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);
0, fontresolution);
}

private static Bitmap generateBitmap(Context context, String time, String timefont, int timecolor,
String date, String datefont, int datecolor, float datefontscale) {
return generateBitmap(context, true, time, timefont, timecolor, date, datefont, datecolor, datefontscale);
String date, String datefont, int datecolor, float datefontscale, int fontresolution) {
return generateBitmap(context, true, time, timefont, timecolor, date, datefont, datecolor, datefontscale, fontresolution);
}

private static Bitmap generateBitmap(Context context, boolean withdate,
String time, String timefont, int timecolor,
String date, String datefont, int datecolor, float fontscale) {
String date, String datefont, int datecolor,
float fontscale, int fontresolution) {
//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
int fontSizePX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, context.getResources().getInteger(R.integer.widgetfontsize), context.getResources().getDisplayMetrics());
int fontSizePX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, fontresolution, context.getResources().getDisplayMetrics());
int pad = (fontSizePX / 9);
Typeface timetypeface = Typeface.defaultFromStyle(Typeface.NORMAL);
timefont = timefont.replace(" ", "_");
Expand Down Expand Up @@ -143,16 +142,15 @@ private static String calculatetime(long timestamp, int houroverhang, int minute
return String.format(Locale.GERMANY, "%02d", h) + ":" + String.format(Locale.GERMANY, "%02d", m) + ":" + String.format(Locale.GERMANY, "%02d", s);
return String.format(Locale.GERMANY, "%02d", h) + ":" + String.format(Locale.GERMANY, "%02d", m);
}

private static String calculatedate(long timestamp, int dayoverhang, int monthoverhang, int yearoverhang) {
/*
private static String calculatedate(long timestamp, int dayoverhang, int monthoverhang) {
// i guess this function is redundant now, meh still gonna leave it here, i dont wanna scrap all that effort
//yearoverhang = 0; //as far as i can think yearoverhang should never be of use
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp);
int day = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
while (day <= dayoverhang | month <= monthoverhang /*| year <= yearoverhang*/) {
while (day <= dayoverhang | month <= monthoverhang) {
if (day <= dayoverhang) {
calendar.add(Calendar.MONTH, -1);
day += calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
Expand All @@ -163,14 +161,10 @@ private static String calculatedate(long timestamp, int dayoverhang, int monthov
year -= 1;
calendar.add(Calendar.YEAR, -1);
}
/*if (year <= yearoverhang) {
// idk what to do this should never happen wtf
break;
}*/
}
return day + "." + month + "." + year;
}

*/
private static String[] combinedcalculate(long timestamp,
int monthoverhang, int dayoverhang,
int houroverhang, int minuteoverhang, int secondoverhang,
Expand Down Expand Up @@ -212,9 +206,9 @@ private static String[] combinedcalculate(long timestamp,
}
}
if (twelvehours & (h >= 12+houroverhang & h <= 24)) h -= 12;
returnstring[0] = String.format(Locale.GERMANY, "%02d", h) + ":" + String.format(Locale.GERMANY, "%02d", m);
if (withseconds)
returnstring[0] = String.format(Locale.GERMANY, "%02d", h) + ":" + String.format(Locale.GERMANY, "%02d", m) + ":" + String.format(Locale.GERMANY, "%02d", s);
returnstring[0] = String.format(Locale.GERMANY, "%02d", h) + ":" + String.format(Locale.GERMANY, "%02d", m);
returnstring[1] = day + "." + month + "." + year;
return returnstring;
}
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.app.AlarmManagerCompat;

import android.text.format.DateFormat;
import android.util.Log;
import android.widget.RemoteViews;

import androidx.core.app.AlarmManagerCompat;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
Expand All @@ -25,7 +27,7 @@ public class ClockWidgetProvider extends AppWidgetProvider {
public static ArrayList<String> fonts = new ArrayList<String>() {{
add("default");
}};
//public static final String[] fonts = new String[] { "default", "faster one", "magneto", "nosifer", "orbitron", "oswald", "permanent marker", "press start 2p" };

private static String CLOCK_WIDGET_UPDATE = "com.JJ.hangoverclock.widgetupdate";

public static void collectfonts(Context context) {
Expand Down Expand Up @@ -71,11 +73,8 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
//Log.d(TAG, "onReceive: got intent " + intent.getAction());
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (CLOCK_WIDGET_UPDATE.equals(intent.getAction())) {
//Log.d(TAG, "onReceive: Recieved Clock Update");
// Get the widget manager and ids for this widget provider, then call the shared clock update method.
ComponentName thisAppWidget = new ComponentName(context.getPackageName(), getClass().getName());
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] ids = appWidgetManager.getAppWidgetIds(thisAppWidget);
Expand Down Expand Up @@ -143,19 +142,19 @@ public void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int secondoverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keysecondoverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaultsecondoverhang));
int dayoverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keydayoverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaultdayoverhang));
int monthoverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keymonthoverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaultmonthoverhang));
int yearoverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keyyearoverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaultyearoverhang));
boolean twelvehour = sharedPreferences.getBoolean(context.getResources().getString(R.string.keytwelvehour) + appWidgetId, !DateFormat.is24HourFormat(context));
boolean enableseconds = sharedPreferences.getBoolean(context.getResources().getString(R.string.keyenableseconds) + appWidgetId, context.getResources().getBoolean(R.bool.defaultenableseconds));
boolean enabledate = sharedPreferences.getBoolean(context.getResources().getString(R.string.keyenabledate) + appWidgetId, context.getResources().getBoolean(R.bool.defaultenabledate));
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, yearoverhang,
twelvehour, enableseconds, enabledate, font, color, fontscale)
secondoverhang, minuteoverhang, houroverhang, dayoverhang, monthoverhang,
twelvehour, enableseconds, enabledate, font, color, fontscale, fontresolution)
);
try {
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
Expand Down
File renamed without changes
File renamed without changes
Loading

0 comments on commit 0d9ed43

Please sign in to comment.