コード例 #1
0
ファイル: Utils.java プロジェクト: dazlee/WorkFlowAndroid
  /**
   * Set the style of TextView according to the status of a task
   *
   * @param context
   * @param status
   * @param task
   */
  public static void setTaskStatusForTextView(Context context, TextView status, Task task) {
    status.setText(Task.getTaskStatusString(context, task));

    switch (task.status) {
      case IN_REVIEW:
        status.setTextColor(context.getResources().getColor(R.color.task_card_status_text_color));
        status.setBackgroundResource(R.drawable.task_card_status_in_review_background);
        break;

      case WIP:
        status.setTextColor(context.getResources().getColor(R.color.task_card_status_text_color));
        status.setBackgroundResource(R.drawable.task_card_status_wip_background);
        break;

      case PENDING:
        status.setTextColor(context.getResources().getColor(R.color.task_card_status_text_color));
        status.setBackgroundResource(R.drawable.task_card_status_pending_background);
        break;

      case UNCLAIMED:
        status.setTextColor(context.getResources().getColor(R.color.task_card_status_text_color));
        status.setBackgroundResource(R.drawable.task_card_status_unclaimed_background);
        break;

      case WARNING:
        status.setTextColor(context.getResources().getColor(R.color.task_card_status_text_color));
        status.setBackgroundResource(R.drawable.task_card_status_warning_background);
        break;

      case DONE:
        status.setTextColor(
            context.getResources().getColor(R.color.task_card_status_done_text_color));
        status.setBackground(null);
        break;
    }
  }
コード例 #2
0
ファイル: Utils.java プロジェクト: dazlee/WorkFlowAndroid
  public static void setTaskItemWarningTextView(
      final Activity activity, final Task item, final TextView v, boolean hasClickListener) {
    if (item.taskWarnings.size() == 0) {
      v.setVisibility(View.GONE);
      return;
    }

    String displayTxt = "";
    int txtColor;
    Drawable background;
    int unSolvedCount = item.getUnSolvedWarningCount();
    int solvedCount = item.taskWarnings.size() - item.getUnSolvedWarningCount();
    if (unSolvedCount > 1) {
      displayTxt =
          activity.getResources().getString(R.string.overview_display_warning_txt, unSolvedCount);
    } else if (solvedCount > 1) {
      displayTxt =
          activity.getResources().getString(R.string.overview_display_warning_txt, solvedCount);
    } else {
      TaskWarning tmp = null;
      for (TaskWarning taskWarning : item.taskWarnings) {
        if (tmp == null) {
          tmp = taskWarning;
        } else {
          if (tmp.status == TaskWarning.Status.CLOSED
              && taskWarning.status == TaskWarning.Status.OPENED) {
            tmp = taskWarning;
          }
        }
        displayTxt = tmp.name;
      }
    }
    if (unSolvedCount > 0) {
      txtColor = activity.getResources().getColor(R.color.red);
      background = activity.getResources().getDrawable(R.drawable.border_textview_bg_red, null);
    } else {
      txtColor = activity.getResources().getColor(R.color.gray1);
      background = activity.getResources().getDrawable(R.drawable.border_textview_bg_gray, null);
    }
    v.setTextColor(txtColor);
    v.setText(displayTxt);
    v.setBackground(background);
    if (hasClickListener && item.taskWarnings.size() > 1) {
      v.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              View view =
                  activity
                      .getLayoutInflater()
                      .inflate(R.layout.warning_list_container_layout, null);
              LinearLayout root = (LinearLayout) view.findViewById(R.id.warning_list_container);
              for (TaskWarning taskWarning : item.taskWarnings) {
                TextView tv =
                    (TextView)
                        activity
                            .getLayoutInflater()
                            .inflate(R.layout.warning_textview_layout, null);
                setTaskItemWarningTextView(activity, taskWarning, tv);
                LinearLayout.LayoutParams params =
                    new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
                params.leftMargin =
                    (int)
                        activity.getResources().getDimension(R.dimen.ov_warning_margin_horizontal);
                params.rightMargin =
                    (int)
                        activity.getResources().getDimension(R.dimen.ov_warning_margin_horizontal);
                root.addView(tv, params);
              }
              final PopupWindow popup =
                  new PopupWindow(
                      view,
                      LinearLayout.LayoutParams.WRAP_CONTENT,
                      LinearLayout.LayoutParams.WRAP_CONTENT);
              popup.setBackgroundDrawable(new BitmapDrawable());
              popup.setOutsideTouchable(true);
              int[] locations = new int[2];
              v.getLocationOnScreen(locations);
              view.measure(
                  View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                  View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
              popup.showAtLocation(
                  v,
                  Gravity.NO_GRAVITY,
                  locations[0] + v.getMeasuredWidth() - view.getMeasuredWidth(),
                  locations[1] - view.getMeasuredHeight());
            }
          });
    }
  }