add optional text shadow to widget for better readability

This commit is contained in:
tibbi 2018-03-12 00:01:20 +01:00
parent 3b5bf64066
commit c1feb66b91
11 changed files with 116 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package com.simplemobiletools.clock.activities
import android.os.Bundle
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.extensions.config
import com.simplemobiletools.clock.extensions.updateWidgets
import com.simplemobiletools.clock.helpers.DEFAULT_MAX_ALARM_REMINDER_SECS
import com.simplemobiletools.clock.helpers.DEFAULT_MAX_TIMER_REMINDER_SECS
import com.simplemobiletools.commons.extensions.*
@ -30,13 +31,14 @@ class SettingsActivity : SimpleActivity() {
setupSnoozeTime()
setupVibrate()
setupTimerMaxReminder()
setupUseTextShadow()
updateTextColors(settings_holder)
setupSectionColors()
}
private fun setupSectionColors() {
val adjustedPrimaryColor = getAdjustedPrimaryColor()
arrayListOf(clock_tab_label, alarm_tab_label, stopwatch_tab_label, timer_tab_label).forEach {
arrayListOf(clock_tab_label, alarm_tab_label, stopwatch_tab_label, timer_tab_label, widgets_label).forEach {
it.setTextColor(adjustedPrimaryColor)
}
}
@ -137,6 +139,15 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupUseTextShadow() {
settings_use_text_shadow.isChecked = config.useTextShadow
settings_use_text_shadow_holder.setOnClickListener {
settings_use_text_shadow.toggle()
config.useTextShadow = settings_use_text_shadow.isChecked
updateWidgets()
}
}
private fun updateSnoozeText() {
settings_snooze_time.text = formatMinutesToTimeString(config.snoozeTime)
}

View file

@ -74,6 +74,11 @@ class WidgetDateTimeConfigureActivity : SimpleActivity() {
val calendar = Calendar.getInstance()
config_time.text = getFormattedTime(calendar, false)
config_date.text = getFormattedDate(calendar)
if (config.useTextShadow) {
config_time.setShadowLayer(1f, 0f, 1f, Color.BLACK)
config_date.setShadowLayer(1f, 0f, 1f, Color.BLACK)
}
}
private fun saveConfig() {

View file

@ -4,6 +4,8 @@ import android.annotation.SuppressLint
import android.app.AlarmManager
import android.app.NotificationManager
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
@ -156,3 +158,15 @@ fun Context.hideNotification(id: Int) {
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.cancel(id)
}
fun Context.updateWidgets() {
val widgetsCnt = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateTimeProvider::class.java))
if (widgetsCnt.isNotEmpty()) {
val ids = intArrayOf(R.xml.widget_date_time_info)
Intent(applicationContext, MyWidgetDateTimeProvider::class.java).apply {
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
sendBroadcast(this)
}
}
}

View file

@ -49,4 +49,8 @@ class Config(context: Context) : BaseConfig(context) {
var alarmMaxReminderSecs: Int
get() = prefs.getInt(ALARM_MAX_REMINDER_SECS, DEFAULT_MAX_ALARM_REMINDER_SECS)
set(alarmMaxReminderSecs) = prefs.edit().putInt(ALARM_MAX_REMINDER_SECS, alarmMaxReminderSecs).apply()
var useTextShadow: Boolean
get() = prefs.getBoolean(USE_TEXT_SHADOW, true)
set(useTextShadow) = prefs.edit().putBoolean(USE_TEXT_SHADOW, useTextShadow).apply()
}

View file

@ -13,6 +13,7 @@ const val TIMER_SOUND_URI = "timer_sound_uri"
const val TIMER_SOUND_TITLE = "timer_sound_title"
const val TIMER_MAX_REMINDER_SECS = "timer_max_reminder_secs"
const val ALARM_MAX_REMINDER_SECS = "alarm_max_reminder_secs"
const val USE_TEXT_SHADOW = "use_text_shadow"
const val TABS_COUNT = 4
const val EDITED_TIME_ZONE_SEPARATOR = ":"

View file

@ -22,7 +22,8 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
private fun performUpdate(context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context)
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
RemoteViews(context.packageName, R.layout.widget_date_time).apply {
val layout = if (context.config.useTextShadow) R.layout.widget_date_time_with_shadow else R.layout.widget_date_time
RemoteViews(context.packageName, layout).apply {
updateTexts(context, this)
updateColors(context, this)
appWidgetManager.updateAppWidget(it, this)

View file

@ -369,5 +369,45 @@
android:clickable="false"/>
</RelativeLayout>
<View
android:id="@+id/widgets_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_grey"
android:importantForAccessibility="no"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/widgets_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/widgets"
android:textAllCaps="true"
android:textSize="@dimen/smaller_text_size"/>
<RelativeLayout
android:id="@+id/settings_use_text_shadow_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_use_text_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/use_text_shadow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget_date_time_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/widget_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textSize="@dimen/widget_time_text_size"
tools:text="00:00"/>
<TextView
android:id="@+id/widget_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/widget_time"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:paddingBottom="@dimen/normal_margin"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textSize="@dimen/normal_text_size"
tools:text="Mon, 1 January"/>
</RelativeLayout>

View file

@ -13,6 +13,7 @@
<string name="max_reminder_duration">Max reminder duration</string>
<string name="time_expired">Time expired</string>
<string name="digital_clock_and_date">Digital clock and date</string>
<string name="use_text_shadow">Use text shadow</string>
<!-- Settings -->
<string name="clock_tab">Relógio</string>

View file

@ -13,6 +13,7 @@
<string name="max_reminder_duration">Maximálna dĺžka upozorňovania</string>
<string name="time_expired">Čas vypršal</string>
<string name="digital_clock_and_date">Digitálne hodiny a dátum</string>
<string name="use_text_shadow">Použiť tieňovanie písma</string>
<!-- Settings -->
<string name="clock_tab">Okno s časom</string>

View file

@ -13,6 +13,7 @@
<string name="max_reminder_duration">Max reminder duration</string>
<string name="time_expired">Time expired</string>
<string name="digital_clock_and_date">Digital clock and date</string>
<string name="use_text_shadow">Use text shadow</string>
<!-- Settings -->
<string name="clock_tab">Clock tab</string>