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 15, 2019
2 parents 0d9ed43 + 042325b commit ed27832
Show file tree
Hide file tree
Showing 25 changed files with 174 additions and 147 deletions.
10 changes: 10 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.JJ.hangoverclock"
minSdkVersion 16
minSdkVersion 14
targetSdkVersion 28
versionCode 4
versionCode 7
versionName "dynamite"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
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":4,"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":7,"versionName":"dynamite","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<receiver android:name=".ClockWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
Expand Down
88 changes: 54 additions & 34 deletions app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
Expand Down Expand Up @@ -155,31 +157,57 @@ public ConfigureWidget() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ClockWidgetProvider.collectfonts(ConfigureWidget.this);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if they press the back button.
setResult(RESULT_CANCELED);
// Set the view layout resource to use.
setContentView(R.layout.widget_configure);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
appWidgetID = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (appWidgetID == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
ClockWidgetProvider.collectfonts(ConfigureWidget.this);
findViewById(R.id.save).setOnClickListener(savelistener);
// Change seekbar colors
//SeekBar sb = (SeekBar) findViewById(R.id.seekBar2);
//sb.getProgressDrawable().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
((SeekBar) findViewById(R.id.seekbarred)).getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
((SeekBar) findViewById(R.id.seekbarblue)).getThumb().setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN);
((SeekBar) findViewById(R.id.seekbargreen)).getThumb().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
((SeekBar) findViewById(R.id.seekbarred)).getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
((SeekBar) findViewById(R.id.seekbargreen)).getThumb().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
((SeekBar) findViewById(R.id.seekbarblue)).getThumb().setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN);
}
((SeekBar) findViewById(R.id.seekbarred)).getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
((SeekBar) findViewById(R.id.seekbarblue)).getProgressDrawable().setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY);
((SeekBar) findViewById(R.id.seekbargreen)).getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
((SeekBar) findViewById(R.id.seekbarred)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbargreen)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbarblue)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbaralpha)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbarblue)).getProgressDrawable().setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY);
int defaultColor = getResources().getColor(R.color.defaultWidgetColor);
((SeekBar) findViewById(R.id.seekbarred)).setProgress(Color.red(defaultColor));
((SeekBar) findViewById(R.id.seekbargreen)).setProgress(Color.green(defaultColor));
((SeekBar) findViewById(R.id.seekbarblue)).setProgress(Color.blue(defaultColor));
((SeekBar) findViewById(R.id.seekbaralpha)).setProgress(Color.alpha(defaultColor));
((SeekBar) findViewById(R.id.seekbarred)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbargreen)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbarblue)).setOnSeekBarChangeListener(colorseekbarlistener);
((SeekBar) findViewById(R.id.seekbaralpha)).setOnSeekBarChangeListener(colorseekbarlistener);
View viewred = (View) findViewById(R.id.viewred);
View viewgreen = (View) findViewById(R.id.viewgreen);
View viewblue = (View) findViewById(R.id.viewblue);
View viewalpha = (View) findViewById(R.id.viewalpha);
View viewcolor = (View) findViewById(R.id.viewcolor);
SeekBar seekbarred = (SeekBar) findViewById(R.id.seekbarred);
SeekBar seekbargreen = (SeekBar) findViewById(R.id.seekbargreen);
SeekBar seekbarblue = (SeekBar) findViewById(R.id.seekbarblue);
SeekBar seekbaralpha = (SeekBar) findViewById(R.id.seekbaralpha);
int color = Color.argb(seekbaralpha.getProgress(), seekbarred.getProgress(), seekbargreen.getProgress(), seekbarblue.getProgress());
viewred.setBackgroundColor(Color.argb(255, Color.red(color), 0, 0));
viewgreen.setBackgroundColor(Color.argb(255, 0, Color.green(color), 0));
viewblue.setBackgroundColor(Color.argb(255, 0, 0, Color.blue(color)));
viewalpha.setBackgroundColor(Color.argb(255, Color.alpha(color), Color.alpha(color), Color.alpha(color)));
viewcolor.setBackgroundColor(color);
TextWatcher inputwatcher = new TextWatcher() {
final int[] ids = {
R.id.overhanginputtimeminutes,
Expand Down Expand Up @@ -226,11 +254,14 @@ 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 = (Spinner) findViewById(R.id.fontspinner);
ArrayList<RowItem> rowItems = new ArrayList<RowItem>();
for (String font : ClockWidgetProvider.fonts) {
RowItem item = new RowItem(font);
rowItems.add(item);
ArrayList<String> fonts = ClockWidgetProvider.fonts;
for (int i = 0; i < fonts.size(); i++) {
String font = fonts.get(i);
RowItem item = new RowItem(ConfigureWidget.this, font, i);
if (item.getVisibility() == View.VISIBLE) rowItems.add(item);
}
final SpinnerAdapter spinnerAdapter = new CustomSpinnerAdapter(ConfigureWidget.this, R.layout.listitems_layout, R.id.spinnerview, rowItems);
fontspinner.setAdapter(spinnerAdapter);
Expand Down Expand Up @@ -272,22 +303,11 @@ public void onClick(View v) {
}
});
updatepreview();
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
appWidgetID = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
// i guess this is a bit late,
//TODO: move this crap up
if (appWidgetID == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
}

private void updatepreview() {
//Log.d(TAG, "updatepreview: i have been called");
//Log.d(TAG, "updatepreview: trace is " + Arrays.toString(Thread.currentThread().getStackTrace()));
final Context context = ConfigureWidget.this;
ImageView imageView = (ImageView) findViewById(R.id.previewclock);
boolean twelvehour = ((Switch) findViewById(R.id.hourselector)).isChecked();
Expand Down Expand Up @@ -358,14 +378,14 @@ private void updatepreview() {
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,
twelvehour, withseconds, withdate,
font, color, fontsizedivider, fontresolution
)
Bitmap bitmap = WidgetGenerator.generateWidget(
context, Calendar.getInstance().getTimeInMillis(),
secondoverhang, minuteoverhang, houroverhang, dayoverhang, monthoverhang,
twelvehour, withseconds, withdate,
font, color, fontsizedivider, fontresolution
);
bitmap.prepareToDraw();
imageView.setImageBitmap(bitmap);

}
}
80 changes: 46 additions & 34 deletions app/src/main/java/com/JJ/hangoverclock/CustomSpinnerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.JJ.hangoverclock;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import androidx.core.content.res.ResourcesCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.core.content.res.ResourcesCompat;

import java.util.List;

public class CustomSpinnerAdapter extends ArrayAdapter<RowItem> {

int spinner = R.id.spinnerview;
String TAG = "CustomSpinnerAdapter";
LayoutInflater flater;
private int spinner = R.id.spinnerview;
private String TAG = "CustomSpinnerAdapter";
private LayoutInflater flater;

CustomSpinnerAdapter(Activity context, int resouceId, int textviewId, List<RowItem> list) {

Expand All @@ -30,7 +32,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
RowItem rowItem = getItem(position);

View rowview = flater.inflate(R.layout.listitems_layout, null, true);

TextView txtTitle = (TextView) rowview.findViewById(spinner);
txtTitle.setText(rowItem.getTitle());
txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
Expand All @@ -47,52 +49,62 @@ public View getView(int position, View convertView, ViewGroup parent) {
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = flater.inflate(R.layout.listitems_layout, parent, false);
public View getDropDownView(int position, View view, ViewGroup parent) {
if (view == null) {
view = flater.inflate(R.layout.listitems_layout, parent, false);
}
RowItem rowItem = getItem(position);
TextView txtTitle = (TextView) convertView.findViewById(spinner);
TextView txtTitle = (TextView) view.findViewById(spinner);
txtTitle.setText(rowItem.getTitle());
txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
if (position == 0) return convertView;
try {
//Log.d(TAG, "getView: tf string is " + rowItem.getTitleFont(position));
//Log.d(TAG, "getView: identifier is " + getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()));
//Log.d(TAG, "getView: typefont is " + ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())));
txtTitle.setTypeface(ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())));
} catch (Exception e) {
Log.e(TAG, "getView: error occured while determiting font", e);
txtTitle.setVisibility(View.GONE);
}
return convertView;
txtTitle.setTypeface(rowItem.getTypeface());
return view;
}
}


class RowItem {

private String Title;
private final static String TAG = "rowitem";
private String title;
private Typeface typeface;
private int visibility;

public RowItem(String Title) {
this.Title = Title;
}

public String getTitle() {
return Title;
RowItem(Context context, String title, int position) {
this.title = title;
if (position == 0) {
typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
return;
}
try {
//Log.d(TAG, "getView: tf string is " + rowItem.getTitleFont(position));
//Log.d(TAG, "getView: identifier is " + getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName()));
//Log.d(TAG, "getView: typefont is " + ResourcesCompat.getFont(getContext(), getContext().getResources().getIdentifier(rowItem.getTitleFont(position), "font", getContext().getPackageName())));
typeface = ResourcesCompat.getFont(context, context.getResources().getIdentifier(getTitleFont(position), "font", context.getPackageName()));
} catch (Exception e) {
Log.e(TAG, "getView: error occured while determiting font "+title, e);
//visibility = View.GONE;
visibility = View.INVISIBLE;
}
}

public void setTitle(String Title) {

this.Title = Title;
String getTitle() {
return title;
}

public String getTitleFont(int position) {
String getTitleFont(int position) {
return ClockWidgetProvider.fonts.get(position).replace(" ", "_");
}


Typeface getTypeface() {
return typeface;
}

int getVisibility() {
return visibility;
}

@Override
public String toString() {
return Title;
return title;
}
}
Loading

0 comments on commit ed27832

Please sign in to comment.