Android Open Source - ccardstats Simple List Activity






From Project

Back to project page ccardstats.

License

The source code is released under:

GNU General Public License

If you think the Android project ccardstats listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.marwinxxii.ccardstats.gui;
/*from   w ww.j  a va 2  s .  c  o m*/
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.marwinxxii.ccardstats.R;
import com.github.marwinxxii.ccardstats.helpers.MoneyHelper;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class SimpleListActivity extends ListActivity {
    
    private static final int ids[] = {
        R.id.stats_item_text, R.id.stats_item_income, R.id.stats_item_outcome
    };
    
    private static Map<String, List<String[]>> cache = new HashMap<String, List<String[]>>();
    
    protected ProgressDialog progressDialog;
    protected String cacheKey;
    protected int itemLayoutId = android.R.layout.simple_list_item_1;
    protected int[] itemFieldsIds = { android.R.id.text1 };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cacheKey = this.getClass().getName();
        if (savedInstanceState == null) cache.remove(cacheKey);
    }
    
    @Override
    public void onStart() {
        super.onStart();
        setListTitle();
    }
    
    @Override
    public void onResume() {
        super.onResume();
        if (getValuesFromCache() != null) {
            setListAdapter();
            return;
        }
        if (progressDialog != null) progressDialog.show();
        getItems();
    }
    
    protected int getItemLayout() {
        return R.layout.stats_item;
    }
    
    protected int[] getItemFieldsIds() {
        return ids;
    }
    
    public void setListTitle() {}
    
    public void setDialogParams(int titleId, String message) {
        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(titleId);
        progressDialog.setMessage(message);
        progressDialog.setCancelable(false);
    }
    
    protected void setListAdapter() {
        List<String[]> values = getValuesFromCache();
        if (values != null && values.size() != 0) {
            TextMappingAdapter adapter = new TextMappingAdapter(this, getItemLayout(),
                    getItemFieldsIds(), values);
            mItemsList.setAdapter(adapter);
        } else {
            setNoItemsTextId(R.string.list_activity_noitems);
        }
    }
    
    protected void getItems() {}
    
    protected void onTaskComplete(Map<Integer, double[]> values) {
        double[] money = values.get(-1);
        if (money != null) {
            String[] temp = {
                    getString(R.string.total),
                    MoneyHelper.formatMoney(money[0], true),
                    MoneyHelper.formatMoney(money[1], false),
            };
            getValuesFromCache().add(temp);
        }
        setListAdapter();
        progressDialog.dismiss();
    }
    
    protected void cacheValues(List<String[]> values) {
        cache.put(cacheKey, values);
    }
    
    protected List<String[]> getValuesFromCache() {
        return cache.get(cacheKey);
    }
    
    protected void clearCache() {
        cache.clear();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
            case R.id.menu_main_prefs:
                startActivity(PreferencesActivity.getStartingIntent(this));
                return true;
        }
        return false;
    }
}




Java Source Code List

com.github.marwinxxii.ccardstats.Application.java
com.github.marwinxxii.ccardstats.SmsReceiver.java
com.github.marwinxxii.ccardstats.db.Card.java
com.github.marwinxxii.ccardstats.db.DBHelper.java
com.github.marwinxxii.ccardstats.gui.CardListActivity.java
com.github.marwinxxii.ccardstats.gui.GetStatsTask.java
com.github.marwinxxii.ccardstats.gui.ListActivity.java
com.github.marwinxxii.ccardstats.gui.MonthStatsActivity.java
com.github.marwinxxii.ccardstats.gui.PreferencesActivity.java
com.github.marwinxxii.ccardstats.gui.SimpleListActivity.java
com.github.marwinxxii.ccardstats.gui.TextMappingAdapter.java
com.github.marwinxxii.ccardstats.gui.YearStatsActivity.java
com.github.marwinxxii.ccardstats.helpers.DateHelper.java
com.github.marwinxxii.ccardstats.helpers.MoneyHelper.java
com.github.marwinxxii.ccardstats.notifications.NotificationReader.java
com.github.marwinxxii.ccardstats.notifications.NotificationService.java
com.github.marwinxxii.ccardstats.notifications.SberbankService.java
com.github.marwinxxii.ccardstats.notifications.SmsNotification.java
com.github.marwinxxii.ccardstats.notifications.SmsParser.java
com.github.marwinxxii.ccardstats.notifications.SmsReader.java