Skip to content

Commit

Permalink
Merge pull request #84 from StephenBlackWasAlreadyTaken/widget-time
Browse files Browse the repository at this point in the history
time on widget
  • Loading branch information
AdrianLxM authored Nov 4, 2016
2 parents a342f54 + ef26945 commit a5a3fb1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dexdrip.stephenblack.nightwatch;

import android.annotation.TargetApi;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
Expand All @@ -11,10 +12,13 @@
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.RemoteViews;

import com.dexdrip.stephenblack.nightwatch.activities.Home;

import java.text.DateFormat;
import java.util.Date;


Expand Down Expand Up @@ -92,10 +96,32 @@ public static void displayCurrentInfo(AppWidgetManager appWidgetManager, int app
if(prefs.getBoolean("widget_show_raw", false)){
raw_string = "\n" + Bg.threeRaw((prefs.getString("units", "mgdl").equals("mgdl")));
}
if (timeAgo == 1) {
views.setTextViewText(R.id.readingAge, timeAgo + " Minute ago" + raw_string);
} else {
views.setTextViewText(R.id.readingAge, timeAgo + " Minutes ago" + raw_string);
if(prefs.getBoolean("widget_show_time", false)){
views.setTextViewText(R.id.readingAge, timeAgo + "' ago" + raw_string);
views.setTextViewText(R.id.widget_time, DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date()));
views.setViewVisibility(R.id.widget_time, View.VISIBLE);

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
views.setTextViewTextSize(R.id.widgetBg, TypedValue.COMPLEX_UNIT_SP, 45);
views.setTextViewTextSize(R.id.widgetArrow, TypedValue.COMPLEX_UNIT_SP, 30);

}

} else {

views.setViewVisibility(R.id.widget_time, View.GONE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
views.setTextViewTextSize(R.id.widgetBg, TypedValue.COMPLEX_UNIT_SP, 55);
views.setTextViewTextSize(R.id.widgetArrow, TypedValue.COMPLEX_UNIT_SP, 37);

}


if (timeAgo == 1) {
views.setTextViewText(R.id.readingAge, timeAgo + " Minute ago" + raw_string);
} else {
views.setTextViewText(R.id.readingAge, timeAgo + " Minutes ago" + raw_string);
}
}
if (timeAgo > 15) {
views.setTextColor(R.id.readingAge, Color.parseColor("#FFBB33"));
Expand Down
30 changes: 24 additions & 6 deletions mobile/src/main/res/layout/nightwatch_widget_small.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,31 @@
</LinearLayout>

</LinearLayout>
<TextView
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="10sp"
android:text="-- minutes ago"
android:id="@+id/readingAge"
android:layout_gravity="center_horizontal"/>
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="30sp"
android:text="00:00"
android:id="@+id/widget_time"
android:visibility="gone"
android:layout_gravity="center_horizontal|left|top"
android:layout_marginTop="0dp"
android:paddingTop="0dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="10sp"
android:text="-- minutes ago"
android:id="@+id/readingAge"
android:layout_gravity="right"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
5 changes: 5 additions & 0 deletions mobile/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
android:title="Show RAW on Widget"
android:summary="Show three raw values on the widget."
android:defaultValue="false" />
<CheckBoxPreference
android:key="widget_show_time"
android:title="Show Time on Widget"
android:summary="Show Time on Widget (only on smaller widget that can be used to pass through to Samsung Gear watches)."
android:defaultValue="false" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit a5a3fb1

Please sign in to comment.