| java.lang.Object | ||
| ↳ | BaseButton | |
| ↳ | com.usebutton.sdk.DropinButton | |
This class is deprecated.
Button Actions has been deprecated. Please contact Button to update your integration.
This is the default UI class that you will have to drop into your layout XML to display a Button.
<com.usebutton.sdk.DropinButton
xmlns:button="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
button:btn_textColor="@color/white"
button:btn_textSize="18dp"
/>
You will have to prepare the button with some context, e.g. the location information for a start
or end location as shown in this example of an android.app.Activity#onCreate(Bundle). You
must then pass the context to an ActionRequest with your Button ID.
Once setup, you may use actions() to fetch a ButtonAction in
response to your request.
// Get the Button View
final DropinButton buttonDropin = (DropinButton) findViewById(R.id.main_dropin);
// Create an ActionQuery for the location you want a ride to. For this, let's assume a screen
// showing our office location in NYC
final ActionQuery query = ActionQuery.withSubjectLocation(new Location("Button HQ", 40.732561,-73.988068)));
final userLocation = new LocationProvider(this).getBestLocation();
if (userLocation != null) {
query.setUserLocation(new Location(userLocation));
}
else {
// Let's fallback to a set of coordinates here in NYC
query.setUserLocation(new Location(40.732561, -73.988068));
}
// Prepare the ActionRequest with the aforementioned ActionQuery
ActionRequest request = new ActionRequest("btn-abc123", query);
// Fetch the ButtonAction in response to our request
Button.actions().fetch(request, new ActionListener(){
@Override
public void onComplete(@Nullable ButtonAction action, @Nullable Throwable t) {
if(action == null) return;
buttonDropin.prepareWithAction(action);
}
}
final DropinButton buttonDropin = new DropinButton(context);
// 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);
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | TEXT_STYLE_LOWER | ||||||||||
| int | TEXT_STYLE_NORMAL | ||||||||||
| int | TEXT_STYLE_UPPER | ||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| DropinButton(Context context) | |||||||||||
| DropinButton(Context context, AttributeSet attrs) | |||||||||||
| DropinButton(Context context, AttributeSet attrs, int defStyleAttr) | |||||||||||
| DropinButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| void | prepareWithAction(ButtonAction action) | ||||||||||
| void |
setGravity_Button(int gravity)
Set gravity of content inside the button, see android.view.Gravity for supported
values.
| ||||||||||
| void |
setInteractionDisabled_Button(boolean disabled)
Call this with
true to disable any interaction on the DropinButton, this can be
relevant for e.g. | ||||||||||
| void | setMinimumHeight(int minHeight) | ||||||||||
| void | setMinimumWidth(int minWidth) | ||||||||||
| void |
setPaddingBottom_Button(int paddingPixels)
Set the bottom padding of the button in pixels.
| ||||||||||
| void |
setPaddingLeft_Button(int paddingPixels)
Set the left padding of the button in pixels.
| ||||||||||
| void |
setPaddingRight_Button(int paddingPixels)
Set the right padding of the button in pixels.
| ||||||||||
| void |
setPaddingTop_Button(int paddingPixels)
Set the top padding of the button in pixels.
| ||||||||||
| void |
setPadding_Button(int paddingPixels)
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. | ||||||||||
| void |
setStyle_Button(int textStyleFlags)
Will format the button text according to the flags passed, any combination of:
TEXT_STYLE_NORMAL (default), TEXT_STYLE_UPPER, TEXT_STYLE_LOWER. | ||||||||||
| void |
setTextColorStates_Button(ColorStateList textColorStates)
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.
| ||||||||||
| void |
setTextSize_Button(int textSizePixels)
Set the text size inside the button.
| ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
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 DropinButton, 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 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. |
|---|