Search in sources :

Example 16 with SimpleHogBug

use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.

the class SettingsSuggestionAdapter method acceptDisableWifi.

private void acceptDisableWifi(ArrayList<SimpleHogBug> result) {
    if (SamplingLibrary.getWifiEnabled(a.getApplicationContext())) {
        SimpleHogBug item = new SimpleHogBug(a.getString(R.string.disablewifi), Constants.Type.OS);
        result.add(item);
    }
}
Also used : SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Example 17 with SimpleHogBug

use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.

the class SettingsSuggestionAdapter method acceptDisableAutoSync.

private void acceptDisableAutoSync(ArrayList<SimpleHogBug> result) {
    if (ContentResolver.getMasterSyncAutomatically() == true) {
        SimpleHogBug item = new SimpleHogBug(a.getString(R.string.disableautomaticsync), Constants.Type.OS);
        // TODO Get expected benefit
        result.add(item);
    }
}
Also used : SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Example 18 with SimpleHogBug

use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.

the class SettingsSuggestionAdapter method getView.

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 appName = item.getAppName();
    Drawable icon = CaratApplication.iconForApp(a.getApplicationContext(), appName);
    if (appName.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(), appName);
        // TODO: modify the labelForApp() method to accommodate returning correct label based on appNames for system settings
        if (label == null)
            label = a.getString(R.string.unknown);
        holder.icon.setImageDrawable(icon);
        Constants.Type type = item.getType();
        if (type == Constants.Type.BRIGHTNESS)
            action = "dim screen brightness";
        else if (type == Constants.Type.WIFI)
            action = "turn off wifi";
        else if (type == Constants.Type.MOBILEDATA)
            action = "turn off mobile data";
        holder.txtName.setText(action + " " + label);
        if (type == Constants.Type.OTHER)
            holder.txtType.setText(item.getAppPriority());
        else
            holder.txtType.setText(CaratApplication.translatedPriority(item.getAppPriority()));
        // 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());
    // TODO: set holder.moreInfos and their click listener ...
    }
    // }
    return convertView;
}
Also used : Drawable(android.graphics.drawable.Drawable) Constants(edu.berkeley.cs.amplab.carat.android.Constants) TextView(android.widget.TextView) SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Example 19 with SimpleHogBug

use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.

the class HogsBugsComparator method acceptHogsOrBugs.

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);
        //			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);
        }
    }
}
Also used : SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Example 20 with SimpleHogBug

use of edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug in project carat by amplab.

the class HogsBugsAdapter method getView.

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.hog, null);
        holder = new ViewHolder();
        holder.appIcon = (ImageView) convertView.findViewById(R.id.appIcon);
        holder.txtName = (TextView) convertView.findViewById(R.id.appName);
        holder.textBenefit = (TextView) convertView.findViewById(R.id.benefit);
        holder.moreInfo = (ImageView) convertView.findViewById(R.id.jscore_info);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    if (allBugsOrHogs == null || position < 0 || position >= allBugsOrHogs.length)
        return convertView;
    SimpleHogBug item = allBugsOrHogs[position];
    if (item == null)
        return convertView;
    Drawable icon = CaratApplication.iconForApp(a.getApplicationContext(), item.getAppName());
    String label = CaratApplication.labelForApp(a.getApplicationContext(), item.getAppName());
    if (label == null)
        label = a.getString(R.string.unknown);
    PackageInfo pak = SamplingLibrary.getPackageInfo(a.getApplicationContext(), item.getAppName());
    String ver = "";
    if (pak != null) {
        ver = pak.versionName;
        if (ver == null)
            ver = pak.versionCode + "";
    }
    holder.txtName.setText(label + " " + ver);
    holder.appIcon.setImageDrawable(icon);
    holder.textBenefit.setText(item.getBenefitText());
    return convertView;
}
Also used : PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Aggregations

SimpleHogBug (edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)23 ListView (android.widget.ListView)4 Drawable (android.graphics.drawable.Drawable)3 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3 TextView (android.widget.TextView)3 LocalizedWebView (edu.berkeley.cs.amplab.carat.android.ui.LocalizedWebView)3 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)2 Constants (edu.berkeley.cs.amplab.carat.android.Constants)2 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 AudioManager (android.media.AudioManager)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 CaratApplication (edu.berkeley.cs.amplab.carat.android.CaratApplication)1