示例#1
0
  public void bindRawText(CharSequence rawText, Message message, boolean isItalic) {
    if (message.getSenderId() == myUid()) {
      messageBubble.setBackgroundResource(R.drawable.bubble_text_out);
    } else {
      messageBubble.setBackgroundResource(R.drawable.bubble_text_in);
    }

    if (isItalic) {
      text.setTypeface(Fonts.italic());
    } else {
      text.setTypeface(Fonts.regular());
    }

    text.setText(rawText);

    // Fixing url long tap
    text.setMovementMethod(new CustomLinkMovementMethod());

    // Fixing span offsets
    //        if (rawText instanceof Spannable) {
    //            Spannable s = (Spannable) rawText;
    //            QuoteSpan[] qSpans = s.getSpans(0, s.length(), QuoteSpan.class);
    //            text.setMinimumWidth(0);
    //            if (qSpans.length > 0) {
    //                text.measure(0, 0);
    //                text.setMinimumWidth(text.getMeasuredWidth() +
    // qSpans[0].getLeadingMargin(true));
    //            }
    //        }

    if (message.getSenderId() == myUid()) {
      status.setVisibility(View.VISIBLE);

      switch (message.getMessageState()) {
        case SENT:
          status.setResource(R.drawable.msg_check_1);
          status.setTint(sentColor);
          break;
        case RECEIVED:
          status.setResource(R.drawable.msg_check_2);
          status.setTint(deliveredColor);
          break;
        case READ:
          status.setResource(R.drawable.msg_check_2);
          status.setTint(readColor);
          break;
        default:
        case PENDING:
          status.setResource(R.drawable.msg_clock);
          status.setTint(waitColor);
          break;
        case ERROR:
          status.setResource(R.drawable.msg_error);
          status.setTint(errorColor);
          break;
      }
    } else {
      status.setVisibility(View.GONE);
    }

    time.setText(Strings.formatTime(message.getDate()));
  }
  private void addFields(
      FrameLayout container, ActorSettingsField[] fields, LayoutInflater inflater) {
    Context context = getActivity();
    LinearLayout ll = new LinearLayout(getActivity());
    ll.setOrientation(LinearLayout.VERTICAL);
    container.addView(
        ll, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);

    for (ActorSettingsField field : fields) {
      if (field.getView() != null) {
        View view = field.getView();
        ll.addView(
            view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      } else {
        LinearLayout fieldLayout =
            (LinearLayout) inflater.inflate(R.layout.actor_settings_field, null);
        TintImageView icon = (TintImageView) fieldLayout.findViewById(R.id.icon);
        icon.setTint(ActorSDK.sharedActor().style.getSettingsIconColor());
        TextView name = (TextView) fieldLayout.findViewById(R.id.name);
        name.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor());
        View rightView = field.getRightView();

        // Icon
        if (field.getIconResourceId() != 0) {
          icon.setResource(field.getIconResourceId());
          if (field.getIconColor() != -1) {
            icon.setTint(field.getIconColor());
          }
        } else {
          icon.setVisibility(View.INVISIBLE);
        }
        // Name
        if (field.getName() != null) {
          name.setText(field.getName());
        } else {
          name.setVisibility(View.GONE);
        }
        // Right view
        if (rightView != null) {
          fieldLayout.addView(
              rightView,
              LinearLayout.LayoutParams.WRAP_CONTENT,
              LinearLayout.LayoutParams.WRAP_CONTENT);
        }
        // Click
        if (field.getOnclickListener() != null) {
          fieldLayout.setOnClickListener(field.getOnclickListener());
        }
        // Field
        ll.addView(
            fieldLayout,
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
      }
      // Divider
      if (field.addBottomDivider()) {
        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
        params.leftMargin = Screen.dp(72);
        params.rightMargin = Screen.dp(16);
        View divider = inflater.inflate(R.layout.actor_settings_divider, null);
        divider.setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
        ll.addView(divider, params);
      }
    }
  }