/**
  * 创建消息回忆的ViewHolder.
  *
  * @param view each_message_view
  */
 public MessageViewHolder(CardView view) {
   super(view);
   cardView = view;
   icon = (ImageView) cardView.findViewById(R.id.personIVMessageView);
   name = (TextView) cardView.findViewById(R.id.nameTVMessageView);
   time = (TextView) cardView.findViewById(R.id.timeTVMessageView);
   message = (TextView) cardView.findViewById(R.id.messageTVMessageView);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle("Impostazioni");
    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    LinearLayout container = new LinearLayout(this);
    container.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    container.setOrientation(LinearLayout.VERTICAL);

    NestedScrollView scrollView = new NestedScrollView(this);
    scrollView.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    scrollView.addView(container);

    headers = new ArrayList();
    onInit();

    // Start parsing and creating the layout
    for (SettingHeader header : headers) {
      CardView headerCard =
          (CardView) LayoutInflater.from(this).inflate(R.layout.settings_header, null);
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      params.setMargins(0, 0, 0, 10);
      headerCard.setLayoutParams(params);

      TextView headerTitle = (TextView) headerCard.findViewById(R.id.headerTitle);
      StaticHeightListView inputsContainer =
          (StaticHeightListView) headerCard.findViewById(R.id.inputContainer);

      headerTitle.setText(header.title);

      inputsContainer.setAdapter(new SettingInputAdapter(this, header.inputs));

      container.addView(headerCard);
    }

    setContentView(scrollView);
  }
 /**
  * 创建图片回忆的ViewHolder.
  *
  * @param view each_picture_view
  */
 public PictureViewHolder(CardView view) {
   super(view);
   view.setOnClickListener(new PictureClickListener());
   placeTv = (TextView) view.findViewById(R.id.titleTVArticleView);
   timeTv = (TextView) view.findViewById(R.id.timeTVArticleView);
   imageView = (ImageView) view.findViewById(R.id.imageView);
   nine = new ImageView[9];
   nine[0] = (ImageView) view.findViewById(R.id.small_1);
   nine[1] = (ImageView) view.findViewById(R.id.small_2);
   nine[2] = (ImageView) view.findViewById(R.id.small_3);
   nine[3] = (ImageView) view.findViewById(R.id.small_4);
   nine[4] = (ImageView) view.findViewById(R.id.small_5);
   nine[5] = (ImageView) view.findViewById(R.id.small_6);
   nine[6] = (ImageView) view.findViewById(R.id.small_7);
   nine[7] = (ImageView) view.findViewById(R.id.small_8);
   nine[8] = (ImageView) view.findViewById(R.id.small_9);
 }
 /**
  * 创建文章回忆的ViewHolder.
  *
  * @param view each_article_view
  */
 public ArticleViewHolder(CardView view) {
   super(view);
   title = (TextView) view.findViewById(R.id.titleTVArticleView);
   time = (TextView) view.findViewById(R.id.timeTVArticleView);
   article = (TextView) view.findViewById(R.id.articleTVArticleView);
 }
 @Override
 public void refresh() {
   FrameLayout tasksView = (FrameLayout) getActivity().findViewById(R.id.scheduler_tasks);
   // the view might have been destroyed, in which case we don't do anything
   if (tasksView != null) {
     float density = getActivity().getResources().getDisplayMetrics().density;
     SimpleArrayMap<String, TaskTracker> tasks = mTasks.getTasks();
     LinearLayout tasksList = new LinearLayout(getActivity());
     tasksList.setOrientation(LinearLayout.VERTICAL);
     for (int i = 0; i < tasks.size(); i++) {
       final TaskTracker task = tasks.valueAt(i);
       CardView taskCard =
           (CardView)
               getActivity().getLayoutInflater().inflate(R.layout.widget_task, tasksList, false);
       ImageView taskIcon = (ImageView) taskCard.findViewById(R.id.task_icon);
       taskIcon.setImageResource(R.drawable.check_circle_grey600);
       taskIcon.setPadding(0, 0, (int) (8 * density), 0);
       TextView taskLabel = (TextView) taskCard.findViewById(R.id.task_title);
       TextView taskParams = (TextView) taskCard.findViewById(R.id.task_params);
       if (task.period == 0) {
         taskLabel.setText(getString(R.string.scheduler_oneoff, task.tag));
         taskParams.setText(
             getString(
                 R.string.scheduler_oneoff_params,
                 task.windowStartElapsedSecs,
                 task.windowStopElapsedSecs));
       } else {
         taskLabel.setText(getString(R.string.scheduler_periodic, task.tag));
         taskParams.setText(getString(R.string.scheduler_periodic_params, task.period, task.flex));
       }
       TextView taskCreatedAt = (TextView) taskCard.findViewById(R.id.task_created_at);
       taskCreatedAt.setText(
           getString(
               R.string.scheduler_secs_ago,
               DateUtils.formatElapsedTime(
                   SystemClock.elapsedRealtime() / 1000 - task.createdAtElapsedSecs)));
       TextView lastExecuted = (TextView) taskCard.findViewById(R.id.task_last_exec);
       if (task.executionTimes.isEmpty()) {
         lastExecuted.setText(getString(R.string.scheduler_na));
       } else {
         long lastExecTime = task.executionTimes.get(task.executionTimes.size() - 1);
         lastExecuted.setText(
             getString(
                 R.string.scheduler_secs_ago,
                 DateUtils.formatElapsedTime(
                     SystemClock.elapsedRealtime() / 1000 - lastExecTime)));
       }
       TextView state = (TextView) taskCard.findViewById(R.id.task_state);
       if (task.isCancelled()) {
         state.setText(getString(R.string.scheduler_cancelled));
       } else if (task.isExecuted()) {
         state.setText(getString(R.string.scheduler_executed));
       } else {
         state.setText(getString(R.string.scheduler_pending));
       }
       Button cancel = (Button) taskCard.findViewById(R.id.task_cancel);
       cancel.setVisibility(View.VISIBLE);
       cancel.setText(R.string.scheduler_cancel);
       Button delete = (Button) taskCard.findViewById(R.id.task_delete);
       delete.setVisibility(View.VISIBLE);
       delete.setText(R.string.scheduler_delete);
       if (!task.isCancelled() && (!task.isExecuted() || task.period != 0)) {
         cancel.setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View view) {
                 cancelTask(task.tag);
                 refresh();
               }
             });
         cancel.setEnabled(true);
         delete.setEnabled(false);
       } else {
         cancel.setEnabled(false);
         delete.setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View view) {
                 mTasks.deleteTask(task.tag);
                 refresh();
               }
             });
         delete.setEnabled(true);
       }
       tasksList.addView(taskCard);
     }
     tasksView.removeAllViews();
     tasksView.addView(tasksList);
   }
 }