DropinButton | Button SDK for Android v7.0.0
DropinButton
This class is deprecated. Button Actions has been deprecated. Please contact Button to update your integration.
Class Overview
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);
}
});
Add a Button to your view with code.
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);
Summary
| Constants |
|---|
| int |
| int |
| int |
Public Constructors
public DropinButton(Context context)
public DropinButton(Context context, AttributeSet attrs)
public DropinButton(Context context, AttributeSet attrs, int defStyleAttr)
public DropinButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Public Methods
public void prepareWithAction(ButtonAction action)
public void setGravity_Button(int gravity)
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.
public void setInteractionDisabled_Button(boolean disabled)
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.
Parameters
| disabled | true to disable interaction |
public void setMinimumHeight(int minHeight)
public void setMinimumWidth(int minWidth)
public void setPaddingBottom_Button(int paddingPixels)
Set the bottom padding of the button in pixels.
Equivalent to using the button:btn_paddingBottom attribute in a XML layout.
Parameters
| paddingPixels | bottom padding in pixels. |
public void setPaddingLeft_Button(int paddingPixels)
Set the left padding of the button in pixels.
Equivalent to using the button:btn_paddingLeft attribute in a XML layout.
Parameters
| paddingPixels | left padding in pixels. |
public void setPaddingRight_Button(int paddingPixels)
Set the right padding of the button in pixels.
Equivalent to using the button:btn_paddingRight attribute in a XML layout.
Parameters
| paddingPixels | right padding in pixels. |
public void setPaddingTop_Button(int paddingPixels)
Set the top padding of the button in pixels.
Equivalent to using the button:btn_paddingTop attribute in a XML layout.
Parameters
| paddingPixels | top padding in pixels. |
public 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.
Equivalent to using the button:btn_padding attribute in a XML layout.
Parameters
| paddingPixels | padding in pixels, all four sides. |
public 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.
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.
Parameters
| textStyleFlags | representing the styling bitmask. |
public 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.
Equivalent to using the button:btn_textColor attribute in a XML layout.
Parameters
| textColorStates | ColorStateList object representing the text color for each state. |
public void setTextSize_Button(int textSizePixels)
Set the text size inside the button.
Equivalent to using the button:btn_textSize attribute in a XML layout.
Parameters
| textSizePixels | text size in pixels.