Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@
android:resource="@xml/widget_dual_info" />
</receiver>

<!-- One-tap meal photo: opens the camera for AI analysis (SnapMealWidget). -->
<receiver
android:name=".widgets.SnapMealWidget"
android:exported="true"
android:label="@string/widget_snap_meal_label">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_snap_meal_info" />
</receiver>

<activity
android:name=".widgets.WidgetConfigActivity"
android:exported="true"
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/com/pulseloop/widgets/SnapMealWidget.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.pulseloop.widgets

import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.widget.RemoteViews
import com.pulseloop.MainActivity
import com.pulseloop.R

/**
* A single-button home-screen widget: tap it and the camera opens to photograph a meal for AI
* analysis, the same path as the "Log meal" icon shortcut (MainActivity.ACTION_LOG_MEAL →
* Nutrition, photo flow). Plain RemoteViews rather than Glance: it shows no data, so there is
* nothing to refresh.
*/
class SnapMealWidget : AppWidgetProvider() {

override fun onUpdate(context: Context, manager: AppWidgetManager, ids: IntArray) {
val intent = Intent(context, MainActivity::class.java)
.setAction(MainActivity.ACTION_LOG_MEAL)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pending = PendingIntent.getActivity(
context, REQUEST_CODE, intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
)
val views = RemoteViews(context.packageName, R.layout.widget_snap_meal).apply {
setOnClickPendingIntent(R.id.snap_meal_root, pending)
}
ids.forEach { manager.updateAppWidget(it, views) }
}

private companion object {
const val REQUEST_CODE = 4101
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/ic_widget_camera.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Material "photo camera" glyph in mint. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:fillColor="#43F3B7" android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
<path android:fillColor="#43F3B7" android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/widget_snap_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Snap-meal widget ground: GMind ink with the mint frame. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#17161A" />
<stroke android:width="2dp" android:color="#43F3B7" />
<corners android:radius="8dp" />
</shape>
28 changes: 28 additions & 0 deletions app/src/main/res/layout/widget_snap_meal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- One-tap "snap a meal" widget: opens the camera for AI meal analysis. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/snap_meal_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/widget_snap_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="6dp">

<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:contentDescription="@string/widget_snap_meal_label"
android:src="@drawable/ic_widget_camera" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="monospace"
android:textStyle="bold"
android:maxLines="1"
android:text="@string/widget_snap_meal_short"
android:textColor="#F2F2F2"
android:textSize="12sp" />
</LinearLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<string name="widget_metric_description">A Today tile of your choice — activity, sleep, heart rate, and more.</string>
<string name="widget_dual_label">Two Metric Tiles</string>
<string name="widget_dual_description">Two Today tiles side by side, each configurable.</string>
<string name="widget_snap_meal_label">Snap a meal</string>
<string name="widget_snap_meal_short">Log meal</string>
<string name="widget_snap_meal_description">One tap opens the camera to log a meal with AI analysis.</string>
</resources>
13 changes: 13 additions & 0 deletions app/src/main/res/xml/widget_snap_meal_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Snap-meal widget: a single button, 1×1 cell. -->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:targetCellWidth="1"
android:targetCellHeight="1"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget_snap_meal"
android:previewLayout="@layout/widget_snap_meal"
android:description="@string/widget_snap_meal_description"
android:widgetCategory="home_screen" />
Loading