/** Generate and update all UI elements */
  private void updateView(
      LinearLayout uiStatesView,
      CpuSpyApp cpuSpyApp,
      CardViewItem.DCardView frequencyCard,
      CardViewItem.DCardView uptimeCard,
      CardViewItem.DCardView additionalCard) {
    if (!isAdded()) return;
    /**
     * Get the CpuStateMonitor from the app, and iterate over all states, creating a row if the
     * duration is > 0 or otherwise marking it in extraStates (missing)
     */
    uiStatesView.removeAllViews();
    List<String> extraStates = new ArrayList<>();
    for (CpuStateMonitor.CpuState state : cpuSpyApp.getCpuStateMonitor().getStates()) {
      if (state.duration > 0) {
        addView(frequencyCard);
        try {
          generateStateRow(state, uiStatesView, cpuSpyApp.getCpuStateMonitor());
        } catch (NullPointerException e) {
          e.printStackTrace();
        }
      } else
        extraStates.add(
            state.freq == 0
                ? getString(R.string.deep_sleep)
                : state.freq / 1000 + getString(R.string.mhz));
    }

    // show the red warning label if no states found
    if (cpuSpyApp.getCpuStateMonitor().getStates().size() == 0) {
      removeView(uptimeCard);
      removeView(frequencyCard);
    }

    // update the total state time
    uptimeCard.setDescription(sToString(cpuSpyApp.getCpuStateMonitor().getTotalStateTime() / 100));

    // for all the 0 duration states, add the the Unused State area
    if (extraStates.size() > 0) {
      int n = 0;
      StringBuilder stringBuilder = new StringBuilder();

      for (String s : extraStates) {
        if (n++ > 0) stringBuilder.append(",").append(" ");
        stringBuilder.append(s);
      }

      additionalCard.setDescription(stringBuilder.toString());
    } else additionalCard.setDescription("-");
  }
예제 #2
0
  private long viewInit(File folder, final Backup.PARTITION partition_type) {
    if (!folder.exists()) if (!folder.mkdirs()) return 0;

    long size = 0;
    String text = null;
    if (folder.toString().endsWith("boot")) text = getString(R.string.boot);
    else if (folder.toString().endsWith("recovery")) text = getString(R.string.recovery);
    else if (folder.toString().endsWith("fota")) text = getString(R.string.fota);
    if (text == null) return 0;
    for (final File file : folder.listFiles())
      if (file.getName().endsWith(".img")) {
        CardViewItem.DCardView cardView = new CardViewItem.DCardView();
        cardView.setTitle(file.getName().replace(".img", ""));
        long fileSize = file.length() / 1024 / 1024;
        size += fileSize;
        cardView.setDescription(text + ", " + fileSize + getString(R.string.mb));
        cardView.setOnDCardListener(
            new CardViewItem.DCardView.OnDCardListener() {
              @Override
              public void onClick(CardViewItem.DCardView dCardView) {
                new AlertDialog.Builder(getActivity())
                    .setItems(
                        getResources().getStringArray(R.array.backup_menu),
                        new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                            switch (which) {
                              case 0:
                                restoreDialog(file, partition_type, true);
                                break;
                              case 1:
                                deleteDialog(file);
                                break;
                            }
                          }
                        })
                    .show();
              }
            });

        addView(cardView);
      }
    return size;
  }