private void recomputePhotoAndScrollingMetrics() {
    mHeaderHeightPixels = mHeaderBox.getHeight();

    mPhotoHeightPixels = 0;
    if (mHasPhoto) {
      mPhotoHeightPixels = (int) (mPhotoView.getWidth() / PHOTO_ASPECT_RATIO);
      mPhotoHeightPixels = Math.min(mPhotoHeightPixels, mScrollView.getHeight() * 2 / 3);
    }

    ViewGroup.LayoutParams lp;
    lp = mPhotoViewContainer.getLayoutParams();
    if (lp.height != mPhotoHeightPixels) {
      lp.height = mPhotoHeightPixels;
      mPhotoViewContainer.setLayoutParams(lp);
    }

    ViewGroup.MarginLayoutParams mlp =
        (ViewGroup.MarginLayoutParams) mDetailsContainer.getLayoutParams();
    if (mlp.topMargin != mHeaderHeightPixels + mPhotoHeightPixels) {
      mlp.topMargin = mHeaderHeightPixels + mPhotoHeightPixels;
      mDetailsContainer.setLayoutParams(mlp);
    }

    onScrollChanged(0, 0); // trigger scroll handling
  }
 /**
  * 根据当前ListView的滚动状态来设定 {@link #ableToPull}
  * 的值,每次都需要在onTouch中第一个执行,这样可以判断出当前应该是滚动ListView,还是应该进行下拉。
  *
  * @param event
  */
 private void setIsAbleToPull(View view, MotionEvent event) {
   boolean oldVal = this.ableToPull;
   this.ableToPull = this.pullableView.isPullable(view, event);
   if (this.ableToPull) {
     if (oldVal == false) {
       yDown = event.getRawY();
     }
   } else if (headerLayoutParams.topMargin != hideHeaderHeight) {
     headerLayoutParams.topMargin = hideHeaderHeight;
     header.setLayoutParams(headerLayoutParams);
   }
   if (pullableView.getView() instanceof ListView) {
     View firstChild = ((ListView) pullableView.getView()).getChildAt(0);
     if (firstChild != null) {
       int firstVisiblePos = ((ListView) pullableView.getView()).getFirstVisiblePosition();
       if (firstVisiblePos == 0 && firstChild.getTop() == 0) {
         if (!ableToPull) {
           yDown = event.getRawY();
         }
         // 如果首个元素的上边缘,距离父布局值为0,就说明ListView滚动到了最顶部,此时应该允许下拉刷新
         ableToPull = true;
       } else {
         if (headerLayoutParams.topMargin != hideHeaderHeight) {
           headerLayoutParams.topMargin = hideHeaderHeight;
           header.setLayoutParams(headerLayoutParams);
         }
         ableToPull = false;
       }
     } else {
       // 如果ListView中没有元素,也应该允许下拉刷新
       ableToPull = true;
     }
   }
 }
Example #3
0
  public void addNavBar(String title, Map<Object, Object> left, Map<Object, Object> right) {
    removeNavBar();

    Context ctx = RhodesActivity.getContext();

    LinearLayout top = new LinearLayout(ctx);
    top.setOrientation(LinearLayout.HORIZONTAL);
    top.setBackgroundColor(Color.GRAY);
    top.setGravity(Gravity.CENTER);
    top.setLayoutParams(new LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 0));

    View leftButton = createButton(left);
    leftButton.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1));
    top.addView(leftButton);

    TextView label = new TextView(ctx);
    label.setText(title);
    label.setGravity(Gravity.CENTER);
    label.setTextSize((float) 30.0);
    label.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 2));
    top.addView(label);

    if (right != null) {
      View rightButton = createButton(right);
      rightButton.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1));
      top.addView(rightButton);
    }

    navBar = top;
    view.addView(navBar, 0);
  }
