Search in sources :

Example 6 with SubcolumnValue

use of lecho.lib.hellocharts.model.SubcolumnValue in project CoCoin by Nightonke.

the class TagViewRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
    switch(getItemViewType(position)) {
        case TYPE_HEADER:
            if (IS_EMPTY) {
                holder.sum.setText(mContext.getResources().getString(R.string.tag_empty));
                holder.sum.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
                holder.from.setVisibility(View.INVISIBLE);
                holder.to.setVisibility(View.INVISIBLE);
            } else {
                holder.from.setText(mContext.getResources().getString(R.string.from) + " " + startYear + " " + CoCoinUtil.GetMonthShort(startMonth));
                holder.sum.setText(CoCoinUtil.GetInMoney((int) Sum));
                holder.to.setText(mContext.getResources().getString(R.string.to) + " " + endYear + " " + CoCoinUtil.GetMonthShort(endMonth));
                holder.to.setTypeface(CoCoinUtil.GetTypeface());
                holder.from.setTypeface(CoCoinUtil.GetTypeface());
            }
            holder.sum.setTypeface(CoCoinUtil.typefaceLatoLight);
            break;
        case TYPE_CELL:
            int year = contents.get(position - 1).get(0).getCalendar().get(Calendar.YEAR);
            int month = contents.get(position - 1).get(0).getCalendar().get(Calendar.MONTH) + 1;
            PieChartData pieChartData;
            List<SubcolumnValue> subcolumnValues;
            final List<Column> columns;
            ColumnChartData columnChartData;
            final List<SliceValue> sliceValues;
            holder.date.setTypeface(CoCoinUtil.GetTypeface());
            holder.expanse.setTypeface(CoCoinUtil.GetTypeface());
            switch(chartType) {
                case PIE:
                    sliceValues = new ArrayList<>();
                    for (Map.Entry<Integer, Double> entry : AllTagExpanse.get(position - 1).entrySet()) {
                        if (entry.getValue() >= 1) {
                            SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), mContext.getResources().getColor(CoCoinUtil.GetTagColorResource(entry.getKey())));
                            sliceValue.setLabel(String.valueOf(entry.getKey()));
                            sliceValues.add(sliceValue);
                        }
                    }
                    pieChartData = new PieChartData(sliceValues);
                    pieChartData.setHasLabels(false);
                    pieChartData.setHasLabelsOnlyForSelected(false);
                    pieChartData.setHasLabelsOutside(false);
                    pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
                    holder.pie.setPieChartData(pieChartData);
                    holder.pie.setOnValueTouchListener(new PieValueTouchListener(position - 1));
                    holder.pie.setChartRotationEnabled(false);
                    if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
                        holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
                    } else {
                        holder.date.setText(year + " ");
                    }
                    holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
                    holder.iconRight.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            SelectedPosition[position] = (SelectedPosition[position] + 1) % sliceValues.size();
                            SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
                            holder.pie.selectValue(selectedValue);
                        }
                    });
                    holder.iconLeft.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            SelectedPosition[position] = (SelectedPosition[position] - 1 + sliceValues.size()) % sliceValues.size();
                            SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
                            holder.pie.selectValue(selectedValue);
                        }
                    });
                    break;
                case SUM_HISTOGRAM:
                    columns = new ArrayList<>();
                    if (type.get(position - 1).equals(SHOW_IN_YEAR)) {
                        int numColumns = 12;
                        for (int i = 0; i < numColumns; i++) {
                            subcolumnValues = new ArrayList<>();
                            SubcolumnValue value = new SubcolumnValue(MonthExpanseSum[(year - startYear) * 12 + i], CoCoinUtil.GetRandomColor());
                            value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + year);
                            subcolumnValues.add(value);
                            Column column = new Column(subcolumnValues);
                            column.setHasLabels(false);
                            column.setHasLabelsOnlyForSelected(false);
                            columns.add(column);
                        }
                        columnChartData = new ColumnChartData(columns);
                        Axis axisX = new Axis();
                        List<AxisValue> axisValueList = new ArrayList<>();
                        for (int i = 0; i < numColumns; i++) {
                            axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetMonthShort(i + 1)));
                        }
                        axisX.setValues(axisValueList);
                        Axis axisY = new Axis().setHasLines(true);
                        columnChartData.setAxisXBottom(axisX);
                        columnChartData.setAxisYLeft(axisY);
                        columnChartData.setStacked(true);
                        holder.chart.setColumnChartData(columnChartData);
                        holder.chart.setZoomEnabled(false);
                        holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
                        holder.date.setText(year + "");
                        holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
                    }
                    if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
                        Calendar tempCal = new GregorianCalendar(year, month - 1, 1);
                        int daysInMonth = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
                        int numColumns = daysInMonth;
                        for (int i = 0; i < numColumns; ++i) {
                            subcolumnValues = new ArrayList<>();
                            SubcolumnValue value = new SubcolumnValue((float) DayExpanseSum[(year - startYear) * 372 + (month - 1) * 31 + i], CoCoinUtil.GetRandomColor());
                            value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + (i + 1) + " " + year);
                            subcolumnValues.add(value);
                            Column column = new Column(subcolumnValues);
                            column.setHasLabels(false);
                            column.setHasLabelsOnlyForSelected(false);
                            columns.add(column);
                        }
                        columnChartData = new ColumnChartData(columns);
                        Axis axisX = new Axis();
                        List<AxisValue> axisValueList = new ArrayList<>();
                        for (int i = 0; i < daysInMonth; i++) {
                            axisValueList.add(new AxisValue(i).setLabel(i + 1 + ""));
                        }
                        axisX.setValues(axisValueList);
                        Axis axisY = new Axis().setHasLines(true);
                        columnChartData.setAxisXBottom(axisX);
                        columnChartData.setAxisYLeft(axisY);
                        columnChartData.setStacked(true);
                        holder.chart.setColumnChartData(columnChartData);
                        holder.chart.setZoomEnabled(false);
                        holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
                        holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
                        holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
                    }
                    holder.iconRight.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                SelectedPosition[position] = (SelectedPosition[position] + 1) % columns.size();
                            } while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.COLUMN);
                            holder.chart.selectValue(selectedValue);
                        }
                    });
                    holder.iconLeft.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                SelectedPosition[position] = (SelectedPosition[position] - 1 + columns.size()) % columns.size();
                            } while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.COLUMN);
                            holder.chart.selectValue(selectedValue);
                        }
                    });
                    break;
                case HISTOGRAM:
                    columns = new ArrayList<>();
                    if (type.get(position - 1).equals(SHOW_IN_YEAR)) {
                        int numColumns = 12;
                        for (int i = 0; i < numColumns; i++) {
                            subcolumnValues = new ArrayList<>();
                            SubcolumnValue value = new SubcolumnValue(MonthExpanseSum[(year - startYear) * 12 + i], CoCoinUtil.GetRandomColor());
                            value.setLabel(CoCoinUtil.MONTHS_SHORT[month] + " " + year);
                            subcolumnValues.add(value);
                            Column column = new Column(subcolumnValues);
                            column.setHasLabels(false);
                            column.setHasLabelsOnlyForSelected(false);
                            columns.add(column);
                        }
                        columnChartData = new ColumnChartData(columns);
                        Axis axisX = new Axis();
                        List<AxisValue> axisValueList = new ArrayList<>();
                        for (int i = 0; i < numColumns; i++) {
                            axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetMonthShort(i + 1)));
                        }
                        axisX.setValues(axisValueList);
                        Axis axisY = new Axis().setHasLines(true);
                        columnChartData.setAxisXBottom(axisX);
                        columnChartData.setAxisYLeft(axisY);
                        columnChartData.setStacked(true);
                        holder.chart.setColumnChartData(columnChartData);
                        holder.chart.setZoomEnabled(false);
                        holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
                        holder.date.setText(year + "");
                        holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
                    }
                    if (type.get(position - 1).equals(SHOW_IN_MONTH)) {
                        Calendar tempCal = Calendar.getInstance();
                        tempCal.set(year, month - 1, 1);
                        tempCal.add(Calendar.SECOND, 0);
                        int daysInMonth = tempCal.getActualMaximum(Calendar.DAY_OF_MONTH);
                        int p = contents.get(position - 1).size() - 1;
                        int numColumns = daysInMonth;
                        for (int i = 0; i < numColumns; ++i) {
                            subcolumnValues = new ArrayList<>();
                            SubcolumnValue value = new SubcolumnValue(0, CoCoinUtil.GetRandomColor());
                            subcolumnValues.add(value);
                            while (p >= 0 && contents.get(position - 1).get(p).getCalendar().get(Calendar.DAY_OF_MONTH) == i + 1) {
                                subcolumnValues.get(0).setValue(subcolumnValues.get(0).getValue() + (float) contents.get(position - 1).get(p).getMoney());
                                subcolumnValues.get(0).setLabel(p + "");
                                p--;
                            }
                            Column column = new Column(subcolumnValues);
                            column.setHasLabels(false);
                            column.setHasLabelsOnlyForSelected(false);
                            columns.add(column);
                        }
                        columnChartData = new ColumnChartData(columns);
                        Axis axisX = new Axis();
                        List<AxisValue> axisValueList = new ArrayList<>();
                        for (int i = 0; i < daysInMonth; i++) {
                            axisValueList.add(new AxisValue(i).setLabel(i + 1 + ""));
                        }
                        axisX.setValues(axisValueList);
                        Axis axisY = new Axis().setHasLines(true);
                        columnChartData.setAxisXBottom(axisX);
                        columnChartData.setAxisYLeft(axisY);
                        columnChartData.setStacked(true);
                        holder.chart.setColumnChartData(columnChartData);
                        holder.chart.setZoomEnabled(false);
                        holder.chart.setOnValueTouchListener(new ValueTouchListener(position - 1));
                        holder.date.setText(year + " " + CoCoinUtil.GetMonthShort(month));
                        holder.expanse.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position - 1)));
                    }
                    holder.iconRight.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                SelectedPosition[position] = (SelectedPosition[position] + 1) % columns.size();
                            } while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
                            holder.chart.selectValue(selectedValue);
                        }
                    });
                    holder.iconLeft.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                SelectedPosition[position] = (SelectedPosition[position] - 1 + columns.size()) % columns.size();
                            } while (holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().size() == 0 || holder.chart.getChartData().getColumns().get(SelectedPosition[position]).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(SelectedPosition[position], 0, SelectedValue.SelectedValueType.NONE);
                            holder.chart.selectValue(selectedValue);
                        }
                    });
                    break;
            }
    }
}
Also used : ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) Column(lecho.lib.hellocharts.model.Column) SubcolumnValue(lecho.lib.hellocharts.model.SubcolumnValue) Axis(lecho.lib.hellocharts.model.Axis) SelectedValue(lecho.lib.hellocharts.model.SelectedValue) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) PieChartData(lecho.lib.hellocharts.model.PieChartData) InjectView(butterknife.InjectView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ColumnChartView(lecho.lib.hellocharts.view.ColumnChartView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) AxisValue(lecho.lib.hellocharts.model.AxisValue) ColumnChartData(lecho.lib.hellocharts.model.ColumnChartData) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 7 with SubcolumnValue

use of lecho.lib.hellocharts.model.SubcolumnValue in project hellocharts-android by lecho.

the class ComboLineColumnChartView method callTouchListener.

@Override
public void callTouchListener() {
    SelectedValue selectedValue = chartRenderer.getSelectedValue();
    if (selectedValue.isSet()) {
        if (SelectedValueType.COLUMN.equals(selectedValue.getType())) {
            SubcolumnValue value = data.getColumnChartData().getColumns().get(selectedValue.getFirstIndex()).getValues().get(selectedValue.getSecondIndex());
            onValueTouchListener.onColumnValueSelected(selectedValue.getFirstIndex(), selectedValue.getSecondIndex(), value);
        } else if (SelectedValueType.LINE.equals(selectedValue.getType())) {
            PointValue value = data.getLineChartData().getLines().get(selectedValue.getFirstIndex()).getValues().get(selectedValue.getSecondIndex());
            onValueTouchListener.onPointValueSelected(selectedValue.getFirstIndex(), selectedValue.getSecondIndex(), value);
        } else {
            throw new IllegalArgumentException("Invalid selected value type " + selectedValue.getType().name());
        }
    } else {
        onValueTouchListener.onValueDeselected();
    }
}
Also used : PointValue(lecho.lib.hellocharts.model.PointValue) SubcolumnValue(lecho.lib.hellocharts.model.SubcolumnValue) SelectedValue(lecho.lib.hellocharts.model.SelectedValue)

Example 8 with SubcolumnValue

use of lecho.lib.hellocharts.model.SubcolumnValue in project CoCoin by Nightonke.

the class TodayViewRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
    switch(getItemViewType(position)) {
        case TYPE_HEADER:
            holder.date.setText(dateString);
            holder.dateBottom.setText(dateString);
            holder.expanseSum.setText(CoCoinUtil.GetInMoney((int) Sum));
            holder.date.setTypeface(CoCoinUtil.GetTypeface());
            holder.dateBottom.setTypeface(CoCoinUtil.GetTypeface());
            holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
            if (IS_EMPTY) {
                holder.emptyTip.setVisibility(View.VISIBLE);
                holder.emptyTip.setText(CoCoinUtil.GetTodayViewEmptyTip(fragmentPosition));
                holder.emptyTip.setTypeface(CoCoinUtil.GetTypeface());
                holder.reset.setVisibility(View.GONE);
                holder.pie.setVisibility(View.GONE);
                holder.iconLeft.setVisibility(View.GONE);
                holder.iconRight.setVisibility(View.GONE);
                holder.histogram.setVisibility(View.GONE);
                holder.histogram_icon_left.setVisibility(View.GONE);
                holder.histogram_icon_right.setVisibility(View.GONE);
                holder.all.setVisibility(View.GONE);
                holder.dateBottom.setVisibility(View.GONE);
            } else {
                holder.emptyTip.setVisibility(View.GONE);
                final ArrayList<SliceValue> sliceValues = new ArrayList<>();
                for (Map.Entry<Integer, Double> entry : TagExpanse.entrySet()) {
                    if (entry.getValue() >= 1) {
                        SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), mContext.getApplicationContext().getResources().getColor(CoCoinUtil.GetTagColorResource(entry.getKey())));
                        sliceValue.setLabel(String.valueOf(entry.getKey()));
                        sliceValues.add(sliceValue);
                    }
                }
                final PieChartData pieChartData = new PieChartData(sliceValues);
                pieChartData.setHasLabels(false);
                pieChartData.setHasLabelsOnlyForSelected(false);
                pieChartData.setHasLabelsOutside(false);
                pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
                holder.pie.setPieChartData(pieChartData);
                holder.pie.setChartRotationEnabled(false);
                // two control button of pie////////////////////////////////////////////////////////////////////////
                holder.iconRight.setVisibility(View.VISIBLE);
                holder.iconRight.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (lastPieSelectedPosition != -1) {
                            pieSelectedPosition = lastPieSelectedPosition;
                        }
                        pieSelectedPosition = (pieSelectedPosition - 1 + sliceValues.size()) % sliceValues.size();
                        SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                        holder.pie.selectValue(selectedValue);
                    }
                });
                holder.iconLeft.setVisibility(View.VISIBLE);
                holder.iconLeft.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (lastPieSelectedPosition != -1) {
                            pieSelectedPosition = lastPieSelectedPosition;
                        }
                        pieSelectedPosition = (pieSelectedPosition + 1) % sliceValues.size();
                        SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                        holder.pie.selectValue(selectedValue);
                    }
                });
                final List<Column> columns = new ArrayList<>();
                final ColumnChartData columnChartData = new ColumnChartData(columns);
                if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                    for (int i = 0; i < columnNumber; i++) {
                        if (lastHistogramSelectedPosition == -1 && originalTargets[i] == 0) {
                            lastHistogramSelectedPosition = i;
                        }
                        SubcolumnValue value = new SubcolumnValue(originalTargets[i], CoCoinUtil.GetRandomColor());
                        List<SubcolumnValue> subcolumnValues = new ArrayList<>();
                        subcolumnValues.add(value);
                        Column column = new Column(subcolumnValues);
                        column.setHasLabels(false);
                        column.setHasLabelsOnlyForSelected(false);
                        columns.add(column);
                    }
                    Axis axisX = new Axis();
                    List<AxisValue> axisValueList = new ArrayList<>();
                    for (int i = 0; i < columnNumber; i++) {
                        axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetAxisDateName(axis_date, i)));
                    }
                    axisX.setValues(axisValueList);
                    Axis axisY = new Axis().setHasLines(true);
                    columnChartData.setAxisXBottom(axisX);
                    columnChartData.setAxisYLeft(axisY);
                    columnChartData.setStacked(true);
                    holder.histogram.setColumnChartData(columnChartData);
                    holder.histogram.setZoomEnabled(false);
                    // two control button of histogram//////////////////////////////////////////////////////////////////
                    holder.histogram_icon_left.setVisibility(View.VISIBLE);
                    holder.histogram_icon_left.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                lastHistogramSelectedPosition = (lastHistogramSelectedPosition - 1 + columnNumber) % columnNumber;
                            } while (columnChartData.getColumns().get(lastHistogramSelectedPosition).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(lastHistogramSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                            holder.histogram.selectValue(selectedValue);
                        }
                    });
                    holder.histogram_icon_right.setVisibility(View.VISIBLE);
                    holder.histogram_icon_right.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            do {
                                lastHistogramSelectedPosition = (lastHistogramSelectedPosition + 1) % columnNumber;
                            } while (columnChartData.getColumns().get(lastHistogramSelectedPosition).getValues().get(0).getValue() == 0);
                            SelectedValue selectedValue = new SelectedValue(lastHistogramSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
                            holder.histogram.selectValue(selectedValue);
                        }
                    });
                }
                if (fragmentPosition == TODAY || fragmentPosition == YESTERDAY) {
                    holder.histogram_icon_left.setVisibility(View.INVISIBLE);
                    holder.histogram_icon_right.setVisibility(View.INVISIBLE);
                    holder.histogram.setVisibility(View.GONE);
                    holder.dateBottom.setVisibility(View.GONE);
                    holder.reset.setVisibility(View.GONE);
                }
                // set value touch listener of pie//////////////////////////////////////////////////////////////////
                holder.pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {

                    @Override
                    public void onValueSelected(int p, SliceValue sliceValue) {
                        // snack bar
                        RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
                        String text;
                        tagId = Integer.valueOf(String.valueOf(sliceValue.getLabelAsChars()));
                        double percent = sliceValue.getValue() / Sum * 100;
                        if ("zh".equals(CoCoinUtil.GetLanguage())) {
                            text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + CoCoinUtil.GetPercentString(percent) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
                        } else {
                            text = "Spend " + (int) sliceValue.getValue() + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
                        }
                        if ("zh".equals(CoCoinUtil.GetLanguage())) {
                            dialogTitle = dateShownString + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
                        } else {
                            dialogTitle = "Spend " + (int) sliceValue.getValue() + dateShownString + "\n" + "in " + CoCoinUtil.GetTagName(tagId);
                        }
                        Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(fragmentPosition - 2)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForPie());
                        SnackbarManager.show(snackbar);
                        if (p == lastPieSelectedPosition) {
                            return;
                        } else {
                            lastPieSelectedPosition = p;
                        }
                        if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                            // histogram data///////////////////////////////////////////////////////////////////////////////////
                            float[] targets = new float[columnNumber];
                            for (int i = 0; i < columnNumber; i++) targets[i] = 0;
                            for (int i = Expanse.get(tagId).size() - 1; i >= 0; i--) {
                                CoCoinRecord coCoinRecord = Expanse.get(tagId).get(i);
                                if (axis_date == Calendar.DAY_OF_WEEK) {
                                    if (CoCoinUtil.WEEK_START_WITH_SUNDAY) {
                                        targets[coCoinRecord.getCalendar().get(axis_date) - 1] += coCoinRecord.getMoney();
                                    } else {
                                        targets[(coCoinRecord.getCalendar().get(axis_date) + 5) % 7] += coCoinRecord.getMoney();
                                    }
                                } else if (axis_date == Calendar.DAY_OF_MONTH) {
                                    targets[coCoinRecord.getCalendar().get(axis_date) - 1] += coCoinRecord.getMoney();
                                } else {
                                    targets[coCoinRecord.getCalendar().get(axis_date)] += coCoinRecord.getMoney();
                                }
                            }
                            lastHistogramSelectedPosition = -1;
                            for (int i = 0; i < columnNumber; i++) {
                                if (lastHistogramSelectedPosition == -1 && targets[i] != 0) {
                                    lastHistogramSelectedPosition = i;
                                }
                                columnChartData.getColumns().get(i).getValues().get(0).setTarget(targets[i]);
                            }
                            holder.histogram.startDataAnimation();
                        }
                    }

                    @Override
                    public void onValueDeselected() {
                    }
                });
                if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                    // set value touch listener of histogram////////////////////////////////////////////////////////////
                    holder.histogram.setOnValueTouchListener(new ColumnChartOnValueSelectListener() {

                        @Override
                        public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
                            lastHistogramSelectedPosition = columnIndex;
                            timeIndex = columnIndex;
                            // snack bar
                            RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
                            String text = CoCoinUtil.GetSpendString((int) value.getValue());
                            if (tagId != -1)
                                // belongs a tag
                                if ("zh".equals(CoCoinUtil.GetLanguage()))
                                    text = getSnackBarDateString() + text + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
                                else
                                    text += getSnackBarDateString() + "\n" + "in " + CoCoinUtil.GetTagName(tagId);
                            else // don't belong to any tag
                            if ("zh".equals(CoCoinUtil.GetLanguage()))
                                text = getSnackBarDateString() + "\n" + text;
                            else
                                text += "\n" + getSnackBarDateString();
                            // setting the snack bar and dialog title of histogram//////////////////////////////////////////////
                            dialogTitle = text;
                            Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(fragmentPosition - 2)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForHistogram());
                            SnackbarManager.show(snackbar);
                        }

                        @Override
                        public void onValueDeselected() {
                        }
                    });
                }
                // set the listener of the reset button/////////////////////////////////////////////////////////////
                if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
                    holder.reset.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            tagId = -1;
                            lastHistogramSelectedPosition = -1;
                            for (int i = 0; i < columnNumber; i++) {
                                if (lastHistogramSelectedPosition == -1 && originalTargets[i] != 0) {
                                    lastHistogramSelectedPosition = i;
                                }
                                columnChartData.getColumns().get(i).getValues().get(0).setTarget(originalTargets[i]);
                            }
                            holder.histogram.startDataAnimation();
                        }
                    });
                }
                // set the listener of the show all button//////////////////////////////////////////////////////////
                holder.all.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, allData, getAllDataDialogTitle()), "MyDialog").commit();
                    }
                });
            }
            break;
        case TYPE_BODY:
            holder.tagImage.setImageResource(CoCoinUtil.GetTagIcon(allData.get(position - 1).getTag()));
            holder.money.setText((int) allData.get(position - 1).getMoney() + "");
            holder.money.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.cell_date.setText(allData.get(position - 1).getCalendarString());
            holder.cell_date.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.remark.setText(allData.get(position - 1).getRemark());
            holder.remark.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.index.setText(position + "");
            holder.index.setTypeface(CoCoinUtil.typefaceLatoLight);
            holder.layout.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String subTitle;
                    double spend = allData.get(position - 1).getMoney();
                    int tagId = allData.get(position - 1).getTag();
                    if ("zh".equals(CoCoinUtil.GetLanguage())) {
                        subTitle = CoCoinUtil.GetSpendString((int) spend) + "于" + CoCoinUtil.GetTagName(tagId);
                    } else {
                        subTitle = "Spend " + (int) spend + "in " + CoCoinUtil.GetTagName(tagId);
                    }
                    dialog = new MaterialDialog.Builder(mContext).icon(CoCoinUtil.GetTagIconDrawable(allData.get(position - 1).getTag())).limitIconToDefaultSize().title(subTitle).customView(R.layout.dialog_a_record, true).positiveText(R.string.get).show();
                    dialogView = dialog.getCustomView();
                    TextView remark = (TextView) dialogView.findViewById(R.id.remark);
                    TextView date = (TextView) dialogView.findViewById(R.id.date);
                    remark.setText(allData.get(position - 1).getRemark());
                    date.setText(allData.get(position - 1).getCalendarString());
                }
            });
            break;
    }
}
Also used : ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) RecordCheckDialogFragment(com.nightonke.saver.fragment.RecordCheckDialogFragment) Column(lecho.lib.hellocharts.model.Column) SubcolumnValue(lecho.lib.hellocharts.model.SubcolumnValue) TextView(android.widget.TextView) Axis(lecho.lib.hellocharts.model.Axis) SelectedValue(lecho.lib.hellocharts.model.SelectedValue) PieChartData(lecho.lib.hellocharts.model.PieChartData) ColumnChartOnValueSelectListener(lecho.lib.hellocharts.listener.ColumnChartOnValueSelectListener) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ColumnChartView(lecho.lib.hellocharts.view.ColumnChartView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) CoCoinRecord(com.nightonke.saver.model.CoCoinRecord) PieChartOnValueSelectListener(lecho.lib.hellocharts.listener.PieChartOnValueSelectListener) FragmentActivity(android.support.v4.app.FragmentActivity) AxisValue(lecho.lib.hellocharts.model.AxisValue) RecordManager(com.nightonke.saver.model.RecordManager) ColumnChartData(lecho.lib.hellocharts.model.ColumnChartData) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Snackbar(com.nispok.snackbar.Snackbar)

Aggregations

SubcolumnValue (lecho.lib.hellocharts.model.SubcolumnValue)8 Column (lecho.lib.hellocharts.model.Column)4 SelectedValue (lecho.lib.hellocharts.model.SelectedValue)4 View (android.view.View)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 ColumnChartData (lecho.lib.hellocharts.model.ColumnChartData)3 PieChartData (lecho.lib.hellocharts.model.PieChartData)3 SliceValue (lecho.lib.hellocharts.model.SliceValue)3 ColumnChartView (lecho.lib.hellocharts.view.ColumnChartView)3 PieChartView (lecho.lib.hellocharts.view.PieChartView)3 Paint (android.graphics.Paint)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ImageView (android.widget.ImageView)2 InjectView (butterknife.InjectView)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Axis (lecho.lib.hellocharts.model.Axis)2 AxisValue (lecho.lib.hellocharts.model.AxisValue)2 PointValue (lecho.lib.hellocharts.model.PointValue)2