Ejemplo n.º 1
0
 /** 全选 */
 public void selectAll(View view) {
   for (TaskInfo info : userTaskInfos) {
     if (info.getPackname().equals(getPackageName())) {
       continue;
     }
     info.setChecked(true);
   }
   for (TaskInfo info : systemTaskInfos) {
     info.setChecked(true);
   }
   adapter.notifyDataSetChanged(); // 通知界面更新
 }
Ejemplo n.º 2
0
  /** 杀死选中的进程 */
  public void killAll(View view) {
    int total = 0;
    long savedMem = 0;
    List<TaskInfo> killedTaskInfos = new ArrayList<TaskInfo>();
    for (TaskInfo info : userTaskInfos) {
      if (info.isChecked()) {
        am.killBackgroundProcesses(info.getPackname());
        total++;
        savedMem += info.getMemsize();
        // userTaskInfos.remove(info);
        killedTaskInfos.add(info);
      }
    }
    for (TaskInfo info : systemTaskInfos) {
      if (info.isChecked()) {
        am.killBackgroundProcesses(info.getPackname());
        total++;
        savedMem += info.getMemsize();
        // systemTaskInfos.remove(info);
        killedTaskInfos.add(info);
      }
    }

    for (TaskInfo info : killedTaskInfos) {
      if (info.isUserTask()) {
        userTaskInfos.remove(info);
      } else {
        systemTaskInfos.remove(info);
      }
    }

    // 给用户一个土司提醒 告诉用户你干了什么事情。
    Toast.makeText(
            this, "杀死了" + total + "个进程,释放了" + Formatter.formatFileSize(this, savedMem) + "的内存", 1)
        .show();
    runningProcessCount -= total;
    availRam += savedMem;
    tv_process_count.setText("运行中进程:" + runningProcessCount + "个");
    tv_mem_info.setText(
        "剩余/总内存:"
            + Formatter.formatFileSize(this, availRam)
            + "/"
            + Formatter.formatFileSize(this, totalRam));
    adapter.notifyDataSetChanged();
  }
Ejemplo n.º 3
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   TaskInfo taskInfo;
   if (position == 0) {
     TextView tv = new TextView(getApplicationContext());
     tv.setTextColor(Color.WHITE);
     tv.setBackgroundColor(Color.GRAY);
     tv.setText("用户进程(" + userTaskInfos.size() + ")");
     return tv;
   } else if (position == (userTaskInfos.size() + 1)) {
     TextView tv = new TextView(getApplicationContext());
     tv.setTextColor(Color.WHITE);
     tv.setBackgroundColor(Color.GRAY);
     tv.setText("系统进程(" + systemTaskInfos.size() + ")");
     return tv;
   } else if (position <= userTaskInfos.size()) {
     taskInfo = userTaskInfos.get(position - 1);
   } else {
     taskInfo = systemTaskInfos.get(position - 1 - userTaskInfos.size() - 1);
   }
   View view;
   ViewHolder holder;
   if (convertView != null && convertView instanceof RelativeLayout) {
     view = convertView;
     holder = (ViewHolder) view.getTag();
   } else {
     view = View.inflate(getApplicationContext(), R.layout.list_task_item, null);
     holder = new ViewHolder();
     holder.iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
     holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
     holder.tv_memsize = (TextView) view.findViewById(R.id.tv_memsize);
     holder.cb = (CheckBox) view.findViewById(R.id.cb);
     view.setTag(holder);
   }
   holder.iv_icon.setImageDrawable(taskInfo.getIcon());
   holder.tv_name.setText(taskInfo.getName());
   holder.tv_memsize.setText(
       Formatter.formatFileSize(getApplicationContext(), taskInfo.getMemsize()));
   holder.cb.setChecked(taskInfo.isChecked());
   if (taskInfo.getPackname().equals(getPackageName())) {
     holder.cb.setVisibility(View.INVISIBLE);
   } else {
     holder.cb.setVisibility(View.VISIBLE);
   }
   return view;
 }