Пример #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
    int height =
        (getCompoundPaddingTop()
            + (int) Math.ceil(Math.abs(fontMetrics.top) + Math.abs(fontMetrics.bottom))
            + getCompoundPaddingBottom());

    final Resources resources = getResources();
    String text = loginText;
    int logInWidth;
    int width;
    if (text == null) {
      text = resources.getString(R.string.com_facebook_loginview_log_in_button_long);
      logInWidth = measureButtonWidth(text);
      width = resolveSize(logInWidth, widthMeasureSpec);
      if (width < logInWidth) {
        text = resources.getString(R.string.com_facebook_loginview_log_in_button);
      }
    }
    logInWidth = measureButtonWidth(text);

    text = logoutText;
    if (text == null) {
      text = resources.getString(R.string.com_facebook_loginview_log_out_button);
    }
    int logOutWidth = measureButtonWidth(text);

    width = resolveSize(Math.max(logInWidth, logOutWidth), widthMeasureSpec);
    setMeasuredDimension(width, height);
  }
Пример #2
0
  public void prioritizeViewRange(int firstVisibleItem, int lastVisibleItem, int prefetchBuffer) {
    if ((lastVisibleItem < firstVisibleItem) || (sectionKeys.size() == 0)) {
      return;
    }

    // We want to prioritize requests for items which are visible but do not have pictures
    // loaded yet. We also want to pre-fetch pictures for items which are not yet visible
    // but are within a buffer on either side of the visible items, on the assumption that
    // they will be visible soon. For these latter items, we'll store the images in memory
    // in the hopes we can immediately populate their image view when needed.

    // Prioritize the requests in reverse order since each call to prioritizeRequest will just
    // move it to the front of the queue. And we want the earliest ones in the range to be at
    // the front of the queue, so all else being equal, the list will appear to populate from
    // the top down.
    for (int i = lastVisibleItem; i >= 0; i--) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        String id = getIdOfGraphObject(sectionAndItem.graphObject);
        ImageRequest request = pendingRequests.get(id);
        if (request != null) {
          ImageDownloader.prioritizeRequest(request);
        }
      }
    }

    // For items which are not visible, but within the buffer on either side, we want to
    // fetch those items and store them in a small in-memory cache of bitmaps.
    int start = Math.max(0, firstVisibleItem - prefetchBuffer);
    int end = Math.min(lastVisibleItem + prefetchBuffer, getCount() - 1);
    ArrayList<T> graphObjectsToPrefetchPicturesFor = new ArrayList<T>();
    // Add the IDs before and after the visible range.
    for (int i = start; i < firstVisibleItem; ++i) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
      }
    }
    for (int i = lastVisibleItem + 1; i <= end; ++i) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
      }
    }
    for (T graphObject : graphObjectsToPrefetchPicturesFor) {
      URI uri = getPictureUriOfGraphObject(graphObject);
      final String id = getIdOfGraphObject(graphObject);

      // This URL already have been requested for pre-fetching, but we want to act in an LRU manner,
      // so move
      // it to the end of the list regardless.
      boolean alreadyPrefetching = prefetchedProfilePictureIds.remove(id);
      prefetchedProfilePictureIds.add(id);

      // If we've already requested it for pre-fetching, no need to do so again.
      if (!alreadyPrefetching) {
        downloadProfilePicture(id, uri, null);
      }
    }
  }
Пример #3
0
 @Override
 public int getSectionForPosition(int position) {
   SectionAndItem<T> sectionAndItem = getSectionAndItem(position);
   if (sectionAndItem != null && sectionAndItem.getType() != SectionAndItem.Type.ACTIVITY_CIRCLE) {
     return Math.max(
         0, Math.min(sectionKeys.indexOf(sectionAndItem.sectionKey), sectionKeys.size() - 1));
   }
   return 0;
 }
Пример #4
0
 @Override
 public int getPositionForSection(int section) {
   if (displaySections) {
     section = Math.max(0, Math.min(section, sectionKeys.size() - 1));
     if (section < sectionKeys.size()) {
       return getPosition(sectionKeys.get(section), null);
     }
   }
   return 0;
 }