Ejemplo n.º 1
0
 @Nullable
 private TxMessage getTxMessage() {
   if (isTxMessageAdded && messageFactory != null && txMessageView.getText().length() != 0) {
     String message = txMessageView.getText().toString();
     try {
       return messageFactory.createPublicMessage(message);
     } catch (Exception e) { // Should not happen
       ACRA.getErrorReporter().handleSilentException(e);
     }
   }
   return null;
 }
Ejemplo n.º 2
0
 private void validateTxMessage() {
   if (isTxMessageAdded && messageFactory != null && txMessageView != null) {
     isTxMessageValid = txMessageView.getText().length() <= messageFactory.maxMessageSize();
     updateView();
   }
 }
Ejemplo n.º 3
0
  private void enableTxMessage(View view) {
    if (messageFactory == null) return;

    txMessageButton.setVisibility(View.VISIBLE);
    txMessageButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (isTxMessageAdded) { // if tx message added, remove it
              hideTxMessage();
            } else { // else show tx message fields
              showTxMessage();
            }
          }
        });

    final int maxMessageLength = messageFactory.maxMessageSize();
    final int messageLengthThreshold = (int) (maxMessageLength * .8); // 80% full
    final int txMessageCounterPaddingOriginal = txMessageView.getPaddingBottom();
    final int txMessageCounterPadding =
        getResources().getDimensionPixelSize(R.dimen.tx_message_counter_padding);
    final int colorWarn = getResources().getColor(R.color.fg_warning);
    final int colorError = getResources().getColor(R.color.fg_error);

    // This listener checks the length of the message and displays a counter if it passes a
    // threshold or the max size. It also changes the bottom padding of the message field
    // to accommodate the counter.
    txMessageView.addTextChangedListener(
        new EditViewListener() {
          @Override
          public void afterTextChanged(final Editable s) {
            int length = s.length();
            boolean isTxMessageValidNow = true;
            if (length < messageLengthThreshold) {
              if (txMessageCounter.getVisibility() != GONE) {
                txMessageCounter.setVisibility(GONE);
                txMessageView.setPadding(0, 0, 0, txMessageCounterPaddingOriginal);
              }
            } else {
              int remaining = maxMessageLength - s.length();
              if (txMessageCounter.getVisibility() != VISIBLE) {
                txMessageCounter.setVisibility(VISIBLE);
                txMessageView.setPadding(0, 0, 0, txMessageCounterPadding);
              }
              txMessageCounter.setText(Integer.toString(remaining));
              if (length <= maxMessageLength) {
                txMessageCounter.setTextColor(colorWarn);
              } else {
                isTxMessageValidNow = false;
                txMessageCounter.setTextColor(colorError);
              }
            }
            // Update view only if the message validity changed
            if (isTxMessageValid != isTxMessageValidNow) {
              isTxMessageValid = isTxMessageValidNow;
              updateView();
            }
          }

          @Override
          public void onFocusChange(final View v, final boolean hasFocus) {
            if (!hasFocus) {
              validateTxMessage();
            }
          }
        });
  }