Enabled setting start button text programmatically

The start button was set through the string resource
lb_onboarding_get_started and could not be set dynamically. This CL
enables setting it to any custom string.

Bug: 37856834
Test: tested on an app which subclasses OnboardingFragment and sets
this text to a custom string in onCreate().

Change-Id: I49d309805cc21d42aa9cda808cbd1b8bd6c60396
(cherry picked from commit 60408831774854fa4b33dd70f72f7de0a58be885)
diff --git a/api/26.0.0-SNAPSHOT.txt b/api/26.0.0-SNAPSHOT.txt
index 8b9ee5a..e920fc1 100644
--- a/api/26.0.0-SNAPSHOT.txt
+++ b/api/26.0.0-SNAPSHOT.txt
@@ -3054,6 +3054,7 @@
     method protected abstract int getPageCount();
     method protected abstract java.lang.CharSequence getPageDescription(int);
     method protected abstract java.lang.CharSequence getPageTitle(int);
+    method public final java.lang.CharSequence getStartButtonText();
     method public final int getTitleViewTextColor();
     method protected final boolean isLogoAnimationFinished();
     method protected void moveToNextPage();
@@ -3074,6 +3075,7 @@
     method public void setDotBackgroundColor(int);
     method public final void setIconResouceId(int);
     method public final void setLogoResourceId(int);
+    method public void setStartButtonText(java.lang.CharSequence);
     method public void setTitleViewTextColor(int);
     method protected final void startEnterAnimation(boolean);
   }
@@ -3089,6 +3091,7 @@
     method protected abstract int getPageCount();
     method protected abstract java.lang.CharSequence getPageDescription(int);
     method protected abstract java.lang.CharSequence getPageTitle(int);
+    method public final java.lang.CharSequence getStartButtonText();
     method public final int getTitleViewTextColor();
     method protected final boolean isLogoAnimationFinished();
     method protected void moveToNextPage();
@@ -3109,6 +3112,7 @@
     method public void setDotBackgroundColor(int);
     method public final void setIconResouceId(int);
     method public final void setLogoResourceId(int);
+    method public void setStartButtonText(java.lang.CharSequence);
     method public void setTitleViewTextColor(int);
     method protected final void startEnterAnimation(boolean);
   }
diff --git a/v17/leanback/src/android/support/v17/leanback/app/OnboardingFragment.java b/v17/leanback/src/android/support/v17/leanback/app/OnboardingFragment.java
index 3305bd1..7879206 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/OnboardingFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/OnboardingFragment.java
@@ -43,6 +43,7 @@
 import android.view.ViewTreeObserver.OnPreDrawListener;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -196,20 +197,24 @@
     int mCurrentPageIndex;
 
     @ColorInt
-    int mTitleViewTextColor = Color.TRANSPARENT;
-    boolean mTitleViewTextColorSet;
+    private int mTitleViewTextColor = Color.TRANSPARENT;
+    private boolean mTitleViewTextColorSet;
 
     @ColorInt
-    int mDescriptionViewTextColor = Color.TRANSPARENT;
-    boolean mDescriptionViewTextColorSet;
+    private int mDescriptionViewTextColor = Color.TRANSPARENT;
+    private boolean mDescriptionViewTextColorSet;
 
     @ColorInt
-    int mDotBackgroundColor = Color.TRANSPARENT;
-    boolean mDotBackgroundColorSet;
+    private int mDotBackgroundColor = Color.TRANSPARENT;
+    private boolean mDotBackgroundColorSet;
 
     @ColorInt
-    int mArrowBackgroundColor = Color.TRANSPARENT;
-    boolean mArrowBackgroundColorSet;
+    private int mArrowBackgroundColor = Color.TRANSPARENT;
+    private boolean mArrowBackgroundColorSet;
+
+    private CharSequence mStartButtonText;
+    private boolean mStartButtonTextSet;
+
 
     private AnimatorSet mAnimator;
 
@@ -325,6 +330,9 @@
         if (mArrowBackgroundColorSet) {
             mPageIndicator.setDotBackgroundColor(mArrowBackgroundColor);
         }
