Show the next alarm time on the widget

This commit is contained in:
tibbi 2018-03-13 15:40:43 +01:00
parent 29e79b5623
commit cb1156fe01
4 changed files with 119 additions and 48 deletions

View File

@ -6,6 +6,7 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.provider.Settings
import android.widget.RemoteViews import android.widget.RemoteViews
import com.simplemobiletools.clock.R import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SplashActivity import com.simplemobiletools.clock.activities.SplashActivity
@ -13,6 +14,7 @@ import com.simplemobiletools.clock.extensions.config
import com.simplemobiletools.clock.extensions.getFormattedDate import com.simplemobiletools.clock.extensions.getFormattedDate
import com.simplemobiletools.clock.extensions.getFormattedTime import com.simplemobiletools.clock.extensions.getFormattedTime
import com.simplemobiletools.clock.extensions.scheduleNextWidgetUpdate import com.simplemobiletools.clock.extensions.scheduleNextWidgetUpdate
import com.simplemobiletools.commons.extensions.getColoredBitmap
import com.simplemobiletools.commons.extensions.setBackgroundColor import com.simplemobiletools.commons.extensions.setBackgroundColor
import com.simplemobiletools.commons.extensions.setText import com.simplemobiletools.commons.extensions.setText
import com.simplemobiletools.commons.extensions.setVisibleIf import com.simplemobiletools.commons.extensions.setVisibleIf
@ -58,6 +60,10 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
} }
setText(R.id.widget_date, context.getFormattedDate(calendar)) setText(R.id.widget_date, context.getFormattedDate(calendar))
setVisibleIf(R.id.widget_time_am_pm, !use24HourFormat) setVisibleIf(R.id.widget_time_am_pm, !use24HourFormat)
val nextAlarm = Settings.System.getString(context.contentResolver, Settings.System.NEXT_ALARM_FORMATTED)
setVisibleIf(R.id.widget_next_alarm, nextAlarm.isNotEmpty())
setText(R.id.widget_next_alarm, nextAlarm)
} }
} }
@ -71,6 +77,8 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() {
setTextColor(R.id.widget_time, widgetTextColor) setTextColor(R.id.widget_time, widgetTextColor)
setTextColor(R.id.widget_time_am_pm, widgetTextColor) setTextColor(R.id.widget_time_am_pm, widgetTextColor)
setTextColor(R.id.widget_date, widgetTextColor) setTextColor(R.id.widget_date, widgetTextColor)
setTextColor(R.id.widget_next_alarm, widgetTextColor)
setImageViewBitmap(R.id.widget_next_alarm_image, context.resources.getColoredBitmap(R.drawable.ic_clock, widgetTextColor))
} }
} }

View File

@ -6,35 +6,64 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <RelativeLayout
android:id="@+id/widget_time" android:id="@+id/widget_time_holder"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:gravity="center_horizontal">
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:textSize="@dimen/widget_time_text_size"
tools:text="00:00"/>
<TextView <TextView
android:id="@+id/widget_time_am_pm" android:id="@+id/widget_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="@dimen/widget_time_height"
android:layout_alignBaseline="@+id/widget_time" android:includeFontPadding="false"
android:layout_toRightOf="@+id/widget_time" android:textSize="@dimen/widget_time_text_size"
android:includeFontPadding="false" tools:text="00:00"/>
android:textSize="@dimen/normal_text_size"
tools:text=" a.m."/> <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."/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/widget_date" android:id="@+id/widget_date"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/widget_time" android:layout_below="@+id/widget_time_holder"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:includeFontPadding="false" android:includeFontPadding="false"
android:paddingBottom="@dimen/normal_margin"
android:textSize="@dimen/normal_text_size" android:textSize="@dimen/normal_text_size"
tools:text="Mon, 1 January"/> tools:text="Mon, 1 January"/>
<RelativeLayout
android:id="@+id/widget_alarm_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/widget_date"
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: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:includeFontPadding="false"
android:paddingLeft="@dimen/small_margin"
android:textSize="@dimen/normal_text_size"
tools:text="Tue, 18:30"/>
</RelativeLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -6,44 +6,76 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/widget_time_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="@+id/widget_time"
android:layout_width="wrap_content"
android:layout_height="@dimen/widget_time_height"
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_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."/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/widget_time" android:id="@+id/widget_date"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/widget_time_holder"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:includeFontPadding="false" android:includeFontPadding="false"
android:shadowColor="@android:color/black" android:shadowColor="@android:color/black"
android:shadowDy="1" android:shadowDy="1"
android:shadowRadius="1" android:shadowRadius="1"
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"
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" android:textSize="@dimen/normal_text_size"
tools:text="Mon, 1 January"/> tools:text="Mon, 1 January"/>
<RelativeLayout
android:id="@+id/widget_alarm_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/widget_date"
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: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:includeFontPadding="false"
android:paddingLeft="@dimen/small_margin"
android:shadowColor="@android:color/black"
android:shadowDy="1"
android:shadowRadius="1"
android:textSize="@dimen/normal_text_size"
tools:text="Tue, 18:30"/>
</RelativeLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -3,6 +3,8 @@
<dimen name="stopwatch_button_small_size">60dp</dimen> <dimen name="stopwatch_button_small_size">60dp</dimen>
<dimen name="stopwatch_button_size">64dp</dimen> <dimen name="stopwatch_button_size">64dp</dimen>
<dimen name="lap_time_size">80dp</dimen> <dimen name="lap_time_size">80dp</dimen>
<dimen name="widget_alarm_icon_size">18dp</dimen>
<dimen name="widget_time_height">50dp</dimen>
<dimen name="min_widget_height">30dp</dimen> <dimen name="min_widget_height">30dp</dimen>
<dimen name="min_widget_width">180dp</dimen> <dimen name="min_widget_width">180dp</dimen>
<dimen name="min_widget_resize_width">110dp</dimen> <dimen name="min_widget_resize_width">110dp</dimen>