/** 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("-");
  }
  /** Initialize the Fragment */
  @Override
  public void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);

    if (CPU.isBigLITTLE()) {
      DDividerCard bigDivider = new DDividerCard();
      bigDivider.setText(getString(R.string.big).toLowerCase());
      addView(bigDivider);
    }

    uptimeCard = new CardViewItem.DCardView();
    uptimeCard.setTitle(getString(R.string.uptime));
    addView(uptimeCard);

    additionalCard = new CardViewItem.DCardView();
    additionalCard.setTitle(getString(R.string.unused_cpu_states));
    addView(additionalCard);

    uiStatesView = new LinearLayout(getActivity());
    uiStatesView.setOrientation(LinearLayout.VERTICAL);
    frequencyCard = new CardViewItem.DCardView();
    frequencyCard.setTitle(getString(R.string.frequency_table));
    frequencyCard.setView(uiStatesView);
    frequencyCard.setFullSpan(true);
    addView(frequencyCard);

    if (CPU.isBigLITTLE()) {
      DDividerCard LITTLEDivider = new DDividerCard();
      LITTLEDivider.setText(getString(R.string.little));
      addView(LITTLEDivider);

      uptimeCardLITTLE = new CardViewItem.DCardView();
      uptimeCardLITTLE.setTitle(getString(R.string.uptime));
      addView(uptimeCardLITTLE);

      additionalCardLITTLE = new CardViewItem.DCardView();
      additionalCardLITTLE.setTitle(getString(R.string.unused_cpu_states));
      addView(additionalCardLITTLE);

      uiStatesViewLITTLE = new LinearLayout(getActivity());
      uiStatesViewLITTLE.setOrientation(LinearLayout.VERTICAL);
      frequencyCardLITTLE = new CardViewItem.DCardView();
      frequencyCardLITTLE.setTitle(getString(R.string.frequency_table));
      frequencyCardLITTLE.setView(uiStatesViewLITTLE);
      frequencyCardLITTLE.setFullSpan(true);
      addView(frequencyCardLITTLE);
    }
  }
Пример #3
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;
  }