Example #4
0
  // 初始化每个页面的数据
  private void initPageView(LinearLayout root, int i) {
    DayBean bean = data.getContent().get(i);
    int layoutIndex = lastDayTime != bean.getTime() ? 0 : (bean.getSrc().length == 1 ? 1 : 2);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(ScreenUtils.getScreenW(), ScreenUtils.getScreenH());
    View v = View.inflate(getContext(), layoutIds[layoutIndex], null);
    v.setLayoutParams(params);
    if (layoutIndex == 0) {
      initItem1(v, bean);
      lastDayTime = bean.getTime();
      nowDay++;
      root.addView(v);
      pageViews.add(new PageView(v, pageSum, bean, true));
      pageSum++;
      // 如果是日期页面,则继续加载
      params = new LinearLayout.LayoutParams(ScreenUtils.getScreenW(), ScreenUtils.getScreenH());
      layoutIndex = (bean.getSrc().length == 1 ? 1 : 2);
      v = View.inflate(getContext(), layoutIds[layoutIndex], null);
      v.setLayoutParams(params);
    }
    if (layoutIndex == 1) {
      initItem2(v, bean);
    } else {
      initItem3(v, bean);
    }

    root.addView(v);
    pageViews.add(new PageView(v, pageSum, bean, false));
    pageSum++;
  }
 @Override
 public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
   View v = null;
   BaseViewHolder viewHolder = null;
   switch (viewType) {
     case 0:
       v = View.inflate(mContext, R.layout.layout_user_header, null);
       v.setLayoutParams(
           new RecyclerView.LayoutParams(
               RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
       viewHolder = new HeaderViewHolder(v, mItemClickListener);
       break;
     case 1:
       v = View.inflate(mContext, R.layout.layout_title_text_arrow, null);
       v.setLayoutParams(
           new RecyclerView.LayoutParams(
               RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
       viewHolder = new ItemViewHolder(v, mItemClickListener);
       break;
     case 2:
       v = View.inflate(mContext, R.layout.layout_divider_item, null);
       v.setLayoutParams(
           new RecyclerView.LayoutParams(
               RecyclerView.LayoutParams.MATCH_PARENT, DisplayUtils.dpToPxInt(mContext, 20)));
       viewHolder = new DividerViewHolder(v, mItemClickListener);
       break;
     default:
       break;
   }
   return viewHolder;
 }
  private void initView() {
    // 添加贴纸水印的画布
    View overlay =
        LayoutInflater.from(PhotoProcessActivity.this)
            .inflate(R.layout.view_drawable_overlay, null);
    mImageView = (MyImageViewDrawableOverlay) overlay.findViewById(R.id.drawable_overlay);
    ViewGroup.LayoutParams params =
        new ViewGroup.LayoutParams(App.getApp().getScreenWidth(), App.getApp().getScreenWidth());
    mImageView.setLayoutParams(params);
    overlay.setLayoutParams(params);
    drawArea.addView(overlay);

    // 添加标签选择器
    RelativeLayout.LayoutParams rparams =
        new RelativeLayout.LayoutParams(
            App.getApp().getScreenWidth(), App.getApp().getScreenWidth());

    // 初始化滤镜图片
    imageView.setLayoutParams(rparams);

    // 初始化推荐标签栏
    commonLabelArea =
        LayoutInflater.from(PhotoProcessActivity.this).inflate(R.layout.view_label_bottom, null);
    commonLabelArea.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    toolArea.addView(commonLabelArea);
    commonLabelArea.setVisibility(View.GONE);
  }
Example #7
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    LogUtil.i("MoveLinearLayout", "[onMeasure] start");
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int count = getChildCount();
    boolean sub2 = false, sub3 = false;
    View view;
    for (int i = 0; i < count; ++i) {
      view = getChildAt(i);

      if (view.getId() == R.id.sub_view_1) {
        LogUtil.i(
            "MoveLinearLayout", "[onMeasure] sub_view_1  widthMeasureSpec : " + widthMeasureSpec);
      }
      if (view.getId() == R.id.sub_view_2 && !sub2) {
        LogUtil.i(
            "MoveLinearLayout", "[onMeasure] sub_view_2  widthMeasureSpec : " + widthMeasureSpec);
        view.setLayoutParams(new LayoutParams(widthMeasureSpec, view.getLayoutParams().height));
        sub2 = true;
      }
      if (view.getId() == R.id.sub_view_3 && sub3 == false) {
        LogUtil.i(
            "MoveLinearLayout", "[onMeasure] : sub_view_3 widthMeasureSpec : " + widthMeasureSpec);
        view.setLayoutParams(new LayoutParams(widthMeasureSpec, view.getLayoutParams().height));
        sub3 = true;
      }
      if (sub2 && sub3) {
        break;
      }
    }
  }
  private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

      View v = tabsContainer.getChildAt(i);

      v.setLayoutParams(defaultTabLayoutParams);
      v.setBackgroundResource(tabBackgroundResId);
      if (shouldExpand) {
        v.setPadding(0, 0, 0, 0);
        v.setLayoutParams(new LinearLayout.LayoutParams(-1, -1, 1.0F));
      } else {
        v.setPadding(tabPadding, 0, tabPadding, 0);
      }

      if (v instanceof TextView) {

        TextView tab = (TextView) v;
        tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
        tab.setTypeface(tabTypeface, tabTypefaceStyle);
        tab.setTextColor(tabTextColor);

        // setAllCaps() is only available from API 14, so the upper case is made manually if we are
        // on a
        // pre-ICS-build
        if (textAllCaps) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            tab.setAllCaps(true);
          } else {
            tab.setText(tab.getText().toString().toUpperCase(locale));
          }
        }
      }
    }
  }
  // suppress this error message to be able to use spaces in higher api levels
  @SuppressLint("NewApi")
  public void refresh() {

    if (mAdapter == null) {
      mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
      if (mListView != null) {
        mListView.setAdapter(mAdapter);
      } else if (mTableLayout != null) {
        TableRow tr = null;
        for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
          // add a new table row with the current context
          tr = new TableRow(mTableLayout.getContext());
          tr.setOrientation(TableRow.HORIZONTAL);
          tr.setLayoutParams(
              new TableRow.LayoutParams(
                  TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
          // add as many cards as the number of columns indicates per row
          for (int j = 0; j < mColumnNumber; j++) {
            if (i + j < mAdapter.getCount()) {
              View card = mAdapter.getView(i + j, null, tr);
              if (card.getLayoutParams() != null) {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        card.getLayoutParams().width, card.getLayoutParams().height, 1f));
              } else {
                card.setLayoutParams(
                    new TableRow.LayoutParams(
                        TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT,
                        1f));
              }
              tr.addView(card);
            }
          }
          mTableLayout.addView(tr);
        }
        if (tr != null) {
          // fill the empty space with spacers
          for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
            View space = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              space = new Space(tr.getContext());
            } else {
              space = new View(tr.getContext());
            }
            space.setLayoutParams(
                new TableRow.LayoutParams(
                    TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
            tr.addView(space);
          }
        }
      }
    } else {
      mAdapter.setSwipeable(mSwipeable); // in case swipeable changed;
      mAdapter.setItems(mStacks);
    }
  }
