This repository has been archived by the owner on Mar 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '40378d0bf850b47af047322aa93b60cb7d138ae0' into HEAD
- Loading branch information
Showing
5 changed files
with
105 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.apb.beacon.common; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AbsListView; | ||
import android.widget.ListAdapter; | ||
import android.widget.ListView; | ||
|
||
/** | ||
* Created by aoe on 4/27/14. | ||
*/ | ||
|
||
public class NestedListView extends ListView implements View.OnTouchListener, AbsListView.OnScrollListener { | ||
|
||
private int listViewTouchAction; | ||
private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 99; | ||
|
||
public NestedListView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
listViewTouchAction = -1; | ||
setOnScrollListener(this); | ||
setOnTouchListener(this); | ||
} | ||
|
||
@Override | ||
public void onScroll(AbsListView view, int firstVisibleItem, | ||
int visibleItemCount, int totalItemCount) { | ||
if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) { | ||
if (listViewTouchAction == MotionEvent.ACTION_MOVE) { | ||
scrollBy(0, -1); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onScrollStateChanged(AbsListView view, int scrollState) { | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
|
||
int newHeight = 0; | ||
final int heightMode = MeasureSpec.getMode(heightMeasureSpec); | ||
int heightSize = MeasureSpec.getSize(heightMeasureSpec); | ||
if (heightMode != MeasureSpec.EXACTLY) { | ||
ListAdapter listAdapter = getAdapter(); | ||
if (listAdapter != null && !listAdapter.isEmpty()) { | ||
int listPosition = 0; | ||
for (listPosition = 0; listPosition < listAdapter.getCount() | ||
&& listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) { | ||
View listItem = listAdapter.getView(listPosition, null, this); | ||
//now it will not throw a NPE if listItem is a ViewGroup instance | ||
if (listItem instanceof ViewGroup) { | ||
listItem.setLayoutParams(new LayoutParams( | ||
LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); | ||
} | ||
listItem.measure(widthMeasureSpec, heightMeasureSpec); | ||
newHeight += listItem.getMeasuredHeight(); | ||
} | ||
newHeight += getDividerHeight() * listPosition; | ||
} | ||
if ((heightMode == View.MeasureSpec.AT_MOST) && (newHeight > heightSize)) { | ||
if (newHeight > heightSize) { | ||
newHeight = heightSize; | ||
} | ||
} | ||
} else { | ||
newHeight = getMeasuredHeight(); | ||
} | ||
setMeasuredDimension(getMeasuredWidth(), newHeight); | ||
} | ||
|
||
@Override | ||
public boolean onTouch(View v, MotionEvent event) { | ||
if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) { | ||
if (listViewTouchAction == MotionEvent.ACTION_MOVE) { | ||
scrollBy(0, 1); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters