diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt
index 9ffada9..f20ea9c 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt
@@ -16,6 +16,7 @@ object Constants {
val WEATHER_APP_REQUEST_CODE = 4
val EVENT_APP_REQUEST_CODE = 6
val WEATHER_PROVIDER_REQUEST_CODE = 5
+ val CLOCK_APP_REQUEST_CODE = 7
val RESULT_CODE_CUSTOM_LOCATION = 45
@@ -56,6 +57,10 @@ object Constants {
val PREF_TEXT_COLOR = "PREF_TEXT_COLOR"
val PREF_TEXT_MAIN_SIZE = "PREF_TEXT_MAIN_SIZE"
val PREF_TEXT_SECOND_SIZE = "PREF_TEXT_SECOND_SIZE"
+ val PREF_WEATHER_PROVIDER = "PREF_WEATHER_PROVIDER"
+ val PREF_SHOW_CLOCK = "PREF_SHOW_CLOCK"
+ val PREF_CLOCK_APP_NAME = "PREF_CLOCK_APP_NAME"
+ val PREF_CLOCK_APP_PACKAGE = "PREF_CLOCK_APP_PACKAGE"
val ACTION_EXTRA_OPEN_WEATHER_PROVIDER = "ACTION_EXTRA_OPEN_WEATHER_PROVIDER"
@@ -68,4 +73,7 @@ object Constants {
val ACTION_CALENDAR_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_CALENDAR_UPDATE"
val ACTION_WEATHER_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_WEATHER_UPDATE"
val ACTION_SOMETHING_APPENED = "com.tommasoberlose.anotherwidget.action.ACTION_SOMETHING_APPENED"
+
+ val WEATHER_PROVIDER_GOOGLE_AWARENESS = 1
+ val WEATHER_PROVIDER_OPEN_WEATHER = 2
}
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/UpdatesReceiver.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/UpdatesReceiver.kt
index 3f871e0..000e585 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/UpdatesReceiver.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/UpdatesReceiver.kt
@@ -23,7 +23,7 @@ class UpdatesReceiver : BroadcastReceiver() {
setUpdates(context)
} else if (intent.action.equals(Constants.ACTION_TIME_UPDATE)) {
val e: Event = CalendarUtil.getNextEvent(context)
- if (e.id == 0 || e.endDate < Calendar.getInstance().timeInMillis) {
+ if (e.id == 0 || e.endDate <= Calendar.getInstance().timeInMillis) {
CalendarUtil.updateEventList(context)
} else {
Util.updateWidget(context)
@@ -36,12 +36,15 @@ class UpdatesReceiver : BroadcastReceiver() {
fun setUpdates(context: Context) {
removeUpdates(context)
CalendarUtil.updateEventList(context)
+ val now = Calendar.getInstance()
+ now.set(Calendar.MILLISECOND, 0)
+ now.set(Calendar.SECOND, 0)
val am = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val i = Intent(context, UpdatesReceiver::class.java)
i.action = Constants.ACTION_TIME_UPDATE
val pi = PendingIntent.getBroadcast(context, 0, i, 0)
- am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (1000 * 60).toLong(), pi)
+ am.setRepeating(AlarmManager.RTC_WAKEUP, now.timeInMillis, (1000 * 60).toLong(), pi)
}
fun removeUpdates(context: Context) {
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt
index 4bd08c8..99ad259 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt
@@ -10,8 +10,10 @@ import android.content.SharedPreferences
import android.preference.PreferenceManager
import android.util.Log
import com.tommasoberlose.anotherwidget.`object`.Constants
+import com.tommasoberlose.anotherwidget.util.CalendarUtil
import com.tommasoberlose.anotherwidget.util.Util
import com.tommasoberlose.anotherwidget.util.WeatherUtil
+import java.util.*
class WeatherReceiver : BroadcastReceiver() {
@@ -41,7 +43,10 @@ class WeatherReceiver : BroadcastReceiver() {
5 -> 60 * 24
else -> 60
}
- am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * refresh, pi)
+ val now = Calendar.getInstance()
+ now.set(Calendar.MILLISECOND, 0)
+ now.set(Calendar.SECOND, 0)
+ am.setRepeating(AlarmManager.RTC_WAKEUP, now.timeInMillis, 1000 * 60 * refresh, pi)
}
fun setOneTimeUpdate(context: Context) {
@@ -49,9 +54,13 @@ class WeatherReceiver : BroadcastReceiver() {
val i = Intent(context, WeatherReceiver::class.java)
i.action = Constants.ACTION_WEATHER_UPDATE
val pi = PendingIntent.getBroadcast(context, 1, i, 0)
- am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60 * 10, pi)
- am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60 * 15, pi)
- am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000 * 60 * 20, pi)
+
+ val now = Calendar.getInstance()
+ now.set(Calendar.MILLISECOND, 0)
+ now.set(Calendar.SECOND, 0)
+ am.setExact(AlarmManager.RTC_WAKEUP, now.timeInMillis + 1000 * 60 * 10, pi)
+ am.setExact(AlarmManager.RTC_WAKEUP, now.timeInMillis + 1000 * 60 * 15, pi)
+ am.setExact(AlarmManager.RTC_WAKEUP, now.timeInMillis + 1000 * 60 * 20, pi)
}
fun removeUpdates(context: Context) {
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt
index c01a719..2d5cfcb 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt
@@ -24,6 +24,7 @@ import com.tommasoberlose.anotherwidget.util.CalendarUtil
import com.tommasoberlose.anotherwidget.util.WeatherUtil
import android.content.DialogInterface
import android.graphics.Color
+import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.os.Build
import android.support.annotation.ColorInt
@@ -41,6 +42,7 @@ import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.key_time_wait_layout.view.*
import kotlinx.android.synthetic.main.main_menu_layout.view.*
import kotlinx.android.synthetic.main.the_widget.*
+import kotlinx.android.synthetic.main.the_widget.view.*
class MainActivity : AppCompatActivity() {
@@ -171,6 +173,8 @@ class MainActivity : AppCompatActivity() {
fun updateUI() {
updateSettings()
updateAppWidget()
+ updateClockView()
+ widget_bitmap.setImageBitmap(Util.getBitmapFromView(main_layout))
}
@@ -180,6 +184,7 @@ class MainActivity : AppCompatActivity() {
widget_bg.setImageDrawable(wallpaper)
updateCalendarView()
updateLocationView()
+ updateClockView()
}
}
@@ -210,6 +215,13 @@ class MainActivity : AppCompatActivity() {
.commit()
Util.updateWidget(this)
updateSettings()
+ } else if (requestCode == Constants.CLOCK_APP_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
+ SP.edit()
+ .putString(Constants.PREF_CLOCK_APP_NAME, data.getStringExtra(Constants.RESULT_APP_NAME))
+ .putString(Constants.PREF_CLOCK_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
+ .commit()
+ Util.updateWidget(this)
+ updateSettings()
} else if (requestCode == Constants.WEATHER_PROVIDER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
WeatherReceiver().setOneTimeUpdate(this)
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
@@ -231,6 +243,17 @@ class MainActivity : AppCompatActivity() {
}
}
+ fun updateClockView() {
+ val SP = PreferenceManager.getDefaultSharedPreferences(this)
+ if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
+ time.visibility = View.GONE
+ } else {
+ time.visibility = View.VISIBLE
+ }
+ val now = Calendar.getInstance()
+ time.text = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(now.timeInMillis) else Constants.goodHourFormat.format(now.timeInMillis)
+ }
+
fun updateCalendarView() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
val now = Calendar.getInstance()
@@ -307,6 +330,17 @@ class MainActivity : AppCompatActivity() {
next_event_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
divider2.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
calendar_temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
+
+
+ val product_sans: Typeface = Typeface.createFromAsset(assets, "fonts/product_sans_regular.ttf")
+ empty_date.typeface = product_sans
+ divider1.typeface = product_sans
+ temp.typeface = product_sans
+ next_event.typeface = product_sans
+ next_event_difference_time.typeface = product_sans
+ next_event_date.typeface = product_sans
+ divider2.typeface = product_sans
+ calendar_temp.typeface = product_sans
}
fun updateLocationView() {
@@ -342,6 +376,31 @@ class MainActivity : AppCompatActivity() {
fun updateSettings() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
+ if (SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
+ clock_settings.visibility = View.VISIBLE
+ action_show_clock.setOnClickListener {
+ SP.edit()
+ .putBoolean(Constants.PREF_SHOW_CLOCK, false)
+ .commit()
+ sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
+ updateSettings()
+ updateAppWidget()
+ }
+ show_clock_label.text = getString(R.string.show_clock_visible)
+ } else {
+ clock_settings.visibility= View.GONE
+ action_show_clock.setOnClickListener {
+ SP.edit()
+ .putBoolean(Constants.PREF_SHOW_CLOCK, true)
+ .commit()
+ sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
+ updateSettings()
+ updateAppWidget()
+ }
+ show_clock_label.text = getString(R.string.show_clock_not_visible)
+ }
+
+
if (SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)) {
calendar_settings.visibility = View.VISIBLE
action_show_events.setOnClickListener {
@@ -352,7 +411,7 @@ class MainActivity : AppCompatActivity() {
updateSettings()
updateAppWidget()
}
- show_events_label.text = getString(R.string.show_events_visible)
+ show_clock_label.text = getString(R.string.show_events_visible)
} else {
calendar_settings.visibility= View.GONE
action_show_events.setOnClickListener {
@@ -459,7 +518,6 @@ class MainActivity : AppCompatActivity() {
SP.edit().remove(Constants.PREF_TEXT_COLOR).commit()
Color.parseColor(SP.getString(Constants.PREF_TEXT_COLOR, "#FFFFFF"))
}
- text_color_icon.setCardBackgroundColor(textColor)
font_color_label.text = SP.getString(Constants.PREF_TEXT_COLOR, "#FFFFFF").toUpperCase()
action_font_color.setOnClickListener {
val cp: ColorPicker = ColorPicker(this@MainActivity, Color.red(textColor), Color.green(textColor), Color.blue(textColor))
@@ -521,20 +579,15 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION)
}
- if (SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps)) == getString(R.string.custom_location_gps)) {
- action_weather_provider_api_key.visibility= View.GONE
+ if (!SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "").equals("")) {
+ label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_all_set)
+ alert_icon.visibility = View.GONE
} else {
- action_weather_provider_api_key.visibility= View.VISIBLE
- if (!SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "").equals("")) {
- label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_all_set)
- alert_icon.visibility = View.GONE
- } else {
- label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_not_set)
- alert_icon.visibility = View.VISIBLE
- }
- action_weather_provider_api_key.setOnClickListener {
- startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
- }
+ label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_not_set)
+ alert_icon.visibility = View.VISIBLE
+ }
+ action_weather_provider_api_key.setOnClickListener {
+ startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
}
calendar_app_label.text = SP.getString(Constants.PREF_CALENDAR_APP_NAME, getString(R.string.default_name))
@@ -547,6 +600,11 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.WEATHER_APP_REQUEST_CODE)
}
+ clock_app_label.text = SP.getString(Constants.PREF_CLOCK_APP_NAME, getString(R.string.default_name))
+ action_clock_app.setOnClickListener {
+ startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CLOCK_APP_REQUEST_CODE)
+ }
+
event_app_label.text = SP.getString(Constants.PREF_EVENT_APP_NAME, getString(R.string.default_name))
action_event_app.setOnClickListener {
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.EVENT_APP_REQUEST_CODE)
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt
index 861a1f7..d090ac4 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/WeatherProviderActivity.kt
@@ -6,6 +6,7 @@ import android.app.AlertDialog
import android.content.ClipboardManager
import android.content.Context
import android.content.DialogInterface
+import android.content.SharedPreferences
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
@@ -26,12 +27,14 @@ import kotlinx.android.synthetic.main.provider_info_layout.view.*
class WeatherProviderActivity : AppCompatActivity() {
+ lateinit var SP: SharedPreferences
+
@SuppressLint("ApplySharedPref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_weather_provider)
- val SP = PreferenceManager.getDefaultSharedPreferences(this)
+ SP = PreferenceManager.getDefaultSharedPreferences(this)
action_paste.setOnClickListener {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
if (clipboard.primaryClip != null && clipboard.primaryClip.itemCount > 0) {
@@ -39,8 +42,7 @@ class WeatherProviderActivity : AppCompatActivity() {
}
}
- Util.collapse(button_container)
- api_key.setText(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, ""))
+ updateUI()
action_save.setOnClickListener {
SP.edit()
@@ -83,9 +85,34 @@ class WeatherProviderActivity : AppCompatActivity() {
}
}
+ @SuppressLint("ApplySharedPref")
+ fun updateUI() {
+ val currentProvider = SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)
+ if (currentProvider == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
+ api_key.visibility = View.GONE
+ } else {
+ api_key.visibility = View.VISIBLE
+ }
+ label_weather_provider.text = when (currentProvider) {
+ Constants.WEATHER_PROVIDER_OPEN_WEATHER -> getString(R.string.provider_open_weather)
+ else -> getString(R.string.provider_google_awareness)
+ }
+ action_change_provider.setOnClickListener {
+ SP.edit()
+ .putInt(Constants.PREF_WEATHER_PROVIDER, when (currentProvider) {
+ Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS -> Constants.WEATHER_PROVIDER_OPEN_WEATHER
+ else -> Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS
+ }).commit()
+ updateUI()
+ }
+
+ Util.collapse(button_container)
+ api_key.setText(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, ""))
+ }
+
override fun onBackPressed() {
val SP = PreferenceManager.getDefaultSharedPreferences(this)
- if (api_key.text.toString().equals("") || !api_key.text.toString().equals(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, ""))) {
+ if (!SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS).equals(Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) && (api_key.text.toString().equals("") || !api_key.text.toString().equals(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "")))) {
AlertDialog.Builder(this)
.setMessage(getString(R.string.error_weather_api_key))
.setNegativeButton(android.R.string.cancel, null)
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt
index 339e301..aa69365 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt
@@ -34,7 +34,10 @@ import android.graphics.BitmapFactory
import android.graphics.drawable.BitmapDrawable
import android.support.v4.content.ContextCompat.startActivity
import android.provider.CalendarContract.Events
+import android.support.v4.content.ContextCompat
import android.util.TypedValue
+import kotlinx.android.synthetic.main.the_widget.*
+import kotlinx.android.synthetic.main.the_widget.view.*
/**
@@ -64,8 +67,13 @@ class TheWidget : AppWidgetProvider() {
internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager,
appWidgetId: Int) {
- var views = RemoteViews(context.packageName, R.layout.the_widget)
-
+ val views = RemoteViews(context.packageName, R.layout.the_widget_sans)
+ var v = View.inflate(context, R.layout.the_widget, null)
+ v = updateCalendarViewByLayout(context, v)
+ v = updateLocationViewByLayout(context, v)
+ v = updateClockViewByLayout(context, v)
+ views.setImageViewBitmap(R.id.bitmap_container, Util.getBitmapFromView(v))
+ /*
views = updateCalendarView(context, views, appWidgetId)
views = updateLocationView(context, views, appWidgetId)
@@ -88,7 +96,7 @@ class TheWidget : AppWidgetProvider() {
views.setTextViewTextSize(R.id.next_event_date, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
views.setTextViewTextSize(R.id.divider2, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
views.setTextViewTextSize(R.id.calendar_temp, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
-
+ */
appWidgetManager.updateAppWidget(appWidgetId, views)
}
@@ -207,6 +215,150 @@ class TheWidget : AppWidgetProvider() {
}
return views
}
+
+ fun updateClockView(context: Context, views: RemoteViews, widgetID: Int) {
+ val SP = PreferenceManager.getDefaultSharedPreferences(context)
+ if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
+ views.setViewVisibility(R.id.time, View.GONE)
+ } else {
+ views.setViewVisibility(R.id.time, View.VISIBLE)
+ }
+ val now = Calendar.getInstance()
+ views.setTextViewText(R.id.time, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(now.timeInMillis) else Constants.goodHourFormat.format(now.timeInMillis))
+ }
+
+ fun updateCalendarViewByLayout(context: Context, v: View): View {
+ val SP = PreferenceManager.getDefaultSharedPreferences(context)
+ val now = Calendar.getInstance()
+ val calendarLayout = SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)
+
+ v.empty_layout.visibility = View.VISIBLE
+ v.calendar_layout.visibility = View.GONE
+ var dateStringValue: String = Util.getCapWordString(Constants.engDateFormat.format(now.time))
+ if (SP.getBoolean(Constants.PREF_ITA_FORMAT_DATE, false)) {
+ dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time))
+ }
+ v.empty_date.text = dateStringValue
+ //empty_date.setImageBitmap(Util.buildUpdate(this, String.format("%s%s", Constants.dateFormat.format(now.time)[0].toUpperCase(), Constants.dateFormat.format(now.time).substring(1)), "fonts/product_sans_regular.ttf"))
+
+ if (calendarLayout) {
+ val e = CalendarUtil.getNextEvent(context)
+
+ if (e.id != 0) {
+ v.next_event.text = e.title
+ v.next_event_difference_time.text = Util.getDifferenceText(context, now.timeInMillis, e.startDate)
+
+ if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) {
+ v.second_row_icon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_action_location))
+ v.next_event_date.text = e.address
+ } else {
+ v.second_row_icon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_action_calendar))
+ if (!e.allDay) {
+ val startHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.startDate) else Constants.goodHourFormat.format(e.startDate)
+ val endHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.endDate) else Constants.goodHourFormat.format(e.endDate)
+ var dayDiff = TimeUnit.MILLISECONDS.toDays(e.endDate - e.startDate)
+
+ val startCal = Calendar.getInstance()
+ startCal.timeInMillis = e.startDate
+
+ val endCal = Calendar.getInstance()
+ endCal.timeInMillis = e.endDate
+
+ if (startCal.get(Calendar.HOUR_OF_DAY) > endCal.get(Calendar.HOUR_OF_DAY)) {
+ dayDiff++
+ } else if (startCal.get(Calendar.HOUR_OF_DAY) == endCal.get(Calendar.HOUR_OF_DAY) && startCal.get(Calendar.MINUTE) >= endCal.get(Calendar.MINUTE)) {
+ dayDiff++
+ }
+ var multipleDay: String = ""
+ if (dayDiff > 0) {
+ multipleDay = String.format(" (+%s%s)", dayDiff, context.getString(R.string.day_char))
+ }
+ v.next_event_date.text = String.format("%s - %s%s", startHour, endHour, multipleDay)
+ } else {
+ v.next_event_date.text = dateStringValue
+ }
+ }
+
+ v.empty_layout.visibility = View.GONE
+ v.calendar_layout.visibility = View.VISIBLE
+ }
+ }
+
+ v.empty_date.setTextColor(Util.getFontColor(SP))
+ v.divider1.setTextColor(Util.getFontColor(SP))
+ v.temp.setTextColor(Util.getFontColor(SP))
+ v.next_event.setTextColor(Util.getFontColor(SP))
+ v.next_event_difference_time.setTextColor(Util.getFontColor(SP))
+ v.next_event_date.setTextColor(Util.getFontColor(SP))
+ v.divider2.setTextColor(Util.getFontColor(SP))
+ v.calendar_temp.setTextColor(Util.getFontColor(SP))
+ v.second_row_icon.setColorFilter(Util.getFontColor(SP))
+
+
+ v.empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
+ v.divider1.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
+ v.temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
+ v.next_event.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
+ v.next_event_difference_time.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
+ v.next_event_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
+ v.divider2.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
+ v.calendar_temp.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
+
+
+ val product_sans: Typeface = Typeface.createFromAsset(context.assets, "fonts/product_sans_regular.ttf")
+ v.empty_date.typeface = product_sans
+ v.divider1.typeface = product_sans
+ v.temp.typeface = product_sans
+ v.next_event.typeface = product_sans
+ v.next_event_difference_time.typeface = product_sans
+ v.next_event_date.typeface = product_sans
+ v.divider2.typeface = product_sans
+ v.calendar_temp.typeface = product_sans
+
+ return v
+ }
+
+ fun updateLocationViewByLayout(context: Context, v: View): View {
+ val SP = PreferenceManager.getDefaultSharedPreferences(context)
+ val locationLayout = SP.getBoolean(Constants.PREF_SHOW_WEATHER, true)
+
+ if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
+ v.weather.visibility = View.VISIBLE
+ v.calendar_weather.visibility = View.VISIBLE
+ val currentTemp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_REAL_TEMP_UNIT, "F"))
+
+
+ v.weather_icon.visibility = View.VISIBLE
+ v.empty_weather_icon.visibility = View.VISIBLE
+ val icon: String = SP.getString(Constants.PREF_WEATHER_ICON, "")
+ if (icon.equals("")) {
+ v.weather_icon.visibility = View.GONE
+ v.empty_weather_icon.visibility = View.GONE
+ } else {
+ v.weather_icon.setImageResource(WeatherUtil.getWeatherIconResource(icon))
+ v.empty_weather_icon.setImageResource(WeatherUtil.getWeatherIconResource(icon))
+ }
+
+ v.temp.text = currentTemp
+ v.calendar_temp.text = currentTemp
+ } else {
+ v.weather.visibility = View.GONE
+ v.calendar_weather.visibility = View.GONE
+ }
+ return v
+ }
+
+ fun updateClockViewByLayout(context: Context, v: View): View {
+ val SP = PreferenceManager.getDefaultSharedPreferences(context)
+ if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
+ v.time.visibility = View.GONE
+ } else {
+ v.time.visibility = View.VISIBLE
+ }
+ val now = Calendar.getInstance()
+ v.time.text = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(now.timeInMillis) else Constants.goodHourFormat.format(now.timeInMillis)
+ return v
+ }
}
}
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt
index 512fbcf..598ea92 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt
@@ -36,6 +36,7 @@ import android.view.View
import android.view.animation.Animation
import android.view.animation.Transformation
import android.widget.LinearLayout
+import android.widget.RemoteViews
import android.widget.Toast
import com.tommasoberlose.anotherwidget.`object`.Constants
import com.tommasoberlose.anotherwidget.`object`.Event
@@ -160,6 +161,21 @@ object Util {
return myBitmap;
}
+ fun getBitmapFromView(view: View): Bitmap {
+ //Define a bitmap with the same size as the view
+ val measuredWidth = View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.UNSPECIFIED)
+ val measuredHeight = View.MeasureSpec.makeMeasureSpec(view.height, View.MeasureSpec.UNSPECIFIED)
+ view.measure(measuredWidth, measuredHeight)
+ view.layout(0,0, measuredWidth, measuredHeight)
+ val returnedBitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
+ //Bind a canvas to it
+ val canvas = Canvas(returnedBitmap)
+ // draw the view on the canvas
+ view.draw(canvas)
+ //return the bitmap
+ return returnedBitmap
+ }
+
fun convertDpToPixel(dp: Float, context: Context): Float {
val resources: Resources = context.resources
val metrics: DisplayMetrics = resources.displayMetrics
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 9498bf7..46a4ebd 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -37,7 +37,7 @@
+
-
+
-
-
-
-
-
-
+ style="@style/AnotherWidget.Settings.Title"
+ android:text="@string/settings_font_color_title"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -55,9 +69,10 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-it-rIT/strings.xml b/app/src/main/res/values-it-rIT/strings.xml
index 1af3afb..f30b826 100644
--- a/app/src/main/res/values-it-rIT/strings.xml
+++ b/app/src/main/res/values-it-rIT/strings.xml
@@ -104,4 +104,10 @@
Colore Testo
Dimensione Testo Prima Riga
Dimensione Testo Seconda Riga
+ Impostazioni Orologio
+ L\'orologio apre
+ Mostra Orologio
+ Mostra l\'ora sopra eventi e meteo
+ Orologio visibile
+ Orologio non visibile
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4ab8a62..6a970cf 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -52,8 +52,8 @@
Refresh Widget
Events are Visible
Events are not Visible
- Weather Info are Visible
- Weather Info are not Visible
+ Weather Info is Visible
+ Weather Info is not Visible
3 Hours later
6 Hours later
12 Hours later
@@ -106,4 +106,12 @@
Text Color
First Row Text Size
Second Row Text Size
+ OpenWeather
+ Google Awareness
+ Clock Settings
+ Tap on clock opens
+ Show Clock
+ View the time over events and weather
+ Clock is visible
+ Clock is not visible