add some special widget handling for devices before Oreo

This commit is contained in:
tibbi 2018-09-18 23:34:57 +02:00
parent fbb3fc6b7b
commit 7148268375
4 changed files with 145 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SplashActivity
import com.simplemobiletools.clock.extensions.*
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isOreoPlus
import java.util.*
class MyWidgetDateTimeProvider : AppWidgetProvider() {
@ -31,8 +32,7 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
private fun performUpdate(context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context)
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val layout = if (context.config.useTextShadow) R.layout.widget_date_time_with_shadow else R.layout.widget_date_time
RemoteViews(context.packageName, layout).apply {
RemoteViews(context.packageName, getProperLayout(context)).apply {
updateTexts(context, this)
updateColors(context, this)
setupAppOpenIntent(context, this)
@ -41,6 +41,20 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
}
}
private fun getProperLayout(context: Context) = if (context.config.useTextShadow) {
if (isOreoPlus()) {
R.layout.widget_date_time_with_shadow
} else {
R.layout.widget_date_time_with_shadow_pre_oreo
}
} else {
if (isOreoPlus()) {
R.layout.widget_date_time
} else {
R.layout.widget_date_time_pre_oreo
}
}
private fun updateTexts(context: Context, views: RemoteViews) {
val timeText = context.getFormattedTime(getPassedSeconds(), false, false).toString()
val nextAlarm = getFormattedNextAlarm(context)

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/small_margin"
android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/small_margin">
<TextView
android:id="@+id/widget_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:textSize="@dimen/widget_time_text_size_small"
tools:text="00:00"/>
<TextView
android:id="@+id/widget_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:textSize="@dimen/actionbar_text_size"
tools:text="Mon, 1 January"/>
<RelativeLayout
android:id="@+id/widget_alarm_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/widget_next_alarm_image"
android:layout_width="@dimen/widget_alarm_icon_size"
android:layout_height="@dimen/widget_alarm_icon_size"
android:layout_alignBottom="@+id/widget_next_alarm"
android:layout_alignTop="@+id/widget_next_alarm"
android:src="@drawable/ic_clock"/>
<TextView
android:id="@+id/widget_next_alarm"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/widget_next_alarm_image"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:paddingLeft="@dimen/small_margin"
android:textSize="@dimen/actionbar_text_size"
tools:text="Tue, 18:30"/>
</RelativeLayout>
</LinearLayout>

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/small_margin"
android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/small_margin">
<TextView
android:id="@+id/widget_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textSize="@dimen/widget_time_text_size_small"
tools:text="00:00"/>
<TextView
android:id="@+id/widget_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textSize="@dimen/actionbar_text_size"
tools:text="Mon, 1 January"/>
<RelativeLayout
android:id="@+id/widget_alarm_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/widget_next_alarm_image"
android:layout_width="@dimen/widget_alarm_icon_size"
android:layout_height="@dimen/widget_alarm_icon_size"
android:layout_alignBottom="@+id/widget_next_alarm"
android:layout_alignTop="@+id/widget_next_alarm"
android:src="@drawable/ic_clock"/>
<TextView
android:id="@+id/widget_next_alarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/widget_next_alarm_image"
android:gravity="center"
android:includeFontPadding="false"
android:maxLines="1"
android:paddingLeft="@dimen/small_margin"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textSize="@dimen/actionbar_text_size"
tools:text="Tue, 18:30"/>
</RelativeLayout>
</LinearLayout>

View File

@ -15,7 +15,6 @@
<dimen name="alarm_text_size">44sp</dimen>
<dimen name="stopwatch_text_size">60sp</dimen>
<dimen name="widget_time_text_size_small">48sp</dimen>
<dimen name="widget_time_text_size_big">64sp</dimen>
<dimen name="widget_details_text_size">14sp</dimen>
<dimen name="reminder_activity_title_size">32sp</dimen>
<dimen name="reminder_activity_text_size">26sp</dimen>