onebusaway-android icon indicating copy to clipboard operation
onebusaway-android copied to clipboard

Add home screen widget that shows arrival information

Open barbeau opened this issue 9 years ago • 5 comments

Summary:

It would be nice to show arrival times for starred stops/routes right on your home screen in a widget.

Related iOS issue: https://github.com/OneBusAway/onebusaway-iphone/issues/322

Screenshots of home screen widgets of other transit apps on iOS: https://github.com/OneBusAway/onebusaway-iphone/issues/322#issuecomment-247826131

barbeau avatar Sep 20 '16 02:09 barbeau

Here's what OBA iOS looks like (from https://github.com/OneBusAway/onebusaway-iphone/releases/tag/v18.2):

image

barbeau avatar Sep 25 '18 17:09 barbeau

@amrhossamdev i would like to work on this issue , please assign it to me .

piyushs-05 avatar Apr 03 '25 01:04 piyushs-05

Can you write a technical plan first, try to include a code snippet, and explain your approach? @CyberFranky05

amrhossamdev avatar Apr 03 '25 12:04 amrhossamdev

@amrhossamdev let me code some simple widget and provide u technical plan with code snippets asap

piyushs-05 avatar Apr 04 '25 15:04 piyushs-05

@amrhossamdev here is the snippet and plan of action as u asked for

Below is a screenshot that shows a widget implementation for seeing list of starred stops ( for testing )

Image

and here is a snippet of code used in implementation of the widget .

@Override
        public RemoteViews getViewAt(int position) {
            // Return empty view if cursor or position is invalid
            if (mCursor == null || !mCursor.moveToPosition(position)) {
                return null;
            }
            
            // Create RemoteViews for list item
            RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_starred_stop_item);
            
            // Get stop ID and name from cursor
            String stopId = mCursor.getString(mCursor.getColumnIndex(ObaContract.Stops._ID));
            String stopName = mCursor.getString(mCursor.getColumnIndex(ObaContract.Stops.UI_NAME));
            
            // Set the text views
            rv.setTextViewText(R.id.widget_stop_name, stopName);
            rv.setTextViewText(R.id.widget_stop_id, stopId);
            
            // Create an intent to launch when this list item is clicked
            Bundle extras = new Bundle();
            extras.putString(MapParams.STOP_ID, stopId);
            extras.putString(MapParams.STOP_NAME, stopName);
            
            Intent fillInIntent = new Intent();
            fillInIntent.putExtras(extras);
            
            // Make the entire list item clickable
            rv.setOnClickFillInIntent(R.id.widget_starred_stop_item, fillInIntent);
            
            return rv;
        }

Action Plan: Bus Arrival Widgets

  1. Configuration Screens

    • Develop Ui : develop UI for stop and route in figma ( currently working on this )
    • Stop Widget Config: let user pick a starred stop
    • Route Widget Config: let user pick a starred route
  2. Layouts

    • Widget XMLs:
      • Stop view (header + list of upcoming arrivals)
      • Route view (header + list of next arrivals per stop)
    • Item XMLs: row templates for arrivals and route‑stop entries
  3. Data Services

    • RemoteViewsService + Factory:
      • Load starred IDs from local DB
      • Fetch fresh arrival data via OBA API
  4. Widget Providers

    • Wire up layouts → data service
    • Handle periodic & manual refresh
    • Respond to “star” changes via broadcasts
    • On‑tap: open detailed stop or map view
  5. Integration & Settings

    • Add widget preferences ( number of arrival per widget)
    • Broadcast favorites updates → trigger widget refresh
    • Use Work Manager for background updates
  6. Testing & Polish

    • Verify on various screen sizes & widget sizes
    • Ensure graceful offline behavior & error messaging
    • Optimize data calls and battery impact

let me know if i can start working on it or if any changes needed .

piyushs-05 avatar Apr 05 '25 21:04 piyushs-05