Release Beta Version
This commit is contained in:
@ -57,10 +57,14 @@ 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_TEXT_CLOCK_SIZE = "PREF_TEXT_CLOCK_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 PREF_TEXT_SHADOW = "PREF_TEXT_SHADOW"
|
||||
val PREF_SHOW_DIFF_TIME = "PREF_SHOW_DIFF_TIME"
|
||||
val PREF_SHOW_DECLINED_EVENTS = "PREF_SHOW_DECLINED_EVENTS"
|
||||
|
||||
val ACTION_EXTRA_OPEN_WEATHER_PROVIDER = "ACTION_EXTRA_OPEN_WEATHER_PROVIDER"
|
||||
|
||||
@ -72,7 +76,8 @@ object Constants {
|
||||
val ACTION_TIME_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_TIME_UPDATE"
|
||||
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 ACTION_SOMETHING_HAPPENED = "com.tommasoberlose.anotherwidget.action.ACTION_SOMETHING_HAPPENED"
|
||||
val ACTION_OPEN_WEATHER_INTENT = "com.tommasoberlose.anotherwidget.action.ACTION_OPEN_WEATHER_INTENT"
|
||||
|
||||
val WEATHER_PROVIDER_GOOGLE_AWARENESS = 1
|
||||
val WEATHER_PROVIDER_OPEN_WEATHER = 2
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.tommasoberlose.anotherwidget.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
|
||||
class OpenWeatherIntentReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == Constants.ACTION_OPEN_WEATHER_INTENT) {
|
||||
context.sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
context.startActivity(Util.getWeatherIntent(context))
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,9 @@ import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.`object`.Event
|
||||
import com.tommasoberlose.anotherwidget.util.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
import java.sql.Time
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
class UpdatesReceiver : BroadcastReceiver() {
|
||||
@ -21,7 +23,7 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action.equals(Intent.ACTION_BOOT_COMPLETED) || intent.action.equals(Intent.ACTION_MY_PACKAGE_REPLACED) || intent.action.equals("android.intent.action.PACKAGE_REPLACED") || intent.action.equals("android.intent.action.PACKAGE_ADDED")) {
|
||||
setUpdates(context)
|
||||
} else if (intent.action.equals(Constants.ACTION_TIME_UPDATE)) {
|
||||
} else if (intent.action.equals(Constants.ACTION_TIME_UPDATE) || intent.action.equals("com.sec.android.widgetapp.APPWIDGET_RESIZE") || intent.action == "android.intent.action.USER_PRESENT") {
|
||||
val e: Event = CalendarUtil.getNextEvent(context)
|
||||
if (e.id == 0 || e.endDate <= Calendar.getInstance().timeInMillis) {
|
||||
CalendarUtil.updateEventList(context)
|
||||
|
@ -27,27 +27,25 @@ import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.support.annotation.ColorInt
|
||||
import android.support.design.widget.BottomSheetDialog
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.text.Html
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.widget.Toast
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.pes.androidmaterialcolorpickerdialog.ColorPicker
|
||||
import com.tommasoberlose.anotherwidget.`object`.CalendarSelector
|
||||
import com.tommasoberlose.anotherwidget.receiver.UpdatesReceiver
|
||||
import io.fabric.sdk.android.Fabric
|
||||
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() {
|
||||
|
||||
var mAppWidgetId: Int = -1
|
||||
private var mAppWidgetId: Int = -1
|
||||
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
@ -59,6 +57,8 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
Fabric.with(this, Crashlytics())
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
|
||||
if (intent.extras?.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER) == true) {
|
||||
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
|
||||
@ -84,12 +84,6 @@ class MainActivity : AppCompatActivity() {
|
||||
action_menu.setOnClickListener {
|
||||
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
|
||||
val menuView: View = getLayoutInflater().inflate(R.layout.main_menu_layout, null)
|
||||
menuView.action_support.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(p0: View?) {
|
||||
Util.openURI(this@MainActivity, "https://paypal.me/tommasoberlose")
|
||||
mBottomSheetDialog.dismiss()
|
||||
}
|
||||
})
|
||||
|
||||
menuView.action_share.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(p0: View?) {
|
||||
@ -143,7 +137,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val filter = IntentFilter()
|
||||
filter.addAction(Constants.ACTION_SOMETHING_APPENED);
|
||||
filter.addAction(Constants.ACTION_SOMETHING_HAPPENED);
|
||||
registerReceiver(receiver, filter);
|
||||
updateUI()
|
||||
}
|
||||
@ -182,10 +176,11 @@ class MainActivity : AppCompatActivity() {
|
||||
val wallpaper: Drawable? = Util.getCurrentWallpaper(this)
|
||||
if (wallpaper != null) {
|
||||
widget_bg.setImageDrawable(wallpaper)
|
||||
updateCalendarView()
|
||||
updateLocationView()
|
||||
updateClockView()
|
||||
}
|
||||
widget_bg.setBackgroundColor(Color.WHITE)
|
||||
updateCalendarView()
|
||||
updateLocationView()
|
||||
updateClockView()
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@ -226,20 +221,6 @@ class MainActivity : AppCompatActivity() {
|
||||
WeatherReceiver().setOneTimeUpdate(this)
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateSettings()
|
||||
|
||||
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
|
||||
val provView: View = layoutInflater.inflate(R.layout.key_time_wait_layout, null)
|
||||
provView.title.text = String.format("%s %s", Util.getEmojiByUnicode(0x1F389), getString(R.string.well_done))
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_all_set), Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_all_set))
|
||||
}
|
||||
provView.action_close.setOnClickListener {
|
||||
mBottomSheetDialog.dismiss()
|
||||
}
|
||||
mBottomSheetDialog.setContentView(provView)
|
||||
mBottomSheetDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,14 +247,18 @@ class MainActivity : AppCompatActivity() {
|
||||
dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time))
|
||||
}
|
||||
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(this)
|
||||
|
||||
if (e.id != 0) {
|
||||
next_event.text = e.title
|
||||
next_event_difference_time.text = Util.getDifferenceText(this, now.timeInMillis, e.startDate)
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) {
|
||||
next_event_difference_time.text = Util.getDifferenceText(this, now.timeInMillis, e.startDate)
|
||||
next_event_difference_time.visibility = View.VISIBLE
|
||||
} else {
|
||||
next_event_difference_time.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) {
|
||||
second_row_icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_action_location))
|
||||
@ -320,6 +305,7 @@ class MainActivity : AppCompatActivity() {
|
||||
divider2.setTextColor(Util.getFontColor(SP))
|
||||
calendar_temp.setTextColor(Util.getFontColor(SP))
|
||||
second_row_icon.setColorFilter(Util.getFontColor(SP))
|
||||
time.setTextColor(Util.getFontColor(SP))
|
||||
|
||||
|
||||
empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
|
||||
@ -330,6 +316,35 @@ 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))
|
||||
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
|
||||
|
||||
val shadowRadius = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 0f
|
||||
1 -> 5f
|
||||
2 -> 4f
|
||||
else -> 5f
|
||||
}
|
||||
val shadowColor = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> Color.TRANSPARENT
|
||||
1 -> R.color.black_50
|
||||
2 -> Color.BLACK
|
||||
else -> R.color.black_50
|
||||
}
|
||||
val shadowDy = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 0f
|
||||
1 -> 0f
|
||||
2 -> 1f
|
||||
else -> 0f
|
||||
}
|
||||
empty_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
divider1.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
temp.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
next_event.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
next_event_difference_time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
next_event_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
divider2.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
calendar_temp.setShadowLayer(shadowRadius, 0f, 0f, shadowColor)
|
||||
time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
|
||||
|
||||
val product_sans: Typeface = Typeface.createFromAsset(assets, "fonts/product_sans_regular.ttf")
|
||||
@ -341,6 +356,7 @@ class MainActivity : AppCompatActivity() {
|
||||
next_event_date.typeface = product_sans
|
||||
divider2.typeface = product_sans
|
||||
calendar_temp.typeface = product_sans
|
||||
time.typeface = product_sans
|
||||
}
|
||||
|
||||
fun updateLocationView() {
|
||||
@ -383,8 +399,6 @@ class MainActivity : AppCompatActivity() {
|
||||
.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 {
|
||||
@ -394,8 +408,6 @@ class MainActivity : AppCompatActivity() {
|
||||
.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)
|
||||
}
|
||||
@ -411,7 +423,7 @@ class MainActivity : AppCompatActivity() {
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
show_clock_label.text = getString(R.string.show_events_visible)
|
||||
show_events_label.text = getString(R.string.show_events_visible)
|
||||
} else {
|
||||
calendar_settings.visibility= View.GONE
|
||||
action_show_events.setOnClickListener {
|
||||
@ -471,6 +483,20 @@ class MainActivity : AppCompatActivity() {
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
show_diff_time_label.text = if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
action_show_diff_time.setOnClickListener {
|
||||
SP.edit().putBoolean(Constants.PREF_SHOW_DIFF_TIME, !SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)).commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
show_declined_events_label.text = if (SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true)) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
action_show_declined_events.setOnClickListener {
|
||||
SP.edit().putBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, !SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true)).commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
hour_format_label.text = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) getString(R.string.settings_hour_format_subtitle_12) else getString(R.string.settings_hour_format_subtitle_24)
|
||||
action_hour_format.setOnClickListener {
|
||||
SP.edit().putString(Constants.PREF_HOUR_FORMAT, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) "24" else "12").commit()
|
||||
@ -511,6 +537,17 @@ class MainActivity : AppCompatActivity() {
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
clock_text_size_label.text = String.format("%.0f%s", SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f), "sp")
|
||||
action_clock_text_size.setOnClickListener {
|
||||
var fontSize = SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f) + 5
|
||||
if (fontSize > 110) {
|
||||
fontSize = 70f
|
||||
}
|
||||
SP.edit().putFloat(Constants.PREF_TEXT_CLOCK_SIZE, fontSize).commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
val textColor = try {
|
||||
Color.parseColor(SP.getString(Constants.PREF_TEXT_COLOR, "#FFFFFF"))
|
||||
@ -544,19 +581,25 @@ class MainActivity : AppCompatActivity() {
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)))
|
||||
action_weather_refresh_period.setOnClickListener {
|
||||
SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)) {
|
||||
0 -> 1
|
||||
1 -> 2
|
||||
2 -> 3
|
||||
3 -> 4
|
||||
4 -> 5
|
||||
5 -> 0
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
WeatherReceiver().setUpdates(this@MainActivity)
|
||||
|
||||
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
|
||||
action_weather_refresh_period.visibility = View.GONE
|
||||
} else {
|
||||
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)))
|
||||
action_weather_refresh_period.setOnClickListener {
|
||||
SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)) {
|
||||
0 -> 1
|
||||
1 -> 2
|
||||
2 -> 3
|
||||
3 -> 4
|
||||
4 -> 5
|
||||
5 -> 0
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
WeatherReceiver().setUpdates(this@MainActivity)
|
||||
}
|
||||
action_weather_refresh_period.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
show_until_label.text = getString(Util.getShowUntilString(SP.getInt(Constants.PREF_SHOW_UNTIL, 1)))
|
||||
@ -567,51 +610,78 @@ class MainActivity : AppCompatActivity() {
|
||||
2 -> 3
|
||||
3 -> 4
|
||||
4 -> 5
|
||||
5 -> 0
|
||||
5 -> 6
|
||||
6 -> 0
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
}
|
||||
|
||||
label_custom_location.text = SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps))
|
||||
action_custom_location.setOnClickListener {
|
||||
startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION)
|
||||
text_shadow_label.text = getString(Util.getTextshadowString(SP.getInt(Constants.PREF_TEXT_SHADOW, 1)))
|
||||
action_text_shadow.setOnClickListener {
|
||||
SP.edit().putInt(Constants.PREF_TEXT_SHADOW, when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 1
|
||||
1 -> 2
|
||||
2 -> 0
|
||||
else -> 1
|
||||
}).commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
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)
|
||||
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
|
||||
action_custom_location.visibility = View.GONE
|
||||
} else {
|
||||
label_custom_location.text = SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps))
|
||||
action_custom_location.setOnClickListener {
|
||||
startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION)
|
||||
}
|
||||
action_custom_location.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
|
||||
label_weather_provider_api_key.text = getString(R.string.provider_google_awareness)
|
||||
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
|
||||
if (SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "") == ("")) {
|
||||
label_weather_provider_api_key.text = getString(R.string.settings_weather_provider_api_key_subtitle_not_set)
|
||||
alert_icon.visibility = View.VISIBLE
|
||||
} else {
|
||||
label_weather_provider_api_key.text = getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) {
|
||||
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> R.string.provider_open_weather
|
||||
else -> R.string.settings_weather_provider_api_key_subtitle_all_set
|
||||
})
|
||||
alert_icon.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
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))
|
||||
calendar_app_label.text = SP.getString(Constants.PREF_CALENDAR_APP_NAME, getString(R.string.default_calendar_app))
|
||||
action_calendar_app.setOnClickListener {
|
||||
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CALENDAR_APP_REQUEST_CODE)
|
||||
}
|
||||
|
||||
weather_app_label.text = SP.getString(Constants.PREF_WEATHER_APP_NAME, getString(R.string.default_name))
|
||||
weather_app_label.text = SP.getString(Constants.PREF_WEATHER_APP_NAME, getString(R.string.default_weather_app))
|
||||
action_weather_app.setOnClickListener {
|
||||
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))
|
||||
clock_app_label.text = SP.getString(Constants.PREF_CLOCK_APP_NAME, getString(R.string.default_clock_app))
|
||||
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))
|
||||
event_app_label.text = SP.getString(Constants.PREF_EVENT_APP_NAME, getString(R.string.default_event_app))
|
||||
action_event_app.setOnClickListener {
|
||||
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.EVENT_APP_REQUEST_CODE)
|
||||
}
|
||||
|
||||
action_filter_calendar.setOnClickListener {
|
||||
val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(this)
|
||||
val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(this).map { CalendarSelector(it.id.toInt(), it.displayName, it.accountName) }
|
||||
var calFiltered = SP.getString(Constants.PREF_CALENDAR_FILTER, "")
|
||||
|
||||
if (!calendarSelectorList.isEmpty()) {
|
||||
|
@ -22,6 +22,7 @@ import com.tommasoberlose.anotherwidget.util.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import kotlinx.android.synthetic.main.activity_weather_provider.*
|
||||
import kotlinx.android.synthetic.main.key_time_wait_layout.view.*
|
||||
import kotlinx.android.synthetic.main.main_menu_layout.view.*
|
||||
import kotlinx.android.synthetic.main.provider_info_layout.view.*
|
||||
|
||||
@ -35,12 +36,6 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_weather_provider)
|
||||
|
||||
SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
action_paste.setOnClickListener {
|
||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
if (clipboard.primaryClip != null && clipboard.primaryClip.itemCount > 0) {
|
||||
api_key.setText(clipboard.primaryClip.getItemAt(0).text)
|
||||
}
|
||||
}
|
||||
|
||||
updateUI()
|
||||
|
||||
@ -71,27 +66,23 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
action_open_provider.setOnClickListener {
|
||||
Util.openURI(this, "https://home.openweathermap.org/users/sign_up")
|
||||
}
|
||||
|
||||
action_open_info_text.setOnClickListener {
|
||||
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
|
||||
val provView: View = layoutInflater.inflate(R.layout.provider_info_layout, null)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_text), Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_text))
|
||||
}
|
||||
mBottomSheetDialog.setContentView(provView)
|
||||
mBottomSheetDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
fun updateUI() {
|
||||
private 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
|
||||
api_key_container.visibility = View.GONE
|
||||
content_info.visibility = View.GONE
|
||||
} else {
|
||||
api_key.visibility = View.VISIBLE
|
||||
api_key_container.visibility = View.VISIBLE
|
||||
content_info.visibility = View.VISIBLE
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
last_info.text = Html.fromHtml(getString(R.string.api_key_info_all_set), Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
last_info.text = Html.fromHtml(getString(R.string.api_key_info_all_set))
|
||||
}
|
||||
}
|
||||
label_weather_provider.text = when (currentProvider) {
|
||||
Constants.WEATHER_PROVIDER_OPEN_WEATHER -> getString(R.string.provider_open_weather)
|
||||
|
@ -31,7 +31,9 @@ import android.widget.TextView
|
||||
import android.content.ComponentName
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.ContextCompat.startActivity
|
||||
import android.provider.CalendarContract.Events
|
||||
import android.support.v4.content.ContextCompat
|
||||
@ -51,6 +53,11 @@ class TheWidget : AppWidgetProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle?) {
|
||||
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
|
||||
override fun onEnabled(context: Context) {
|
||||
UpdatesReceiver().setUpdates(context)
|
||||
WeatherReceiver().setUpdates(context)
|
||||
@ -67,16 +74,16 @@ class TheWidget : AppWidgetProvider() {
|
||||
internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int) {
|
||||
|
||||
val views = RemoteViews(context.packageName, R.layout.the_widget_sans)
|
||||
var 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 = updateCalendarView(context, views, appWidgetId)
|
||||
views = updateLocationView(context, views, appWidgetId)
|
||||
views = updateClockView(context, views, appWidgetId)
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
views.setTextColor(R.id.empty_date, Util.getFontColor(SP))
|
||||
@ -96,7 +103,8 @@ 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)
|
||||
}
|
||||
|
||||
@ -112,11 +120,10 @@ class TheWidget : AppWidgetProvider() {
|
||||
dateStringValue = Util.getCapWordString(Constants.itDateFormat.format(now.time))
|
||||
}
|
||||
views.setTextViewText(R.id.empty_date, dateStringValue)
|
||||
//views.setImageViewBitmap(R.id.empty_date, Util.buildUpdate(context, Constants.dateFormat.format(now.time)[0].toUpperCase() + Constants.dateFormat.format(now.time).substring(1), "fonts/product_sans_regular.ttf"))
|
||||
|
||||
|
||||
val calPIntent = PendingIntent.getActivity(context, widgetID, Util.getCalendarIntent(context), 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, calPIntent)
|
||||
views.setOnClickPendingIntent(R.id.empty_date, calPIntent)
|
||||
|
||||
|
||||
if (calendarLayout) {
|
||||
@ -124,7 +131,12 @@ class TheWidget : AppWidgetProvider() {
|
||||
|
||||
if (e.id != 0) {
|
||||
views.setTextViewText(R.id.next_event, e.title)
|
||||
views.setTextViewText(R.id.next_event_difference_time, Util.getDifferenceText(context, now.timeInMillis, e.startDate))
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) {
|
||||
views.setTextViewText(R.id.next_event_difference_time, Util.getDifferenceText(context, now.timeInMillis, e.startDate))
|
||||
views.setViewVisibility(R.id.next_event_difference_time, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.next_event_difference_time, View.GONE)
|
||||
}
|
||||
|
||||
if (!e.address.equals("") && SP.getBoolean(Constants.PREF_SHOW_EVENT_LOCATION, false)) {
|
||||
|
||||
@ -173,7 +185,9 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setViewVisibility(R.id.calendar_layout, View.VISIBLE)
|
||||
|
||||
val pIntent = PendingIntent.getActivity(context, widgetID, Util.getEventIntent(context, e), 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event_date, pIntent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,7 +219,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setTextViewText(R.id.calendar_temp, temp)
|
||||
|
||||
|
||||
val weatherPIntent = PendingIntent.getActivity(context, widgetID, Util.getWeatherIntent(context), 0)
|
||||
val weatherPIntent = PendingIntent.getBroadcast(context, widgetID, Intent(Constants.ACTION_OPEN_WEATHER_INTENT), 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent)
|
||||
@ -216,7 +230,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
return views
|
||||
}
|
||||
|
||||
fun updateClockView(context: Context, views: RemoteViews, widgetID: Int) {
|
||||
fun updateClockView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
|
||||
views.setViewVisibility(R.id.time, View.GONE)
|
||||
@ -225,6 +239,11 @@ class TheWidget : AppWidgetProvider() {
|
||||
}
|
||||
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))
|
||||
|
||||
val clockPIntent = PendingIntent.getActivity(context, widgetID, Util.getClockIntent(context), 0)
|
||||
views.setOnClickPendingIntent(R.id.time, clockPIntent)
|
||||
|
||||
return views
|
||||
}
|
||||
|
||||
fun updateCalendarViewByLayout(context: Context, v: View): View {
|
||||
@ -239,14 +258,18 @@ class TheWidget : AppWidgetProvider() {
|
||||
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 (SP.getBoolean(Constants.PREF_SHOW_DIFF_TIME, true)) {
|
||||
v.next_event_difference_time.text = Util.getDifferenceText(context, now.timeInMillis, e.startDate)
|
||||
v.next_event_difference_time.visibility = View.VISIBLE
|
||||
} else {
|
||||
v.next_event_difference_time.visibility = View.GONE
|
||||
}
|
||||
|
||||
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))
|
||||
@ -293,6 +316,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
v.divider2.setTextColor(Util.getFontColor(SP))
|
||||
v.calendar_temp.setTextColor(Util.getFontColor(SP))
|
||||
v.second_row_icon.setColorFilter(Util.getFontColor(SP))
|
||||
v.time.setTextColor(Util.getFontColor(SP))
|
||||
|
||||
|
||||
v.empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
|
||||
@ -303,6 +327,35 @@ class TheWidget : AppWidgetProvider() {
|
||||
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))
|
||||
v.time.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
|
||||
|
||||
val shadowRadius = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 0f
|
||||
1 -> 5f
|
||||
2 -> 5f
|
||||
else -> 5f
|
||||
}
|
||||
val shadowColor = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> Color.TRANSPARENT
|
||||
1 -> R.color.black_50
|
||||
2 -> Color.BLACK
|
||||
else -> R.color.black_50
|
||||
}
|
||||
val shadowDy = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 0f
|
||||
1 -> 0f
|
||||
2 -> 1f
|
||||
else -> 0f
|
||||
}
|
||||
v.empty_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.divider1.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.temp.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.next_event.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.next_event_difference_time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.next_event_date.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.divider2.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
v.calendar_temp.setShadowLayer(shadowRadius, 0f, 0f, shadowColor)
|
||||
v.time.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
|
||||
|
||||
|
||||
val product_sans: Typeface = Typeface.createFromAsset(context.assets, "fonts/product_sans_regular.ttf")
|
||||
@ -314,6 +367,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
v.next_event_date.typeface = product_sans
|
||||
v.divider2.typeface = product_sans
|
||||
v.calendar_temp.typeface = product_sans
|
||||
v.time.typeface = product_sans
|
||||
|
||||
return v
|
||||
}
|
||||
|
@ -9,12 +9,17 @@ import android.net.Uri
|
||||
import android.preference.PreferenceManager
|
||||
import android.provider.CalendarContract
|
||||
import android.util.Log
|
||||
import android.util.TimeUtils
|
||||
import android.widget.Toast
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.`object`.CalendarSelector
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.`object`.Event
|
||||
import me.everything.providers.android.calendar.CalendarProvider
|
||||
import me.everything.providers.android.contacts.ContactsProvider
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.Comparator
|
||||
|
||||
/**
|
||||
* Created by tommaso on 08/10/17.
|
||||
@ -36,6 +41,7 @@ object CalendarUtil {
|
||||
3 -> limit.add(Calendar.DAY_OF_MONTH, 1)
|
||||
4 -> limit.add(Calendar.DAY_OF_MONTH, 3)
|
||||
5 -> limit.add(Calendar.DAY_OF_MONTH, 7)
|
||||
6 -> limit.add(Calendar.HOUR, 1)
|
||||
else -> limit.add(Calendar.HOUR, 6)
|
||||
}
|
||||
|
||||
@ -47,49 +53,45 @@ object CalendarUtil {
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) {
|
||||
resetNextEventData(context)
|
||||
} else {
|
||||
|
||||
val instanceCursor = context.contentResolver.query(builder.build(), arrayOf(CalendarContract.Instances.EVENT_ID, CalendarContract.Instances.BEGIN, CalendarContract.Instances.END), null, null, null)
|
||||
if (instanceCursor != null && instanceCursor.count > 0) {
|
||||
instanceCursor.moveToFirst()
|
||||
|
||||
for (i in 0 until instanceCursor.count) {
|
||||
val ID = instanceCursor.getInt(0)
|
||||
|
||||
val eventCursor = context.contentResolver.query(CalendarContract.Events.CONTENT_URI, arrayOf(CalendarContract.Events.TITLE, CalendarContract.Events.ALL_DAY, CalendarContract.Events.CALENDAR_ID, CalendarContract.Events.EVENT_LOCATION),
|
||||
CalendarContract.Events._ID + " = ?",
|
||||
arrayOf(Integer.toString(ID)), null)
|
||||
|
||||
if (eventCursor != null && eventCursor.count > 0) {
|
||||
eventCursor.moveToFirst()
|
||||
|
||||
for (j in 0 until eventCursor.count) {
|
||||
val e = Event(eventCursor, instanceCursor)
|
||||
val allDay: Boolean = !eventCursor.getString(1).equals("0")
|
||||
if ((SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false) || !allDay) && !(SP.getString(Constants.PREF_CALENDAR_FILTER, "").contains(" " + e.calendarID + ","))) {
|
||||
eventList.add(e)
|
||||
}
|
||||
eventCursor.moveToNext()
|
||||
}
|
||||
|
||||
eventCursor.close()
|
||||
}
|
||||
|
||||
instanceCursor.moveToNext()
|
||||
val provider = CalendarProvider(context)
|
||||
val instances = provider.getInstances(now.timeInMillis, limit.timeInMillis).list
|
||||
for (instance in instances) {
|
||||
val e = provider.getEvent(instance.eventId)
|
||||
if (e != null && (SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false) || !e.allDay) && !(SP.getString(Constants.PREF_CALENDAR_FILTER, "").contains(" " + e.calendarId + ",")) && (SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true) || !e.selfAttendeeStatus.equals(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED))) {
|
||||
eventList.add(Event(e.id.toInt(), e.title, e.dTStart, e.dTend, e.calendarId.toInt(), e.allDay, e.eventLocation))
|
||||
}
|
||||
|
||||
instanceCursor.close()
|
||||
}
|
||||
|
||||
if (eventList.isEmpty()) {
|
||||
resetNextEventData(context)
|
||||
} else {
|
||||
Collections.sort(eventList, { event: Event, event1: Event ->
|
||||
if (event.startDate > event1.startDate) {
|
||||
return@sort 1
|
||||
} else if (event.startDate < event1.startDate) {
|
||||
return@sort -1
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
0
|
||||
} else {
|
||||
if (event.allDay) {
|
||||
Log.d("AW1", event.title + " " + event.startDate + " - " + event1.title + " " + event1.startDate)
|
||||
if (TimeUnit.MILLISECONDS.toMinutes(event1.startDate - now.timeInMillis) > 31 || now.timeInMillis > event1.endDate) {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
} else if (event1.allDay) {
|
||||
Log.d("AW2", event.title + " " + event.startDate + " - " + event1.title + " " + event1.startDate)
|
||||
if (TimeUnit.MILLISECONDS.toMinutes(event.startDate - now.timeInMillis) > 31 || now.timeInMillis > event.endDate) {
|
||||
-1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
} else {
|
||||
if (event.startDate > event1.startDate) {
|
||||
1
|
||||
} else if (event.startDate < event1.startDate) {
|
||||
-1
|
||||
}
|
||||
0
|
||||
}
|
||||
}
|
||||
return@sort 0
|
||||
})
|
||||
saveNextEventData(context, eventList.get(0))
|
||||
}
|
||||
@ -100,13 +102,16 @@ object CalendarUtil {
|
||||
|
||||
}
|
||||
|
||||
fun getCalendarList(context: Context): List<CalendarSelector> {
|
||||
val calendarList = ArrayList<CalendarSelector>()
|
||||
fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
|
||||
val calendarList = ArrayList<me.everything.providers.android.calendar.Calendar>()
|
||||
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) {
|
||||
return calendarList
|
||||
}
|
||||
val provider = CalendarProvider(context)
|
||||
return provider.calendars.list
|
||||
|
||||
/*
|
||||
try {
|
||||
val calendarCursor = context.contentResolver.query(Uri.parse("content://com.android.calendar/calendars"),
|
||||
arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.ACCOUNT_NAME),
|
||||
@ -157,7 +162,7 @@ object CalendarUtil {
|
||||
}
|
||||
} finally {
|
||||
return calendarList
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
|
@ -28,6 +28,7 @@ import android.util.TypedValue
|
||||
import android.content.Intent
|
||||
import android.content.ComponentName
|
||||
import android.preference.PreferenceManager
|
||||
import android.provider.AlarmClock
|
||||
import android.provider.CalendarContract
|
||||
import android.provider.Settings
|
||||
import android.support.v4.graphics.drawable.DrawableCompat
|
||||
@ -62,7 +63,7 @@ object Util {
|
||||
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
|
||||
update.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
context.sendBroadcast(update)
|
||||
context.sendBroadcast(Intent(Constants.ACTION_SOMETHING_APPENED))
|
||||
context.sendBroadcast(Intent(Constants.ACTION_SOMETHING_HAPPENED))
|
||||
}
|
||||
|
||||
fun showNotification(context: Context) {
|
||||
@ -144,23 +145,6 @@ object Util {
|
||||
}
|
||||
}
|
||||
|
||||
fun buildUpdate(context: Context, time: String, fontPath: String): Bitmap {
|
||||
val myBitmap:Bitmap = Bitmap.createBitmap(convertDpToPixel(300f, context).toInt(), convertDpToPixel(40f, context).toInt(), Bitmap.Config.ARGB_8888)
|
||||
val myCanvas: Canvas = Canvas(myBitmap)
|
||||
val paint: Paint = Paint()
|
||||
val clock: Typeface = Typeface.createFromAsset(context.assets, fontPath)
|
||||
paint.isAntiAlias = true
|
||||
paint.isSubpixelText = true
|
||||
paint.typeface = clock
|
||||
paint.style = Paint.Style.FILL
|
||||
paint.color = Color.WHITE
|
||||
paint.textSize = convertSpToPixels(14f, context)
|
||||
paint.textAlign = Paint.Align.CENTER
|
||||
paint.setShadowLayer(5f,0f, 0f, R.color.black_50)
|
||||
myCanvas.drawText("Ultra Pixel Meeting Ciao Ciao", convertDpToPixel(150f, context), convertDpToPixel(20f, context), paint)
|
||||
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)
|
||||
@ -223,10 +207,20 @@ object Util {
|
||||
3 -> R.string.settings_show_until_subtitle_3
|
||||
4 -> R.string.settings_show_until_subtitle_4
|
||||
5 -> R.string.settings_show_until_subtitle_5
|
||||
6 -> R.string.settings_show_until_subtitle_6
|
||||
else -> R.string.settings_show_until_subtitle_1
|
||||
}
|
||||
}
|
||||
|
||||
fun getTextshadowString(shadow: Int): Int {
|
||||
return when (shadow) {
|
||||
0 -> R.string.settings_text_shadow_subtitle_none
|
||||
1 -> R.string.settings_text_shadow_subtitle_low
|
||||
2 -> R.string.settings_text_shadow_subtitle_high
|
||||
else -> R.string.settings_text_shadow_subtitle_low
|
||||
}
|
||||
}
|
||||
|
||||
fun getCalendarIntent(context: Context): Intent {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (SP.getString(Constants.PREF_CALENDAR_APP_PACKAGE, "").equals("")) {
|
||||
@ -298,6 +292,26 @@ object Util {
|
||||
}
|
||||
}
|
||||
|
||||
fun getClockIntent(context: Context): Intent {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (SP.getString(Constants.PREF_CLOCK_APP_PACKAGE, "").equals("")) {
|
||||
val clockIntent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
||||
clockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return clockIntent
|
||||
} else {
|
||||
val pm: PackageManager = context.packageManager
|
||||
return try {
|
||||
val intent: Intent = pm.getLaunchIntentForPackage(SP.getString(Constants.PREF_CLOCK_APP_PACKAGE, ""))
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
intent
|
||||
} catch (e: Exception) {
|
||||
val clockIntent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
||||
clockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return clockIntent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCapWordString(text: String): String {
|
||||
return try {
|
||||
val ar = text.split(" ")
|
||||
@ -427,9 +441,10 @@ object Util {
|
||||
val nowDate = DateTime(now)
|
||||
val eventDate = DateTime(start)
|
||||
|
||||
val difference = start - now
|
||||
var difference = start - now
|
||||
difference += 60 * 1000 - (difference % (60 * 1000))
|
||||
|
||||
if (difference < 0) {
|
||||
if (difference <= 0) {
|
||||
return ""
|
||||
} else if (TimeUnit.MILLISECONDS.toHours(difference) < 1) {
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(difference)
|
||||
|
@ -20,10 +20,14 @@ import android.support.v4.content.ContextCompat.startActivity
|
||||
import android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
|
||||
import android.content.Intent
|
||||
import android.location.LocationManager
|
||||
import android.support.annotation.NonNull
|
||||
import android.util.Log
|
||||
import com.google.android.gms.awareness.Awareness
|
||||
import com.google.android.gms.awareness.snapshot.WeatherResponse
|
||||
import com.google.android.gms.awareness.snapshot.WeatherResult
|
||||
import com.google.android.gms.awareness.state.Weather
|
||||
import com.google.android.gms.common.api.GoogleApiClient
|
||||
import com.google.android.gms.common.api.ResultCallback
|
||||
import com.google.android.gms.tasks.OnFailureListener
|
||||
import com.google.android.gms.tasks.OnSuccessListener
|
||||
import java.util.*
|
||||
@ -40,40 +44,53 @@ object WeatherUtil {
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
if (SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").equals("")) {
|
||||
|
||||
newWeatherProvider(context)
|
||||
return
|
||||
/*
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
return
|
||||
}
|
||||
var gpsEnabled = false
|
||||
var networkEnabled = false
|
||||
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
try {
|
||||
gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
|
||||
try {
|
||||
networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
|
||||
if (!gpsEnabled && !networkEnabled && SP.getBoolean(Constants.PREF_SHOW_WEATHER, true)) {
|
||||
Util.showLocationNotification(context, true)
|
||||
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
|
||||
newWeatherProvider(context)
|
||||
} else {
|
||||
if (gpsEnabled) {
|
||||
val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
|
||||
if (gpsLocation != null) {
|
||||
getCurrentWeather(context, gpsLocation)
|
||||
return
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
return
|
||||
}
|
||||
val mGoogleApiClient = GoogleApiClient.Builder(context)
|
||||
.addApi(Awareness.API)
|
||||
.build()
|
||||
mGoogleApiClient.connect()
|
||||
Awareness.SnapshotApi.getLocation(mGoogleApiClient)
|
||||
.setResultCallback({ locationResult ->
|
||||
if (locationResult.status.isSuccess) {
|
||||
getCurrentWeather(context, locationResult.location)
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
var gpsEnabled = false
|
||||
var networkEnabled = false
|
||||
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
try {
|
||||
gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
|
||||
try {
|
||||
networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||
} catch (ex: Exception) {
|
||||
}
|
||||
|
||||
if (!gpsEnabled && !networkEnabled && SP.getBoolean(Constants.PREF_SHOW_WEATHER, true)) {
|
||||
Util.showLocationNotification(context, true)
|
||||
} else {
|
||||
if (gpsEnabled) {
|
||||
val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
|
||||
if (gpsLocation != null) {
|
||||
getCurrentWeather(context, gpsLocation)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (networkEnabled) {
|
||||
getCurrentWeather(context, locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER))
|
||||
}
|
||||
}
|
||||
if (networkEnabled) {
|
||||
getCurrentWeather(context, locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER))
|
||||
}
|
||||
}*/
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
weatherNetworkRequest(context, SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").toDouble(), SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").toDouble())
|
||||
}
|
||||
@ -84,17 +101,25 @@ object WeatherUtil {
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
return
|
||||
}
|
||||
Awareness.getSnapshotClient(context).weather
|
||||
.addOnSuccessListener { weatherResponse ->
|
||||
val weather: Weather = weatherResponse.weather
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
SP.edit()
|
||||
.putFloat(Constants.PREF_WEATHER_TEMP, weather.getTemperature(if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) Weather.FAHRENHEIT else Weather.CELSIUS))
|
||||
.putString(Constants.PREF_WEATHER_ICON, getIconCodeFromAwareness(weather.conditions))
|
||||
.putString(Constants.PREF_WEATHER_REAL_TEMP_UNIT, SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F"))
|
||||
.commit()
|
||||
Util.updateWidget(context)
|
||||
}
|
||||
val mGoogleApiClient = GoogleApiClient.Builder(context)
|
||||
.addApi(Awareness.API)
|
||||
.build();
|
||||
mGoogleApiClient.connect()
|
||||
|
||||
Awareness.SnapshotApi.getWeather(mGoogleApiClient)
|
||||
.setResultCallback({ weatherResult ->
|
||||
if (weatherResult.status.isSuccess) {
|
||||
val weather: Weather = weatherResult.weather
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
SP.edit()
|
||||
.putFloat(Constants.PREF_WEATHER_TEMP, weather.getTemperature(if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) Weather.FAHRENHEIT else Weather.CELSIUS))
|
||||
.putString(Constants.PREF_WEATHER_ICON, getIconCodeFromAwareness(weather.conditions))
|
||||
.putString(Constants.PREF_WEATHER_REAL_TEMP_UNIT, SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F"))
|
||||
.commit()
|
||||
Util.updateWidget(context)
|
||||
}
|
||||
mGoogleApiClient.disconnect()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user