Android Open Source - ccardstats Year Stats 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;
/* w w w  .j av  a  2 s.  c o  m*/
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.github.marwinxxii.ccardstats.db.Card;
import com.github.marwinxxii.ccardstats.db.DBHelper;
import com.github.marwinxxii.ccardstats.gui.GetStatsTask.FilterType;
import com.github.marwinxxii.ccardstats.helpers.DateHelper;
import com.github.marwinxxii.ccardstats.helpers.MoneyHelper;
import com.github.marwinxxii.ccardstats.R;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class YearStatsActivity extends SimpleListActivity implements OnItemClickListener{
    
    private String card;
    private int year;
    private static List<Integer> months;
    private Toast toast;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setDialogParams(R.string.reading_stats_dialog_title,
                getString(R.string.year_stats_dialog_message));
        Intent i = getIntent();
        card = i.getStringExtra("card");
        year = i.getIntExtra("year", DateHelper.year);
        mItemsList.setOnItemClickListener(this);
        toast = Toast.makeText(this, R.string.year_stats_nomonth_toast, Toast.LENGTH_SHORT);
    }
    
    @Override
    public void setListTitle() {
        super.setTitleText(getString(R.string.year_stats_title, card, year));
    }
    
    @Override
    public void getItems() {
        new GetStatsTask(this, card, FilterType.YEAR, year, 0).execute();
    }
    
    @Override
    public void onTaskComplete(Map<Integer, double[]> values) {
        ArrayList<String[]> result = new ArrayList<String[]>(values.size());
        months = new ArrayList<Integer>(values.size());
        for (Integer month:values.keySet()) {
            if (month == -1) continue;
            double[] money = values.get(month);
            String[] temp = {
                    DateHelper.getMonthName(month),
                    MoneyHelper.formatMoney(money[0], true),
                    MoneyHelper.formatMoney(money[1], false),
            };
            result.add(temp);
            months.add(month);
        }
        cacheValues(result);
        super.onTaskComplete(values);
    }
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (!DBHelper.storeMonth) {
            int month = months.get(position);
            startActivity(MonthStatsActivity.getStartingIntent(this, card, year, month));
        } else {
            toast.show();
        }
    }
    
    @Override
    public void onStop() {
        super.onStop();
        toast.cancel();
    }
    
    public static Intent getStartingIntent(Context context, String card, int year) {
        Intent i = new Intent(context, YearStatsActivity.class);
        i.putExtra("card", card);
        i.putExtra("year", year);
        return i;
    }
}




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