private void acceptHogsOrBugs(SimpleHogBug[] input, ArrayList<SimpleHogBug> result) {
    if (input == null) return;
    for (SimpleHogBug item : input) {
      if (item == null) continue;
      double benefit = 100.0 / item.getExpectedValueWithout() - 100.0 / item.getExpectedValue();
      // TODO other filter conditions?
      // Limit max number of items?
      String appName = item.getAppName();
      if (appName == null) appName = a.getString(R.string.unknown);

      // don't show (skip) special/system apps
      // (DISABLED FOR DEBUGGING. TODO: ENABLE IT AFTER DEBUGGING, and check whether this has any
      // problem)
      //			if (SpecialAppCases.isSpecialApp(appName))
      if (appName.equals(Constants.CARAT_PACKAGE_NAME) || appName.equals(Constants.CARAT_OLD))
        continue;
      if (SamplingLibrary.isHidden(a.getApplicationContext(), appName)) continue;

      if (addFakeItem && appName.equals(FAKE_ITEM)) result.add(item);
      // Filter out if benefit is too small
      if (SamplingLibrary.isRunning(a.getApplicationContext(), appName) && benefit > 60) {
        result.add(item);
      }
    }
  }
 @Override
 public int compare(SimpleHogBug lhs, SimpleHogBug rhs) {
   double benefitL = 100.0 / lhs.getExpectedValueWithout() - 100.0 / lhs.getExpectedValue();
   double benefitR = 100.0 / rhs.getExpectedValueWithout() - 100.0 / rhs.getExpectedValue();
   if (benefitL > benefitR) return -1;
   else if (benefitL < benefitR) return 1;
   return 0;
 }
Example #3
0
  public void setHogsBugs(SimpleHogBug bugOrHog, String appName, boolean isBug) {
    this.xVals = bugOrHog.getxVals();
    this.yVals = bugOrHog.getyVals();
    this.xValsWithout = bugOrHog.getxValsWithout();
    this.yValsWithout = bugOrHog.getyValsWithout();

    this.type = isBug ? Type.BUG : Type.HOG;
    this.appName = appName;
  }
  public HogBugSuggestionsAdapter(CaratApplication a, SimpleHogBug[] hogs, SimpleHogBug[] bugs) {
    this.a = a;

    ArrayList<SimpleHogBug> temp = new ArrayList<SimpleHogBug>();
    acceptHogsOrBugs(hogs, temp);
    acceptHogsOrBugs(bugs, temp);
    // TODO: Disabled for stability until we know what to do on pre-ICS phones for this.
    addFeatureActions(temp);

    if (addFakeItem) {
      SimpleHogBug fake = new SimpleHogBug(FAKE_ITEM, Constants.Type.BUG);
      fake.setExpectedValue(0.0);
      fake.setExpectedValueWithout(0.0);
      temp.add(fake);
    }
    Collections.sort(temp, new HogsBugsComparator());

    indexes = temp.toArray(new SimpleHogBug[temp.size()]);

    mInflater = LayoutInflater.from(a.getApplicationContext());
  }
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.suggestion, null);
      holder = new ViewHolder();
      holder.icon = (ImageView) convertView.findViewById(R.id.suggestion_app_icon);
      holder.txtName = (TextView) convertView.findViewById(R.id.actionName);
      holder.txtType = (TextView) convertView.findViewById(R.id.suggestion_type);
      holder.txtBenefit = (TextView) convertView.findViewById(R.id.expectedBenefit);
      holder.moreInfo = (ImageView) convertView.findViewById(R.id.jscore_info);

      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    if (indexes == null || position < 0 || position >= indexes.length) return convertView;

    SimpleHogBug item = indexes[position];
    if (item == null) return convertView;

    final String raw = item.getAppName();
    Drawable icon = CaratApplication.iconForApp(a.getApplicationContext(), raw);

    if (raw.equals(FAKE_ITEM)) {
      holder.txtName.setText(a.getString(R.string.osupgrade));
      holder.txtType.setText(a.getString(R.string.information));
      holder.txtBenefit.setText(a.getString(R.string.unknown));
    } else {

      String label = CaratApplication.labelForApp(a.getApplicationContext(), raw);
      if (label == null) label = a.getString(R.string.unknown);

      holder.icon.setImageDrawable(icon);
      Constants.Type type = item.getType();
      if (type == Constants.Type.BUG)
        holder.txtName.setText(a.getString(R.string.restart) + " " + label);
      else if (type == Constants.Type.HOG)
        holder.txtName.setText(a.getString(R.string.kill) + " " + label);
      else { // Other action
        holder.txtName.setText(label);
      }
      if (type == Constants.Type.OTHER) holder.txtType.setText(item.getAppPriority());
      else holder.txtType.setText(CaratApplication.translatedPriority(item.getAppPriority()));

      /*if (raw.equals(a.getString(R.string.disablebluetooth))){
          double benefitOther=SamplingLibrary.bluetoothBenefit(a.getApplicationContext());
          hours = (int) (benefitOther);
          min= (int) ((benefitOther- hours)*60);
      }
      else if(raw.equals(a.getString(R.string.disablewifi))){
          double benefitOther=SamplingLibrary.wifiBenefit(a.getApplicationContext());
          hours = (int) (benefitOther);
          min= (int) ((benefitOther- hours)*60);
      }
      else if(raw.equals(a.getString(R.string.dimscreen))){
          double benefitOther=SamplingLibrary.screenBrightnessBenefit(a.getApplicationContext());
          hours = (int) (benefitOther);
          min = (int) ((benefitOther- hours)*60);
      }*/
      // Do not show a benefit for things that have none.
      if (item.getExpectedValue() == 0 && item.getExpectedValueWithout() == 0) {
        holder.txtBenefit.setText("");
        TextView bl = (TextView) convertView.findViewById(R.id.benefitLegend);
        bl.setText("");
      } else holder.txtBenefit.setText(item.getBenefitText());

      // holder.moreInfo...
    }
    // }
    return convertView;
  }