public class

ButtonDropin

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.usebutton.sdk.ButtonDropin

Class Overview

This is the only 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"
       />
 

Prepare Button with context.

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 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
      public void onPrepared(final boolean willDisplay) {
          // Toggle visibility of UI items here if necessary
      }
   });
 

Add a Button to your view with code.

     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);
 

Summary

Nested Classes
interface ButtonDropin.Listener  
Constants
int TEXT_STYLE_LOWER
int TEXT_STYLE_NORMAL
int TEXT_STYLE_UPPER
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ButtonDropin(Context context)
ButtonDropin(Context context, AttributeSet attrs)
ButtonDropin(Context context, AttributeSet attrs, int defStyleAttr)
ButtonDropin(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Public Methods
observable()
void prepareForDisplay(ButtonContext context, ButtonDropin.Listener listener)
This is where you prepare this ButtonDropin with a context so we can serve a highly customized button, depending on your use case.
void prepareForDisplay(ButtonContext context)
void refresh()
void setBackgroundColor_Button(int color)
Set the background of the button to be a solid color.
void setBackgroundDrawable_Button(Drawable drawable)
Set background for the button, you can use any Drawable object (9-patch, selector, solid color etc).
void setButtonId(String buttonId)
Set the button Id for this instance.
void setDrawablePadding_Button(int paddingPixels)
Padding around icon to surrounding text/button outline.
void setFont_Button(String font)
Set the button's font.
void setGravity_Button(int gravity)
Set gravity of content inside the button, see android.view.Gravity for supported values.
void setIconSize_Button(int iconSizePixels)
Set the icon's size, use this to adjust the size of the icon so it suits your designs.
void setListener(ButtonDropin.Listener listener)
Set a permanent listener to observe changes in visibility for this promotion.
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.
Protected Methods
void onAttachedToWindow()
void onDetachedFromWindow()
void onDraw(Canvas canvas)
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int TEXT_STYLE_LOWER

Constant Value: 1 (0x00000001)

public static final int TEXT_STYLE_NORMAL

Constant Value: 0 (0x00000000)

public static final int TEXT_STYLE_UPPER

Constant Value: 16 (0x00000010)

Public Constructors

public ButtonDropin (Context context)

public ButtonDropin (Context context, AttributeSet attrs)

public ButtonDropin (Context context, AttributeSet attrs, int defStyleAttr)

public ButtonDropin (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public Methods

public observable ()

public void prepareForDisplay (ButtonContext context, ButtonDropin.Listener listener)

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

Parameters
context the context used to customize your button, e.g. location information, see ButtonDropin
listener one time callback for this call,

public void prepareForDisplay (ButtonContext context)

public void refresh ()

public void setBackgroundColor_Button (int color)

Set the background of the button to be a solid color. Equivalent to using the button:btn_backgroundColor attribute in a XML layout.

Parameters
color integer representing the background color, see android.graphics.Color.

public void setBackgroundDrawable_Button (Drawable drawable)

Set background for the button, you can use any Drawable object (9-patch, selector, solid color etc). Equivalent to using the button:btn_backgroundDrawable attribute in a XML layout.

Parameters
drawable any drawable to be used as background.

public void setButtonId (String buttonId)

Set the button Id for this instance. Equivalent to using the button:btn_buttonId attribute in a XML layout.

public void setDrawablePadding_Button (int paddingPixels)

Padding around icon to surrounding text/button outline. Equivalent to using the button:btn_drawablePadding attribute in a XML layout.

Parameters
paddingPixels padding around icon in pixels, all four sides.

public void setFont_Button (String font)

Set the button's font. Equivalent to using the button:btn_font attribute in a XML layout.

Parameters
font name or relative path to font in /assets folder

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 setIconSize_Button (int iconSizePixels)

Set the icon's size, use this to adjust the size of the icon so it suits your designs. Set to 0 to hide the icon. Equivalent to using the button:iconSize attribute in a XML layout.

Parameters
iconSizePixels height/width constraint for icon in pixels.

public void setListener (ButtonDropin.Listener listener)

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

Parameters
listener will be called whenever a promotion change happens.

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, 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.

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.

Protected Methods

protected void onAttachedToWindow ()

protected void onDetachedFromWindow ()

protected void onDraw (Canvas canvas)