Example #10
0
  @Override
  public View getView(final int position, View convertView, final ViewGroup parent) {
    int viewType = getItemViewType(position);

    if (viewType == TYPE_CAMERA) {
      CameraViewHolder holder;
      if (convertView == null) {
        convertView = mInflater.inflate(R.layout.media_camera_item, parent, false);
        AbsListView.LayoutParams params = (AbsListView.LayoutParams) convertView.getLayoutParams();
        int width = (mWidth - 2 * getPixelSize(R.dimen.media_item_horizontal_spacing)) / 3;
        params.width = width;
        params.height = width;
        convertView.setLayoutParams(params);

        holder = new CameraViewHolder(convertView);
        convertView.setTag(holder);
      } else {
        holder = (CameraViewHolder) convertView.getTag();
      }
    } else {
      MediaViewHolder holder;
      if (convertView == null) {
        convertView = mInflater.inflate(R.layout.media_item, parent, false);
        AbsListView.LayoutParams params = (AbsListView.LayoutParams) convertView.getLayoutParams();
        int width = (mWidth - 2 * getPixelSize(R.dimen.media_item_horizontal_spacing)) / 3;
        params.width = width;
        params.height = width;
        convertView.setLayoutParams(params);

        holder = new MediaViewHolder(convertView);
        convertView.setTag(holder);
      } else {
        holder = (MediaViewHolder) convertView.getTag();
      }

      final Media media = mMedias.get(position);

      setImage(holder.photoIv, media.getData());
      setIndex(holder.indexTv, contains(media));
      setText(holder.sizeTv, ByteUtil.format(media.getSize()));
      setVisibility(holder.indexTv, true);
      setVisibility(holder.videoLayout, media.getMediaType() == MediaType.MEDIA_TYPE_VIDEO);

      final View view = convertView;
      holder.indexTv.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (mOnItemCheckedListener == null) return;

              mOnItemCheckedListener.onItemChecked(view, position);
            }
          });
    }

    return convertView;
  }
