java.lang.Object | ||
↳ | BaseButton | |
↳ | com.usebutton.sdk.ButtonDropin |
This is the default UI class that you will have to drop into your layout XML to display a Button. It's
important that you set a button ID in your layout XML, like show below. You find or create your button ID
in the dashboard See Button
for full instructions on how to
initialize the SDK.
<com.usebutton.sdk.ButtonDropin
xmlns:button="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
button:btn_buttonId="your-button-id"
button:btn_textColor="@color/white"
button:btn_textSize="18dp"
/>
onCreate(Bundle)
// Get the Button View final ButtonDropin buttonDropin = (ButtonDropin) findViewById(R.id.main_dropin); // Create a PlacementContext for the location you want a ride to. For this, let's assume a screen // showing our office location in NYC final ButtonContext context = ButtonContext.withSubjectLocation(new Location("Button HQ", 40.732561,-73.988068))); final userLocation = new LocationProvider(this).getBestLocation(); if (userLocation != null) { context.setUserLocation(new Location(userLocation)); } else { // Let's fallback to a set of coordinates here in NYC context.setUserLocation(new Location(40.732561, -73.988068)); } // Prepare the Button for display with our context buttonDropin.prepareForDisplayWithContext(context); // OR: buttonDropin.prepareForDisplayWithContext(context, new ButtonDropin.Listener() { @Override void onPrepared(final boolean willDisplay) { // Toggle visibility of UI items here if necessary } @Override void onClick(final ButtonDropin dropin) { // You can put for example your own analytics tracking here } });
final ButtonDropin buttonDropin = new ButtonDropin(context);
// Important, you have to set the Button ID before calling any of the prepareForDisplay
methods.
buttonDropin.setButtonId("your-button-id");
// Let's do some styling
Resources res = context.getResources();
buttonDropin.setTextSize_Button(res.getDimensionPixelSize(R.dimen.my_text_size));
buttonDropin.setTextColor_Button(Color.RED);
// Remember to set some layout params if you add the button to a ViewGroup that requires this.
final LayoutParams layoutParams = new LayoutParams(MATCH_PARENT, res.getDimensionPixelSize(R.dimen.button_height));
buttonDropin.setLayoutParams(layoutParams);
someParentView.addView(buttonDropin);
// Prepare the Button for display with some context.
final ButtonContext context = ButtonContext.withSubjectLocation(new Location("Button HQ", 40.732561,-73.988068)));
final userLocation = new LocationProvider(this).getBestLocation();
if (userLocation != null) {
context.setUserLocation(new Location(userLocation));
}
buttonDropin.prepareForDisplayWithContext(context);
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ButtonDropin.Listener |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | TEXT_STYLE_LOWER | ||||||||||
int | TEXT_STYLE_NORMAL | ||||||||||
int | TEXT_STYLE_UPPER |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
Use
prepareWithAction(AppAction) instead. This method will be removed
in the next major version release.
This is where you prepare this ButtonDropin with a context so we can serve a highly customized
button, depending on your use case.
See setListener(Listener) on how to set a permanent listener for this dropin instance | |||||||||||
This method is deprecated.
Use
prepareWithAction(AppAction) instead. This method will be removed
in the next major version release.
See prepareForDisplay(ButtonContext, Listener) | |||||||||||
Set the button Id for this instance.
| |||||||||||
Set gravity of content inside the button, see android.view.Gravity for supported
values.
| |||||||||||
Call this with
true to disable any interaction on the ButtonDropin, this can be
relevant for e.g. | |||||||||||
Set a permanent listener to observe changes in visibility for this promotion.
| |||||||||||
Set the bottom padding of the button in pixels.
| |||||||||||
Set the left padding of the button in pixels.
| |||||||||||
Set the right padding of the button in pixels.
| |||||||||||
Set the top padding of the button in pixels.
| |||||||||||
Set the padding of the button in pixels, this will set the same padding on all four sides of
the button, for controlling the individual sides, see
setPaddingTop_Button(int) , setPaddingRight_Button(int) ,
setPaddingBottom_Button(int) , setPaddingRight_Button(int)
Equivalent to using the button:btn_padding attribute in a XML layout. | |||||||||||
Will format the button text according to the flags passed, any combination of:
TEXT_STYLE_NORMAL (default), TEXT_STYLE_UPPER , TEXT_STYLE_LOWER . | |||||||||||
Set text color of the button in the different states (normal, pressed etc), see ColorStateList
for more information on how to specify the color for each state.
| |||||||||||
Set the text size inside the button.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
This method is deprecated.
Use prepareWithAction(AppAction)
instead. This method will be removed
in the next major version release.
setListener(Listener)
on how to set a permanent listener for this dropin instance
context | the context used to customize your button, e.g. location information, see ButtonDropin |
---|---|
listener | one time callback for this call |
This method is deprecated.
Use prepareWithAction(AppAction)
instead. This method will be removed
in the next major version release.
prepareForDisplay(ButtonContext, Listener)
context | The Button context that should be used to fetch the app action. |
---|
Set the button Id for this instance. Equivalent to using the button:btn_buttonId
attribute in a XML layout.
Set gravity of content inside the button, see android.view.Gravity for supported
values.
Equivalent to using the button:btn_gravity
attribute in a XML layout.
Call this with true
to disable any interaction on the ButtonDropin, this can be
relevant for e.g. a preview of the Button where the user is not supposed to be able to click
it until a later screen.
disabled | true to disable interaction |
---|
Set a permanent listener to observe changes in visibility for this promotion. Can be used to e.g. enable/disable other UI elements. Set to null to unregister
listener | will be called whenever a promotion change happens. |
---|
Set the bottom padding of the button in pixels.
Equivalent to using the button:btn_paddingBottom
attribute in a XML layout.
paddingPixels | bottom padding in pixels. |
---|
Set the left padding of the button in pixels.
Equivalent to using the button:btn_paddingLeft
attribute in a XML layout.
paddingPixels | left padding in pixels. |
---|
Set the right padding of the button in pixels.
Equivalent to using the button:btn_paddingRight
attribute in a XML layout.
paddingPixels | right padding in pixels. |
---|
Set the top padding of the button in pixels.
Equivalent to using the button:btn_paddingTop
attribute in a XML layout.
paddingPixels | top padding in pixels. |
---|
Set the padding of the button in pixels, this will set the same padding on all four sides of
the button, for controlling the individual sides, see setPaddingTop_Button(int)
, setPaddingRight_Button(int)
,
setPaddingBottom_Button(int)
, setPaddingRight_Button(int)
Equivalent to using the button:btn_padding
attribute in a XML layout.
paddingPixels | padding in pixels, all four sides. |
---|
Will format the button text according to the flags passed, any combination of:
TEXT_STYLE_NORMAL
(default), TEXT_STYLE_UPPER
, TEXT_STYLE_LOWER
.
Currently no combination of these flags make sense, but in the future there might be
additional styling flags that can be combined.
Equivalent to using the button:btn_allCaps
attribute in a XML layout.
textStyleFlags | representing the styling bitmask. |
---|
Set text color of the button in the different states (normal, pressed etc), see ColorStateList
for more information on how to specify the color for each state.
Equivalent to using the button:btn_textColor
attribute in a XML layout.
textColorStates | ColorStateList object representing the text color for each state. |
---|
Set the text size inside the button.
Equivalent to using the button:btn_textSize
attribute in a XML layout.
textSizePixels | text size in pixels. |
---|