Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions devsmartlib/src/com/devsmart/android/ui/HorizontalListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public HorizontalListView(Context context, AttributeSet attrs) {
initView();
}

private synchronized void initView() {
private void initView() {
mLeftViewIndex = -1;
mRightViewIndex = 0;
mDisplayOffset = 0;
Expand All @@ -92,22 +92,20 @@ public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener liste
mOnItemLongClicked = listener;
}

private DataSetObserver mDataObserver = new DataSetObserver() {
private final DataSetObserver mDataObserver = new DataSetObserver() {

@Override
public void onChanged() {
synchronized(HorizontalListView.this){
mDataChanged = true;
}
invalidate();
requestLayout();
}

@Override
public void onInvalidated() {
reset();
invalidate();
requestLayout();
}

};
Expand All @@ -133,10 +131,10 @@ public void setAdapter(ListAdapter adapter) {
reset();
}

private synchronized void reset(){
private void reset(){
initView();
removeAllViewsInLayout();
requestLayout();
invalidate();
}

@Override
Expand All @@ -147,7 +145,7 @@ public void setSelection(int position) {
private void addAndMeasureChild(final View child, int viewPos) {
LayoutParams params = child.getLayoutParams();
if(params == null) {
params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}

addViewInLayout(child, viewPos, params, true);
Expand All @@ -158,9 +156,7 @@ private void addAndMeasureChild(final View child, int viewPos) {


@Override
protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);

public void computeScroll() {
if(mAdapter == null){
return;
}
Expand All @@ -176,6 +172,8 @@ protected synchronized void onLayout(boolean changed, int left, int top, int rig
if(mScroller.computeScrollOffset()){
int scrollx = mScroller.getCurrX();
mNextX = scrollx;

postInvalidate();
}

if(mNextX <= 0){
Expand All @@ -194,17 +192,15 @@ protected synchronized void onLayout(boolean changed, int left, int top, int rig
positionItems(dx);

mCurrentX = mNextX;

if(!mScroller.isFinished()){
post(new Runnable(){
@Override
public void run() {
requestLayout();
}
});

}
}

// @Override
// protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
// super.onLayout(changed, left, top, right, bottom);
//
//
//
// }

private void fillList(final int dx) {
int edge = 0;
Expand Down Expand Up @@ -286,10 +282,10 @@ private void positionItems(final int dx) {
}
}

public synchronized void scrollTo(int x) {
mScroller.startScroll(mNextX, 0, x - mNextX, 0);
requestLayout();
}
// public void scrollTo(int x) {
// mScroller.startScroll(mNextX, 0, x - mNextX, 0);
// invalidate();
// }

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Expand All @@ -303,7 +299,7 @@ protected boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
synchronized(HorizontalListView.this){
mScroller.fling(mNextX, 0, (int)-velocityX, 0, 0, mMaxX, 0, 0);
}
requestLayout();
invalidate();

return true;
}
Expand Down Expand Up @@ -333,7 +329,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2,
synchronized(HorizontalListView.this){
mNextX += (int)distanceX;
}
requestLayout();
invalidate();

return true;
}
Expand Down