diff --git a/README.md b/README.md index 69c3a1e..1bcd945 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,16 @@ Welcome to HangoverClock, the only clock which displays the real time in an unre If you just want to see what this widget looks like now, please click [here](https://github.com/programminghoch10/HangoverClock#the-next-generation) +[Download from Play Store](https://play.google.com/store/apps/details?id=com.JJ.hangoverclock) + [Download the newest APK](https://github.com/programminghoch10/HangoverClock/raw/master/app/release/app-release.apk) or look at the [latest stable releases](https://github.com/programminghoch10/HangoverClock/releases) For Wear OS Users, please look [here](https://github.com/programminghoch10/HangoverClock/tree/weardev) -![HangoverClock Icon new](icon/clock.png) -![HangoverClock Icon old](app/src/main/res/drawable-v24/clock.png) +![HangoverClock Icon new](icon/clockc.png) +![HangoverClock Icon old](icon/clock.png) ## What makes HangoverClock special? @@ -50,6 +52,8 @@ So my friends inspired me saying the idea is amazing, but the clocks design suck ## The next generation +![HangoverClock Dynamite Google Play Banner](pictures/playbannercutted.png) + ![HangoverClock Dynamite Picture 1](pictures/dynamite1.jpg) ![HangoverClock Dynamite Picture 2](pictures/dynamite2.png) (background not included) @@ -114,4 +118,15 @@ I'm always on the quest to make this the best HangoverClock ever. ## Thanksgiving Thanks to all my friends, who motivated me to do this. -Also thanks to my laptop, which crashed 2 times with literally nothing saved to disk. \ No newline at end of file +Also thanks to my laptop, which crashed 2 times with literally nothing saved to disk. + +  + +## Screenshots + +![Screenshot 1](pictures/playphone.png) +![Screenshot 2](pictures/playphoneconfig.png) + +![Screenshot 3](pictures/play10inch.png) + +![Screenshot 4](pictures/play7inch.png) \ No newline at end of file diff --git a/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java b/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java index 0a6ddf5..15172e6 100644 --- a/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java +++ b/app/src/main/java/com/JJ/hangoverclock/ConfigureWidget.java @@ -29,363 +29,363 @@ import java.util.Calendar; public class ConfigureWidget extends Activity { - - String TAG = "ConfigureWidget"; - int appWidgetID = AppWidgetManager.INVALID_APPWIDGET_ID; - View.OnClickListener savelistener = new View.OnClickListener() { - public void onClick(View v) { - final Context context = ConfigureWidget.this; - 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()); - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = sharedPreferences.edit(); - int minuteoverhang; - try { - minuteoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimeminutes)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - minuteoverhang = getResources().getInteger(R.integer.defaultminuteoverhang); - } - int houroverhang; - try { - houroverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimehours)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - houroverhang = context.getResources().getInteger(R.integer.defaulthouroverhang); - } - int secondoverhang = context.getResources().getInteger(R.integer.defaultsecondoverhang); - secondoverhang = minuteoverhang; - int dayoverhang; - try { - dayoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatedays)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - dayoverhang = getResources().getInteger(R.integer.defaultdayoverhang); - } - int monthoverhang; - try { - monthoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatemonths)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - monthoverhang = context.getResources().getInteger(R.integer.defaultmonthoverhang); - } - String font; - try { - font = ((Spinner) findViewById(R.id.fontspinner)).getSelectedItem().toString().replace(" ", "_"); - } catch (NullPointerException nulle) { - //maybe default language? - font = "default"; - } - SeekBar fontsizedividerseekbar = ((SeekBar) findViewById(R.id.datefontsizeseekbar)); - float fontscale = context.getResources().getInteger(R.integer.maxfontscale) - (float) (fontsizedividerseekbar.getMax() - fontsizedividerseekbar.getProgress()) / 100; - boolean enableseconds = ((Switch) findViewById(R.id.secondsselector)).isChecked(); - boolean autotwelvehours = ((Switch) findViewById(R.id.autohourselector)).isChecked(); - 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 - 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)) - editor.putString(context.getResources().getString(R.string.keyfont) + appWidgetID, font); - if (as | (context.getResources().getInteger(R.integer.defaultdatefontscale) != fontscale & enabledate)) - editor.putFloat(context.getResources().getString(R.string.keyfontscale) + appWidgetID, fontscale); - if (as | context.getResources().getInteger(R.integer.defaulthouroverhang) != houroverhang) - editor.putInt(context.getResources().getString(R.string.keyhouroverhang) + appWidgetID, houroverhang); - if (as | context.getResources().getInteger(R.integer.defaultminuteoverhang) != minuteoverhang) - editor.putInt(context.getResources().getString(R.string.keyminuteoverhang) + appWidgetID, minuteoverhang); - if (as | context.getResources().getInteger(R.integer.defaultsecondoverhang) != secondoverhang) - editor.putInt(context.getResources().getString(R.string.keysecondoverhang) + appWidgetID, secondoverhang); - if (as | context.getResources().getInteger(R.integer.defaultdayoverhang) != dayoverhang) - 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().getColor(R.color.defaultWidgetColor) != color) - editor.putInt(context.getResources().getString(R.string.keycolor) + appWidgetID, color); - if (!autotwelvehours) - editor.putBoolean(context.getResources().getString(R.string.keytwelvehour) + appWidgetID, twelvehours); - if (as | context.getResources().getBoolean(R.bool.defaultenabledate) != enabledate) - editor.putBoolean(context.getResources().getString(R.string.keyenabledate) + appWidgetID, enabledate); - editor.apply(); - // Push widget update to surface with newly set prefix - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - ClockWidgetProvider clockWidgetProvider = new ClockWidgetProvider(); - clockWidgetProvider.updateAppWidget(context, appWidgetManager, appWidgetID); - // Make sure we pass back the original appWidgetId - Intent resultValue = new Intent(); - resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetID); - setResult(RESULT_OK, resultValue); - finish(); - } - }; - SeekBar.OnSeekBarChangeListener colorseekbarlistener = new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - 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)); - viewblue.setBackgroundColor(Color.argb(255, 0, 0, Color.blue(color))); - viewgreen.setBackgroundColor(Color.argb(255, 0, Color.green(color), 0)); - viewalpha.setBackgroundColor(Color.argb(255, Color.alpha(color), Color.alpha(color), Color.alpha(color))); - viewcolor.setBackgroundColor(color); - updatepreview(); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - } - }; - - public ConfigureWidget() { - super(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // 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 + + String TAG = "ConfigureWidget"; + int appWidgetID = AppWidgetManager.INVALID_APPWIDGET_ID; + View.OnClickListener savelistener = new View.OnClickListener() { + public void onClick(View v) { + final Context context = ConfigureWidget.this; + SeekBar seekbarred = findViewById(R.id.seekbarred); + SeekBar seekbargreen = findViewById(R.id.seekbargreen); + SeekBar seekbarblue = findViewById(R.id.seekbarblue); + SeekBar seekbaralpha = findViewById(R.id.seekbaralpha); + int color = Color.argb(seekbaralpha.getProgress(), seekbarred.getProgress(), seekbargreen.getProgress(), seekbarblue.getProgress()); + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPreferences.edit(); + int minuteoverhang; + try { + minuteoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimeminutes)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + minuteoverhang = getResources().getInteger(R.integer.defaultminuteoverhang); + } + int houroverhang; + try { + houroverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimehours)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + houroverhang = context.getResources().getInteger(R.integer.defaulthouroverhang); + } + int secondoverhang = context.getResources().getInteger(R.integer.defaultsecondoverhang); + secondoverhang = minuteoverhang; + int dayoverhang; + try { + dayoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatedays)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + dayoverhang = getResources().getInteger(R.integer.defaultdayoverhang); + } + int monthoverhang; + try { + monthoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatemonths)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + monthoverhang = context.getResources().getInteger(R.integer.defaultmonthoverhang); + } + String font; + try { + font = ((Spinner) findViewById(R.id.fontspinner)).getSelectedItem().toString().replace(" ", "_"); + } catch (NullPointerException nulle) { + //maybe default language? + font = "default"; + } + SeekBar fontsizedividerseekbar = findViewById(R.id.datefontsizeseekbar); + float fontscale = context.getResources().getInteger(R.integer.maxfontscale) - (float) (fontsizedividerseekbar.getMax() - fontsizedividerseekbar.getProgress()) / 100; + boolean enableseconds = ((Switch) findViewById(R.id.secondsselector)).isChecked(); + boolean autotwelvehours = ((Switch) findViewById(R.id.autohourselector)).isChecked(); + 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 + 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)) + editor.putString(context.getResources().getString(R.string.keyfont) + appWidgetID, font); + if (as | (context.getResources().getInteger(R.integer.defaultdatefontscale) != fontscale & enabledate)) + editor.putFloat(context.getResources().getString(R.string.keyfontscale) + appWidgetID, fontscale); + if (as | context.getResources().getInteger(R.integer.defaulthouroverhang) != houroverhang) + editor.putInt(context.getResources().getString(R.string.keyhouroverhang) + appWidgetID, houroverhang); + if (as | context.getResources().getInteger(R.integer.defaultminuteoverhang) != minuteoverhang) + editor.putInt(context.getResources().getString(R.string.keyminuteoverhang) + appWidgetID, minuteoverhang); + if (as | context.getResources().getInteger(R.integer.defaultsecondoverhang) != secondoverhang) + editor.putInt(context.getResources().getString(R.string.keysecondoverhang) + appWidgetID, secondoverhang); + if (as | context.getResources().getInteger(R.integer.defaultdayoverhang) != dayoverhang) + 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().getColor(R.color.defaultWidgetColor) != color) + editor.putInt(context.getResources().getString(R.string.keycolor) + appWidgetID, color); + if (!autotwelvehours) + editor.putBoolean(context.getResources().getString(R.string.keytwelvehour) + appWidgetID, twelvehours); + if (as | context.getResources().getBoolean(R.bool.defaultenabledate) != enabledate) + editor.putBoolean(context.getResources().getString(R.string.keyenabledate) + appWidgetID, enabledate); + editor.apply(); + // Push widget update to surface with newly set prefix + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + ClockWidgetProvider clockWidgetProvider = new ClockWidgetProvider(); + clockWidgetProvider.updateAppWidget(context, appWidgetManager, appWidgetID); + // Make sure we pass back the original appWidgetId + Intent resultValue = new Intent(); + resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetID); + setResult(RESULT_OK, resultValue); + finish(); + } + }; + SeekBar.OnSeekBarChangeListener colorseekbarlistener = new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + View viewred = findViewById(R.id.viewred); + View viewgreen = findViewById(R.id.viewgreen); + View viewblue = findViewById(R.id.viewblue); + View viewalpha = findViewById(R.id.viewalpha); + View viewcolor = findViewById(R.id.viewcolor); + SeekBar seekbarred = findViewById(R.id.seekbarred); + SeekBar seekbargreen = findViewById(R.id.seekbargreen); + SeekBar seekbarblue = findViewById(R.id.seekbarblue); + SeekBar seekbaralpha = 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)); + viewblue.setBackgroundColor(Color.argb(255, 0, 0, Color.blue(color))); + viewgreen.setBackgroundColor(Color.argb(255, 0, Color.green(color), 0)); + viewalpha.setBackgroundColor(Color.argb(255, Color.alpha(color), Color.alpha(color), Color.alpha(color))); + viewcolor.setBackgroundColor(color); + updatepreview(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }; + + public ConfigureWidget() { + super(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // 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 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.seekbargreen)).getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY); - ((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, - R.id.overhanginputtimehours, - R.id.overhanginputdatedays, - R.id.overhanginputdatemonths, - }; - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - - @Override - public void afterTextChanged(Editable s) { - for (int id : ids) { - EditText editText = ((EditText) findViewById(id)); - String input = editText.getText().toString(); - String regexed = input.replaceAll("[^0-9]", ""); - if (!input.equals(regexed)) editText.setText(regexed); - } - updatepreview(); - } - }; - ((EditText) findViewById(R.id.overhanginputtimeminutes)).addTextChangedListener(inputwatcher); - ((EditText) findViewById(R.id.overhanginputdatedays)).addTextChangedListener(inputwatcher); - ((EditText) findViewById(R.id.overhanginputtimehours)).addTextChangedListener(inputwatcher); - ((EditText) findViewById(R.id.overhanginputdatemonths)).addTextChangedListener(inputwatcher); - CompoundButton.OnCheckedChangeListener updatepreviewlistener = new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updatepreview(); - } - }; - ((Switch) findViewById(R.id.hourselector)).setChecked(!DateFormat.is24HourFormat(ConfigureWidget.this)); - ((Switch) findViewById(R.id.dateselector)).setChecked(ConfigureWidget.this.getResources().getBoolean(R.bool.defaultenabledate)); - ((Switch) findViewById(R.id.secondsselector)).setChecked(ConfigureWidget.this.getResources().getBoolean(R.bool.defaultenableseconds)); - ((Switch) findViewById(R.id.autohourselector)).setChecked(ConfigureWidget.this.getResources().getBoolean(R.bool.defaultautotimeselector)); - ((Switch) findViewById(R.id.hourselector)).setEnabled(!((Switch) findViewById(R.id.autohourselector)).isChecked()); - ((Switch) findViewById(R.id.hourselector)).setOnCheckedChangeListener(updatepreviewlistener); - ((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 rowItems = new ArrayList(); - ArrayList 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); - fontspinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - updatepreview(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - } - }); - ((SeekBar) findViewById(R.id.datefontsizeseekbar)).setMax((ConfigureWidget.this.getResources().getInteger(R.integer.maxfontscale) - 3) * 100); - ((SeekBar) findViewById(R.id.datefontsizeseekbar)).setProgress( - ConfigureWidget.this.getResources().getInteger(R.integer.defaultdatefontscale) * 100 - - ((SeekBar) findViewById(R.id.datefontsizeseekbar)).getMax() - ); - ((SeekBar) findViewById(R.id.datefontsizeseekbar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - updatepreview(); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - } - }); - ((View) findViewById(R.id.viewcolor)).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ((SeekBar) findViewById(R.id.seekbarred)).setProgress((int) (Math.random() * 255)); - ((SeekBar) findViewById(R.id.seekbarblue)).setProgress((int) (Math.random() * 255)); - ((SeekBar) findViewById(R.id.seekbargreen)).setProgress((int) (Math.random() * 255)); - } - }); - updatepreview(); - } - - 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(); - boolean withdate = ((Switch) findViewById(R.id.dateselector)).isChecked(); - int minuteoverhang; - try { - minuteoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimeminutes)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - minuteoverhang = getResources().getInteger(R.integer.defaultminuteoverhang); - } - int houroverhang; - try { - houroverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimehours)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - houroverhang = context.getResources().getInteger(R.integer.defaulthouroverhang); - } - int secondoverhang = context.getResources().getInteger(R.integer.defaultsecondoverhang); - secondoverhang = minuteoverhang; - int dayoverhang; - try { - dayoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatedays)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - dayoverhang = getResources().getInteger(R.integer.defaultdayoverhang); - } - int monthoverhang; - try { - monthoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatemonths)).getText().toString()); - } catch (NumberFormatException numerr) { - //Expected error if no value was choosen, just set to default value - monthoverhang = context.getResources().getInteger(R.integer.defaultmonthoverhang); - } - boolean withseconds = ((Switch) findViewById(R.id.secondsselector)).isChecked(); - 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()); - SeekBar fontsizedividerseekbar = ((SeekBar) findViewById(R.id.datefontsizeseekbar)); - float fontsizedivider = context.getResources().getInteger(R.integer.maxfontscale) - (float) (fontsizedividerseekbar.getMax() - fontsizedividerseekbar.getProgress()) / 100; - if (((Switch) findViewById(R.id.dateselector)).isChecked()) { - findViewById(R.id.overhanginputdate).setVisibility(View.VISIBLE); - fontsizedividerseekbar.setVisibility(View.VISIBLE); - } else { - findViewById(R.id.overhanginputdate).setVisibility(View.GONE); - fontsizedividerseekbar.setVisibility(View.GONE); - } - if (((Switch) findViewById(R.id.secondsselector)).isChecked()) { - findViewById(R.id.secondsinfo).setVisibility(View.VISIBLE); - ((TextView) findViewById(R.id.secondsinfo)).setWidth(((Switch) findViewById(R.id.secondsselector)).getWidth()); - } else { - findViewById(R.id.secondsinfo).setVisibility(View.GONE); - } - if (((Switch) findViewById(R.id.autohourselector)).isChecked()) { - findViewById(R.id.hourselector).setEnabled(false); - ((Switch) findViewById(R.id.hourselector)).setChecked(!DateFormat.is24HourFormat(ConfigureWidget.this)); - } else { - findViewById(R.id.hourselector).setEnabled(true); - } - Spinner spinner = (Spinner) findViewById(R.id.fontspinner); - String font; - try { - font = spinner.getSelectedItem().toString(); - } catch (NullPointerException nulle) { - //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 - ); - bitmap.prepareToDraw(); - imageView.setImageBitmap(bitmap); - - } + ((SeekBar) findViewById(R.id.seekbarred)).getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY); + ((SeekBar) findViewById(R.id.seekbargreen)).getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY); + ((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 = findViewById(R.id.viewred); + View viewgreen = findViewById(R.id.viewgreen); + View viewblue = findViewById(R.id.viewblue); + View viewalpha = findViewById(R.id.viewalpha); + View viewcolor = findViewById(R.id.viewcolor); + SeekBar seekbarred = findViewById(R.id.seekbarred); + SeekBar seekbargreen = findViewById(R.id.seekbargreen); + SeekBar seekbarblue = findViewById(R.id.seekbarblue); + SeekBar seekbaralpha = 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, + R.id.overhanginputtimehours, + R.id.overhanginputdatedays, + R.id.overhanginputdatemonths, + }; + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + for (int id : ids) { + EditText editText = findViewById(id); + String input = editText.getText().toString(); + String regexed = input.replaceAll("[^0-9]", ""); + if (!input.equals(regexed)) editText.setText(regexed); + } + updatepreview(); + } + }; + ((EditText) findViewById(R.id.overhanginputtimeminutes)).addTextChangedListener(inputwatcher); + ((EditText) findViewById(R.id.overhanginputdatedays)).addTextChangedListener(inputwatcher); + ((EditText) findViewById(R.id.overhanginputtimehours)).addTextChangedListener(inputwatcher); + ((EditText) findViewById(R.id.overhanginputdatemonths)).addTextChangedListener(inputwatcher); + CompoundButton.OnCheckedChangeListener updatepreviewlistener = new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + updatepreview(); + } + }; + ((Switch) findViewById(R.id.hourselector)).setChecked(!DateFormat.is24HourFormat(ConfigureWidget.this)); + ((Switch) findViewById(R.id.dateselector)).setChecked(ConfigureWidget.this.getResources().getBoolean(R.bool.defaultenabledate)); + ((Switch) findViewById(R.id.secondsselector)).setChecked(ConfigureWidget.this.getResources().getBoolean(R.bool.defaultenableseconds)); + ((Switch) findViewById(R.id.autohourselector)).setChecked(ConfigureWidget.this.getResources().getBoolean(R.bool.defaultautotimeselector)); + findViewById(R.id.hourselector).setEnabled(!((Switch) findViewById(R.id.autohourselector)).isChecked()); + ((Switch) findViewById(R.id.hourselector)).setOnCheckedChangeListener(updatepreviewlistener); + ((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; + 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); + fontspinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + updatepreview(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + ((SeekBar) findViewById(R.id.datefontsizeseekbar)).setMax((ConfigureWidget.this.getResources().getInteger(R.integer.maxfontscale) - 3) * 100); + ((SeekBar) findViewById(R.id.datefontsizeseekbar)).setProgress( + ConfigureWidget.this.getResources().getInteger(R.integer.defaultdatefontscale) * 100 + - ((SeekBar) findViewById(R.id.datefontsizeseekbar)).getMax() + ); + ((SeekBar) findViewById(R.id.datefontsizeseekbar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + updatepreview(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + findViewById(R.id.viewcolor).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ((SeekBar) findViewById(R.id.seekbarred)).setProgress((int) (Math.random() * 255)); + ((SeekBar) findViewById(R.id.seekbarblue)).setProgress((int) (Math.random() * 255)); + ((SeekBar) findViewById(R.id.seekbargreen)).setProgress((int) (Math.random() * 255)); + } + }); + updatepreview(); + } + + 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 = findViewById(R.id.previewclock); + boolean twelvehour = ((Switch) findViewById(R.id.hourselector)).isChecked(); + boolean withdate = ((Switch) findViewById(R.id.dateselector)).isChecked(); + int minuteoverhang; + try { + minuteoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimeminutes)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + minuteoverhang = getResources().getInteger(R.integer.defaultminuteoverhang); + } + int houroverhang; + try { + houroverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputtimehours)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + houroverhang = context.getResources().getInteger(R.integer.defaulthouroverhang); + } + int secondoverhang = context.getResources().getInteger(R.integer.defaultsecondoverhang); + secondoverhang = minuteoverhang; + int dayoverhang; + try { + dayoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatedays)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + dayoverhang = getResources().getInteger(R.integer.defaultdayoverhang); + } + int monthoverhang; + try { + monthoverhang = Integer.valueOf(((EditText) findViewById(R.id.overhanginputdatemonths)).getText().toString()); + } catch (NumberFormatException numerr) { + //Expected error if no value was choosen, just set to default value + monthoverhang = context.getResources().getInteger(R.integer.defaultmonthoverhang); + } + boolean withseconds = ((Switch) findViewById(R.id.secondsselector)).isChecked(); + SeekBar seekbarred = findViewById(R.id.seekbarred); + SeekBar seekbargreen = findViewById(R.id.seekbargreen); + SeekBar seekbarblue = findViewById(R.id.seekbarblue); + 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; + if (((Switch) findViewById(R.id.dateselector)).isChecked()) { + findViewById(R.id.overhanginputdate).setVisibility(View.VISIBLE); + fontsizedividerseekbar.setVisibility(View.VISIBLE); + } else { + findViewById(R.id.overhanginputdate).setVisibility(View.GONE); + fontsizedividerseekbar.setVisibility(View.GONE); + } + if (((Switch) findViewById(R.id.secondsselector)).isChecked()) { + findViewById(R.id.secondsinfo).setVisibility(View.VISIBLE); + ((TextView) findViewById(R.id.secondsinfo)).setWidth(findViewById(R.id.secondsselector).getWidth()); + } else { + findViewById(R.id.secondsinfo).setVisibility(View.GONE); + } + if (((Switch) findViewById(R.id.autohourselector)).isChecked()) { + findViewById(R.id.hourselector).setEnabled(false); + ((Switch) findViewById(R.id.hourselector)).setChecked(!DateFormat.is24HourFormat(ConfigureWidget.this)); + } else { + findViewById(R.id.hourselector).setEnabled(true); + } + Spinner spinner = findViewById(R.id.fontspinner); + String font; + try { + font = spinner.getSelectedItem().toString(); + } catch (NullPointerException nulle) { + //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 + ); + bitmap.prepareToDraw(); + imageView.setImageBitmap(bitmap); + + } } diff --git a/app/src/main/java/com/JJ/hangoverclock/CustomSpinnerAdapter.java b/app/src/main/java/com/JJ/hangoverclock/CustomSpinnerAdapter.java index 171282e..790f861 100644 --- a/app/src/main/java/com/JJ/hangoverclock/CustomSpinnerAdapter.java +++ b/app/src/main/java/com/JJ/hangoverclock/CustomSpinnerAdapter.java @@ -15,96 +15,96 @@ import java.util.List; public class CustomSpinnerAdapter extends ArrayAdapter { - - private int spinner = R.id.spinnerview; - private String TAG = "CustomSpinnerAdapter"; - private LayoutInflater flater; - - CustomSpinnerAdapter(Activity context, int resouceId, int textviewId, List list) { - - super(context, resouceId, textviewId, list); - flater = context.getLayoutInflater(); - } - - @Override - 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)); - if (position == 0) return rowview; - 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); - } - return rowview; - } - - @Override - 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) view.findViewById(spinner); - txtTitle.setText(rowItem.getTitle()); - txtTitle.setTypeface(rowItem.getTypeface()); - return view; - } + + private int spinner = R.id.spinnerview; + private String TAG = "CustomSpinnerAdapter"; + private LayoutInflater flater; + + CustomSpinnerAdapter(Activity context, int resouceId, int textviewId, List list) { + + super(context, resouceId, textviewId, list); + flater = context.getLayoutInflater(); + } + + @Override + 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 = rowview.findViewById(spinner); + txtTitle.setText(rowItem.getTitle()); + txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); + if (position == 0) return rowview; + 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); + } + return rowview; + } + + @Override + 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 = view.findViewById(spinner); + txtTitle.setText(rowItem.getTitle()); + txtTitle.setTypeface(rowItem.getTypeface()); + return view; + } } class RowItem { - - private final static String TAG = "rowitem"; - private String title; - private Typeface typeface; - private int visibility; - - 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; - } - } - - String getTitle() { - return title; - } - - String getTitleFont(int position) { - return ClockWidgetProvider.fonts.get(position).replace(" ", "_"); - } - Typeface getTypeface() { - return typeface; - } + private final static String TAG = "rowitem"; + private String title; + private Typeface typeface; + private int visibility; + + 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; + } + } + + String getTitle() { + return title; + } + + String getTitleFont(int position) { + return ClockWidgetProvider.fonts.get(position).replace(" ", "_"); + } + + Typeface getTypeface() { + return typeface; + } - int getVisibility() { - return visibility; - } + int getVisibility() { + return visibility; + } - @Override - public String toString() { - return title; - } + @Override + public String toString() { + return title; + } } diff --git a/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java b/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java index 58317d9..db0c559 100644 --- a/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java +++ b/app/src/main/java/com/jj/hangoverclock/ClockWidgetProvider.java @@ -10,7 +10,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; - import android.text.format.DateFormat; import android.util.Log; import android.widget.RemoteViews; @@ -22,144 +21,143 @@ import java.util.Calendar; public class ClockWidgetProvider extends AppWidgetProvider { - - static final String TAG = "ClockWidgetProvider"; - public static ArrayList fonts = new ArrayList() {{ - add("default"); - }}; - - private static String CLOCK_WIDGET_UPDATE = "com.JJ.hangoverclock.widgetupdate"; - - public static void collectfonts(Context context) { - Field[] fontfields = R.font.class.getFields(); - fonts.set(0, context.getString(R.string.defaultfonttext)); - for (int i = 1; i < fontfields.length + 1; i++) { - Field fontfield = fontfields[i - 1]; - String fontname; - try { - fontname = fontfield.getName().replace("_", " "); - } catch (Exception e) { - fontname = null; - } - //Log.d(TAG, "collectfonts: fontname " + i + " is \"" + fontname + "\""); - if (fontname != null) { - boolean indexexists; - try { - //noinspection ResultOfMethodCallIgnored - fonts.get(i); - indexexists = true; - } catch (IndexOutOfBoundsException indexerr) { - indexexists = false; - } - if (!indexexists) { - fonts.add(i, fontname); - } else { - fonts.set(i, fontname); - } - } - } - } - - public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { - for (int appWidgetId : appWidgetIds) { - RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); - appWidgetManager.updateAppWidget(appWidgetId, remoteViews); - updateAppWidget(context, appWidgetManager, appWidgetId); - onEnabled(context); - } - setAlarmManager(context); - } - - @Override - public void onReceive(Context context, Intent intent) { - super.onReceive(context, intent); - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - if (CLOCK_WIDGET_UPDATE.equals(intent.getAction())) { - ComponentName thisAppWidget = new ComponentName(context.getPackageName(), getClass().getName()); - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - int[] ids = appWidgetManager.getAppWidgetIds(thisAppWidget); - boolean increaserefreshrate = false; - for (int appWidgetID : ids) { - if (sharedPreferences.getBoolean(context.getResources().getString(R.string.keyenableseconds) + appWidgetID, - context.getResources().getBoolean(R.bool.defaultenableseconds))) - increaserefreshrate = true; - updateAppWidget(context, appWidgetManager, appWidgetID); - } - SharedPreferences.Editor editor = sharedPreferences.edit(); - if (context.getResources().getBoolean(R.bool.alwayssavepreference) - | increaserefreshrate != context.getResources().getBoolean(R.bool.defaultincreaserefreshrate)) - editor.putBoolean(context.getResources().getString(R.string.keyincreaserefreshrate), increaserefreshrate); - editor.apply(); - setAlarmManager(context); - } - } - - private PendingIntent createClockTickIntent(Context context) { - Intent intent = new Intent(context, getClass()); - intent.setAction(CLOCK_WIDGET_UPDATE); - return PendingIntent.getBroadcast(context, 23, intent, PendingIntent.FLAG_UPDATE_CURRENT); - } - - @SuppressLint("ApplySharedPref") - @Override - public void onDisabled(Context context) { - super.onDisabled(context); - AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - alarmManager.cancel(createClockTickIntent(context)); - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.clear(); - editor.commit(); //commit is intentional, i want to wait until cleanup is done - Log.i(TAG, "Final cleanup done, Goodbye!"); - } - - @Override - public void onEnabled(Context context) { - super.onEnabled(context); - Log.i(TAG, "Hello World!"); - setAlarmManager(context); - collectfonts(context); - } - - private void setAlarmManager(Context context) { - AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( - context.getResources().getString(R.string.keyincreaserefreshrate), - context.getResources().getBoolean(R.bool.defaultincreaserefreshrate))) { - calendar.add(Calendar.SECOND, 1); - } else { - calendar.add(Calendar.SECOND, (60 - calendar.get(Calendar.SECOND))); - } - AlarmManagerCompat.setExact(alarmManager, AlarmManager.RTC, calendar.getTimeInMillis(), createClockTickIntent(context)); - } - - public void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - int houroverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keyhouroverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaulthouroverhang)); - int minuteoverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keyminuteoverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaultminuteoverhang)); - 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)); - 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, - twelvehour, enableseconds, enabledate, font, color, fontscale, fontresolution) - ); - try { - appWidgetManager.updateAppWidget(appWidgetId, remoteViews); - } catch (Exception e) { - Log.e(TAG, "updateAppWidget: error pushing bitmap", e); - } - } + + static final String TAG = "ClockWidgetProvider"; + public static ArrayList fonts = new ArrayList() {{ + add("default"); + }}; + + private static String CLOCK_WIDGET_UPDATE = "com.JJ.hangoverclock.widgetupdate"; + + public static void collectfonts(Context context) { + Field[] fontfields = R.font.class.getFields(); + fonts.set(0, context.getString(R.string.defaultfonttext)); + for (int i = 1; i < fontfields.length + 1; i++) { + Field fontfield = fontfields[i - 1]; + String fontname; + try { + fontname = fontfield.getName().replace("_", " "); + } catch (Exception e) { + fontname = null; + } + //Log.d(TAG, "collectfonts: fontname " + i + " is \"" + fontname + "\""); + if (fontname != null) { + boolean indexexists; + try { + //noinspection ResultOfMethodCallIgnored + fonts.get(i); + indexexists = true; + } catch (IndexOutOfBoundsException indexerr) { + indexexists = false; + } + if (!indexexists) { + fonts.add(i, fontname); + } else { + fonts.set(i, fontname); + } + } + } + } + + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + for (int appWidgetId : appWidgetIds) { + RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); + appWidgetManager.updateAppWidget(appWidgetId, remoteViews); + updateAppWidget(context, appWidgetManager, appWidgetId); + } + setAlarmManager(context); + } + + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + if (CLOCK_WIDGET_UPDATE.equals(intent.getAction())) { + ComponentName thisAppWidget = new ComponentName(context.getPackageName(), getClass().getName()); + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + int[] ids = appWidgetManager.getAppWidgetIds(thisAppWidget); + boolean increaserefreshrate = false; + for (int appWidgetID : ids) { + if (sharedPreferences.getBoolean(context.getResources().getString(R.string.keyenableseconds) + appWidgetID, + context.getResources().getBoolean(R.bool.defaultenableseconds))) + increaserefreshrate = true; + updateAppWidget(context, appWidgetManager, appWidgetID); + } + SharedPreferences.Editor editor = sharedPreferences.edit(); + if (context.getResources().getBoolean(R.bool.alwayssavepreference) + | increaserefreshrate != context.getResources().getBoolean(R.bool.defaultincreaserefreshrate)) + editor.putBoolean(context.getResources().getString(R.string.keyincreaserefreshrate), increaserefreshrate); + editor.apply(); + setAlarmManager(context); + } + } + + private PendingIntent createClockTickIntent(Context context) { + Intent intent = new Intent(context, getClass()); + intent.setAction(CLOCK_WIDGET_UPDATE); + return PendingIntent.getBroadcast(context, 23, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } + + @SuppressLint("ApplySharedPref") + @Override + public void onDisabled(Context context) { + super.onDisabled(context); + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + alarmManager.cancel(createClockTickIntent(context)); + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.clear(); + editor.commit(); //commit is intentional, i want to wait until cleanup is done + Log.i(TAG, "Final cleanup done, Goodbye!"); + } + + @Override + public void onEnabled(Context context) { + super.onEnabled(context); + Log.i(TAG, "Hello World!"); + setAlarmManager(context); + collectfonts(context); + } + + private void setAlarmManager(Context context) { + AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( + context.getResources().getString(R.string.keyincreaserefreshrate), + context.getResources().getBoolean(R.bool.defaultincreaserefreshrate))) { + calendar.add(Calendar.SECOND, 1); + } else { + calendar.add(Calendar.SECOND, (60 - calendar.get(Calendar.SECOND))); + } + AlarmManagerCompat.setExact(alarmManager, AlarmManager.RTC, calendar.getTimeInMillis(), createClockTickIntent(context)); + } + + public void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + int houroverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keyhouroverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaulthouroverhang)); + int minuteoverhang = sharedPreferences.getInt(context.getResources().getString(R.string.keyminuteoverhang) + appWidgetId, context.getResources().getInteger(R.integer.defaultminuteoverhang)); + 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)); + 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, + twelvehour, enableseconds, enabledate, font, color, fontscale, fontresolution) + ); + try { + appWidgetManager.updateAppWidget(appWidgetId, remoteViews); + } catch (Exception e) { + Log.e(TAG, "updateAppWidget: error pushing bitmap", e); + } + } } diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml index b6cd50b..506fa11 100644 --- a/app/src/main/res/values/integers.xml +++ b/app/src/main/res/values/integers.xml @@ -1,6 +1,6 @@ - 150 + 150 5 5 \ No newline at end of file diff --git a/icon/clock.png b/icon/clock.png index 3bc46c2..6978433 100644 Binary files a/icon/clock.png and b/icon/clock.png differ diff --git a/icon/clockc.png b/icon/clockc.png new file mode 100644 index 0000000..3bc46c2 Binary files /dev/null and b/icon/clockc.png differ diff --git a/icon/clock.xcf b/icon/clockc.xcf similarity index 100% rename from icon/clock.xcf rename to icon/clockc.xcf diff --git a/icon/clock c.png b/icon/clockconly.png similarity index 100% rename from icon/clock c.png rename to icon/clockconly.png diff --git a/icon/clock c.xcf b/icon/clockconly.xcf similarity index 100% rename from icon/clock c.xcf rename to icon/clockconly.xcf diff --git a/pictures/play10inch.png b/pictures/play10inch.png new file mode 100644 index 0000000..080a636 Binary files /dev/null and b/pictures/play10inch.png differ diff --git a/pictures/play7inch.png b/pictures/play7inch.png new file mode 100644 index 0000000..3fa0f6b Binary files /dev/null and b/pictures/play7inch.png differ diff --git a/pictures/playbanner.png b/pictures/playbanner.png new file mode 100644 index 0000000..8b7d78a Binary files /dev/null and b/pictures/playbanner.png differ diff --git a/pictures/playbannercutted.png b/pictures/playbannercutted.png new file mode 100644 index 0000000..5c34d6b Binary files /dev/null and b/pictures/playbannercutted.png differ diff --git a/pictures/playbannerfinished.png b/pictures/playbannerfinished.png new file mode 100644 index 0000000..b41acc4 Binary files /dev/null and b/pictures/playbannerfinished.png differ diff --git a/pictures/playphone.png b/pictures/playphone.png new file mode 100644 index 0000000..bdc961c Binary files /dev/null and b/pictures/playphone.png differ diff --git a/pictures/playphoneconfig.png b/pictures/playphoneconfig.png new file mode 100644 index 0000000..5df9b7f Binary files /dev/null and b/pictures/playphoneconfig.png differ