Skip to content

Commit

Permalink
Time widget improvementes
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Aug 25, 2016
1 parent f4f6f42 commit 7373903
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.widget.RemoteViews;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

Expand All @@ -28,7 +29,7 @@ public class TimeWidgetProvider extends AbstractWidgetProvider {

private static final String ACTION_UPDATE_TIME = "cz.martykan.forecastie.UPDATE_TIME";

private static final long DURATION_MINUTE = TimeUnit.MINUTES.toMillis(1);
private static final long DURATION_MINUTE = TimeUnit.SECONDS.toMillis(30);

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Expand Down Expand Up @@ -60,8 +61,22 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
}

DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
String defaultDateFormat = context.getResources().getStringArray(R.array.dateFormatsValues)[0];
String dateFormat = sp.getString("dateFormat", defaultDateFormat);
dateFormat = dateFormat.substring(0, dateFormat.indexOf("-")-1);
if ("custom".equals(dateFormat)) {
dateFormat = sp.getString("dateFormatCustom", defaultDateFormat);
}
String dateString;
try {
SimpleDateFormat resultFormat = new SimpleDateFormat(dateFormat);
dateString = resultFormat.format(new Date());
} catch (IllegalArgumentException e) {
dateString = context.getResources().getString(R.string.error_dateFormat);
}

remoteViews.setTextViewText(R.id.time, timeFormat.format(new Date()));
remoteViews.setTextViewText(R.id.date, dateString);
remoteViews.setTextViewText(R.id.widgetCity, widgetWeather.getCity() + ", " + widgetWeather.getCountry());
remoteViews.setTextViewText(R.id.widgetTemperature, widgetWeather.getTemperature());
remoteViews.setTextViewText(R.id.widgetDescription, widgetWeather.getDescription());
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/res/layout/time_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,28 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="100sp"
android:textSize="80sp"
android:layout_centerHorizontal="true"
tools:text="11:50"/>

<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Clear Sky"
android:layout_marginTop="0sp"
android:layout_marginBottom="5sp"
android:textColor="@android:color/white"
android:textSize="16sp"
android:layout_below="@+id/time"
android:layout_centerHorizontal="true" />

<LinearLayout
android:id="@+id/textHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/time">
android:layout_below="@id/date">

<TextView
android:id="@+id/widgetDescription"
Expand All @@ -47,7 +59,7 @@
android:id="@+id/widgetIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/time"
android:layout_below="@id/date"
android:layout_toEndOf="@id/textHolder"
android:layout_toRightOf="@id/textHolder"
android:layout_toLeftOf="@+id/widgetTemperature"
Expand All @@ -61,7 +73,7 @@
tools:text="0 °C"
android:textColor="@android:color/white"
android:textSize="48sp"
android:layout_below="@id/time"
android:layout_below="@id/date"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>

Expand Down

0 comments on commit 7373903

Please sign in to comment.