Example #11
0
    @Override
    public void onBindViewHolder(SimpleViewHolder holder, int position) {
      holder.title.setText(String.valueOf(position));

      boolean isVertical = (mRecyclerView.getOrientation() == Orientation.VERTICAL);
      final View itemView = holder.itemView;

      if (mLayoutId == R.layout.layout_staggered_grid) {
        final int id;
        if (position % 3 == 0) {
          id = R.dimen.staggered_child_medium;
        } else if (position % 5 == 0) {
          id = R.dimen.staggered_child_large;
        } else if (position % 7 == 0) {
          id = R.dimen.staggered_child_xlarge;
        } else {
          id = R.dimen.staggered_child_small;
        }

        final int span;
        if (position == 2) {
          span = 2;
        } else {
          span = 1;
        }

        final int size = mContext.getResources().getDimensionPixelSize(id);

        final StaggeredGridLayoutManager.LayoutParams lp =
            (StaggeredGridLayoutManager.LayoutParams) itemView.getLayoutParams();
        if (!isVertical && lp.width != id) {
          lp.span = span;
          lp.width = size;
          itemView.setLayoutParams(lp);
        } else if (isVertical && lp.height != id) {
          lp.span = span;
          lp.height = size;
          itemView.setLayoutParams(lp);
        }
      } else if (mLayoutId == R.layout.layout_spannable_grid) {
        final SpannableGridLayoutManager.LayoutParams lp =
            (SpannableGridLayoutManager.LayoutParams) itemView.getLayoutParams();

        final int span1 = (position == 0 || position == 3 ? 2 : 1);
        final int span2 = (position == 0 ? 2 : (position == 3 ? 3 : 1));

        final int colSpan = (isVertical ? span2 : span1);
        final int rowSpan = (isVertical ? span1 : span2);

        if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) {
          lp.rowSpan = rowSpan;
          lp.colSpan = colSpan;
          itemView.setLayoutParams(lp);
        }
      }
    }
 private void ensureHeaderHasLayoutParams(View view) {
   android.view.ViewGroup.LayoutParams layoutparams = view.getLayoutParams();
   if (layoutparams == null) {
     view.setLayoutParams(new android.widget.AbsListView.LayoutParams(-1, -2));
   } else if (layoutparams.height == -1) {
     layoutparams.height = -2;
     view.setLayoutParams(layoutparams);
     return;
   }
 }
 private void ensureHeaderHasCorrectLayoutParams(View header) {
   ViewGroup.LayoutParams lp = header.getLayoutParams();
   if (lp == null) {
     lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
     header.setLayoutParams(lp);
   } else if (lp.height == LayoutParams.MATCH_PARENT || lp.width == LayoutParams.WRAP_CONTENT) {
     lp.height = LayoutParams.WRAP_CONTENT;
     lp.width = LayoutParams.MATCH_PARENT;
     header.setLayoutParams(lp);
   }
 }
 private void updateTabStyles() {
   for (int i = 0; i < tabCount; i++) {
     View v = tabsContainer.getChildAt(i);
     v.setLayoutParams(defaultTabLayoutParams);
     if (shouldExpand) {
       v.setPadding(0, 0, 0, 0);
       v.setLayoutParams(new LinearLayout.LayoutParams(-1, -1, 1.0F));
     } else {
       v.setPadding(tabPadding, 0, tabPadding, 0);
     }
   }
 }
  private void init(final Context context, AttributeSet attrs) {
    final View rootView = View.inflate(context, R.layout.view_expandable, this);
    headerLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_headerlayout);
    final TypedArray typedArray =
        context.obtainStyledAttributes(attrs, R.styleable.ExpandableLayout);
    final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_headerLayout, -1);
    final int contentID =
        typedArray.getResourceId(R.styleable.ExpandableLayout_el_contentLayout, -1);
    contentLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_contentLayout);

    if (headerID == -1 || contentID == -1)
      throw new IllegalArgumentException("HeaderLayout and ContentLayout cannot be null!");

    if (isInEditMode()) return;

    duration =
        typedArray.getInt(
            R.styleable.ExpandableLayout_el_duration,
            getContext().getResources().getInteger(android.R.integer.config_shortAnimTime));
    final View headerView = View.inflate(context, headerID, null);
    headerView.setLayoutParams(
        new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    headerLayout.addView(headerView);
    final View contentView = View.inflate(context, contentID, null);
    contentView.setLayoutParams(
        new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    contentLayout.addView(contentView);
    contentLayout.setVisibility(GONE);
    headerLayout.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!isAnimationRunning) {
              if (contentLayout.getVisibility() == VISIBLE) collapse(contentLayout);
              else expand(contentLayout);

              isAnimationRunning = true;
              new Handler()
                  .postDelayed(
                      new Runnable() {
                        @Override
                        public void run() {
                          isAnimationRunning = false;
                        }
                      },
                      duration);
            }
          }
        });

    typedArray.recycle();
  }
 private void onCreateView(View view, boolean defaultItem) {
   if (defaultItem) {
     AbsListView.LayoutParams lp =
         new AbsListView.LayoutParams(convertViewWidth, convertViewHight);
     view.setLayoutParams(lp);
   } else {
     int offset =
         context
             .getResources()
             .getDimensionPixelOffset(R.dimen.default_vertical_margin_in_setting_of_listItem);
     AbsListView.LayoutParams lp =
         new AbsListView.LayoutParams(convertViewWidth, convertViewHight + offset);
     view.setLayoutParams(lp);
   }
 }
