Skip to content

Commit

Permalink
Merge branch 'fix/pre_1.9.0_fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
SamAmco committed Jun 23, 2020
2 parents 01cf8f2 + db3842f commit 237368a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import android.view.View
import android.widget.RemoteViews
import androidx.core.content.ContextCompat
import com.samco.trackandgraph.R
Expand Down Expand Up @@ -79,7 +80,7 @@ class TrackWidgetProvider : AppWidgetProvider() {
}
}

setWidgetDrawable(context, disable, requireInput, remoteViews)
setWidgetDrawable(disable, requireInput, remoteViews)

return remoteViews
}
Expand All @@ -105,32 +106,25 @@ class TrackWidgetProvider : AppWidgetProvider() {
* Pre-Lollipop, construct a bitmap for the drawable.
*/
private fun setWidgetDrawable(
context: Context,
disable: Boolean,
requireInput: Boolean?,
remoteViews: RemoteViews
) {
val drawable = when {
disable -> R.drawable.warning_icon
requireInput == false -> R.drawable.add_box_tint
else -> R.drawable.add_box
}

// Vector graphics in appwidgets need to be programmatically added.
// Pre-Lollipop, these vectors need to be converted to a bitmap first.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
remoteViews.setImageViewResource(R.id.track_widget_icon, drawable)
} else {
ContextCompat.getDrawable(context, drawable)?.let { drawable ->
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
remoteViews.setImageViewBitmap(R.id.track_widget_icon, bitmap)
when {
disable -> {
remoteViews.setViewVisibility(R.id.track_widget_icon_warning, View.VISIBLE)
remoteViews.setViewVisibility(R.id.track_widget_icon_default, View.INVISIBLE)
remoteViews.setViewVisibility(R.id.track_widget_icon, View.INVISIBLE)
}
requireInput == false -> {
remoteViews.setViewVisibility(R.id.track_widget_icon_warning, View.INVISIBLE)
remoteViews.setViewVisibility(R.id.track_widget_icon_default, View.VISIBLE)
remoteViews.setViewVisibility(R.id.track_widget_icon, View.INVISIBLE)
}
else -> {
remoteViews.setViewVisibility(R.id.track_widget_icon_warning, View.INVISIBLE)
remoteViews.setViewVisibility(R.id.track_widget_icon_default, View.INVISIBLE)
remoteViews.setViewVisibility(R.id.track_widget_icon, View.VISIBLE)
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/add_box_tint.xml

This file was deleted.

29 changes: 25 additions & 4 deletions app/src/main/res/layout/track_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
android:clickable="true"
android:focusable="true">

<!--TODO can we apply dark theme to widgets?-->
<TextView
android:id="@+id/track_widget_title"
android:layout_width="match_parent"
Expand All @@ -32,8 +31,6 @@
android:textStyle="bold"
tools:text="Track" />

<!--No tint here since this image is replaced at runtime
if the tint should be different-->
<ImageView
android:id="@+id/track_widget_icon"
android:layout_width="40dp"
Expand All @@ -43,6 +40,30 @@
android:layout_marginTop="@dimen/card_margin_small"
android:layout_marginEnd="@dimen/card_margin_small"
android:layout_marginBottom="@dimen/card_margin_small"
tools:src="@drawable/add_box" />
android:tint="?attr/colorControlNormal"
android:src="@drawable/add_box" />

<ImageView
android:id="@+id/track_widget_icon_default"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/card_margin_small"
android:layout_marginEnd="@dimen/card_margin_small"
android:layout_marginBottom="@dimen/card_margin_small"
android:tint="?attr/colorPrimary"
android:src="@drawable/add_box" />

<ImageView
android:id="@+id/track_widget_icon_warning"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/card_margin_small"
android:layout_marginEnd="@dimen/card_margin_small"
android:layout_marginBottom="@dimen/card_margin_small"
android:src="@drawable/warning_icon" />
</RelativeLayout>
</FrameLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@
<string name="faq_text_5_12">We can fix this using plot totals. For example if we plot monthly totals we would see the following graph:</string>
<string name="faq_text_5_13">Notice a point is plotted at the end of each month representing the total of all tracked values in that month.</string>
<string name="faq_text_5_14">You can use scale, offset, averaging and totals all at once. The order of precedence is as follows:</string>
<string name="faq_text_5_15">• First your data is converted to totals\n• Then each point is converted to its moving average\n• Then your points are multiplied by the scale value\n• Finally the offset is added to each point</string>
<string name="faq_text_6_1">Notes allow you to keep track of qualitative data alongside your quantitative data. There are two types of notes:\n\n• Global notes (added directly in the notes menu)\n• Data point notes (attached to specific data points)\n\nWhen adding a data point you may wish to track an important piece of information specific to that data set. For example:</string>
<string name="faq_text_5_15">• First your data is converted to totals\n\n• Then each point is converted to its moving average\n\n• Then your points are multiplied by the scale value\n\n• Finally the offset is added to each point</string>
<string name="faq_text_6_1">Notes allow you to keep track of qualitative data alongside your quantitative data. There are two types of notes:\n\n• Global notes (added directly in the notes menu)\n\n• Data point notes (attached to specific data points)\n\nWhen adding a data point you may wish to track an important piece of information specific to that data set. For example:</string>
<string name="faq_text_6_2">After adding this note you will notice it shows up in a list underneath any graph of that data set. If you tap the note it will open in a dialog window and a marker will be added to the graph.</string>
<string name="faq_text_6_3">However some pieces of information might be relevant to all your data. In this case you can add a global note by tapping the plus button in the global notes menu:</string>
<string name="faq_text_6_4">You will notice this note now shows up underneath all graphs.</string>
Expand Down

0 comments on commit 237368a

Please sign in to comment.