示例#1
0
  /** @return a View that correpsonds to a CPU freq state row as specified by the state parameter */
  private View generateStateRow(CpuStateMonitor.CpuState state, ViewGroup parent) {
    // inflate the XML into a view in the parent
    LayoutInflater inf = LayoutInflater.from(getActivity());
    LinearLayout theRow = (LinearLayout) inf.inflate(R.layout.state_row, parent, false);
    // what percetnage we've got
    CpuStateMonitor monitor = _app.getCpuStateMonitor();
    float per = (float) state.duration * 100 / monitor.getTotalStateTime();

    // state name
    String sFreq;
    if (state.freq == 0) {
      sFreq = getString(R.string.deep_sleep);
    } else {
      sFreq = state.freq / 1000 + " MHz";
    }

    // duration
    long tSec = state.duration / 100;
    String sDur = sToString(tSec);

    // map UI elements to objects
    TextView freqText = (TextView) theRow.findViewById(R.id.ui_freq_text);
    TextView durText = (TextView) theRow.findViewById(R.id.ui_duration_text);
    CircleChart perText = (CircleChart) theRow.findViewById(R.id.ui_percentage_text);

    // modify the row
    freqText.setText(sFreq);
    perText.setMax(100);
    perText.setProgress((int) per);
    durText.setText(sDur);

    // add it to parent and return
    parent.addView(theRow);
    return theRow;
  }
示例#2
0
  /** Generate and update all UI elements */
  public void updateView() {
    /**
     * 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)
     */
    CpuStateMonitor monitor = _app.getCpuStateMonitor();
    _uiStatesView.removeAllViews();
    List<String> extraStates = new ArrayList<String>();
    for (CpuStateMonitor.CpuState state : monitor.getStates()) {
      if (state.duration > 0) {
        generateStateRow(state, _uiStatesView);
      } else {
        if (state.freq == 0) {
          extraStates.add("Deep Sleep");
        } else {
          extraStates.add(state.freq / 1000 + " MHz");
        }
      }
    }

    // show the red warning label if no states found
    if (monitor.getStates().size() == 0) {
      _uiHeaderTotalStateTime.setVisibility(View.GONE);
      _uiTotalStateTime.setVisibility(View.GONE);
      _uiStatesView.setVisibility(View.GONE);
    }

    // update the total state time
    long totTime = monitor.getTotalStateTime() / 100;
    _uiTotalStateTime.setText(sToString(totTime));

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

      for (String s : extraStates) {
        if (n++ > 0) str += ", ";
        str += s;
      }

      _uiAdditionalStates.setVisibility(View.VISIBLE);
      _uiHeaderAdditionalStates.setVisibility(View.VISIBLE);
      _uiAdditionalStates.setText(str);
    } else {
      _uiAdditionalStates.setVisibility(View.GONE);
      _uiHeaderAdditionalStates.setVisibility(View.GONE);
    }
  }