Example #17
0
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view = LayoutInflater.from(context).inflate(R.layout.item_feed, parent, false);
    final CellFeedViewHolder cellFeedViewHolder = new CellFeedViewHolder(view);
    if (viewType == VIEW_TYPE_DEFAULT) {
      cellFeedViewHolder.btnComments.setOnClickListener(this);
      cellFeedViewHolder.btnMore.setOnClickListener(this);
      cellFeedViewHolder.ivFeedCenter.setOnClickListener(this);
      cellFeedViewHolder.btnLike.setOnClickListener(this);
      cellFeedViewHolder.ivUserProfile.setOnClickListener(this);
    } else if (viewType == VIEW_TYPE_LOADER) {
      View bgView = new View(context);
      bgView.setLayoutParams(
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
      bgView.setBackgroundColor(0x77ffffff);
      cellFeedViewHolder.vImageRoot.addView(bgView);
      cellFeedViewHolder.vProgressBg = bgView;

      FrameLayout.LayoutParams params =
          new FrameLayout.LayoutParams(loadingViewSize, loadingViewSize);
      params.gravity = Gravity.CENTER;
      SendingProgressView sendingProgressView = new SendingProgressView(context);
      sendingProgressView.setLayoutParams(params);
      cellFeedViewHolder.vImageRoot.addView(sendingProgressView);
      cellFeedViewHolder.vSendingProgress = sendingProgressView;
    }

    return cellFeedViewHolder;
  }
  public void updateCharts(List<?> statsForApp) {
    Chart chart = new Chart();
    int page = myAdapter.getCurrentPage();
    int column = myAdapter.getCurrentColumn();

    int position = -1;
    List<View> charts = new ArrayList<View>();

    int pos = 0;
    for (int i = 0; i < myAdapter.getNumPages(); i++)
      for (int j = 1; j < myAdapter.getNumCharts(i); j++) {
        int pageColumn[] = new int[3];
        View chartView = myAdapter.buildChart(getActivity(), chart, statsForApp, i, j);
        /*
         * if(chartView==null) {
         * Log.i(LOG_TAG,"Ignoring chart p="+i+" c="+j+"for class="
         * +this.getClass().toString()); continue; }
         */
        Gallery.LayoutParams params =
            new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        chartView.setLayoutParams(params);
        pageColumn[0] = i;
        pageColumn[1] = j;
        pageColumn[2] = myAdapter.getNumCharts(i);
        if (i == page && j == column) position = pos;
        pos++;
        chartView.setTag(pageColumn);
        charts.add(chartView);
      }
    chartGallery.setIgnoreLayoutCalls(false);
    chartGalleryAdapter.setViews(charts);
    if (position >= 0) chartGallery.setSelection(position);
    chartGalleryAdapter.notifyDataSetChanged();
    chartGallery.invalidate();
  }
