Search in sources :

Example 1 with State

use of com.asksven.android.common.kernelutils.State in project BetterBatteryStats by asksven.

the class StatsProvider method getCpuStateList.

/**
 * Get the CPU states to be displayed
 *
 * @param bFilter
 *            defines if zero-values should be filtered out
 * @return a List of Other usages sorted by duration (descending)
 * @throws Exception
 *             if the API call failed
 */
public ArrayList<StatElement> getCpuStateList(Reference refFrom, Reference refTo, boolean bFilter) throws Exception {
    Context ctx = BbsApplication.getAppContext();
    // List to store the other usages to
    ArrayList<StatElement> myStates = refTo.m_refCpuStates;
    ArrayList<StatElement> myStats = new ArrayList<StatElement>();
    if ((refFrom == null) || (refTo == null)) {
        myStats.add(new Notification(ctx.getString(R.string.NO_REF_ERR)));
        return myStats;
    }
    if (refTo.m_refCpuStates == null) {
        myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
        return myStats;
    }
    String strCurrent = myStates.toString();
    String strRef = "";
    String strRefDescr = "";
    if (LogSettings.DEBUG) {
        if (refFrom != null) {
            strRefDescr = refFrom.whoAmI();
            if (refFrom.m_refCpuStates != null) {
                strRef = refFrom.m_refCpuStates.toString();
            } else {
                strRef = "CPU States is null";
            }
        }
        Log.d(TAG, "Processing CPU States from " + refFrom.m_fileName + " to " + refTo.m_fileName);
        Log.d(TAG, "Reference used: " + strRefDescr);
        Log.d(TAG, "It is now " + DateUtils.now());
        Log.d(TAG, "Substracting " + strRef);
        Log.d(TAG, "from " + strCurrent);
    }
    ArrayList<State> myResultStates = new ArrayList<State>();
    for (int i = 0; i < myStates.size(); i++) {
        State state = ((State) myStates.get(i)).clone();
        state.substractFromRef(refFrom.m_refCpuStates);
        if ((!bFilter) || ((state.m_duration) > 0)) {
            myResultStates.add(state);
        }
    }
    Collections.sort(myResultStates);
    for (int i = 0; i < myResultStates.size(); i++) {
        myStats.add(myResultStates.get(i));
    }
    return myStats;
}
Also used : Context(android.content.Context) State(com.asksven.android.common.kernelutils.State) StatElement(com.asksven.android.common.privateapiproxies.StatElement) ArrayList(java.util.ArrayList) Notification(com.asksven.android.common.privateapiproxies.Notification) SuppressLint(android.annotation.SuppressLint)

Example 2 with State

use of com.asksven.android.common.kernelutils.State in project BetterBatteryStats by asksven.

the class StatsProvider method getCurrentCpuStateList.

public ArrayList<StatElement> getCurrentCpuStateList(boolean bFilter) throws Exception {
    // List to store the other usages to
    ArrayList<State> myStates = CpuStates.getTimesInStates();
    ArrayList<StatElement> myStats = new ArrayList<StatElement>();
    if (myStates == null) {
        return myStats;
    }
    String strCurrent = myStates.toString();
    String strRef = "";
    String strRefDescr = "";
    for (int i = 0; i < myStates.size(); i++) {
        State state = myStates.get(i);
        if ((!bFilter) || ((state.m_duration) > 0)) {
            myStats.add(state);
        }
    }
    return myStats;
}
Also used : State(com.asksven.android.common.kernelutils.State) StatElement(com.asksven.android.common.privateapiproxies.StatElement) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint)

Example 3 with State

use of com.asksven.android.common.kernelutils.State in project BetterBatteryStats by asksven.

the class StatsAdapter method getView.

