예제 #1
0
  /**
   * Sets the adapter of ContentAdapter to this view for displaying contents
   *
   * @param adapter
   */
  public void setAdapter(ContentAdapter adapter) {
    mContentAdapter = adapter;
    mContentAdapter.mSubjectView = this;
    mContentWrapper.setAdapter(mContentAdapter);

    /** update avatar by confusing all subject's image */
    Debug.dumpLog(TAG, "adapter is confusing the select content because a new adapter is assigned");
    mContentAdapter.confuseSelectContent();
  }
예제 #2
0
  /**
   * Sets the layout align of subject of this view, the align has four places are left, top, right ,
   * and bottom
   *
   * @param align
   */
  public void setSubjectAlign(int align) {
    if (align != SUBJECT_ALIGN_LEFT
        && align != SUBJECT_ALIGN_TOP
        && align != SUBJECT_ALIGN_RIGHT
        && align != SUBJECT_ALIGN_BOTTOM) return;

    Debug.dumpLog(TAG, "sets layout params for resetting align of subject toolbar");

    int subjectScrollerId = 0;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
      subjectScrollerId = GenerateIntID.generateViewId();
    else subjectScrollerId = View.generateViewId();

    FrameLayout subjectScroller = null;
    ScrollView.LayoutParams subjectWrapperLp = null;
    RelativeLayout.LayoutParams subjectScrollerLp = null;
    RelativeLayout.LayoutParams contentWrapperLp = null;
    switch (align) {
      case SUBJECT_ALIGN_LEFT:
        subjectScroller = new ScrollView(getContext());
        mSubjectWrapper.setOrientation(LinearLayout.VERTICAL);
        subjectWrapperLp =
            new ScrollView.LayoutParams(
                ScrollView.LayoutParams.WRAP_CONTENT, ScrollView.LayoutParams.MATCH_PARENT);
        subjectScrollerLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
        subjectScrollerLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        contentWrapperLp =
            new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        contentWrapperLp.addRule(RIGHT_OF, subjectScrollerId);
        break;
      case SUBJECT_ALIGN_TOP:
        subjectScroller = new HorizontalScrollView(getContext());
        mSubjectWrapper.setOrientation(LinearLayout.HORIZONTAL);
        subjectWrapperLp =
            new ScrollView.LayoutParams(
                ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.WRAP_CONTENT);
        subjectScrollerLp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        subjectScrollerLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        subjectScrollerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        contentWrapperLp =
            new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        contentWrapperLp.addRule(RelativeLayout.BELOW, subjectScrollerId);
        break;
      case SUBJECT_ALIGN_RIGHT:
        subjectScroller = new ScrollView(getContext());
        mSubjectWrapper.setOrientation(LinearLayout.VERTICAL);
        subjectWrapperLp =
            new ScrollView.LayoutParams(
                ScrollView.LayoutParams.WRAP_CONTENT, ScrollView.LayoutParams.MATCH_PARENT);
        subjectScrollerLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
        subjectScrollerLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        contentWrapperLp =
            new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        contentWrapperLp.addRule(LEFT_OF, subjectScrollerId);
        break;
      case SUBJECT_ALIGN_BOTTOM:
        subjectScroller = new HorizontalScrollView(getContext());
        mSubjectWrapper.setOrientation(LinearLayout.HORIZONTAL);
        subjectWrapperLp =
            new ScrollView.LayoutParams(
                ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.WRAP_CONTENT);
        subjectScrollerLp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        subjectScrollerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        contentWrapperLp =
            new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        contentWrapperLp.addRule(ABOVE, subjectScrollerId);
        break;
    }

    do {
      if (subjectScroller == null) break;
      if (subjectWrapperLp == null) break;
      if (subjectScrollerLp == null) break;
      if (contentWrapperLp == null) break;

      // release
      if (mSubjectScrollView != null) mSubjectScrollView.removeAllViews();

      // adjust layout
      mSubjectScrollView = subjectScroller;
      mSubjectScrollView.setId(subjectScrollerId);
      mSubjectWrapper.setLayoutParams(subjectWrapperLp);
      mSubjectScrollView.addView(mSubjectWrapper);
      mSubjectScrollView.setLayoutParams(subjectScrollerLp);
      this.addView(mSubjectScrollView);
      mContentWrapper.setLayoutParams(contentWrapperLp);
      if (mContentWrapper.getParent() == null) this.addView(mContentWrapper);

      mSubjectAlign = align;
      this.invalidate();

      Debug.dumpLog(TAG, "resets subject toolbar success");
    } while (false);
  }