Android Open Source - Thrift-box Adapter Expenses






From Project

Back to project page Thrift-box.

License

The source code is released under:

GNU General Public License

If you think the Android project Thrift-box 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 ru.sash0k.thriftbox;
/*from  www . ja v  a 2s.  c  o  m*/
import android.content.AsyncQueryHandler;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget_fixed.CursorTreeAdapter;

import ru.sash0k.thriftbox.database.DB;

/**
 * ???????? ???????? ?????????
 * Created by sash0k on 28.04.14.
 */
public class AdapterExpenses extends CursorTreeAdapter {
    private static final int TOKEN_CHILD = 1;
    private final QueryHandler mQueryHandler;

    private final LayoutInflater mInflater;
    private final String[] categories;

    public AdapterExpenses(Context context) {
        super(null, context, true);
        this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.categories = context.getResources().getStringArray(R.array.categories);
        this.mQueryHandler = new QueryHandler(context, this);
    }
    // ============================================================================

    @Override
    protected View newGroupView(Context context, Cursor cursor, boolean b, ViewGroup viewGroup) {
        View view = mInflater.inflate(R.layout.group_expense, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.date = (TextView) view.findViewById(R.id.expense_date);
        viewHolder.value = (TextView) view.findViewById(R.id.expense_value);
        viewHolder.date_col = cursor.getColumnIndexOrThrow(DB.DATE);
        viewHolder.value_col = cursor.getColumnIndexOrThrow(DB.VALUE);
        view.setTag(viewHolder);
        return view;
    }
    // ============================================================================

    @Override
    protected void bindGroupView(View view, Context context, Cursor cursor, boolean b) {
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        viewHolder.date.setText(cursor.getString(viewHolder.date_col));
        viewHolder.value.setText(((MainActivity)context).parseRouble(Utils.formatValue(cursor.getLong(viewHolder.value_col)) + Utils.ROUBLE));
    }
    // ============================================================================

    @Override
    protected View newChildView(Context context, Cursor cursor, boolean b, ViewGroup viewGroup) {
        View view = mInflater.inflate(R.layout.item_expense, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.category = (TextView) view.findViewById(R.id.expense_category);
        viewHolder.value = (TextView) view.findViewById(R.id.expense_value);
        viewHolder.comment = (TextView) view.findViewById(R.id.expense_comment);

        viewHolder.category_col = cursor.getColumnIndexOrThrow(DB.CATEGORY);
        viewHolder.value_col = cursor.getColumnIndexOrThrow(DB.VALUE);
        viewHolder.comment_col = cursor.getColumnIndexOrThrow(DB.COMMENT);
        view.setTag(viewHolder);
        return view;
    }
    // ============================================================================

    @Override
    protected void bindChildView(View view, Context context, Cursor cursor, boolean b) {
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        viewHolder.category.setText(categories[cursor.getInt(viewHolder.category_col)]);
        viewHolder.value.setText(((MainActivity)context).parseRouble(Utils.formatValue(cursor.getLong(viewHolder.value_col)) + Utils.ROUBLE));
        final String comment = cursor.getString(viewHolder.comment_col);
        viewHolder.comment.setText(comment);
        viewHolder.comment.setVisibility(comment == null ? View.GONE : View.VISIBLE);
    }
    // ============================================================================

    @Override
    protected Cursor getChildrenCursor(Cursor groupCursor) {
        final String date = groupCursor.getString(groupCursor.getColumnIndex(DB.DATE));
        mQueryHandler.startQuery(TOKEN_CHILD, groupCursor.getPosition(),
                DB.getUri(DB.EXPENSES_VIEW), null, DB.DATE + "=?", new String[]{date}, DB.TIMESTAMP + " DESC");
        return null;
    }
    // ============================================================================

    private static final class QueryHandler extends AsyncQueryHandler {
        private CursorTreeAdapter mAdapter;

        public QueryHandler(Context context, CursorTreeAdapter adapter) {
            super(context.getContentResolver());
            this.mAdapter = adapter;
        }

        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            if (token == TOKEN_CHILD) {
                if (cursor != null && cursor.moveToFirst()) {
                    Utils.log("setChildrenCursor count:" + cursor.getCount());
                    int groupPosition = (Integer) cookie;
                    mAdapter.setChildrenCursor(groupPosition, cursor);
                }
            } else {
                if (cursor != null && cursor.moveToFirst()) {
                    Utils.log("setGroupCursor count:" + cursor.getCount());
                    mAdapter.setGroupCursor(cursor);
                }
            }
        }
    }
    // ============================================================================

    private static class ViewHolder {
        private TextView category;
        private TextView date;
        private TextView value;
        private TextView comment;
        private int date_col, category_col, value_col, comment_col;
    }
    // ============================================================================
}




Java Source Code List

android.support.v4.preference.PreferenceFragment.java
android.support.v4.preference.PreferenceManagerCompat.java
android.widget_fixed.CursorFilter.java
android.widget_fixed.CursorTreeAdapter.java
com.github.mikephil.charting.charts.Chart.java
com.github.mikephil.charting.charts.PieChart.java
com.github.mikephil.charting.charts.PieRadarChartBase.java
com.github.mikephil.charting.data.ChartData.java
com.github.mikephil.charting.data.DataSet.java
com.github.mikephil.charting.data.Entry.java
com.github.mikephil.charting.data.PieDataSet.java
com.github.mikephil.charting.data.PieData.java
com.github.mikephil.charting.data.filter.Approximator.java
com.github.mikephil.charting.exception.DrawingDataSetNotCreatedException.java
com.github.mikephil.charting.interfaces.ChartInterface.java
com.github.mikephil.charting.interfaces.OnChartGestureListener.java
com.github.mikephil.charting.interfaces.OnChartValueSelectedListener.java
com.github.mikephil.charting.interfaces.OnDrawLineChartTouchListener.java
com.github.mikephil.charting.interfaces.OnDrawListener.java
com.github.mikephil.charting.listener.PieRadarChartTouchListener.java
com.github.mikephil.charting.matrix.Vector3.java
com.github.mikephil.charting.renderer.Transformer.java
com.github.mikephil.charting.utils.ColorFormatter.java
com.github.mikephil.charting.utils.ColorTemplate.java
com.github.mikephil.charting.utils.Highlight.java
com.github.mikephil.charting.utils.LabelBase.java
com.github.mikephil.charting.utils.LargeValueFormatter.java
com.github.mikephil.charting.utils.Legend.java
com.github.mikephil.charting.utils.LimitLine.java
com.github.mikephil.charting.utils.MarkerView.java
com.github.mikephil.charting.utils.PointD.java
com.github.mikephil.charting.utils.SelInfo.java
com.github.mikephil.charting.utils.Utils.java
com.github.mikephil.charting.utils.ValueFormatter.java
com.github.mikephil.charting.utils.XLabels.java
com.github.mikephil.charting.utils.YLabels.java
net.margaritov.preference.colorpicker.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.ColorPickerDialog.java
net.margaritov.preference.colorpicker.ColorPickerPanelView.java
net.margaritov.preference.colorpicker.ColorPickerPreference.java
net.margaritov.preference.colorpicker.ColorPickerView.java
ru.sash0k.thriftbox.AdapterExpenses.java
ru.sash0k.thriftbox.MainActivity.java
ru.sash0k.thriftbox.TypefaceSpan2.java
ru.sash0k.thriftbox.Utils.java
ru.sash0k.thriftbox.Widget.java
ru.sash0k.thriftbox.categories.Categories.java
ru.sash0k.thriftbox.categories.InterceptingHorizontalScrollView.java
ru.sash0k.thriftbox.database.DBProvider.java
ru.sash0k.thriftbox.database.DB.java
ru.sash0k.thriftbox.fragments.CommentDialog.java
ru.sash0k.thriftbox.fragments.DeleteConfirmDialog.java
ru.sash0k.thriftbox.fragments.ExpandableListFragment.java
ru.sash0k.thriftbox.fragments.ExpensesFragment.java
ru.sash0k.thriftbox.fragments.InputFragment.java
ru.sash0k.thriftbox.fragments.PieChartFragment.java
ru.sash0k.thriftbox.fragments.SettingsFragment.java