public class

ButtonContext

extends BaseEntity
implements Parcelable
java.lang.Object
   ↳ BaseEntity
     ↳ com.usebutton.sdk.ButtonContext

Class Overview

This is the main class holding context information for the current screen of your application. Create an instance of this class and set relevant information representing the information presented to the user so the appropriate button can be created with as much information as possible. An instance of this class can be passed to willDisplayButton(String, ButtonContext, ButtonDropin.Listener) or prepareForDisplay(ButtonContext) to respectively see if a button will be displayed and to actually prepare the button.

Location Example context for a screen showing information about a restaurant where we want to provide the user with transportation methods from their location to the venue:

 final Location restaurant = new Location("Feast", 40.7325614, -73.988068);
 final ButtonContext context = ButtonContext.withSubjectLocation(restaurant);
 context.setUserLocation(new Location("Work", 40.7382869, -73.9823721));

 ButtonDropin button = (ButtonDropin) findViewById(R.id.button);
 button.prepareForDisplayWithContext(context);
 

Event Example context for a screen showing event information, for example a calendar event. This context information can in turn be used for e.g. on demand parking or nearby restaurants for when the show is over.
 final Event event = new Event("Concert at Madison Square Garden");
 event.setStart(new Date());
 event.setEnd(new Date(System.currentTimeMills() + 3*3600*1000));
 final Location msg = new Location("Madison Square Garden", 40.7505045,-73.9956274);
 event.setLocation(msg);
 

Summary

[Expand]
Inherited Constants
From interface android.os.Parcelable
Public Constructors
ButtonContext()
Public Methods
ButtonContext addItem(Item item)
Add an item to the context, for example the items of a shopping cart or ingredients of a recipe.
static ButtonContext deepCopy(ButtonContext context)
This method will create a new instance of context, creating a deep copy of all values.
ButtonContext setArtist(MusicArtist artist)
Sets an artist object represented by the current screen, for example for a streaming music player you would here set the artist for the track currently playing.
ButtonContext setDate(Date date)
Sets the time and date for the information represented on screen - the time of a reservation, date of a hotel reservation or similar.
ButtonContext setDateRange(Date startDate, Date endDate)
Sets the date range relevant to the current screen, for a concert this could be the start and end time of the concert or the start and end time for a calendar event.
ButtonContext setEvent(Event event)
Sets an event to this context, an example would be a calendar reminder representing a location and start & end time.
ButtonContext setJourney(Journey journey)
Sets a journey object to this context, this will represent for example a trip with a start & end location, travel method and start & end time.
ButtonContext setSubjectLocation(Location location)
Sets the physical location represented by the current screen, this can have coordinates, a structured address or simply just a name.
ButtonContext setUserLocation(Location location)
The current location of the user.
static ButtonContext withArtist(MusicArtist artist)
Creates a new ButtonContext instance and calls setArtist(MusicArtist).
static ButtonContext withDate(Date date)
Creates a new ButtonContext instance and calls setDate(Date).
static ButtonContext withDateRange(Date startDate, Date endDate)
Creates a new ButtonContext instance and calls setDateRange(Date, Date).
static ButtonContext withEvent(Event event)
Creates a new ButtonContext instance and calls setEvent(Event).
static ButtonContext withJourney(Journey journey)
Creates a new ButtonContext instance and calls setJourney(Journey).
static ButtonContext withSubjectLocation(Location location)
Creates a new ButtonContext instance and calls setSubjectLocation(Location).
static ButtonContext withUserLocation(Location location)
Creates a new ButtonContext instance and calls setUserLocation(Location).
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Public Constructors

public ButtonContext ()

Public Methods

public ButtonContext addItem (Item item)

Add an item to the context, for example the items of a shopping cart or ingredients of a recipe.

Returns
  • the same object for chaining calls.

public static ButtonContext deepCopy (ButtonContext context)

This method will create a new instance of context, creating a deep copy of all values. If context is null, null is returned. JSONObject doesn't have a good method to do a deep copy without going to json string and back, so this is not an ideal solution.

Returns
  • a deep copy of context or null.

public ButtonContext setArtist (MusicArtist artist)

Sets an artist object represented by the current screen, for example for a streaming music player you would here set the artist for the track currently playing.

Returns
  • the same object for chaining calls.

public ButtonContext setDate (Date date)

Sets the time and date for the information represented on screen - the time of a reservation, date of a hotel reservation or similar.

Returns
  • the same object for chaining calls.

public ButtonContext setDateRange (Date startDate, Date endDate)

Sets the date range relevant to the current screen, for a concert this could be the start and end time of the concert or the start and end time for a calendar event.

public ButtonContext setEvent (Event event)

Sets an event to this context, an example would be a calendar reminder representing a location and start & end time.

Returns
  • the same object for chaining calls.

public ButtonContext setJourney (Journey journey)

Sets a journey object to this context, this will represent for example a trip with a start & end location, travel method and start & end time.

Returns
  • the same object for chaining calls.

public ButtonContext setSubjectLocation (Location location)

Sets the physical location represented by the current screen, this can have coordinates, a structured address or simply just a name. An example for this would be a restaurant listing or a venue for an event.

Returns
  • the same object for chaining calls.

public ButtonContext setUserLocation (Location location)

The current location of the user. Provide whatever level of granularity makes sense for the context / that you have access to. You can use LocationProvider to quickly get the user's last location if you have the correct permissions declared.

Returns
  • the same object for chaining calls.

public static ButtonContext withArtist (MusicArtist artist)

Creates a new ButtonContext instance and calls setArtist(MusicArtist).

public static ButtonContext withDate (Date date)

Creates a new ButtonContext instance and calls setDate(Date).

public static ButtonContext withDateRange (Date startDate, Date endDate)

Creates a new ButtonContext instance and calls setDateRange(Date, Date).

public static ButtonContext withEvent (Event event)

Creates a new ButtonContext instance and calls setEvent(Event).

public static ButtonContext withJourney (Journey journey)

Creates a new ButtonContext instance and calls setJourney(Journey).

public static ButtonContext withSubjectLocation (Location location)

Creates a new ButtonContext instance and calls setSubjectLocation(Location).

public static ButtonContext withUserLocation (Location location)

Creates a new ButtonContext instance and calls setUserLocation(Location).