Search in sources :

Example 1 with GraphablePie

use of com.asksven.betterbatterystats.widgets.GraphablePie 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)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 State (com.asksven.android.common.kernelutils.State)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 Process (com.asksven.android.common.privateapiproxies.Process)1 SensorUsage (com.asksven.android.common.privateapiproxies.SensorUsage)1 StatElement (com.asksven.android.common.privateapiproxies.StatElement)1 GraphablePie (com.asksven.betterbatterystats.widgets.GraphablePie)1