Example #19
0
  @Override
  public View getView(Context context) {

    View view = LayoutInflater.from(context).inflate(getCardLayout(), null);

    mCardLayout = view;

    try {
      ((FrameLayout) view.findViewById(R.id.cardContent)).addView(getCardContent(context));
    } catch (NullPointerException e) {
      e.printStackTrace();
    }

    // ((TextView) view.findViewById(R.id.title)).setText(this.title);

    LinearLayout.LayoutParams lp =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    int bottom = Utils.convertDpToPixelInt(context, 12);
    lp.setMargins(0, 0, 0, bottom);

    view.setLayoutParams(lp);

    return view;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gridview);
    ObservableGridView scrollable = (ObservableGridView) findViewById(R.id.scrollable);
    // Set padding view for GridView. This is the flexible space.
    headerView = new View(this);
    final int flexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    FrameLayout.LayoutParams lp =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight);
    headerView.setLayoutParams(lp);

    // This is required to disable header's list selector effect
    headerView.setClickable(true);

    scrollable.addHeaderView(headerView);
    scrollable.setScrollViewCallbacks(this);
    UiTestUtils.setDummyData(this, scrollable);
    scrollable.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}
        });
  }
Example #21
0
 private void addTab(@NonNull List<String> tabTexts, int i) {
   final TextView tab = new TextView(getContext());
   tab.setSingleLine();
   tab.setEllipsize(TextUtils.TruncateAt.END);
   tab.setGravity(Gravity.CENTER);
   tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
   tab.setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
   tab.setTextColor(textUnselectedColor);
   tab.setCompoundDrawablesWithIntrinsicBounds(
       null, null, getResources().getDrawable(menuUnselectedIcon), null);
   tab.setText(tabTexts.get(i));
   tab.setPadding(dpTpPx(5), dpTpPx(12), dpTpPx(5), dpTpPx(12));
   // 添加点击事件
   tab.setOnClickListener(
       new OnClickListener() {
         @Override
         public void onClick(View v) {
           switchMenu(tab);
           if (mDropDownMenuListener != null) mDropDownMenuListener.onClickListener(v);
         }
       });
   tabMenuView.addView(tab);
   // 添加分割线
   if (i < tabTexts.size() - 1) {
     View view = new View(getContext());
     view.setLayoutParams(new LayoutParams(dpTpPx(0.5f), ViewGroup.LayoutParams.MATCH_PARENT));
     view.setBackgroundColor(dividerColor);
     tabMenuView.addView(view);
   }
 }
  public static void setListViewHeightBasedOnChildren(ListView listView) {

    ListAdapter listAdapter = listView.getAdapter();

    if (listAdapter == null) return;

    int desiredWidth =
        View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);

    int totalHeight = 0;

    View view = null;

    for (int i = 0; i < listAdapter.getCount(); i++) {

      view = listAdapter.getView(i, view, listView);

      if (i == 0)
        view.setLayoutParams(
            new ViewGroup.LayoutParams(desiredWidth, AbsListView.LayoutParams.MATCH_PARENT));

      view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);

      totalHeight += view.getMeasuredHeight() + 20;
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();

    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));

    listView.setLayoutParams(params);
  }
  public int getRowHeight() {
    if (mRowHeight > 0) {
      return mRowHeight;
    }
    ListAdapter adapter = getAdapter();
    int numColumns = getNumColumnsCompatible();

    // adapter has not been set or has no views in it;
    if (adapter == null
        || adapter.getCount() <= numColumns * (mHeaderViewInfos.size() + mFooterViewInfos.size())) {
      return -1;
    }
    int mColumnWidth = getColumnWidthCompatible();
    View view =
        getAdapter().getView(numColumns * mHeaderViewInfos.size(), mViewForMeasureRowHeight, this);
    AbsListView.LayoutParams p = (AbsListView.LayoutParams) view.getLayoutParams();
    if (p == null) {
      p = new AbsListView.LayoutParams(-1, -2, 0);
      view.setLayoutParams(p);
    }
    int childHeightSpec =
        getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);
    int childWidthSpec =
        getChildMeasureSpec(
            MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width);
    view.measure(childWidthSpec, childHeightSpec);
    mViewForMeasureRowHeight = view;
    mRowHeight = view.getMeasuredHeight();
    return mRowHeight;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("WOW");

    view = new CustomView(getApplicationContext(), actionBar);
    setContentView(view);
    view.setRefreshListner(SampleForGmailLikePullToRefresh.this);
    view.setActionBar(SampleForGmailLikePullToRefresh.this);
    mListView = view.getListView();

    list = new ArrayList<Integer>();
    adapter = new DummyAdapter(SampleForGmailLikePullToRefresh.this, 0, list);

    LayoutInflater layoutInflater =
        (LayoutInflater)
            SampleForGmailLikePullToRefresh.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View loadingView = layoutInflater.inflate(R.layout.view_listview_loading, null);
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    params.setMargins(0, 5, 0, 0);
    loadingView.setLayoutParams(params);
    mListView.setEmptyView(null);
  }
  public void addFooterView(View v, Object data, boolean isSelectable) {
    ListAdapter mAdapter = getAdapter();
    if (mAdapter != null && !(mAdapter instanceof HeaderViewGridAdapter)) {
      throw new IllegalStateException(
          "Cannot add header view to grid -- setAdapter has already been called.");
    }

    ViewGroup.LayoutParams lyp = v.getLayoutParams();

    FixedViewInfo info = new FixedViewInfo();
    FrameLayout fl = new FullWidthFixedViewLayout(getContext());

    if (lyp != null) {
      v.setLayoutParams(new FrameLayout.LayoutParams(lyp.width, lyp.height));
      fl.setLayoutParams(new AbsListView.LayoutParams(lyp.width, lyp.height));
    }
    fl.addView(v);
    info.view = v;
    info.viewContainer = fl;
    info.data = data;
    info.isSelectable = isSelectable;
    mFooterViewInfos.add(info);

    if (mAdapter != null) {
      ((HeaderViewGridAdapter) mAdapter).notifyDataSetChanged();
    }
  }
  private void createListView() {
    root = (FrameLayout) inflater.inflate(R.layout.qrh__listview_container, null);
    root.addView(content);

    listView.getViewTreeObserver().addOnGlobalLayoutListener(this);
    ListViewScrollObserver observer = new ListViewScrollObserver(listView);
    // listView.setOnScrollListener(this);
    observer.setOnScrollUpAndDownListener(
        new OnListViewScrollListener() {
          @Override
          public void onScrollUpDownChanged(int delta, int scrollPosition, boolean exact) {
            onNewScroll(delta);
            snap(headerTop == scrollPosition);
          }

          @Override
          public void onScrollIdle() {
            QuickReturnHeaderHelper.this.onScrollIdle();
          }
        });

    root.addView(realHeader, realHeaderLayoutParams);

    dummyHeader = new View(context);
    AbsListView.LayoutParams params =
        new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, headerHeight);
    dummyHeader.setLayoutParams(params);
    listView.addHeaderView(dummyHeader);
  }
  private void initView(View layout) {
    lamp = layout.findViewById(R.id.v_lamp);
    menuLv = (ListView) layout.findViewById(R.id.lv_menu);
    subjectLv = (ListView) layout.findViewById(R.id.lv_subject);
    foldBtn = layout.findViewById(R.id.ll_title_sp);
    foldContent = layout.findViewById(R.id.ll_lv_sp);
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) foldBtn.getLayoutParams();
    lp.leftMargin = location[0];
    lp.topMargin = location[1];
    foldBtn.setLayoutParams(lp);
    foldBtn.setOnClickListener(this);
    lamp.setOnClickListener(this);
    menuAdapter = new DataAdapter(getActivity().getBaseContext());

    menuAdapter.setData(allocateData());
    menuLv.setAdapter(menuAdapter);
    menuLv.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            menuAdapter.checked(i);
            subjectAdapter.setData(allocateSubject());
            subjectAdapter.notifyDataSetChanged();
          }
        });
    subjectAdapter = new DataAdapter(getActivity().getBaseContext());
    subjectAdapter.checked(-1);
    subjectAdapter.setData(allocateSubject());
    subjectLv.setAdapter(subjectAdapter);
  }
