/** Config UI just one time */
  private void configUI() {
    setOrientation(LinearLayout.VERTICAL);
    setPadding(8, 8, 8, 8);

    TextView titleView = new TextView(ctx);
    titleView.setText(TEXT_TITLE);
    titleView.setTextColor(Color.LTGRAY);
    addView(titleView);

    LinearLayout subLayout = new LinearLayout(ctx);
    subLayout.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams subLayoutParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // configuring the iconView
    iconView.setImageDrawable(icon);
    LayoutParams icParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    icParams.gravity = Gravity.CENTER_VERTICAL;

    // configuring the msgView
    msgView.setText(msg);
    msgView.setPadding(10, 0, 0, 0);
    msgView.setTextSize(20);
    msgView.setTextColor(Color.WHITE);
    msgView.setGravity(Gravity.CENTER_VERTICAL);
    msgView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    msgView.setMaxLines(1);
    LayoutParams tvParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    subLayout.addView(iconView, icParams);
    subLayout.addView(msgView, tvParams);

    addView(subLayout, subLayoutParams);

    actionBtn.setText(TEXT_DELETE);
    actionBtn.setTextColor(Color.WHITE);
    addView(actionBtn, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    undoRedoLayout.setOrientation(LinearLayout.HORIZONTAL);
    undoView = new ImageView(ctx);
    redoView = new ImageView(ctx);
    undoView.setImageDrawable(DrawableFactory.build(ctx, DrawableFactory.ICON_UNDO));
    redoView.setImageDrawable(DrawableFactory.build(ctx, DrawableFactory.ICON_REDO));
    undoView.setClickable(true);
    redoView.setClickable(true);
    LayoutParams undoRedoParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    undoRedoParams.weight = 1;
    undoRedoLayout.addView(undoView, undoRedoParams);
    undoRedoLayout.addView(redoView, undoRedoParams);
    addView(undoRedoLayout);
  }
Example #2
0
  public LoadingLayout(
      Context context,
      final PullToRefreshBase.Mode mode,
      final PullToRefreshBase.Orientation scrollDirection,
      TypedArray attrs) {
    super(context);
    mMode = mode;
    mScrollDirection = scrollDirection;

    switch (scrollDirection) {
      case HORIZONTAL:
        LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_horizontal, this);
        break;
      case VERTICAL:
      default:
        LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_vertical, this);
        break;
    }

    mInnerLayout = (LinearLayout) findViewById(R.id.ll_inner);
    mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
    mHeaderProgress = (ProgressBar) mInnerLayout.findViewById(R.id.pull_to_refresh_progress);
    mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);
    mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image);

    LayoutParams lp = (LayoutParams) mInnerLayout.getLayoutParams();

    switch (mode) {
      case PULL_FROM_END:
        lp.gravity =
            scrollDirection == PullToRefreshBase.Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
        break;

      case PULL_FROM_START:
      default:
        lp.gravity =
            scrollDirection == PullToRefreshBase.Orientation.VERTICAL
                ? Gravity.BOTTOM
                : Gravity.RIGHT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
        break;
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
      Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
      if (null != background) {
        ViewCompat.setBackground(this, background);
      }
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) {
      TypedValue styleID = new TypedValue();
      attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
      setTextAppearance(styleID.data);
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) {
      TypedValue styleID = new TypedValue();
      attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
      setSubTextAppearance(styleID.data);
    }

    // Text Color attrs need to be set after TextAppearance attrs
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
      ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
      if (null != colors) {
        setTextColor(colors);
      }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
      ColorStateList colors =
          attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
      if (null != colors) {
        setSubTextColor(colors);
      }
    }

    // Try and get defined drawable from Attrs
    Drawable imageDrawable = null;
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) {
      imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable);
    }

    // Check Specific Drawable from Attrs, these overrite the generic
    // drawable attr above
    switch (mode) {
      case PULL_FROM_START:
      default:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
          Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
        }
        break;

      case PULL_FROM_END:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
          Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
          imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
        }
        break;
    }

    // If we don't have a user defined drawable, load the default
    if (null == imageDrawable) {
      imageDrawable = context.getResources().getDrawable(getDefaultDrawableResId());
    }

    // Set Drawable, and save width/height
    setLoadingDrawable(imageDrawable);

    reset();
  }