+        if (mStartButtonTextSet) {
+            ((Button) mStartButton).setText(mStartButtonText);
+        }
         final Context context = FragmentUtil.getContext(this);
         if (sSlideDistance == 0) {
             sSlideDistance = (int) (SLIDE_DISTANCE * context.getResources()
@@ -466,6 +474,28 @@
     }
 
     /**
+     * Returns the start button text if it's set through
+     * {@link #setStartButtonText(CharSequence)}}. If no string was set, null is returned.
+     */
+    public final CharSequence getStartButtonText() {
+        return mStartButtonText;
+    }
+
+    /**
+     * Sets the text on the start button text. If not set, the default text set in
+     * {@link R.styleable#LeanbackOnboardingTheme_onboardingStartButtonStyle} will be used.
+     *
+     * @param text the start button text
+     */
+    public void setStartButtonText(CharSequence text) {
+        mStartButtonText = text;
+        mStartButtonTextSet = true;
+        if (mStartButton != null) {
+            ((Button) mStartButton).setText(mStartButtonText);
+        }
+    }
+
+    /**
      * Returns the theme used for styling the fragment. The default returns -1, indicating that the
      * host Activity's theme should be used.
      *
diff --git a/v17/leanback/src/android/support/v17/leanback/app/OnboardingSupportFragment.java b/v17/leanback/src/android/support/v17/leanback/app/OnboardingSupportFragment.java
index 0431c18..1ceac51 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/OnboardingSupportFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/OnboardingSupportFragment.java
@@ -46,6 +46,7 @@
 import android.view.ViewTreeObserver.OnPreDrawListener;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -199,20 +200,24 @@
     int mCurrentPageIndex;
 
     @ColorInt
-    int mTitleViewTextColor = Color.TRANSPARENT;
-    boolean mTitleViewTextColorSet;
+    private int mTitleViewTextColor = Color.TRANSPARENT;
+    private boolean mTitleViewTextColorSet;
 
     @ColorInt
-    int mDescriptionViewTextColor = Color.TRANSPARENT;
-    boolean mDescriptionViewTextColorSet;
+    private int mDescriptionViewTextColor = Color.TRANSPARENT;
+    private boolean mDescriptionViewTextColorSet;
 
     @ColorInt
-    int mDotBackgroundColor = Color.TRANSPARENT;
-    boolean mDotBackgroundColorSet;
+    private int mDotBackgroundColor = Color.TRANSPARENT;
+    private boolean mDotBackgroundColorSet;
 
     @ColorInt
-    int mArrowBackgroundColor = Color.TRANSPARENT;
-    boolean mArrowBackgroundColorSet;
+    private int mArrowBackgroundColor = Color.TRANSPARENT;
+    private boolean mArrowBackgroundColorSet;
+
+    private CharSequence mStartButtonText;
+    private boolean mStartButtonTextSet;
+
 
     private AnimatorSet mAnimator;
 
@@ -328,6 +333,9 @@
         if (mArrowBackgroundColorSet) {
             mPageIndicator.setDotBackgroundColor(mArrowBackgroundColor);
         }
+        if (mStartButtonTextSet) {
+            ((Button) mStartButton).setText(mStartButtonText);
+        }
         final Context context = getContext();
         if (sSlideDistance == 0) {
             sSlideDistance = (int) (SLIDE_DISTANCE * context.getResources()
@@ -469,6 +477,28 @@
     }
 
     /**
+     * Returns the start button text if it's set through
+     * {@link #setStartButtonText(CharSequence)}}. If no string was set, null is returned.
+     */
+    public final CharSequence getStartButtonText() {
+        return mStartButtonText;
+    }
+
+    /**
+     * Sets the text on the start button text. If not set, the default text set in
+     * {@link R.styleable#LeanbackOnboardingTheme_onboardingStartButtonStyle} will be used.
+     *
+     * @param text the start button text
+     */
+    public void setStartButtonText(CharSequence text) {
+        mStartButtonText = text;
+        mStartButtonTextSet = true;
+        if (mStartButton != null) {
+            ((Button) mStartButton).setText(mStartButtonText);
+        }
+    }
+
+    /**
      * Returns the theme used for styling the fragment. The default returns -1, indicating that the
      * host Activity's theme should be used.
      *