Example #28
0
  public void addAvailableAddresses() {

    for (int i = 0; i < Constants.addressData.size(); i++) {

      rowView = layoutInflater.inflate(R.layout.include_available_address, null);
      LinearLayout.LayoutParams params =
          (LinearLayout.LayoutParams)
              new LinearLayout.LayoutParams(
                  LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      params.setMargins(0, 0, 0, 5);
      rowView.setLayoutParams(params);

      address = (CustomTextView) rowView.findViewById(R.id.address_text_included);
      address.setTag("address_" + i);
      address.setVisibility(View.VISIBLE);
      Log.d(
          Constants.LOG_TAG,
          " Setting the adress " + Constants.addressData.get(i).getFullAddress());
      address.setText(Constants.addressData.get(i).getFullAddress());
      address.setOnClickListener(inflatedViewListener);

      mobileNumber = (CustomTextView) rowView.findViewById(R.id.mobile_number_text_included);
      mobileNumber.setTag("number_" + i);
      mobileNumber.setVisibility(View.VISIBLE);
      Log.d(
          Constants.LOG_TAG,
          " Setting the mobile number " + Constants.addressData.get(i).getMobileNumber());
      mobileNumber.setText(Constants.addressData.get(i).getMobileNumber());
      mobileNumber.setOnClickListener(inflatedViewListener);

      selectAddressChild.addView(rowView);
    }
  }
  private void init() {
    Log.d(TAG, "call TwitterSelectUserItemView init");
    LayoutInflater factory = LayoutInflater.from(mContext);
    removeAllViews();

    // container
    FrameLayout view =
        (FrameLayout) FrameLayout.inflate(getContext(), R.layout.sns_container_normal, null);
    FrameLayout.LayoutParams paras =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    view.setLayoutParams(paras);
    view.setVerticalScrollBarEnabled(true);
    addView(view);

    // child 1
    View v = factory.inflate(R.layout.sns_user_select_item, null);
    v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    view.addView(v);

    chekbox = (CheckBox) v.findViewById(R.id.sns_user_select_checkbox);
    username = (TextView) v.findViewById(R.id.sns_user_name_item);
    chekbox.setOnClickListener(stOnClik);
    setUI();
  }
Example #30
0
  private void init(Context context) {
    inflater = LayoutInflater.from(context);
    view = inflater.inflate(R.layout.cs_message_about, null);
    LinearLayout.LayoutParams param_view =
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    param_view.leftMargin = DisplayManager.GetInstance().changeWidthSize(30);
    param_view.rightMargin = DisplayManager.GetInstance().changeWidthSize(30);
    param_view.topMargin = DisplayManager.GetInstance().changeWidthSize(20);
    view.setLayoutParams(param_view);
    version_title = (TextView) view.findViewById(R.id.version_title);
    version_content = (TextView) view.findViewById(R.id.version_content);
    help_title = (TextView) view.findViewById(R.id.help_title);
    help_title.setFocusable(true);
    help_title.setFocusableInTouchMode(true);
    help_content = (TextView) view.findViewById(R.id.help_content);

    version_title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE);
    version_content.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE);
    help_title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE);
    help_content.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE);

    version_title.setText("版本信息");
    version_content.setText("当前版本:" + Config.GetInstance().getVersionDisplayText());
    help_title.setText("使用帮助");
    addView(view);

    setContentData(getHelpContent(Config.OemType.getOemType(Config.GetInstance().getOemType())));
  }