Android Open Source - Xpense Cash List






From Project

Back to project page Xpense.

License

The source code is released under:

MIT License

If you think the Android project Xpense 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.kevinzhu.xpense;
//  w  w  w.  j  a  va 2  s.  c  o  m
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

import java.util.ArrayList;
import java.util.List;


public class CashList extends Activity {
    public static ArrayList<CashFlow> expenseArrayList = new ArrayList<>();
    CashFlowListAdapter cfla;
    Context c = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cash_list);
        Main.parents.push(getClass());

        final Context ctxt = this;
        final ListView listView = (ListView) findViewById(R.id.cash_flow_list_view);

        Intent intent = getIntent();
        String type = intent.getStringExtra("type");
        String currentListType;

        ParseQuery<ParseObject> pq_listType;

        //Get all the expenses
        if (type.equals("expense_all")){
            currentListType = "expense_all";
            pq_listType = ParseQuery.getQuery("Expense");
        }
        else if (type.equals("income_all")){
            currentListType = "income_all";
            pq_listType = ParseQuery.getQuery("Income");
        }
        else if (type.equals("expense_month")){
            currentListType = "expense_month";
            pq_listType = ParseQuery.getQuery("Expense");
        }
        else if (type.equals("income_month")){
            currentListType = "income_month";
            pq_listType = ParseQuery.getQuery("Income");
        }
        else{
            currentListType = "Blank";
            pq_listType = ParseQuery.getQuery("Blank");
        }

        //Get the data from Parse and create the listview
        pq_listType.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> expenseList, ParseException e) {
                if (e == null){
                    expenseArrayList.clear();
                    //Retrieval of data into objects
                    for (int i = 0; i < expenseList.size(); i++){

                        String expenseType = expenseList.get(i).getString("expenseType");
                        double amount = 0;
                        try {
                            amount = Double.parseDouble(expenseList.get(i).getString("amount"));
                        } catch(NumberFormatException nfe){

                        }
                        String objectID = expenseList.get(i).getObjectId();
                        String category = expenseList.get(i).getString("category");
                        String subcategory = expenseList.get(i).getString("subCategory");
                        String paymentSource = expenseList.get(i).getString("paymentSource");
                        String date = expenseList.get(i).getString("date");
                        String notes = expenseList.get(i).getString("notes");

                        //Create the object
                        CashFlow expense = new CashFlow(expenseType, amount, category, subcategory,
                                paymentSource, date, notes, objectID );
                        expenseArrayList.add(expense);
                    }

                    cfla = new CashFlowListAdapter(ctxt, expenseArrayList);
                    listView.setAdapter(cfla);
                    listView.setDividerHeight(0);
                    listView.setDivider(null);

                }
                else{
                    Log.d("Cash List", "Error: " + e.getMessage());
                }
            }
        });

        //Self note: This declares and instantiates a touchListener for use (you're not using it yet)
        //Instantiate with the created listView and callback fubctions
        SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(
                listView,
                new SwipeDismissListViewTouchListener.DismissCallbacks() {
                    @Override
                    public boolean canDismiss(int position) {
                        return true;
                    }

                    @Override
                    public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                        //Do something
                        cfla.notifyDataSetChanged();
                    }
                },
                c, //Context for updating views
                currentListType
        );
        listView.setOnTouchListener(touchListener);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_cash_list, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event){
        switch(keyCode){
            case KeyEvent.KEYCODE_BACK:
                // do something here
                Main.parents.pop(); //Prevent current activity from being registered as the parent
                Intent parentActivityIntent = new Intent(this, Main.parents.pop());
                parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(parentActivityIntent);
                return true;
        }
        return super.onKeyDown(keyCode, event);
    }



}




Java Source Code List

com.kevinzhu.xpense.ApplicationTest.java
com.kevinzhu.xpense.CashFlowListAdapter.java
com.kevinzhu.xpense.CashFlow.java
com.kevinzhu.xpense.CashList.java
com.kevinzhu.xpense.DatePickerFragment.java
com.kevinzhu.xpense.Main.java
com.kevinzhu.xpense.NewEntry.java
com.kevinzhu.xpense.SwipeDismissListViewTouchListener.java
com.kevinzhu.xpense.Xpense.java