@Override
 public boolean onSingleTapConfirmed(MotionEvent e) {
   Rect viewRect = new Rect();
   for (int i = 0; i < getChildCount(); i++) {
     View child = getChildAt(i);
     int left = child.getLeft();
     int right = child.getRight();
     int top = child.getTop();
     int bottom = child.getBottom();
     viewRect.set(left, top, right, bottom);
     if (viewRect.contains((int) e.getX(), (int) e.getY())) {
       if (mOnItemClicked != null) {
         mOnItemClicked.onItemClick(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       if (mOnItemSelected != null) {
         mOnItemSelected.onItemSelected(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       break;
     }
   }
   return true;
 }
Ejemplo n.º 2
0
  public boolean onTestReceive(MotionEvent e) {

    if (e.getAction() == MotionEvent.ACTION_UP) {
      Rect viewRect = new Rect();
      for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        int left = child.getLeft();
        int right = child.getRight();
        int top = child.getTop() + this.getTop();
        int bottom = child.getBottom() + this.getBottom();
        int x = (int) e.getX();
        int y = (int) e.getY();
        viewRect.set(left, top, right, bottom);
        if (viewRect.contains(x, y)) {
          if (mOnItemClicked != null) {
            mOnItemClicked.onItemClick(
                HorizontalListView.this,
                child,
                mLeftViewIndex + 1 + i,
                mAdapter.getItemId(mLeftViewIndex + 1 + i));
          }
          if (mOnItemSelected != null) {
            mOnItemSelected.onItemSelected(
                HorizontalListView.this,
                child,
                mLeftViewIndex + 1 + i,
                mAdapter.getItemId(mLeftViewIndex + 1 + i));
          }
          break;
        }
      }
      return true;
    }
    return false;
  }
Ejemplo n.º 3
0
        @Override
        public void onLongPress(MotionEvent e) {
          Rect viewRect = new Rect();
          for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            int left = child.getLeft();
            int right = child.getRight();
            int top = child.getTop();
            int bottom = child.getBottom();
            viewRect.set(left, top, right, bottom);
            if (viewRect.contains((int) e.getX(), (int) e.getY())) {

              if (mOnItemLongClickListener != null) {
                mOnItemLongClickListener.onItemLongClick(
                    HorizontalListView.this,
                    child,
                    mLeftViewIndex + 1 + i,
                    mAdapter.getItemId(mLeftViewIndex + 1 + i));
              }
              if (mOnItemSelected != null) {
                mOnItemSelected.onItemSelected(
                    HorizontalListView.this,
                    child,
                    mLeftViewIndex + 1 + i,
                    mAdapter.getItemId(mLeftViewIndex + 1 + i));
              }
              break;
            }
          }
        }
  /**
   * Stores a reference to the views above and below the item currently corresponding to the hover
   * cell. It is important to note that if this item is either at the top or bottom of the list,
   * mAboveItemId or mBelowItemId may be invalid.
   */
  private void updateNeighborViewsForId(long itemId) {
    int position = getPositionForId(itemId);
    ListAdapter adapter = getAdapter();
    if (!adapter.hasStableIds()) {
      throw new IllegalStateException(
          "Adapter doesn't have stable ids! Make sure your adapter has stable ids, and override hasStableIds() to return true.");
    }

    mAboveItemId = position - 1 >= 0 ? adapter.getItemId(position - 1) : INVALID_ROW_ID;
    mBelowItemId =
        position + 1 < adapter.getCount() ? adapter.getItemId(position + 1) : INVALID_ROW_ID;
  }
Ejemplo n.º 5
0
 public void onClick(DialogInterface dialoginterface, int i) {
   a.setSelection(i);
   if (a.mOnItemClickListener != null) {
     a.performItemClick(null, i, c.getItemId(i));
   }
   a();
 }
Ejemplo n.º 6
0
  private void dataSetChanged() {
    final int currentPage = mCurrentPage;

    // if the adapter has stable ids, try to keep the page currently on
    // stable.
    if (mAdapter.hasStableIds() && mCurrentPage != INVALID_PAGE_POSITION) {
      mCurrentPage = getNewPositionOfCurrentPage();
    } else if (mCurrentPage == INVALID_PAGE_POSITION) {
      mCurrentPage = 0;
    }

    // remove all the current views
    removeAllViews();
    mActivePageQueue.clear();

    mPageCount = mAdapter.getCount();

    // put the current page within the new adapter range
    mCurrentPage =
        Math.min(mPageCount - 1, mCurrentPage == INVALID_PAGE_POSITION ? 0 : mCurrentPage);

    if (mCurrentPage != INVALID_PAGE_POSITION) {
      mRecycler.setViewTypeCount(mAdapter.getViewTypeCount());
      mCurrentPageId = mAdapter.getItemId(mCurrentPage);
      addView(viewForPage(mCurrentPage));
      if (mCurrentPage != currentPage) {
        flipTo(mCurrentPage);
      }
    } else {
      mPageCount = 0;
      mFlipDistance = 0;
    }

    updateEmptyStatus();
  }
Ejemplo n.º 7
0
  /**
   * @param adapter a regular ListAdapter, not all methods if the list adapter are used by the
   *     flipview
   */
  public void setAdapter(ListAdapter adapter) {
    if (mAdapter != null) {
      mAdapter.unregisterDataSetObserver(dataSetObserver);
    }

    // remove all the current views
    removeAllViews();
    mActivePageQueue.clear();

    mAdapter = adapter;
    mPageCount = adapter == null ? 0 : mAdapter.getCount();

    // put the current page within the new adapter range
    mCurrentPage =
        Math.min(mPageCount - 1, mCurrentPage == INVALID_PAGE_POSITION ? 0 : mCurrentPage);

    if (adapter != null) {
      mAdapter.registerDataSetObserver(dataSetObserver);
    }

    if (mCurrentPage != INVALID_PAGE_POSITION) {
      mRecycler.setViewTypeCount(mAdapter.getViewTypeCount());
      mCurrentPageId = mAdapter.getItemId(mCurrentPage);
      addView(viewForPage(mCurrentPage));
    } else {
      mPageCount = 0;
      mFlipDistance = 0;
    }

    updateEmptyStatus();
  }
Ejemplo n.º 8
0
  private int getNewPositionOfCurrentPage() {
    // check if id is on same position, this is because it will
    // often be that and this way you do not need to iterate the whole
    // dataset. If it is the same position, you are done.
    if (mCurrentPageId == mAdapter.getItemId(mCurrentPageIndex)) {
      return mCurrentPageIndex;
    }

    // iterate the dataset and look for the correct id. If it
    // exists, set that position as the current position.
    for (int i = 0; i < mAdapter.getCount(); i++) {
      if (mCurrentPageId == mAdapter.getItemId(i)) {
        return i;
      }
    }

    // Id no longer is dataset, keep current page
    return mCurrentPageIndex;
  }
 public long getItemId(int position) {
   int numHeaders = getHeadersCount();
   if (mAdapter != null && position >= numHeaders) {
     int adjPosition = position - numHeaders;
     int adapterCount = mAdapter.getCount();
     if (adjPosition < adapterCount) {
       return mAdapter.getItemId(adjPosition);
     }
   }
   return -1;
 }
 @Override
 public long getItemId(int position) {
   int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
   if (mAdapter != null && position >= numHeadersAndPlaceholders) {
     int adjPosition = position - numHeadersAndPlaceholders;
     int adapterCount = mAdapter.getCount();
     if (adjPosition < adapterCount) {
       return mAdapter.getItemId(adjPosition);
     }
   }
   return -1;
 }
Ejemplo n.º 11
0
 public final void run() {
   if (!b.aj) {
     ListAdapter listadapter = b.j;
     int i = a;
     if (listadapter != null && b.ao > 0 && i != -1 && i < listadapter.getCount() && b()) {
       android.view.View view = b.getChildAt(i - b.V);
       if (view != null) {
         b.a(view, i, listadapter.getItemId(i));
         return;
       }
     }
   }
 }
Ejemplo n.º 12
0
  /**
   * Get the row id associated with the specified position in the list.
   *
   * @param position Position of the item whose data we want
   */
  @Override
  public long getItemId(int position) {
    for (ListAdapter piece : pieces) {
      int size = piece.getCount();

      if (position < size) {
        return (piece.getItemId(position));
      }

      position -= size;
    }

    return (-1);
  }
 @Override
 public boolean onSingleTapConfirmed(MotionEvent e) {
   for (int i = 0; i < getChildCount(); i++) {
     View child = getChildAt(i);
     if (isEventWithinView(e, child)) {
       if (mOnItemClicked != null) {
         mOnItemClicked.onItemClick(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       if (mOnItemSelected != null) {
         mOnItemSelected.onItemSelected(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       break;
     }
   }
   return true;
 }
Ejemplo n.º 14
0
  @Override
  protected void dispatchDraw(Canvas canvas) {

    if (mPageCount < 1) {
      return;
    }

    boolean needsInvalidate = false;

    if (!mScroller.isFinished() && mScroller.computeScrollOffset()) {
      mFlipDistance = mScroller.getCurrY();
      needsInvalidate = true;
    }

    if (mIsFlipping || !mScroller.isFinished() || mPeakAnim != null) {
      drawPreviousHalf(canvas);
      drawNextHalf(canvas);
      drawFlippingHalf(canvas);
    } else {
      endScroll();
      final int currentPage = getCurrentPageFloor();
      if (mCurrentPage != currentPage) {
        postRemoveView(getChildAt(0));
      }
      final View v = viewForPage(currentPage);
      if (mCurrentPage != currentPage) {
        postAddView(v);
        postFlippedToPage(currentPage);
        mCurrentPage = currentPage;
        mCurrentPageId = mAdapter.getItemId(mCurrentPage);
      }
      setDrawWithLayer(v, false);
      v.draw(canvas);
    }

    // if overflip is GLOW mode and the edge effects needed drawing, make
    // sure to invalidate
    needsInvalidate |= mOverFlipper.draw(canvas);

    if (needsInvalidate) {
      // always invalidate whole screen as it is needed 99% of the time.
      // This is because of the shadows and shines put on the non-flipping
      // pages
      invalidate();
    }
  }
 @Override
 public void onLongPress(MotionEvent e) {
   int childCount = getChildCount();
   for (int i = 0; i < childCount; i++) {
     View child = getChildAt(i);
     if (isEventWithinView(e, child)) {
       if (mOnItemLongClicked != null) {
         mOnItemLongClicked.onItemLongClick(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       break;
     }
   }
 }
  /** Retrieves the view in the list corresponding to itemId */
  private View getViewForId(long itemId) {
    int firstVisiblePosition = getFirstVisiblePosition();
    ListAdapter adapter = getAdapter();
    if (!adapter.hasStableIds()) {
      throw new IllegalStateException(
          "Adapter doesn't have stable ids! Make sure your adapter has stable ids, and override hasStableIds() to return true.");
    }

    for (int i = 0; i < getChildCount(); i++) {
      View v = getChildAt(i);
      int position = firstVisiblePosition + i;
      long id = adapter.getItemId(position);
      if (id == itemId) {
        return v;
      }
    }
    return null;
  }
Ejemplo n.º 17
0
  private void setFlipDistance(float flipDistance) {

    if (mPageCount < 1) {
      mFlipDistance = 0;
      mCurrentPageIndex = INVALID_PAGE_POSITION;
      mCurrentPageId = -1;
      recycleActiveViews();
      return;
    }

    if (flipDistance == mFlipDistance) {
      return;
    }

    mFlipDistance = flipDistance;

    final int currentPageIndex = (int) Math.round(mFlipDistance / FLIP_DISTANCE_PER_PAGE);

    if (mCurrentPageIndex != currentPageIndex) {
      mCurrentPageIndex = currentPageIndex;
      mCurrentPageId = mAdapter.getItemId(mCurrentPageIndex);

      // TODO be smarter about this. Dont remove a view that will be added
      // again on the next line.
      recycleActiveViews();

      // add the new active views
      if (mCurrentPageIndex > 0) {
        fillPageForIndex(mPreviousPage, mCurrentPageIndex - 1);
        addView(mPreviousPage.v);
      }
      if (mCurrentPageIndex >= 0 && mCurrentPageIndex < mPageCount) {
        fillPageForIndex(mCurrentPage, mCurrentPageIndex);
        addView(mCurrentPage.v);
      }
      if (mCurrentPageIndex < mPageCount - 1) {
        fillPageForIndex(mNextPage, mCurrentPageIndex + 1);
        addView(mNextPage.v);
      }
    }

    invalidate();
  }
Ejemplo n.º 18
0
  public boolean onTestMove(MotionEvent event) {

    float xInit = event.getHistoricalX(0);
    float yInit = event.getHistoricalY(0);

    float xNow = event.getX();
    float yNow = event.getY();

    Rect viewRect = new Rect();
    if (!isMove) {
      for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        int left = child.getLeft();
        int right = child.getRight();
        int top = child.getTop();
        int bottom = child.getBottom();
        viewRect.set(left, top, right, bottom);
        if (viewRect.contains((int) xInit, (int) yInit)) {
          if (yNow > yInit) {

            Log.d("relache", "pass� in ");
            if (mOnItemMoveListener != null) {
              mOnItemMoveListener.onTouch(child, event);
              this.childSelected = child;
            }

            if (mOnItemClicked != null) {
              mOnItemClicked.onItemClick(
                  HorizontalListView.this,
                  child,
                  mLeftViewIndex + 1 + i,
                  mAdapter.getItemId(mLeftViewIndex + 1 + i));
            }

            isMove = true;
            return true;
          }
        }
      }
    } else {
      mOnItemMoveListener.onTouch(childSelected, event);

      if (event.getAction() == MotionEvent.ACTION_UP) {
        int left = this.getLeft();
        int right = this.getRight();
        int top = this.getTop();
        int bottom = this.getBottom();
        Rect rect = new Rect(left, top, right, bottom);

        if (!rect.contains((int) xNow, (int) yNow)) {

          if (mOnItemOutListener != null) {
            mOnItemOutListener.onTouch(this.childSelected, event);
          }
        }

        isMove = false;
        return false;
      }

      return true;
    }

    return false;
  }
Ejemplo n.º 19
0
 @Override
 public long getItemId(final int position) {
   return wrapped.getItemId(position);
 }
Ejemplo n.º 20
0
 @Override
 public long getItemId(int i) {
   if (pattern.insertForIndex(i)) return -1L;
   return wrappedAdapter.getItemId(i - getOffsetForIndex(i));
 }
 @Override
 public long getItemId(final int position) {
   return adapter.getItemId(position);
 }
Ejemplo n.º 22
0
 @Override
 public long getItemId(final int position) {
   return isSectionHeaderPosition(position)
       ? Integer.MAX_VALUE - mSections.indexOfKey(position)
       : mBaseAdapter.getItemId(sectionedPositionToPosition(position));
 }
Ejemplo n.º 23
0
 @Override
 public long getItemId(int position) {
   return mAdapter.getItemId(position);
 }