Added public API alternatives to reflective calls on ScrollBarDrawable
Added public setter/getter APIs on View to set/get the track/thumb Drawables for the vertical and horizontal scroll bars to support configuring scrollbars programmatically in addition to xml attributes Change-Id: Ic0b42742e8a795fe616887369dd0e592cde5c2fa Fixes: 123769505 Test: Added View.java test cases to verify new setter/getters
This commit is contained in:
@@ -50357,6 +50357,8 @@ package android.view {
|
||||
method public void getHitRect(android.graphics.Rect);
|
||||
method public int getHorizontalFadingEdgeLength();
|
||||
method protected int getHorizontalScrollbarHeight();
|
||||
method @Nullable public android.graphics.drawable.Drawable getHorizontalScrollbarThumbDrawable();
|
||||
method @Nullable public android.graphics.drawable.Drawable getHorizontalScrollbarTrackDrawable();
|
||||
method @android.view.ViewDebug.CapturedViewProperty @IdRes public int getId();
|
||||
method @android.view.ViewDebug.ExportedProperty(category="accessibility", mapping={@android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO, to="auto"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES, to="yes"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO, to="no"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, to="noHideDescendants")}) public int getImportantForAccessibility();
|
||||
method @android.view.ViewDebug.ExportedProperty(mapping={@android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_AUTOFILL_AUTO, to="auto"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_AUTOFILL_YES, to="yes"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_AUTOFILL_NO, to="no"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS, to="yesExcludeDescendants"), @android.view.ViewDebug.IntToString(from=android.view.View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS, to="noExcludeDescendants")}) public int getImportantForAutofill();
|
||||
@@ -50447,6 +50449,8 @@ package android.view {
|
||||
method public long getUniqueDrawingId();
|
||||
method public int getVerticalFadingEdgeLength();
|
||||
method public int getVerticalScrollbarPosition();
|
||||
method @Nullable public android.graphics.drawable.Drawable getVerticalScrollbarThumbDrawable();
|
||||
method @Nullable public android.graphics.drawable.Drawable getVerticalScrollbarTrackDrawable();
|
||||
method public int getVerticalScrollbarWidth();
|
||||
method public android.view.ViewTreeObserver getViewTreeObserver();
|
||||
method @android.view.ViewDebug.ExportedProperty(mapping={@android.view.ViewDebug.IntToString(from=android.view.View.VISIBLE, to="VISIBLE"), @android.view.ViewDebug.IntToString(from=android.view.View.INVISIBLE, to="INVISIBLE"), @android.view.ViewDebug.IntToString(from=android.view.View.GONE, to="GONE")}) public int getVisibility();
|
||||
@@ -50690,6 +50694,8 @@ package android.view {
|
||||
method public void setHasTransientState(boolean);
|
||||
method public void setHorizontalFadingEdgeEnabled(boolean);
|
||||
method public void setHorizontalScrollBarEnabled(boolean);
|
||||
method public void setHorizontalScrollbarThumbDrawable(@Nullable android.graphics.drawable.Drawable);
|
||||
method public void setHorizontalScrollbarTrackDrawable(@Nullable android.graphics.drawable.Drawable);
|
||||
method public void setHovered(boolean);
|
||||
method public void setId(@IdRes int);
|
||||
method public void setImportantForAccessibility(int);
|
||||
@@ -50779,6 +50785,8 @@ package android.view {
|
||||
method public void setVerticalFadingEdgeEnabled(boolean);
|
||||
method public void setVerticalScrollBarEnabled(boolean);
|
||||
method public void setVerticalScrollbarPosition(int);
|
||||
method public void setVerticalScrollbarThumbDrawable(@Nullable android.graphics.drawable.Drawable);
|
||||
method public void setVerticalScrollbarTrackDrawable(@Nullable android.graphics.drawable.Drawable);
|
||||
method public void setVisibility(int);
|
||||
method @Deprecated public void setWillNotCacheDrawing(boolean);
|
||||
method public void setWillNotDraw(boolean);
|
||||
|
||||
@@ -6440,6 +6440,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
arr.recycle();
|
||||
}
|
||||
|
||||
private void initializeScrollBarDrawable() {
|
||||
initScrollCache();
|
||||
|
||||
if (mScrollCache.scrollBar == null) {
|
||||
mScrollCache.scrollBar = new ScrollBarDrawable();
|
||||
mScrollCache.scrollBar.setState(getDrawableState());
|
||||
mScrollCache.scrollBar.setCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Initializes the scrollbars from a given set of styled attributes. This
|
||||
@@ -6525,6 +6535,106 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
resolvePadding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the vertical scrollbar thumb drawable
|
||||
* @attr ref android.R.styleable#View_scrollbarThumbVertical
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isVerticalScrollBarEnabled()
|
||||
* @see #setVerticalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public void setVerticalScrollbarThumbDrawable(@Nullable Drawable drawable) {
|
||||
initializeScrollBarDrawable();
|
||||
mScrollCache.scrollBar.setVerticalThumbDrawable(drawable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the vertical scrollbar track drawable
|
||||
* @attr ref android.R.styleable#View_scrollbarTrackVertical
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isVerticalScrollBarEnabled()
|
||||
* @see #setVerticalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public void setVerticalScrollbarTrackDrawable(@Nullable Drawable drawable) {
|
||||
initializeScrollBarDrawable();
|
||||
mScrollCache.scrollBar.setVerticalTrackDrawable(drawable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the horizontal thumb drawable
|
||||
* @attr ref android.R.styleable#View_scrollbarThumbHorizontal
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isHorizontalScrollBarEnabled()
|
||||
* @see #setHorizontalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public void setHorizontalScrollbarThumbDrawable(@Nullable Drawable drawable) {
|
||||
initializeScrollBarDrawable();
|
||||
mScrollCache.scrollBar.setHorizontalThumbDrawable(drawable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the horizontal track drawable
|
||||
* @attr ref android.R.styleable#View_scrollbarTrackHorizontal
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isHorizontalScrollBarEnabled()
|
||||
* @see #setHorizontalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public void setHorizontalScrollbarTrackDrawable(@Nullable Drawable drawable) {
|
||||
initializeScrollBarDrawable();
|
||||
mScrollCache.scrollBar.setHorizontalTrackDrawable(drawable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured Drawable for the thumb of the vertical scroll bar if it
|
||||
* exists, null otherwise.
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isVerticalScrollBarEnabled()
|
||||
* @see #setVerticalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public @Nullable Drawable getVerticalScrollbarThumbDrawable() {
|
||||
return mScrollCache != null ? mScrollCache.scrollBar.getVerticalThumbDrawable() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured Drawable for the track of the vertical scroll bar if it
|
||||
* exists, null otherwise.
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isVerticalScrollBarEnabled()
|
||||
* @see #setVerticalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public @Nullable Drawable getVerticalScrollbarTrackDrawable() {
|
||||
return mScrollCache != null ? mScrollCache.scrollBar.getVerticalTrackDrawable() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured Drawable for the thumb of the horizontal scroll bar if it
|
||||
* exists, null otherwise.
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isHorizontalScrollBarEnabled()
|
||||
* @see #setHorizontalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public @Nullable Drawable getHorizontalScrollbarThumbDrawable() {
|
||||
return mScrollCache != null ? mScrollCache.scrollBar.getHorizontalThumbDrawable() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured Drawable for the track of the horizontal scroll bar if it
|
||||
* exists, null otherwise.
|
||||
*
|
||||
* @see #awakenScrollBars(int)
|
||||
* @see #isHorizontalScrollBarEnabled()
|
||||
* @see #setHorizontalScrollBarEnabled(boolean)
|
||||
*/
|
||||
public @Nullable Drawable getHorizontalScrollbarTrackDrawable() {
|
||||
return mScrollCache != null ? mScrollCache.scrollBar.getHorizontalTrackDrawable() : null;
|
||||
}
|
||||
|
||||
private void initializeScrollIndicatorsInternal() {
|
||||
// Some day maybe we'll break this into top/left/start/etc. and let the
|
||||
// client control it. Until then, you can have any scroll indicator you
|
||||
|
||||
@@ -17,12 +17,15 @@
|
||||
package android.widget;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.widget.ScrollBarUtils;
|
||||
|
||||
@@ -36,7 +39,7 @@ import com.android.internal.widget.ScrollBarUtils;
|
||||
public class ScrollBarDrawable extends Drawable implements Drawable.Callback {
|
||||
private Drawable mVerticalTrack;
|
||||
private Drawable mHorizontalTrack;
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768422)
|
||||
private Drawable mVerticalThumb;
|
||||
private Drawable mHorizontalThumb;
|
||||
|
||||
@@ -226,7 +229,10 @@ public class ScrollBarDrawable extends Drawable implements Drawable.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
@UnsupportedAppUsage
|
||||
/**
|
||||
* @see android.view.View#setVerticalThumbDrawable(Drawable)
|
||||
*/
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
||||
public void setVerticalThumbDrawable(Drawable thumb) {
|
||||
if (mVerticalThumb != null) {
|
||||
mVerticalThumb.setCallback(null);
|
||||
@@ -236,6 +242,37 @@ public class ScrollBarDrawable extends Drawable implements Drawable.Callback {
|
||||
mVerticalThumb = thumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see View#getVerticalTrackDrawable()
|
||||
*/
|
||||
public @Nullable Drawable getVerticalTrackDrawable() {
|
||||
return mVerticalTrack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see View#getVerticalThumbDrawable()
|
||||
*/
|
||||
public @Nullable Drawable getVerticalThumbDrawable() {
|
||||
return mVerticalThumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see View#getHorizontalTrackDrawable()
|
||||
*/
|
||||
public @Nullable Drawable getHorizontalTrackDrawable() {
|
||||
return mHorizontalTrack;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see View#getHorizontalThumbDrawable()
|
||||
*/
|
||||
public @Nullable Drawable getHorizontalThumbDrawable() {
|
||||
return mHorizontalThumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see android.view.View#setVerticalTrackDrawable(Drawable)
|
||||
*/
|
||||
public void setVerticalTrackDrawable(Drawable track) {
|
||||
if (mVerticalTrack != null) {
|
||||
mVerticalTrack.setCallback(null);
|
||||
@@ -245,7 +282,10 @@ public class ScrollBarDrawable extends Drawable implements Drawable.Callback {
|
||||
mVerticalTrack = track;
|
||||
}
|
||||
|
||||
@UnsupportedAppUsage
|
||||
/**
|
||||
* @see android.view.View#setHorizontalThumbDrawable(Drawable)
|
||||
*/
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
||||
public void setHorizontalThumbDrawable(Drawable thumb) {
|
||||
if (mHorizontalThumb != null) {
|
||||
mHorizontalThumb.setCallback(null);
|
||||
|
||||
Reference in New Issue
Block a user