java.lang.Object | ||
↳ | BaseEntity | |
↳ | com.usebutton.sdk.ButtonContext |
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);
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);
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add an item to the context, for example the items of a shopping cart or ingredients of
a recipe.
| |||||||||||
This method will create a new instance of context, creating a deep copy of all values.
| |||||||||||
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.
| |||||||||||
Sets the time and date for the information represented on screen - the time of a reservation,
date of a hotel reservation or similar.
| |||||||||||
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.
| |||||||||||
Sets an event to this context, an example would be a calendar reminder representing a
location and start & end time.
| |||||||||||
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.
| |||||||||||
Sets the physical location represented by the current screen, this can have coordinates,
a structured address or simply just a name.
| |||||||||||
Sets a URL as context, we can use this to enrich the context with more information
from the provided URL.
| |||||||||||
The current location of the user.
| |||||||||||
Creates a new ButtonContext instance and calls
setArtist(MusicArtist) . | |||||||||||
Creates a new ButtonContext instance and calls
setDate(Date) . | |||||||||||
Creates a new ButtonContext instance and calls
setDateRange(Date, Date) . | |||||||||||
Creates a new ButtonContext instance and calls
setEvent(Event) . | |||||||||||
Creates a new ButtonContext instance and calls
setJourney(Journey) . | |||||||||||
Creates a new ButtonContext instance and calls
setSubjectLocation(Location) . | |||||||||||
Creates a new ButtonContext instance and calls
setUserLocation(Location) . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Add an item to the context, for example the items of a shopping cart or ingredients of a recipe.
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.
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.
Sets the time and date for the information represented on screen - the time of a reservation, date of a hotel reservation or similar.
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.
Sets an event to this context, an example would be a calendar reminder representing a location and start & end time.
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.
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.
Sets a URL as context, we can use this to enrich the context with more information from the provided URL.
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.
Creates a new ButtonContext instance and calls setArtist(MusicArtist)
.
Creates a new ButtonContext instance and calls setDate(Date)
.
Creates a new ButtonContext instance and calls setDateRange(Date, Date)
.
Creates a new ButtonContext instance and calls setEvent(Event)
.
Creates a new ButtonContext instance and calls setJourney(Journey)
.
Creates a new ButtonContext instance and calls setSubjectLocation(Location)
.
Creates a new ButtonContext instance and calls setUserLocation(Location)
.