public View getView(int position, View convertView, ViewGroup viewGroup) {
    StatElement entry = m_listData.get(position);
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.m_context);
    if (LogSettings.DEBUG) {
        Log.i(TAG, "Values: " + entry.getVals());
    }
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.stat_row, null);
    }
    final float scale = this.m_context.getResources().getDisplayMetrics().density;
    TextView tvName = (TextView) convertView.findViewById(R.id.TextViewName);
    // ///////////////////////////////////////
    // we do some stuff here to handle settings about font size and thumbnail size
    String fontSize = sharedPrefs.getString("medium_font_size", "16");
    int mediumFontSize = Integer.parseInt(fontSize);
    // we need to change "since" fontsize
    tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize);
    // We need to handle an exception here: Sensors do not have a name so we use the fqn instead
    if (entry instanceof SensorUsage) {
        tvName.setText(entry.getFqn(UidNameResolver.getInstance()));
    } else {
        tvName.setText(entry.getName());
    }
    TextView tvFqn = (TextView) convertView.findViewById(R.id.TextViewFqn);
    tvFqn.setText(entry.getFqn(UidNameResolver.getInstance()));
    TextView tvData = (TextView) convertView.findViewById(R.id.TextViewData);
    // for alarms the values is wakeups per hour so we need to take the time as reference for the text
    if (entry instanceof Alarm) {
        tvData.setText(entry.getData((long) m_timeSince));
    } else {
        tvData.setText(entry.getData((long) m_maxValue));
    }
    LinearLayout myFqnLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutFqn);
    LinearLayout myRow = (LinearLayout) convertView.findViewById(R.id.LinearLayoutEntry);
    // long press for "copy to clipboard"
    convertView.setOnLongClickListener(new OnItemLongClickListener(position));
    GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge);
    if (entry instanceof NetworkUsage) {
        gauge.setValue(entry.getValues()[0], ((NetworkUsage) entry).getTotal());
    } else {
        double max = m_maxValue;
        // avoid rounding errors leading to values > 100 %
        if (entry.getValues()[0] > max) {
            max = entry.getValues()[0];
            Log.i(TAG, "Upping gauge max to " + max);
        }
        gauge.setValue(entry.getValues()[0], max);
    }
    ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
    LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon);
    // show / hide fqn text
    if ((entry instanceof Process) || (entry instanceof State) || (entry instanceof Misc) || (entry instanceof NativeKernelWakelock) || (entry instanceof Alarm) || (entry instanceof SensorUsage)) {
        myFqnLayout.setVisibility(View.GONE);
    } else {
        myFqnLayout.setVisibility(View.VISIBLE);
    }
    // show / hide package icons (we show / hide the whole layout as it contains a margin that must be hidded as well
    if ((entry instanceof NativeKernelWakelock) || (entry instanceof State) || (entry instanceof Misc)) {
        iconView.setVisibility(View.GONE);
    } else {
        iconView.setVisibility(View.VISIBLE);
        iconView.setImageDrawable(entry.getIcon(UidNameResolver.getInstance()));
        // set a click listener for the list
        iconView.setOnClickListener(new OnPackageClickListener(position));
    }
    // add on click listener for the list entry if details are availble
    if ((entry instanceof Alarm) || (entry instanceof NativeKernelWakelock) || (entry instanceof SensorUsage)) {
        convertView.setOnClickListener(new OnItemClickListener(position));
    }
    return convertView;
}
Also used : SharedPreferences(android.content.SharedPreferences) NetworkUsage(com.asksven.android.common.privateapiproxies.NetworkUsage) Misc(com.asksven.android.common.privateapiproxies.Misc) SensorUsage(com.asksven.android.common.privateapiproxies.SensorUsage) Process(com.asksven.android.common.privateapiproxies.Process) SuppressLint(android.annotation.SuppressLint) NativeKernelWakelock(com.asksven.android.common.privateapiproxies.NativeKernelWakelock) State(com.asksven.android.common.kernelutils.State) StatElement(com.asksven.android.common.privateapiproxies.StatElement) LayoutInflater(android.view.LayoutInflater) Alarm(com.asksven.android.common.privateapiproxies.Alarm) GraphablePie(com.asksven.betterbatterystats.widgets.GraphablePie) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Aggregations

SuppressLint (android.annotation.SuppressLint)3 State (com.asksven.android.common.kernelutils.State)3 StatElement (com.asksven.android.common.privateapiproxies.StatElement)3 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 LayoutInflater (android.view.LayoutInflater)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Alarm (com.asksven.android.common.privateapiproxies.Alarm)1 Misc (com.asksven.android.common.privateapiproxies.Misc)1 NativeKernelWakelock (com.asksven.android.common.privateapiproxies.NativeKernelWakelock)1 NetworkUsage (com.asksven.android.common.privateapiproxies.NetworkUsage)1 Notification (com.asksven.android.common.privateapiproxies.Notification)1 Process (com.asksven.android.common.privateapiproxies.Process)1 SensorUsage (com.asksven.android.common.privateapiproxies.SensorUsage)1 GraphablePie (com.asksven.betterbatterystats.widgets.GraphablePie)1