Beispiel #1
0
  public <T> void setCurrencyText(TextView textView, T currency) {

    if (currency instanceof Double) {
      if (textView instanceof CountTextView) {
        ((CountTextView) textView).setCountText(Methods.currencyFormat((Double) currency));
      } else {
        textView.setText(Methods.currencyFormat((Double) currency));
      }
    } else if (currency instanceof String) {
      if (TextUtils.isEmpty((String) currency)) {
        textView.setText("");
        return;
      }
      try {
        if (textView instanceof CountTextView) {
          ((CountTextView) textView)
              .setCountText(Methods.currencyFormat(Double.parseDouble((String) currency)));
        } else {
          textView.setText(Methods.currencyFormat(Double.parseDouble((String) currency)));
        }
      } catch (NumberFormatException e) {
        if (textView instanceof CountTextView) {
          ((CountTextView) textView).setCountText((String) currency);
        } else {
          textView.setText((String) currency);
        }
      }
    } else {
      textView.setText("");
    }
  }
Beispiel #2
0
 public <T> void setCurrencyColorText(
     TextView textView, T currency, String suffix, int type, boolean isAdjustTextSize) {
   int color = 0;
   switch (type) {
     case 0:
       color = R.color.common_white;
       break;
     case 1:
       color = R.color.common_orange_text;
       break;
     case 2:
       color = R.color.common_black_text;
       break;
     default:
       color = R.color.common_white;
       break;
   }
   if (currency instanceof Double) {
     if ((Double) currency > 0) {
       textView.setTextColor(getResources().getColor(color));
     } else if ((Double) currency < 0) {
       textView.setTextColor(getResources().getColor(R.color.common_green_text));
     }
     if (textView instanceof CountTextView && isAdjustTextSize) {
       ((CountTextView) textView).setCountText(Methods.currencyFormat((Double) currency) + suffix);
     } else {
       textView.setText(Methods.currencyFormat((Double) currency) + suffix);
     }
   } else if (currency instanceof String) {
     if (TextUtils.isEmpty((String) currency)) {
       textView.setText("");
       return;
     }
     try {
       double value = Double.parseDouble((String) currency);
       if (value > 0) {
         textView.setTextColor(getResources().getColor(color));
       } else if (value < 0) {
         textView.setTextColor(getResources().getColor(R.color.common_green_text));
       }
       if (textView instanceof CountTextView && isAdjustTextSize) {
         ((CountTextView) textView).setCountText(Methods.currencyFormat(value) + suffix);
       } else {
         textView.setText(Methods.currencyFormat(value) + suffix);
       }
     } catch (NumberFormatException e) {
       if (textView instanceof CountTextView) {
         ((CountTextView) textView).setCountText(currency + suffix);
       } else {
         textView.setText(currency + suffix);
       }
     }
   } else {
     textView.setText("");
   }
 }