Text Shadow, Clock, Product Sans Font, Multiple Events and more
This commit is contained in:
@ -23,6 +23,7 @@ import android.support.v7.widget.LinearLayoutManager
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import com.tommasoberlose.anotherwidget.`object`.AppInfoSavedEvent
|
||||
import com.tommasoberlose.anotherwidget.ui.adapter.ApplicationInfoAdapter
|
||||
|
||||
@ -41,6 +42,14 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
selectDefaultApp()
|
||||
}
|
||||
|
||||
action_back.setOnClickListener {
|
||||
onBackPressed()
|
||||
}
|
||||
|
||||
action_none.setOnClickListener {
|
||||
removeClickAction()
|
||||
}
|
||||
|
||||
list_view.setHasFixedSize(true);
|
||||
val mLayoutManager = LinearLayoutManager(this);
|
||||
list_view.layoutManager = mLayoutManager;
|
||||
@ -67,9 +76,25 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
|
||||
fun selectDefaultApp() {
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, getString(R.string.default_name))
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, "")
|
||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, "")
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
fun removeClickAction() {
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, getString(R.string.action_none))
|
||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, "_")
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
fun multiEventAction() {
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, getString(R.string.action_go_to_next_event))
|
||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, Constants.PREF_SHOW_NEXT_EVENT)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,9 @@ import android.os.Build
|
||||
import android.support.design.widget.BottomSheetDialog
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.text.Html
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.RelativeSizeSpan
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.widget.Toast
|
||||
@ -42,6 +45,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() {
|
||||
@ -113,6 +117,12 @@ class MainActivity : AppCompatActivity() {
|
||||
Util.updateWidget(this)
|
||||
mBottomSheetDialog.dismiss()
|
||||
}
|
||||
|
||||
menuView.action_support.setOnClickListener {
|
||||
startActivity(Intent(this, SupportDevActivity::class.java))
|
||||
mBottomSheetDialog.dismiss()
|
||||
}
|
||||
|
||||
mBottomSheetDialog.setContentView(menuView)
|
||||
mBottomSheetDialog.show();
|
||||
}
|
||||
@ -193,28 +203,28 @@ class MainActivity : AppCompatActivity() {
|
||||
updateSettings()
|
||||
} else if (requestCode == Constants.CALENDAR_APP_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_CALENDAR_APP_NAME, data.getStringExtra(Constants.RESULT_APP_NAME))
|
||||
.putString(Constants.PREF_CALENDAR_APP_NAME, if (data.getStringExtra(Constants.RESULT_APP_NAME) != "") data.getStringExtra(Constants.RESULT_APP_NAME) else getString(R.string.default_calendar_app))
|
||||
.putString(Constants.PREF_CALENDAR_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
|
||||
.commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
} else if (requestCode == Constants.WEATHER_APP_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_WEATHER_APP_NAME, data.getStringExtra(Constants.RESULT_APP_NAME))
|
||||
.putString(Constants.PREF_WEATHER_APP_NAME, if (data.getStringExtra(Constants.RESULT_APP_NAME) != "") data.getStringExtra(Constants.RESULT_APP_NAME) else getString(R.string.default_weather_app))
|
||||
.putString(Constants.PREF_WEATHER_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
|
||||
.commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
} else if (requestCode == Constants.EVENT_APP_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_EVENT_APP_NAME, data.getStringExtra(Constants.RESULT_APP_NAME))
|
||||
.putString(Constants.PREF_EVENT_APP_NAME, if (data.getStringExtra(Constants.RESULT_APP_NAME) != "") data.getStringExtra(Constants.RESULT_APP_NAME) else getString(R.string.default_event_app))
|
||||
.putString(Constants.PREF_EVENT_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
|
||||
.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_NAME, if (data.getStringExtra(Constants.RESULT_APP_NAME) != "") data.getStringExtra(Constants.RESULT_APP_NAME) else getString(R.string.default_clock_app))
|
||||
.putString(Constants.PREF_CLOCK_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
|
||||
.commit()
|
||||
Util.updateWidget(this)
|
||||
@ -234,7 +244,15 @@ class MainActivity : AppCompatActivity() {
|
||||
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)
|
||||
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12") == "12") {
|
||||
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis))
|
||||
textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
|
||||
textBadHour.length, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
|
||||
|
||||
time.text = textBadHour
|
||||
} else {
|
||||
time.text = Constants.goodHourFormat.format(now.timeInMillis)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCalendarView() {
|
||||
@ -255,6 +273,13 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
if (e.id != 0) {
|
||||
next_event.text = e.title
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, false) && CalendarUtil.getEventsCount(this) > 1) {
|
||||
multiple_events.visibility = View.VISIBLE
|
||||
} else {
|
||||
multiple_events.visibility = View.GONE
|
||||
}
|
||||
|
||||
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
|
||||
@ -324,6 +349,12 @@ class MainActivity : AppCompatActivity() {
|
||||
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))
|
||||
|
||||
second_row_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
second_row_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
|
||||
multiple_events.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
multiple_events.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
|
||||
val shadowRadius = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 0f
|
||||
1 -> 5f
|
||||
@ -352,17 +383,28 @@ class MainActivity : AppCompatActivity() {
|
||||
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")
|
||||
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
|
||||
time.typeface = product_sans
|
||||
if (SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS) == Constants.CUSTOM_FONT_PRODUCT_SANS) {
|
||||
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
|
||||
time.typeface = product_sans
|
||||
} else {
|
||||
empty_date.typeface = Typeface.DEFAULT
|
||||
divider1.typeface = Typeface.DEFAULT
|
||||
temp.typeface = Typeface.DEFAULT
|
||||
next_event.typeface = Typeface.DEFAULT
|
||||
next_event_difference_time.typeface = Typeface.DEFAULT
|
||||
next_event_date.typeface = Typeface.DEFAULT
|
||||
divider2.typeface = Typeface.DEFAULT
|
||||
calendar_temp.typeface = Typeface.DEFAULT
|
||||
time.typeface = Typeface.DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLocationView() {
|
||||
@ -489,6 +531,13 @@ class MainActivity : AppCompatActivity() {
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
show_multiple_events_label.text = if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, true)) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
action_show_multiple_events.setOnClickListener {
|
||||
SP.edit().putBoolean(Constants.PREF_SHOW_NEXT_EVENT, !SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, true)).commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
|
||||
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()
|
||||
@ -526,7 +575,7 @@ class MainActivity : AppCompatActivity() {
|
||||
main_text_size_label.text = String.format("%.0f%s", SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f), "sp")
|
||||
action_main_text_size.setOnClickListener {
|
||||
var fontSize = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) + 1
|
||||
if (fontSize > 30) {
|
||||
if (fontSize > 36) {
|
||||
fontSize = 20f
|
||||
}
|
||||
SP.edit().putFloat(Constants.PREF_TEXT_MAIN_SIZE, fontSize).commit()
|
||||
@ -538,13 +587,12 @@ class MainActivity : AppCompatActivity() {
|
||||
second_text_size_label.text = String.format("%.0f%s", SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f), "sp")
|
||||
action_second_text_size.setOnClickListener {
|
||||
var fontSize = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) + 1
|
||||
if (fontSize > 20) {
|
||||
if (fontSize > 28) {
|
||||
fontSize = 12f
|
||||
}
|
||||
SP.edit().putFloat(Constants.PREF_TEXT_SECOND_SIZE, fontSize).commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
clock_text_size_label.text = String.format("%.0f%s", SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f), "sp")
|
||||
@ -556,7 +604,6 @@ class MainActivity : AppCompatActivity() {
|
||||
SP.edit().putFloat(Constants.PREF_TEXT_CLOCK_SIZE, fontSize).commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
val textColor = try {
|
||||
@ -621,14 +668,15 @@ class MainActivity : AppCompatActivity() {
|
||||
3 -> 4
|
||||
4 -> 5
|
||||
5 -> 6
|
||||
6 -> 0
|
||||
6 -> 7
|
||||
7 -> 0
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
}
|
||||
|
||||
text_shadow_label.text = getString(Util.getTextshadowString(SP.getInt(Constants.PREF_TEXT_SHADOW, 1)))
|
||||
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
|
||||
@ -641,6 +689,18 @@ class MainActivity : AppCompatActivity() {
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
custom_font_label.text = getString(Util.getCustomFontLabel(SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS)))
|
||||
action_custom_font.setOnClickListener {
|
||||
SP.edit().putInt(Constants.PREF_CUSTOM_FONT, when (SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS)) {
|
||||
0 -> Constants.CUSTOM_FONT_PRODUCT_SANS
|
||||
Constants.CUSTOM_FONT_PRODUCT_SANS -> 0
|
||||
else -> Constants.CUSTOM_FONT_PRODUCT_SANS
|
||||
}).commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_TIME_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) {
|
||||
action_custom_location.visibility = View.GONE
|
||||
} else {
|
||||
@ -675,7 +735,9 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
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)
|
||||
val i = Intent(this, ChooseApplicationActivity::class.java)
|
||||
i.putExtra("requestCode", Constants.CALENDAR_APP_REQUEST_CODE)
|
||||
startActivityForResult(i, Constants.CALENDAR_APP_REQUEST_CODE)
|
||||
}
|
||||
|
||||
weather_app_label.text = SP.getString(Constants.PREF_WEATHER_APP_NAME, getString(R.string.default_weather_app))
|
||||
|
@ -0,0 +1,99 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.activity
|
||||
|
||||
import android.content.Intent
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import com.anjlab.android.iab.v3.BillingProcessor
|
||||
import com.anjlab.android.iab.v3.TransactionDetails
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
import kotlinx.android.synthetic.main.activity_support_dev.*
|
||||
|
||||
class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler {
|
||||
internal var bp: BillingProcessor? = null
|
||||
|
||||
internal val BILLING_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAox5CcxuoLJ6CmNS7s6lVQzJ253njKKGF8MoQ/gQ5gEw2Fr03fBvtHpiVMpnjhNLw5NMeIpzRvkVqeQ7BfkC7c0BLCJUqf/fFA11ArQe8na6QKt5O4d+v4sbHtP7mm3GQNPOBaqRzcpFZaiAbfk6mnalo+tzM47GXrQFt5bNSrMctCs7bbChqJfH2cyMW0F8DHWEEeO5xElBmH3lh4FVpwIUTPYJIV3n0yhE3qqRA0WXkDej66g/uAt/rebmMZLmwNwIive5cObU4o41YyKRv2wSAicrv3W40LftzXAOOordIbmzDFN8ksh3VrnESqwCDGG97nZVbPG/+3LD0xHWiRwIDAQAB"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_support_dev)
|
||||
bp = BillingProcessor(this, BILLING_KEY, this)
|
||||
|
||||
action_website.setOnClickListener {
|
||||
Util.openURI(this, "http://tommasoberlose.com/")
|
||||
}
|
||||
|
||||
action_translate.setOnClickListener {
|
||||
Util.openURI(this, "https://github.com/tommasoberlose/another-widget/blob/master/app/src/main/res/values/strings.xml")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBillingInitialized() {
|
||||
loader.visibility = View.GONE
|
||||
val isAvailable = BillingProcessor.isIabServiceAvailable(this)
|
||||
val isOneTimePurchaseSupported = bp!!.isOneTimePurchaseSupported
|
||||
if (isAvailable && isOneTimePurchaseSupported) {
|
||||
val coffee = bp!!.getPurchaseListingDetails("donation_coffee")
|
||||
val donuts = bp!!.getPurchaseListingDetails("donation_donuts")
|
||||
val breakfast = bp!!.getPurchaseListingDetails("donation_breakfast")
|
||||
val lunch = bp!!.getPurchaseListingDetails("donation_lunch")
|
||||
val dinner = bp!!.getPurchaseListingDetails("donation_dinner")
|
||||
|
||||
import_donation_coffee.text = coffee.priceText
|
||||
action_donation_coffee.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_coffee")
|
||||
}
|
||||
|
||||
import_donation_donuts.text = donuts.priceText
|
||||
action_donation_donuts.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_donuts")
|
||||
}
|
||||
|
||||
import_donation_breakfast.text = breakfast.priceText
|
||||
action_donation_breakfast.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_breakfast")
|
||||
}
|
||||
|
||||
import_donation_lunch.text = lunch.priceText
|
||||
action_donation_lunch.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_lunch")
|
||||
}
|
||||
|
||||
import_donation_dinner.text = dinner.priceText
|
||||
action_donation_dinner.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_dinner")
|
||||
}
|
||||
|
||||
products_list.visibility = View.VISIBLE
|
||||
} else {
|
||||
products_card.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPurchaseHistoryRestored() {
|
||||
}
|
||||
|
||||
override fun onProductPurchased(productId: String, details: TransactionDetails?) {
|
||||
Toast.makeText(this, R.string.thanks, Toast.LENGTH_SHORT).show()
|
||||
bp!!.consumePurchase(productId)
|
||||
}
|
||||
|
||||
override fun onBillingError(errorCode: Int, error: Throwable?) {
|
||||
Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
|
||||
if (!bp!!.handleActivityResult(requestCode, resultCode, data)) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onDestroy() {
|
||||
if (bp != null) {
|
||||
bp!!.release()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.view
|
||||
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Typeface
|
||||
import android.text.TextPaint
|
||||
import android.text.style.TypefaceSpan
|
||||
|
||||
class CustomTypefaceSpan(family: String, private val newType: Typeface) : TypefaceSpan(family) {
|
||||
|
||||
override fun updateDrawState(ds: TextPaint) {
|
||||
applyCustomTypeFace(ds, newType)
|
||||
}
|
||||
|
||||
override fun updateMeasureState(paint: TextPaint) {
|
||||
applyCustomTypeFace(paint, newType)
|
||||
}
|
||||
|
||||
private fun applyCustomTypeFace(paint: Paint, tf: Typeface) {
|
||||
val oldStyle: Int
|
||||
val old = paint.typeface
|
||||
if (old == null) {
|
||||
oldStyle = 0
|
||||
} else {
|
||||
oldStyle = old.style
|
||||
}
|
||||
|
||||
val fake = oldStyle and tf.style.inv()
|
||||
if (fake and Typeface.BOLD != 0) {
|
||||
paint.isFakeBoldText = true
|
||||
}
|
||||
|
||||
if (fake and Typeface.ITALIC != 0) {
|
||||
paint.textSkewX = -0.25f
|
||||
}
|
||||
|
||||
paint.typeface = tf
|
||||
}
|
||||
}
|
@ -38,8 +38,13 @@ import android.os.Bundle
|
||||
import android.support.v4.content.ContextCompat.startActivity
|
||||
import android.provider.CalendarContract.Events
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.RelativeSizeSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.TypedValue
|
||||
import com.tommasoberlose.anotherwidget.ui.view.CustomTypefaceSpan
|
||||
import kotlinx.android.synthetic.main.the_widget.*
|
||||
import kotlinx.android.synthetic.main.the_widget.view.*
|
||||
|
||||
@ -77,25 +82,21 @@ class TheWidget : AppWidgetProvider() {
|
||||
|
||||
internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int) {
|
||||
val displayMetrics = Resources.getSystem().getDisplayMetrics()
|
||||
val height = displayMetrics.heightPixels
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val displayMetrics = Resources.getSystem().displayMetrics
|
||||
val widgetInfo = appWidgetManager.getAppWidgetInfo(appWidgetId)
|
||||
var height = widgetInfo.minHeight
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
|
||||
height += Util.convertSpToPixels(SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f), context).toInt() + Util.convertDpToPixel(8f, context).toInt()
|
||||
}
|
||||
val width = displayMetrics.widthPixels
|
||||
|
||||
val widgetInfo = appWidgetManager.getAppWidgetInfo(appWidgetId)
|
||||
generateWidgetView(context, appWidgetId, appWidgetManager, width - Util.convertDpToPixel(32f, context).toInt(), widgetInfo.minHeight)
|
||||
generateWidgetView(context, appWidgetId, appWidgetManager, width - Util.convertDpToPixel(16f, context).toInt(), height)
|
||||
}
|
||||
|
||||
fun generateWidgetView(context: Context, appWidgetId: Int, appWidgetManager: AppWidgetManager, w: Int, h: Int) {
|
||||
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, w, h))
|
||||
|
||||
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))
|
||||
@ -106,6 +107,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setTextColor(R.id.next_event_date, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
|
||||
views.setTextColor(R.id.divider2, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
|
||||
views.setTextColor(R.id.calendar_temp, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
|
||||
views.setTextColor(R.id.time, Util.getFontColor(PreferenceManager.getDefaultSharedPreferences(context)))
|
||||
|
||||
views.setTextViewTextSize(R.id.empty_date, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
|
||||
views.setTextViewTextSize(R.id.divider1, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f))
|
||||
@ -115,6 +117,16 @@ 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))
|
||||
views.setTextViewTextSize(R.id.time, TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f))
|
||||
|
||||
v = updateCalendarViewByLayout(context, v)
|
||||
v = updateLocationViewByLayout(context, v)
|
||||
v = updateClockViewByLayout(context, v)
|
||||
views.setImageViewBitmap(R.id.bitmap_container, Util.getBitmapFromView(v, w, h))
|
||||
|
||||
views = updateCalendarView(context, views, appWidgetId)
|
||||
views = updateLocationView(context, views, appWidgetId)
|
||||
views = updateClockView(context, views, appWidgetId)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
@ -142,6 +154,19 @@ class TheWidget : AppWidgetProvider() {
|
||||
|
||||
if (e.id != 0) {
|
||||
views.setTextViewText(R.id.next_event, e.title)
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, false) && CalendarUtil.getEventsCount(context) > 1) {
|
||||
val multipleIntent = PendingIntent.getBroadcast(context, widgetID, Intent(Constants.ACTION_GO_TO_NEXT_EVENT), 0)
|
||||
views.setViewVisibility(R.id.multiple_events, View.VISIBLE)
|
||||
views.setOnClickPendingIntent(R.id.multiple_events, multipleIntent)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.multiple_events, View.GONE)
|
||||
}
|
||||
|
||||
val pIntent = PendingIntent.getActivity(context, widgetID, Util.getEventIntent(context, e), 0)
|
||||
views.setOnClickPendingIntent(R.id.next_event, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time, pIntent)
|
||||
|
||||
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)
|
||||
@ -174,8 +199,12 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setImageViewBitmap(R.id.second_row_icon, result)
|
||||
|
||||
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 startHour = Constants.goodHourFormat.format(e.startDate)
|
||||
var endHour = Constants.goodHourFormat.format(e.endDate)
|
||||
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
|
||||
startHour = Constants.badHourFormat.format(e.startDate)
|
||||
endHour = Constants.badHourFormat.format(e.endDate)
|
||||
}
|
||||
var dayDiff = TimeUnit.MILLISECONDS.toDays(e.endDate - e.startDate)
|
||||
|
||||
val startCal = Calendar.getInstance()
|
||||
@ -199,15 +228,11 @@ class TheWidget : AppWidgetProvider() {
|
||||
} else {
|
||||
views.setTextViewText(R.id.next_event_date, dateStringValue)
|
||||
}
|
||||
views.setOnClickPendingIntent(R.id.next_event_date, pIntent)
|
||||
}
|
||||
|
||||
views.setViewVisibility(R.id.empty_layout, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.VISIBLE)
|
||||
|
||||
val pIntent = PendingIntent.getActivity(context, widgetID, Util.getEventIntent(context, e), 0)
|
||||
views.setOnClickPendingIntent(R.id.next_event, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event_date, pIntent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +283,18 @@ class TheWidget : AppWidgetProvider() {
|
||||
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))
|
||||
|
||||
|
||||
|
||||
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
|
||||
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
|
||||
textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
|
||||
textBadHour.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE)
|
||||
|
||||
views.setTextViewText(R.id.time, textBadHour)
|
||||
} else {
|
||||
views.setTextViewText(R.id.time, Constants.goodHourFormat.format(now.timeInMillis))
|
||||
}
|
||||
|
||||
val clockPIntent = PendingIntent.getActivity(context, widgetID, Util.getClockIntent(context), 0)
|
||||
views.setOnClickPendingIntent(R.id.time, clockPIntent)
|
||||
@ -285,6 +321,13 @@ class TheWidget : AppWidgetProvider() {
|
||||
|
||||
if (e.id != 0) {
|
||||
v.next_event.text = e.title
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, false) && CalendarUtil.getEventsCount(context) > 1) {
|
||||
v.multiple_events.visibility = View.VISIBLE
|
||||
} else {
|
||||
v.multiple_events.visibility = View.GONE
|
||||
}
|
||||
|
||||
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
|
||||
@ -301,8 +344,12 @@ class TheWidget : AppWidgetProvider() {
|
||||
} 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 startHour = Constants.goodHourFormat.format(e.startDate)
|
||||
var endHour = Constants.goodHourFormat.format(e.endDate)
|
||||
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
|
||||
startHour = Constants.badHourFormat.format(e.startDate)
|
||||
endHour = Constants.badHourFormat.format(e.endDate)
|
||||
}
|
||||
var dayDiff = TimeUnit.MILLISECONDS.toDays(e.endDate - e.startDate)
|
||||
|
||||
val startCal = Calendar.getInstance()
|
||||
@ -321,6 +368,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
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
|
||||
}
|
||||
@ -341,6 +389,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
v.calendar_temp.setTextColor(Util.getFontColor(SP))
|
||||
v.second_row_icon.setColorFilter(Util.getFontColor(SP))
|
||||
v.time.setTextColor(Util.getFontColor(SP))
|
||||
v.multiple_events.setColorFilter(Util.getFontColor(SP))
|
||||
|
||||
|
||||
v.empty_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f))
|
||||
@ -353,6 +402,12 @@ class TheWidget : AppWidgetProvider() {
|
||||
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))
|
||||
|
||||
v.second_row_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
v.second_row_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
|
||||
v.multiple_events.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
v.multiple_events.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
|
||||
val shadowRadius = when (SP.getInt(Constants.PREF_TEXT_SHADOW, 1)) {
|
||||
0 -> 0f
|
||||
1 -> 5f
|
||||
@ -381,17 +436,18 @@ class TheWidget : AppWidgetProvider() {
|
||||
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")
|
||||
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
|
||||
v.time.typeface = product_sans
|
||||
if (SP.getInt(Constants.PREF_CUSTOM_FONT, Constants.CUSTOM_FONT_PRODUCT_SANS) == Constants.CUSTOM_FONT_PRODUCT_SANS) {
|
||||
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
|
||||
v.time.typeface = product_sans
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
@ -434,7 +490,15 @@ class TheWidget : AppWidgetProvider() {
|
||||
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)
|
||||
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
|
||||
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
|
||||
textBadHour.setSpan(RelativeSizeSpan(0.4f), textBadHour.length - 2,
|
||||
textBadHour.length, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
|
||||
v.time.text = textBadHour
|
||||
} else {
|
||||
v.time.text = Constants.goodHourFormat.format(now.timeInMillis)
|
||||
}
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user