Search in sources :

Example 1 with StatsAdapter

use of com.asksven.betterbatterystats.adapters.StatsAdapter in project BetterBatteryStats by asksven.

the class StatsActivity method setListViewAdapter.

/**
 * In order to refresh the ListView we need to re-create the Adapter
 * (should be the case but notifyDataSetChanged doesn't work so
 * we recreate and set a new one)
 */
private void setListViewAdapter() throws Exception {
    LinearLayout notificationPanel = (LinearLayout) findViewById(R.id.Notification);
    ListView listView = (ListView) findViewById(android.R.id.list);
    ArrayList<StatElement> myStats = StatsProvider.getInstance().getStatList(m_iStat, m_refFromName, m_iSorting, m_refToName);
    if ((myStats != null) && (!myStats.isEmpty())) {
        // check if notification
        if (myStats.get(0) instanceof Notification) {
            // Show Panel
            notificationPanel.setVisibility(View.VISIBLE);
            // Hide list
            listView.setVisibility(View.GONE);
            // set Text
            TextView tvNotification = (TextView) findViewById(R.id.TextViewNotification);
            tvNotification.setText(myStats.get(0).getName());
        } else {
            // hide Panel
            notificationPanel.setVisibility(View.GONE);
            // Show list
            listView.setVisibility(View.VISIBLE);
        }
    }
    // make sure we only instanciate when the reference does not exist
    if (m_listViewAdapter == null) {
        m_listViewAdapter = new StatsAdapter(this, myStats, StatsActivity.this);
        Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this);
        Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this);
        long sinceMs = StatsProvider.getInstance().getSince(myReferenceFrom, myReferenceTo);
        m_listViewAdapter.setTotalTime(sinceMs);
        setListAdapter(m_listViewAdapter);
    }
}
Also used : ListView(android.widget.ListView) Reference(com.asksven.betterbatterystats.data.Reference) StatElement(com.asksven.android.common.privateapiproxies.StatElement) TextView(android.widget.TextView) StatsAdapter(com.asksven.betterbatterystats.adapters.StatsAdapter) LinearLayout(android.widget.LinearLayout) Notification(com.asksven.android.common.privateapiproxies.Notification)

Aggregations

LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Notification (com.asksven.android.common.privateapiproxies.Notification)1 StatElement (com.asksven.android.common.privateapiproxies.StatElement)1 StatsAdapter (com.asksven.betterbatterystats.adapters.StatsAdapter)1 Reference (com.asksven.betterbatterystats.data.Reference)1