コード例 #1
0
ファイル: IndexAdapter.java プロジェクト: jnksu/Demo
  protected void buildMultiPic(final GridLayout gridLayout) {
    gridLayout.setVisibility(View.VISIBLE);
    // 获取当前屏幕尺寸
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    // 设置图片的宽度和高度
    int picWidth = metrics.widthPixels / 3 - 48;

    for (int i = 0; i < 9; i++) {
      // 获取View
      SimpleDraweeView simpleDraweeView = (SimpleDraweeView) gridLayout.getChildAt(i);
      // 设置布局参数
      GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
      layoutParams.width = picWidth;
      layoutParams.height = picWidth;
      layoutParams.setMargins(8, 8, 8, 8);
      simpleDraweeView.setLayoutParams(layoutParams);
      // 设置图片数据源
      simpleDraweeView.setImageURI(Uri.parse(Image.imageThumbUrls[i]));
      // 准备传递数据
      final ImageViewPageMessage imageViewPageMessage =
          new ImageViewPageMessage(Image.imageThumbUrls, i);
      simpleDraweeView.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              EventBus.getDefault().postSticky(imageViewPageMessage);
              Intent intent = new Intent(mContext, ImageViewPagerActivity.class);
              mContext.startActivity(intent);
            }
          });
    }
  }
コード例 #2
0
  // Abstract Method in BaseAdapter
  public View getView(int position, View convertView, ViewGroup parent) {
    if (position >= (mRowCount - PREFETCH_BOUNDARY) && mNewerRequests <= mNewerRequestsProcessed) {
      if (DEBUGLOG) Log.e(TAG, "queryForNewerEvents: ");
      mNewerRequests++;
      queueQuery(new QuerySpec(QUERY_TYPE_NEWER));
    }

    if (position < PREFETCH_BOUNDARY && mOlderRequests <= mOlderRequestsProcessed) {
      if (DEBUGLOG) Log.e(TAG, "queryForOlderEvents: ");
      mOlderRequests++;
      queueQuery(new QuerySpec(QUERY_TYPE_OLDER));
    }

    final View v;
    DayAdapterInfo info = getAdapterInfoByPosition(position);
    if (info != null) {
      int offset = position - info.offset;
      v = info.dayAdapter.getView(offset, convertView, parent);

      // Turn on the past/present separator if the view is a day header
      // and it is the first day with events after yesterday.
      if (info.dayAdapter.isDayHeaderView(offset)) {
        View simpleDivider = v.findViewById(R.id.top_divider_simple);
        View pastPresentDivider = v.findViewById(R.id.top_divider_past_present);
        if (info.dayAdapter.isFirstDayAfterYesterday(offset)) {
          if (simpleDivider != null && pastPresentDivider != null) {
            simpleDivider.setVisibility(View.GONE);
            pastPresentDivider.setVisibility(View.VISIBLE);
          }
        } else if (simpleDivider != null && pastPresentDivider != null) {
          simpleDivider.setVisibility(View.VISIBLE);
          pastPresentDivider.setVisibility(View.GONE);
        }
      }
    } else {
      // TODO
      Log.e(TAG, "BUG: getAdapterInfoByPosition returned null!!! " + position);
      TextView tv = new TextView(mContext);
      tv.setText("Bug! " + position);
      v = tv;
    }

    // If this is not a tablet config don't do selection highlighting
    if (!mIsTabletConfig) {
      return v;
    }
    // Show selected marker if this is item is selected
    boolean selected = false;
    Object yy = v.getTag();
    if (yy instanceof AgendaAdapter.ViewHolder) {
      AgendaAdapter.ViewHolder vh = (AgendaAdapter.ViewHolder) yy;
      selected = mSelectedInstanceId == vh.instanceId;
      vh.selectedMarker.setVisibility((selected && mShowEventOnStart) ? View.VISIBLE : View.GONE);
      if (mShowEventOnStart) {
        GridLayout.LayoutParams lp = (GridLayout.LayoutParams) vh.textContainer.getLayoutParams();
        if (selected) {
          mSelectedVH = vh;
          v.setBackgroundColor(mSelectedItemBackgroundColor);
          vh.title.setTextColor(mSelectedItemTextColor);
          vh.when.setTextColor(mSelectedItemTextColor);
          vh.where.setTextColor(mSelectedItemTextColor);
          lp.setMargins(0, 0, 0, 0);
          vh.textContainer.setLayoutParams(lp);
        } else {
          lp.setMargins(0, 0, (int) mItemRightMargin, 0);
          vh.textContainer.setLayoutParams(lp);
        }
      }
    }

    if (DEBUGLOG) {
      Log.e(TAG, "getView " + position + " = " + getViewTitle(v));
    }
    return v;
  }