Exemplo n.º 1
0
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    RideCursor c = (RideCursor) cursor;

    // Title (name / date)
    TextView txtTitle = ViewHolder.get(view, R.id.txtTitle);
    String name = c.getName();
    long createdDateLong = c.getCreatedDate().getTime();
    String createdDateTimeStr =
        DateUtils.formatDateTime(
            context, createdDateLong, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    if (name == null) {
      txtTitle.setText(createdDateTimeStr);
    } else {
      txtTitle.setText(name + "\n" + createdDateTimeStr);
    }

    // Summary
    TextView txtSummary = ViewHolder.get(view, R.id.txtSummary);
    CharSequence details = null;
    Animator animator = (Animator) view.getTag(R.id.animator);
    // Cancel the animation / reset the alpha in any case
    if (animator != null) animator.cancel();
    txtSummary.setAlpha(1);
    RideState rideState = c.getState();
    switch (rideState) {
      case CREATED:
        details = context.getString(R.string.ride_list_notStarted);
        txtSummary.setTextColor(mColorDefault);
        txtSummary.setEnabled(false);
        break;

      case ACTIVE:
        details = context.getString(R.string.ride_list_active);
        if (animator == null) {
          animator = AnimatorInflater.loadAnimator(context, R.animator.blink);
          animator.setTarget(txtSummary);
          view.setTag(R.id.animator, animator);
        }
        animator.start();
        txtSummary.setTextColor(mColorActive);
        txtSummary.setEnabled(true);
        break;

      case PAUSED:
        // Distance
        float distance = c.getDistance();
        details = TextUtils.concat(UnitUtil.formatDistance(distance, true, .85f, false), "  -  ");

        // Duration
        long duration = c.getDuration();
        details = TextUtils.concat(details, DateTimeUtil.formatDuration(context, duration));
        txtSummary.setTextColor(mColorDefault);
        txtSummary.setEnabled(true);
        break;
    }
    txtSummary.setText(details);
  }