fix fastscroller's crash

This commit is contained in:
houzh 2023-09-21 16:22:58 +08:00
parent 0f643ae309
commit 2175400906
3 changed files with 12 additions and 9 deletions

View File

@ -525,10 +525,10 @@
<item name="backgroundRight">?attr/fastScrollPreviewBackgroundRight</item>
<item name="position">?attr/fastScrollOverlayPosition</item>
<item name="textColor">?attr/fastScrollTextColor</item>
<item name="thumbMinWidth">64dp</item>
<item name="thumbMinWidth">16dp</item>
<item name="thumbMinHeight">52dp</item>
<item name="textSize">52sp</item>
<item name="minWidth">72dp</item>
<item name="minWidth">16dp</item>
<item name="minHeight">72dp</item>
<item name="padding">16dp</item>
</style>

View File

@ -25,8 +25,11 @@ FastScroller::FastScroller(AbsListView*listView,const std::string& styleResId){
mScrollCompleted = true;
mState = STATE_VISIBLE;
mMatchDragPosition =true;// context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB;
mCurrentSection =-1;
mScrollbarPosition=-1;
AttributeSet atts;
atts.setContext(listView->getContext(),"");
mTrackImage = new ImageView(context,atts);
mTrackImage->setScaleType(ScaleType::FIT_XY);
mThumbImage = new ImageView(context,atts);
@ -37,7 +40,7 @@ FastScroller::FastScroller(AbsListView*listView,const std::string& styleResId){
mPrimaryText = createPreviewTextView(context);
mSecondaryText = createPreviewTextView(context);
mMinimumTouchTarget = 20;//listView.getResources().getDimensionPixelSize(
mMinimumTouchTarget = 16;//listView.getResources().getDimensionPixelSize(
//com.android.internal.R.dimen.fast_scroller_minimum_touch_target);
setStyle(styleResId);
@ -249,7 +252,7 @@ void FastScroller::updateLongList(int childCount, int itemCount) {
TextView* FastScroller::createPreviewTextView(Context* context) {
LayoutParams* params = new LayoutParams( LayoutParams::WRAP_CONTENT, LayoutParams::WRAP_CONTENT);
AttributeSet atts;
AttributeSet atts(context,"");
TextView* textView = new TextView(context,atts);
textView->setLayoutParams(params);
textView->setSingleLine(true);
@ -604,8 +607,8 @@ void FastScroller::getSectionsFromIndexer() {
adapter = ((HeaderViewListAdapter*) adapter)->getWrappedAdapter();
}
/*if (adapter instanceof ExpandableListConnector) {
ExpandableListAdapter expAdapter = ((ExpandableListConnector) adapter)
/*if (dynamic_cast<ExpandableListConnector*>(adapter)){
ExpandableListAdapter* expAdapter = ((ExpandableListConnector*) adapter)
.getAdapter();
if (expAdapter instanceof SectionIndexer) {
mSectionIndexer = (SectionIndexer) expAdapter;
@ -1140,7 +1143,7 @@ bool FastScroller::isPointInsideY(float y) {
// Apply the minimum touch target size.
float targetSizeDiff = mMinimumTouchTarget - (bottom - top);
float adjust = targetSizeDiff > 0 ? targetSizeDiff / 2 : 0;
float adjust = targetSizeDiff > 0 ? targetSizeDiff / 2.f : 0;
return y >= (top - adjust) && y <= (bottom + adjust);
}

View File

@ -121,10 +121,10 @@ private:
int mHeaderCount;
/** The index of the current section. */
int mCurrentSection = -1;
int mCurrentSection;
/** The current scrollbar position. */
int mScrollbarPosition = -1;
int mScrollbarPosition;
/** Whether the list is long enough to need a fast scroller. */
bool mLongList;