Search in sources :

Example 6 with NativeKernelWakelock

use of com.asksven.android.common.privateapiproxies.NativeKernelWakelock 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);
    boolean bShowBars = sharedPrefs.getBoolean("show_gauge", false);
    if (LogSettings.DEBUG) {
        Log.i(TAG, "Values: " + entry.getVals());
    }
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // depending on settings show new pie gauge or old bar gauge
        if (!bShowBars) {
            convertView = inflater.inflate(R.layout.stat_row, null);
        } else {
            convertView = inflater.inflate(R.layout.stat_row_gauge, 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());
    }
    boolean bShowKb = sharedPrefs.getBoolean("enable_kb", true);
    ImageView iconKb = (ImageView) convertView.findViewById(R.id.imageKB);
    iconKb.setVisibility(View.INVISIBLE);
    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 myLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutBar);
    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));
    if (!bShowBars) {
        GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge);
        // ///////////////////////////////////////
        // we do some stuff here to handle settings about font size and thumbnail size
        String iconDim = sharedPrefs.getString("thumbnail_size", "56");
        int iconSize = Integer.parseInt(iconDim);
        int pixels = (int) (iconSize * scale + 0.5f);
        // we need to change "since" fontsize
        gauge.getLayoutParams().height = pixels;
        gauge.getLayoutParams().width = pixels;
        gauge.requestLayout();
        // //////////////////////////////////////////////////////////////////////////////////
        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);
        }
    } else {
        GraphableBars buttonBar = (GraphableBars) convertView.findViewById(R.id.ButtonBar);
        int iHeight = 10;
        try {
            iHeight = Integer.valueOf(sharedPrefs.getString("graph_bar_height", "10"));
        } catch (Exception e) {
            iHeight = 10;
        }
        if (iHeight == 0) {
            iHeight = 10;
        }
        buttonBar.setMinimumHeight(iHeight);
        buttonBar.setName(entry.getName());
        buttonBar.setValues(entry.getValues(), m_maxValue);
    }
    ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
    LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon);
    // ///////////////////////////////////////
    // we do some stuff here to handle settings about font size and thumbnail size
    String iconDim = sharedPrefs.getString("thumbnail_size", "56");
    int iconSize = Integer.parseInt(iconDim);
    int pixels = (int) (iconSize * scale + 0.5f);
    // we need to change "since" fontsize
    iconView.getLayoutParams().width = pixels;
    iconView.getLayoutParams().height = pixels;
    iconView.requestLayout();
    // 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) GraphableBars(com.asksven.betterbatterystats.widgets.GraphableBars)

Aggregations

NativeKernelWakelock (com.asksven.android.common.privateapiproxies.NativeKernelWakelock)6 StatElement (com.asksven.android.common.privateapiproxies.StatElement)6 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)3 ActivityManager (android.app.ActivityManager)3 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)3 SharedPreferences (android.content.SharedPreferences)3 Context (android.content.Context)2 IOException (java.io.IOException)2 PackageManager (android.content.pm.PackageManager)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 BatteryStatsProxy (com.asksven.android.common.privateapiproxies.BatteryStatsProxy)1 Misc (com.asksven.android.common.privateapiproxies.Misc)1 NetworkUsage (com.asksven.android.common.privateapiproxies.NetworkUsage)1 Notification (com.asksven.android.common.privateapiproxies.Notification)1