コード例 #1
0
    /* (non-Javadoc)
     * manipulates the view for amount (setting expenses to red) and
     * category (indicate transfer direction with => or <=
     * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      convertView = super.getView(position, convertView, parent);
      ViewHolder viewHolder = (ViewHolder) convertView.getTag();
      TextView tv1 = viewHolder.amount;
      Cursor c = getCursor();
      c.moveToPosition(position);
      if (mAccount.getId() < 0) {
        int color = c.getInt(c.getColumnIndex("color"));
        viewHolder.colorAccount.setBackgroundColor(color);
      }
      long amount = c.getLong(columnIndexAmount);
      setColor(tv1, amount < 0);
      TextView tv2 = viewHolder.category;
      CharSequence catText = tv2.getText();
      if (DbUtils.getLongOrNull(c, columnIndexTransferPeer) != null) {
        catText = ((amount < 0) ? "=> " : "<= ") + catText;
      } else {
        Long catId = DbUtils.getLongOrNull(c, KEY_CATID);
        if (SPLIT_CATID.equals(catId)) catText = getString(R.string.split_transaction);
        else if (catId == null) {
          catText = getString(R.string.no_category_assigned);
        } else {
          String label_sub = c.getString(columnIndexLabelSub);
          if (label_sub != null && label_sub.length() > 0) {
            catText = catText + categorySeparator + label_sub;
          }
        }
      }
      String referenceNumber = c.getString(columnIndexReferenceNumber);
      if (referenceNumber != null && referenceNumber.length() > 0)
        catText = "(" + referenceNumber + ") " + catText;
      SpannableStringBuilder ssb;
      String comment = c.getString(columnIndexComment);
      if (comment != null && comment.length() > 0) {
        ssb = new SpannableStringBuilder(comment);
        ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, comment.length(), 0);
        catText = TextUtils.concat(catText, commentSeparator, ssb);
      }
      String payee = c.getString(columnIndexPayee);
      if (payee != null && payee.length() > 0) {
        ssb = new SpannableStringBuilder(payee);
        ssb.setSpan(new UnderlineSpan(), 0, payee.length(), 0);
        catText = TextUtils.concat(catText, commentSeparator, ssb);
      }
      tv2.setText(catText);

      if (!mAccount.type.equals(Type.CASH)) {
        CrStatus status;
        try {
          status = CrStatus.valueOf(c.getString(columnIndexCrStatus));
        } catch (IllegalArgumentException ex) {
          status = CrStatus.UNRECONCILED;
        }
        viewHolder.color1.setBackgroundColor(status.color);
        viewHolder.colorContainer.setTag(status == CrStatus.RECONCILED ? -1 : getItemId(position));
      }
      return convertView;
    }
コード例 #2
0
 private void configureMenuInternal(Menu menu, int position) {
   if (mTransactionsCursor != null) {
     // templates for splits is not yet implemented
     if (mTransactionsCursor.moveToPosition(position)
         && SPLIT_CATID.equals(DbUtils.getLongOrNull(mTransactionsCursor, KEY_CATID)))
       menu.findItem(R.id.CREATE_TEMPLATE_COMMAND).setVisible(false);
   }
 }