improve am/pm displaying at the widget
This commit is contained in:
parent
803e88992c
commit
f1fd39ab8f
7 changed files with 45 additions and 5 deletions
|
@ -41,7 +41,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.15.14'
|
||||
implementation 'com.simplemobiletools:commons:3.15.15'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
implementation 'com.shawnlin:number-picker:2.4.6'
|
||||
|
|
|
@ -82,6 +82,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
settings_hour_format_holder.setOnClickListener {
|
||||
settings_hour_format.toggle()
|
||||
config.use24HourFormat = settings_hour_format.isChecked
|
||||
updateWidgets()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.simplemobiletools.clock.extensions.getFormattedTime
|
|||
import com.simplemobiletools.clock.extensions.scheduleNextWidgetUpdate
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.setText
|
||||
import com.simplemobiletools.commons.extensions.setVisibleIf
|
||||
import java.util.*
|
||||
|
||||
class MyWidgetDateTimeProvider : AppWidgetProvider() {
|
||||
|
@ -44,9 +45,19 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
|
|||
|
||||
private fun updateTexts(context: Context, views: RemoteViews) {
|
||||
val calendar = Calendar.getInstance()
|
||||
val use24HourFormat = context.config.use24HourFormat
|
||||
|
||||
val timeText = context.getFormattedTime(getPassedSeconds(), false, false).toString()
|
||||
views.apply {
|
||||
setText(R.id.widget_time, context.getFormattedTime(getPassedSeconds(), false, false).toString())
|
||||
if (use24HourFormat) {
|
||||
setText(R.id.widget_time, timeText)
|
||||
} else {
|
||||
val timeParts = timeText.split(" ")
|
||||
setText(R.id.widget_time, timeParts[0])
|
||||
setText(R.id.widget_time_am_pm, " ${timeParts[1]}")
|
||||
}
|
||||
setText(R.id.widget_date, context.getFormattedDate(calendar))
|
||||
setVisibleIf(R.id.widget_time_am_pm, !use24HourFormat)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +69,7 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
|
|||
views.apply {
|
||||
setBackgroundColor(R.id.widget_date_time_holder, widgetBgColor)
|
||||
setTextColor(R.id.widget_time, widgetTextColor)
|
||||
setTextColor(R.id.widget_time_am_pm, widgetTextColor)
|
||||
setTextColor(R.id.widget_date, widgetTextColor)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,24 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/widget_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:includeFontPadding="false"
|
||||
android:textSize="@dimen/widget_time_text_size"
|
||||
tools:text="00:00"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_time_am_pm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@+id/widget_time"
|
||||
android:layout_toRightOf="@+id/widget_time"
|
||||
android:includeFontPadding="false"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text=" a.m."/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_date"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/widget_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:includeFontPadding="false"
|
||||
android:shadowColor="@android:color/black"
|
||||
|
@ -18,6 +19,19 @@
|
|||
android:textSize="@dimen/widget_time_text_size"
|
||||
tools:text="00:00"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_time_am_pm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@+id/widget_time"
|
||||
android:layout_toRightOf="@+id/widget_time"
|
||||
android:includeFontPadding="false"
|
||||
android:shadowColor="@android:color/black"
|
||||
android:shadowDy="1"
|
||||
android:shadowRadius="1"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text=" a.m."/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_date"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
<dimen name="stopwatch_button_size">64dp</dimen>
|
||||
<dimen name="lap_time_size">80dp</dimen>
|
||||
<dimen name="min_widget_height">30dp</dimen>
|
||||
<dimen name="min_widget_width">110dp</dimen>
|
||||
<dimen name="min_widget_width">180dp</dimen>
|
||||
<dimen name="min_widget_resize_width">110dp</dimen>
|
||||
|
||||
<dimen name="clock_text_size">70sp</dimen>
|
||||
<dimen name="clock_text_size_smaller">60sp</dimen>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
android:configure="com.simplemobiletools.clock.activities.WidgetDateTimeConfigureActivity"
|
||||
android:initialLayout="@layout/widget_date_time"
|
||||
android:minHeight="@dimen/min_widget_height"
|
||||
android:minResizeWidth="@dimen/min_widget_resize_width"
|
||||
android:minWidth="@dimen/min_widget_width"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="86400000"/>
|
||||
|
|
Loading…
Reference in a new issue