use of lecho.lib.hellocharts.listener.PieChartOnValueSelectListener in project CoCoin by Nightonke.
the class ReportViewFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
IS_EMPTY = RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.isEmpty();
mScrollView = (ObservableScrollView) view.findViewById(R.id.scrollView);
MaterialViewPagerHelper.registerScrollView(getActivity(), mScrollView, null);
expenseTV = (TextView) view.findViewById(R.id.expense);
expenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
expenseTV.setText(CoCoinUtil.GetInMoney(0));
tagsTV = (TextView) view.findViewById(R.id.tags);
tagsTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
tagsTV.setText("");
title = (TextView) view.findViewById(R.id.title);
title.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
pieLayout = (LinearLayout) view.findViewById(R.id.pie_layout);
pieLayout.setVisibility(View.GONE);
pieTitle = (TextView) view.findViewById(R.id.pie_title);
pieTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
pie = (PieChartView) view.findViewById(R.id.chart_pie);
pie.setChartRotationEnabled(false);
pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {
@Override
public void onValueSelected(int p, SliceValue sliceValue) {
// snack bar
String text;
tagId = Integer.valueOf(String.valueOf(sliceValue.getLabelAsChars()));
double percent = sliceValue.getValue() / expense * 100;
if ("zh".equals(CoCoinUtil.GetLanguage())) {
text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + CoCoinUtil.GetPercentString(percent) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
} else {
text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
}
if ("zh".equals(CoCoinUtil.GetLanguage())) {
if (selectYear) {
dialogTitle = from.get(Calendar.YEAR) + "年" + "\n" + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + "于" + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = from.get(Calendar.YEAR) + "年" + (from.get(Calendar.MONTH) + 1) + "月" + "\n" + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + "于" + CoCoinUtil.GetTagName(tagId);
}
} else {
if (selectYear) {
dialogTitle = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " in " + from.get(Calendar.YEAR) + "\n" + "on " + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " in " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.YEAR) + "\n" + "on " + 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(-3)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
new GetData(from, to, tagId, dialogTitle).execute();
}
});
SnackbarManager.show(snackbar);
if (p == lastPieSelectedPosition) {
return;
} else {
lastPieSelectedPosition = p;
}
}
@Override
public void onValueDeselected() {
}
});
iconRight = (MaterialIconView) view.findViewById(R.id.icon_right);
iconRight.setOnClickListener(this);
iconLeft = (MaterialIconView) view.findViewById(R.id.icon_left);
iconLeft.setOnClickListener(this);
emptyTip = (TextView) view.findViewById(R.id.empty_tip);
emptyTip.setTypeface(CoCoinUtil.GetTypeface());
if (RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size() != 0) {
emptyTip.setText(mContext.getResources().getString(R.string.report_view_please_select_data));
} else {
emptyTip.setText(mContext.getResources().getString(R.string.report_view_no_data));
isEmpty = true;
}
highestTagLayout = (LinearLayout) view.findViewById(R.id.highest_tag_layout);
highestTagLayout.setVisibility(View.GONE);
highestTagTitle = (TextView) view.findViewById(R.id.highest_tag_title);
highestTagTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestFirst = (LinearLayout) view.findViewById(R.id.highest_first);
highestFirst.setOnClickListener(this);
highestTagIcon = (ImageView) view.findViewById(R.id.highest_tag_icon);
highestTagText = (TextView) view.findViewById(R.id.highest_tag_text);
highestTagText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestTagExpenseTV = (TextView) view.findViewById(R.id.highest_tag_expense);
highestTagExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestTagRecord = (TextView) view.findViewById(R.id.highest_tag_sum);
highestTagRecord.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestTags = (ExpandedListView) view.findViewById(R.id.highest_tags);
highestTagsLayout = (ExpandableRelativeLayout) view.findViewById(R.id.expand_highest_tag);
highestTagMore = (LinearLayout) view.findViewById(R.id.highest_tag_more);
highestTagMore.setOnClickListener(this);
highestTagMoreText = (TextView) view.findViewById(R.id.highest_tag_more_text);
highestTagMoreText.setTypeface(CoCoinUtil.getInstance().GetTypeface());
highestTags.setOnItemClickListener(this);
lowestTagLayout = (LinearLayout) view.findViewById(R.id.lowest_tag_layout);
lowestTagLayout.setVisibility(View.GONE);
lowestTagTitle = (TextView) view.findViewById(R.id.lowest_tag_title);
lowestTagTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestFirst = (LinearLayout) view.findViewById(R.id.lowest_first);
lowestFirst.setOnClickListener(this);
lowestTagIcon = (ImageView) view.findViewById(R.id.lowest_tag_icon);
lowestTagText = (TextView) view.findViewById(R.id.lowest_tag_text);
lowestTagText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestTagExpenseTV = (TextView) view.findViewById(R.id.lowest_tag_expense);
lowestTagExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestTagRecord = (TextView) view.findViewById(R.id.lowest_tag_sum);
lowestTagRecord.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestTags = (ExpandedListView) view.findViewById(R.id.lowest_tags);
lowestTagsLayout = (ExpandableRelativeLayout) view.findViewById(R.id.expand_lowest_tag);
lowestTagMore = (LinearLayout) view.findViewById(R.id.lowest_tag_more);
lowestTagMore.setOnClickListener(this);
lowestTagMoreText = (TextView) view.findViewById(R.id.lowest_tag_more_text);
lowestTagMoreText.setTypeface(CoCoinUtil.getInstance().GetTypeface());
lowestTags.setOnItemClickListener(this);
lineLayout = (LinearLayout) view.findViewById(R.id.line_layout);
lineLayout.setVisibility(View.GONE);
lineTitle = (TextView) view.findViewById(R.id.line_title);
lineTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
line = (LineChartView) view.findViewById(R.id.chart_line);
line.setZoomEnabled(false);
line.setOnValueTouchListener(new LineChartOnValueSelectListener() {
@Override
public void onValueSelected(int lineIndex, int pointIndex, PointValue value) {
// snack bar
String text;
double percent = value.getY() / expense * 100;
if ("zh".equals(CoCoinUtil.GetLanguage())) {
if (selectYear) {
text = "在" + reportYear + " " + CoCoinUtil.getInstance().GetMonthShort((int) value.getX() + 1) + "\n" + CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent);
} else {
text = "在" + CoCoinUtil.getInstance().GetMonthShort(reportMonth) + " " + ((int) value.getX() + 1) + CoCoinUtil.getInstance().GetWhetherFuck() + "\n" + CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent);
}
} else {
if (selectYear) {
text = CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent) + "\n" + "in " + reportYear + " " + CoCoinUtil.getInstance().GetMonthShort((int) value.getX() + 1);
} else {
text = CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent) + "\n" + "on " + CoCoinUtil.getInstance().GetMonthShort(reportMonth) + " " + ((int) value.getX() + 1) + CoCoinUtil.getInstance().GetWhetherFuck();
}
}
if ("zh".equals(CoCoinUtil.GetLanguage())) {
if (selectYear) {
dialogTitle = "在" + reportYear + " " + CoCoinUtil.getInstance().GetMonthShort((int) value.getX() + 1) + "\n" + CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent);
} else {
dialogTitle = "在" + CoCoinUtil.getInstance().GetMonthShort(reportMonth) + " " + ((int) value.getX() + 1) + CoCoinUtil.getInstance().GetWhetherFuck() + "\n" + CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent);
}
} else {
if (selectYear) {
dialogTitle = CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent) + "\n" + "in " + reportYear + " " + CoCoinUtil.getInstance().GetMonthShort((int) value.getX() + 1);
} else {
dialogTitle = CoCoinUtil.GetSpendString((int) value.getY()) + CoCoinUtil.GetPercentString(percent) + "\n" + "on " + CoCoinUtil.getInstance().GetMonthShort(reportMonth) + " " + ((int) value.getX() + 1) + CoCoinUtil.getInstance().GetWhetherFuck();
}
}
final Calendar tempFrom = Calendar.getInstance();
final Calendar tempTo = Calendar.getInstance();
if (selectYear) {
tempFrom.set(reportYear, (int) value.getX(), 1, 0, 0, 0);
tempFrom.add(Calendar.SECOND, 0);
tempTo.set(reportYear, (int) value.getX(), tempFrom.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);
tempTo.add(Calendar.SECOND, 0);
} else {
tempFrom.set(reportYear, reportMonth - 1, (int) value.getX() + 1, 0, 0, 0);
tempFrom.add(Calendar.SECOND, 0);
tempTo.set(reportYear, reportMonth - 1, (int) value.getX() + 1, 23, 59, 59);
tempTo.add(Calendar.SECOND, 0);
}
Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(-3)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
new GetData(tempFrom, tempTo, Integer.MIN_VALUE, dialogTitle).execute();
}
});
SnackbarManager.show(snackbar);
if (pointIndex == lastLineSelectedPosition) {
return;
} else {
lastLineSelectedPosition = pointIndex;
}
}
@Override
public void onValueDeselected() {
}
});
iconRightLine = (MaterialIconView) view.findViewById(R.id.icon_right_line);
iconRightLine.setOnClickListener(this);
iconLeftLine = (MaterialIconView) view.findViewById(R.id.icon_left_line);
iconLeftLine.setOnClickListener(this);
highestMonthLayout = (LinearLayout) view.findViewById(R.id.highest_month_layout);
highestMonthLayout.setVisibility(View.GONE);
monthTitle = (TextView) view.findViewById(R.id.month_title);
monthTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestFirstMonth = (LinearLayout) view.findViewById(R.id.highest_first_month);
highestFirstMonth.setOnClickListener(this);
highestFirstIcon = (TextView) view.findViewById(R.id.highest_month_icon);
highestFirstIcon.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestFirstText = (TextView) view.findViewById(R.id.highest_month_text);
highestFirstText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestFirstExpenseTV = (TextView) view.findViewById(R.id.highest_month_expense);
highestFirstExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestFirstRecord = (TextView) view.findViewById(R.id.highest_month_sum);
highestFirstRecord.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestMonths = (ExpandedListView) view.findViewById(R.id.highest_month);
highestMonths.setOnItemClickListener(this);
highestMonthsLayout = (ExpandableRelativeLayout) view.findViewById(R.id.expand_highest_month);
highestLast = (LinearLayout) view.findViewById(R.id.highest_last_month);
highestLast.setOnClickListener(this);
highestLastIcon = (TextView) view.findViewById(R.id.lowest_month_icon);
highestLastIcon.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestLastText = (TextView) view.findViewById(R.id.lowest_month_text);
highestLastText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestLastExpenseTV = (TextView) view.findViewById(R.id.lowest_month_expense);
highestLastExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestLastRecord = (TextView) view.findViewById(R.id.lowest_month_sum);
highestLastRecord.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestMonthMore = (LinearLayout) view.findViewById(R.id.highest_month_more);
highestMonthMore.setOnClickListener(this);
highestMonthMoreText = (TextView) view.findViewById(R.id.highest_month_more_text);
highestMonthMoreText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
averageMonthText = (TextView) view.findViewById(R.id.average_month_text);
averageMonthText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
averageMonthExpenseTV = (TextView) view.findViewById(R.id.average_month_expense);
averageMonthExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
averageMonthRecordTV = (TextView) view.findViewById(R.id.average_month_sum);
averageMonthRecordTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestDayLayout = (LinearLayout) view.findViewById(R.id.highest_day_layout);
highestDayLayout.setVisibility(View.GONE);
highestDayTitle = (TextView) view.findViewById(R.id.highest_day_title);
highestDayTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestFirstDay = (LinearLayout) view.findViewById(R.id.highest_first_day);
highestFirstDay.setOnClickListener(this);
highestDayIcon = (TextView) view.findViewById(R.id.highest_day_icon);
highestDayIcon.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestDayText = (TextView) view.findViewById(R.id.highest_day_text);
highestDayText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestDayExpenseTV = (TextView) view.findViewById(R.id.highest_day_expense);
highestDayExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestDayRecord = (TextView) view.findViewById(R.id.highest_day_sum);
highestDayRecord.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
highestDays = (ExpandedListView) view.findViewById(R.id.highest_days);
highestDaysLayout = (ExpandableRelativeLayout) view.findViewById(R.id.expand_highest_day);
highestDayMore = (LinearLayout) view.findViewById(R.id.highest_day_more);
highestDayMore.setOnClickListener(this);
highestDayMoreText = (TextView) view.findViewById(R.id.highest_day_more_text);
highestDayMoreText.setTypeface(CoCoinUtil.getInstance().GetTypeface());
highestDays.setOnItemClickListener(this);
lowestDayLayout = (LinearLayout) view.findViewById(R.id.lowest_day_layout);
lowestDayLayout.setVisibility(View.GONE);
lowestDayTitle = (TextView) view.findViewById(R.id.lowest_day_title);
lowestDayTitle.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestFirstDay = (LinearLayout) view.findViewById(R.id.lowest_first_day);
lowestFirstDay.setOnClickListener(this);
lowestDayIcon = (TextView) view.findViewById(R.id.lowest_day_icon);
lowestDayIcon.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestDayText = (TextView) view.findViewById(R.id.lowest_day_text);
lowestDayText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestDayExpenseTV = (TextView) view.findViewById(R.id.lowest_day_expense);
lowestDayExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestDayRecord = (TextView) view.findViewById(R.id.lowest_day_sum);
lowestDayRecord.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
lowestDays = (ExpandedListView) view.findViewById(R.id.lowest_days);
lowestDaysLayout = (ExpandableRelativeLayout) view.findViewById(R.id.expand_lowest_day);
lowestDayMore = (LinearLayout) view.findViewById(R.id.lowest_day_more);
lowestDayMore.setOnClickListener(this);
lowestDayMoreText = (TextView) view.findViewById(R.id.lowest_day_more_text);
lowestDayMoreText.setTypeface(CoCoinUtil.getInstance().GetTypeface());
lowestDays.setOnItemClickListener(this);
averageDayText = (TextView) view.findViewById(R.id.average_day_text);
averageDayText.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
averageDayExpenseTV = (TextView) view.findViewById(R.id.average_day_expense);
averageDayExpenseTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
averageDayRecordTV = (TextView) view.findViewById(R.id.average_day_sum);
averageDayRecordTV.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
foot = (TextView) view.findViewById(R.id.foot);
foot.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
foot.setVisibility(View.GONE);
if (IS_EMPTY) {
emptyTip.setVisibility(View.GONE);
}
button = (FloatingActionButton) view.findViewById(R.id.button);
button.setOnClickListener(this);
new GetSelectListData(false).execute();
}
use of lecho.lib.hellocharts.listener.PieChartOnValueSelectListener in project CoCoin by Nightonke.
the class CustomViewFragment method select.
private void select() {
if (RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS == null || RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size() == 0) {
return;
}
start = -1;
end = 0;
Sum = 0;
lastPieSelectedPosition = -1;
if (from.after(RecordManager.RECORDS.get(RecordManager.RECORDS.size() - 1).getCalendar())) {
return;
}
if (to.before(RecordManager.RECORDS.get(0).getCalendar())) {
return;
}
for (int i = RecordManager.RECORDS.size() - 1; i >= 0; i--) {
if (RecordManager.RECORDS.get(i).getCalendar().before(from)) {
end = i + 1;
break;
} else if (RecordManager.RECORDS.get(i).getCalendar().before(to)) {
if (start == -1) {
start = i;
}
}
}
startDayCalendar = (Calendar) from.clone();
startDayCalendar.set(Calendar.HOUR_OF_DAY, 0);
startDayCalendar.set(Calendar.MINUTE, 0);
startDayCalendar.set(Calendar.SECOND, 0);
final long startDay = TimeUnit.MILLISECONDS.toDays(startDayCalendar.getTimeInMillis());
final long days = TimeUnit.MILLISECONDS.toDays(to.getTimeInMillis()) - startDay + 1;
TagExpanse = new TreeMap<>();
Expanse = new HashMap<>();
originalTargets = new float[(int) days];
int size = RecordManager.TAGS.size();
for (int j = 2; j < size; j++) {
TagExpanse.put(RecordManager.TAGS.get(j).getId(), Double.valueOf(0));
Expanse.put(RecordManager.TAGS.get(j).getId(), new ArrayList<CoCoinRecord>());
}
for (int i = start; i >= end; i--) {
CoCoinRecord coCoinRecord = RecordManager.RECORDS.get(i);
TagExpanse.put(coCoinRecord.getTag(), TagExpanse.get(coCoinRecord.getTag()) + Double.valueOf(coCoinRecord.getMoney()));
Expanse.get(coCoinRecord.getTag()).add(coCoinRecord);
Sum += coCoinRecord.getMoney();
originalTargets[(int) (TimeUnit.MILLISECONDS.toDays(coCoinRecord.getCalendar().getTimeInMillis()) - startDay)] += coCoinRecord.getMoney();
}
expense.setText(CoCoinUtil.GetInMoney(Sum));
emptyTip.setVisibility(View.GONE);
TagExpanse = CoCoinUtil.SortTreeMapByValues(TagExpanse);
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(), CoCoinUtil.GetTagColor(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());
pie.setPieChartData(pieChartData);
pie.setChartRotationEnabled(false);
pie.setVisibility(View.VISIBLE);
iconRight.setVisibility(View.VISIBLE);
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);
pie.selectValue(selectedValue);
}
});
iconLeft.setVisibility(View.VISIBLE);
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);
pie.selectValue(selectedValue);
}
});
// set value touch listener of pie//////////////////////////////////////////////////////////////////
dateShownString = mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + " " + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR);
pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {
@Override
public void onValueSelected(int p, SliceValue sliceValue) {
// snack bar
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 = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
}
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + "于" + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "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(-3)).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;
}
}
@Override
public void onValueDeselected() {
}
});
all.setVisibility(View.VISIBLE);
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<CoCoinRecord> data = new LinkedList<CoCoinRecord>();
for (int i = start; i >= end; i--) data.add(RecordManager.RECORDS.get(i));
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString(Sum) + "于" + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = CoCoinUtil.GetSpendString(Sum) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "in " + CoCoinUtil.GetTagName(tagId);
}
((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, data, dialogTitle), "MyDialog").commit();
}
});
}
use of lecho.lib.hellocharts.listener.PieChartOnValueSelectListener 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;
}
}
Aggregations