Merge pull request #475 from httpdispatch/master

Parent project update
This commit is contained in:
Patrick Santana 2014-03-16 10:39:11 -07:00
commit 667957bcde
4 changed files with 102 additions and 16 deletions

View file

@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trovebox.android.app" package="com.trovebox.android.app"
android:installLocation="auto" android:installLocation="auto"
android:versionCode="15" android:versionCode="16"
android:versionName="2.4" > android:versionName="2.5" >
<uses-sdk <uses-sdk
android:minSdkVersion="7" android:minSdkVersion="7"

View file

@ -288,7 +288,7 @@ public class TroveboxApi extends ApiBase implements ITroveboxApi {
IOException, IllegalStateException, IOException, IllegalStateException,
JSONException JSONException
{ {
return getPhotos(null, null, null, null, hash, null, null); return getPhotos(null, null, null, null, hash, null, null, null);
} }
@Override @Override

View file

@ -67,6 +67,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
private OnItemClickListener mOnItemClicked; private OnItemClickListener mOnItemClicked;
private OnItemLongClickListener mOnItemLongClicked; private OnItemLongClickListener mOnItemLongClicked;
private OnDownListener mOnDownListener; private OnDownListener mOnDownListener;
private OnUpListener mOnUpListener;
private boolean mDataChanged = false; private boolean mDataChanged = false;
private Runnable mRunnable = new Runnable() { private Runnable mRunnable = new Runnable() {
@Override @Override
@ -110,6 +111,10 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
mOnDownListener = listener; mOnDownListener = listener;
} }
public void setOnUpListener(OnUpListener listener) {
mOnUpListener = listener;
}
private DataSetObserver mDataObserver = new DataSetObserver() { private DataSetObserver mDataObserver = new DataSetObserver() {
@Override @Override
@ -175,7 +180,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
} }
private void measureChild(final View child) { private void measureChild(final View child) {
child.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), child.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST)); MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
} }
@ -266,7 +271,8 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
"rightEdge = %1$d; childWidth = %2$d; rightViewIndex = %3$d" "rightEdge = %1$d; childWidth = %2$d; rightViewIndex = %3$d"
+ "; count = %4$d; prognosed max width = %5$d", + "; count = %4$d; prognosed max width = %5$d",
rightEdge, child.getMeasuredWidth(), mRightViewIndex, rightEdge, child.getMeasuredWidth(), mRightViewIndex,
mAdapter.getCount(), child.getMeasuredWidth() * mAdapter.getCount() - getWidth()); mAdapter.getCount(), child.getMeasuredWidth() * mAdapter.getCount()
- getWidth());
if (mRightViewIndex == mAdapter.getCount() - 1) { if (mRightViewIndex == mAdapter.getCount() - 1) {
mMaxX = mCurrentX + rightEdge - getWidth(); mMaxX = mCurrentX + rightEdge - getWidth();
@ -293,16 +299,20 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
int totalWidth = 0; int totalWidth = 0;
Queue<View> viewQueue = new LinkedList<View>(); Queue<View> viewQueue = new LinkedList<View>();
while (leftEdge + dx > 0 && mLeftViewIndex >= 0) { while (leftEdge + dx > 0 && mLeftViewIndex >= 0) {
CommonUtils.verbose(TAG, "mRemovedViewQueue.size = %1$d", mRemovedViewQueue.size()); CommonUtils.verbose(TAG, "fillListLeft: mRemovedViewQueue.size = %1$d",
mRemovedViewQueue.size());
View child = mAdapter.getView(mLeftViewIndex, mRemovedViewQueue.poll(), this); View child = mAdapter.getView(mLeftViewIndex, mRemovedViewQueue.poll(), this);
measureChild(child); measureChild(child);
viewQueue.offer(child); viewQueue.offer(child);
int childWidth = child.getMeasuredWidth(); int childWidth = child.getMeasuredWidth();
leftEdge -= childWidth; leftEdge -= childWidth;
totalWidth += childWidth; totalWidth += childWidth;
totalWidth = removeNonVisibleItemsFromRight(totalWidth, getWidth(), viewQueue); totalWidth = removeNonVisibleItemsFromRight(totalWidth, getWidth() + childWidth,
viewQueue);
mLeftViewIndex--; mLeftViewIndex--;
mDisplayOffset -= child.getMeasuredWidth(); mDisplayOffset -= child.getMeasuredWidth();
CommonUtils.verbose(TAG, "fillListLeft: mLeftViewIndex = %1$d; mDisplayOffset = %2$d",
mLeftViewIndex, mDisplayOffset);
} }
View child; View child;
while ((child = viewQueue.poll()) != null) while ((child = viewQueue.poll()) != null)
@ -345,7 +355,9 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
while (child != null) { while (child != null) {
int childWidth = child.getMeasuredWidth(); int childWidth = child.getMeasuredWidth();
CommonUtils CommonUtils
.verbose(TAG, "totalWidth = %1$d, childWidth = %2$d", totalWidth, childWidth); .verbose(TAG,
"removeNonVisibleItemsFromLeft: totalWidth = %1$d, childWidth = %2$d",
totalWidth, childWidth);
if (totalWidth - childWidth < minRestWidth) if (totalWidth - childWidth < minRestWidth)
{ {
break; break;
@ -357,7 +369,10 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
mLeftViewIndex++; mLeftViewIndex++;
child = viewQueue.peek(); child = viewQueue.peek();
} }
CommonUtils.verbose(TAG, "mDisplayOffset = %1$d; totalWidth = %2$d; mLeftViewIndex = %3$d", CommonUtils
.verbose(
TAG,
"removeNonVisibleItemsFromLeft: mDisplayOffset = %1$d; totalWidth = %2$d; mLeftViewIndex = %3$d",
mDisplayOffset, mDisplayOffset,
totalWidth, mLeftViewIndex); totalWidth, mLeftViewIndex);
return totalWidth; return totalWidth;
@ -406,6 +421,26 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
} }
} }
public int getScrollOffsetForIndex(int index)
{
Queue<View> viewQueue = new LinkedList<View>();
int i = 0;
int result = 0;
while (i < index && i < mAdapter.getCount()) {
CommonUtils.verbose(TAG, "mRemovedViewQueue.size = %1$d", mRemovedViewQueue.size());
View child = mAdapter.getView(mRightViewIndex, viewQueue.poll(), this);
measureChild(child);
viewQueue.offer(child);
result += child.getMeasuredWidth();
i++;
}
return result;
}
public void scrollToIndex(int index) {
scrollTo(getScrollOffsetForIndex(index));
}
public synchronized void scrollTo(int x) { public synchronized void scrollTo(int x) {
CommonUtils.verbose(TAG, "Requested scroll from x = %1$d to x = %2$d", mNextX, x); CommonUtils.verbose(TAG, "Requested scroll from x = %1$d to x = %2$d", mNextX, x);
mScroller.startScroll(mNextX, 0, x - mNextX, 0); mScroller.startScroll(mNextX, 0, x - mNextX, 0);
@ -416,10 +451,38 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
{ {
return mNextX; return mNextX;
} }
public int getMaxX() {
return mMaxX;
}
float mInitialX;
float mInitialY;
boolean mIsMoving;
@Override @Override
public boolean dispatchTouchEvent(MotionEvent ev) { public boolean dispatchTouchEvent(MotionEvent ev) {
boolean handled = super.dispatchTouchEvent(ev); // experimental update to avoid view flickers and onclick events fired
handled |= mGesture.onTouchEvent(ev); // after move
boolean handled = mGesture.onTouchEvent(ev);
switch (ev.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mInitialX = ev.getX();
mInitialY = ev.getY();
mIsMoving = false;
break;
case MotionEvent.ACTION_MOVE: {
final float deltaX = Math.abs(ev.getX() - mInitialX);
final float deltaY = Math.abs(ev.getY() - mInitialY);
mIsMoving = deltaX > 5 || deltaY > 5;
}
break;
case MotionEvent.ACTION_UP:
onUp(ev);
break;
}
if (!mIsMoving) {
handled |= super.dispatchTouchEvent(ev);
}
return handled; return handled;
} }
@ -442,6 +505,13 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
return true; return true;
} }
protected boolean onUp(MotionEvent e) {
if (mOnUpListener != null) {
mOnUpListener.onUp(e);
}
return true;
}
private OnGestureListener mOnGesture = new GestureDetector.SimpleOnGestureListener() { private OnGestureListener mOnGesture = new GestureDetector.SimpleOnGestureListener() {
@Override @Override
@ -522,4 +592,20 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
{ {
void onDown(MotionEvent e); void onDown(MotionEvent e);
} }
public static interface OnUpListener {
void onUp(MotionEvent e);
}
public int getRightViewIndex() {
return mRightViewIndex;
}
public int getLeftViewIndex() {
return mLeftViewIndex;
}
public boolean isMoving() {
return mIsMoving;
}
} }

View file

@ -46,7 +46,7 @@ public class TrackerUtils {
} }
/** /**
* Setup uncaug exception handler * Setup uncaught exception handler
*/ */
public static void setupTrackerUncaughtExceptionHandler() { public static void setupTrackerUncaughtExceptionHandler() {
EasyTracker.getInstance().setContext(CommonConfigurationUtils.getApplicationContext()); EasyTracker.getInstance().setContext(CommonConfigurationUtils.getApplicationContext());