use of lecho.lib.hellocharts.model.SelectedValue in project CoCoin by Nightonke.
the class MonthViewRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
if (IS_EMPTY) {
holder.expanseSum.setText("¥0");
holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.emptyTip.setText(mContext.getResources().getString(R.string.tag_empty));
holder.emptyTip.setTypeface(CoCoinUtil.GetTypeface());
holder.tags.setVisibility(View.GONE);
holder.date.setVisibility(View.INVISIBLE);
holder.pie.setVisibility(View.INVISIBLE);
holder.iconLeft.setVisibility(View.INVISIBLE);
holder.iconRight.setVisibility(View.INVISIBLE);
holder.all.setVisibility(View.GONE);
} else {
holder.date.setText(dateStringList.get(position));
holder.expanseSum.setText(CoCoinUtil.GetInMoney((int) (double) SumList.get(position)));
holder.date.setTypeface(CoCoinUtil.GetTypeface());
holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.tags.setTypeface(CoCoinUtil.typefaceLatoLight);
if ("zh".equals(CoCoinUtil.GetLanguage())) {
holder.tags.setText(" ● " + records + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_records) + tags + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_tags));
} else {
holder.tags.setText(" ● " + records + " " + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_records) + " " + tags + " " + CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_tags));
}
if (SumList.get(position).equals(Double.valueOf(0))) {
holder.emptyTip.setVisibility(View.VISIBLE);
holder.emptyTip.setTypeface(CoCoinUtil.typefaceLatoLight);
} else {
holder.emptyTip.setVisibility(View.GONE);
}
holder.pie.setPieChartData(pieChartDataList.get(position));
holder.pie.setOnValueTouchListener(new PieValueTouchListener(position));
holder.pie.setChartRotationEnabled(false);
if (!SumList.get(position).equals(Double.valueOf(0))) {
holder.iconRight.setVisibility(View.VISIBLE);
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectedPositionList.set(position, (selectedPositionList.get(position) + 1) % sliceValuesList.get(position).size());
SelectedValue selectedValue = new SelectedValue(selectedPositionList.get(position), 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) {
selectedPositionList.set(position, (selectedPositionList.get(position) - 1 + sliceValuesList.get(position).size()) % sliceValuesList.get(position).size());
SelectedValue selectedValue = new SelectedValue(selectedPositionList.get(position), 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
} else {
holder.iconLeft.setVisibility(View.GONE);
holder.iconRight.setVisibility(View.GONE);
}
holder.all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = mContext.getResources().getString(R.string.in) + dateStringList.get(position) + " " + CoCoinUtil.GetSpendString((int) (double) SumList.get(position));
} else {
dialogTitle = CoCoinUtil.GetSpendString((int) (double) SumList.get(position)) + mContext.getResources().getString(R.string.in) + " " + dateStringList.get(position);
}
((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, list, dialogTitle), "MyDialog").commit();
}
});
}
}
use of lecho.lib.hellocharts.model.SelectedValue 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;
}
}
}
use of lecho.lib.hellocharts.model.SelectedValue in project CoCoin by Nightonke.
the class ReportViewFragment method onClick.
@Override
public void onClick(View v) {
SelectedValue selectedValue = null;
switch(v.getId()) {
case R.id.icon_right:
if (lastPieSelectedPosition != -1) {
pieSelectedPosition = lastPieSelectedPosition;
}
pieSelectedPosition = (pieSelectedPosition - 1 + pieChartData.getValues().size()) % pieChartData.getValues().size();
selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
pie.selectValue(selectedValue);
break;
case R.id.icon_left:
if (lastPieSelectedPosition != -1) {
pieSelectedPosition = lastPieSelectedPosition;
}
pieSelectedPosition = (pieSelectedPosition + 1) % pieChartData.getValues().size();
selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
pie.selectValue(selectedValue);
break;
case R.id.highest_first:
onItemClick(highestTags, highestTags.getChildAt(0), -1, -1);
break;
case R.id.highest_tag_more:
if (highestTagsLayout != null) {
if (highestTagsLayout.isExpanded()) {
highestTagsLayout.collapse();
highestTagMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_highest_tag_show_more));
} else {
highestTagsLayout.expand();
highestTagMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_highest_tag_show_less));
}
}
break;
case R.id.lowest_first:
onItemClick(lowestTags, lowestTags.getChildAt(0), -1, -1);
break;
case R.id.lowest_tag_more:
if (lowestTagsLayout != null) {
if (lowestTagsLayout.isExpanded()) {
lowestTagsLayout.collapse();
lowestTagMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_more));
} else {
lowestTagsLayout.expand();
lowestTagMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_less));
}
}
break;
case R.id.icon_left_line:
if (lastLineSelectedPosition != -1) {
lineSelectedPosition = lastLineSelectedPosition;
}
lineSelectedPosition = (lineSelectedPosition - 1 + lineChartData.getLines().get(0).getValues().size()) % lineChartData.getLines().get(0).getValues().size();
selectedValue = new SelectedValue(0, lineSelectedPosition, SelectedValue.SelectedValueType.NONE);
line.selectValue(selectedValue);
break;
case R.id.icon_right_line:
if (lastLineSelectedPosition != -1) {
lineSelectedPosition = lastLineSelectedPosition;
}
lineSelectedPosition = (lineSelectedPosition + 1) % lineChartData.getLines().get(0).getValues().size();
selectedValue = new SelectedValue(0, lineSelectedPosition, SelectedValue.SelectedValueType.NONE);
line.selectValue(selectedValue);
break;
case R.id.highest_first_month:
onItemClick(highestMonths, highestMonths.getChildAt(0), -1, -1);
break;
case R.id.highest_last_month:
onItemClick(highestMonths, highestMonths.getChildAt(0), 10, -1);
break;
case R.id.highest_month_more:
if (highestMonthsLayout != null) {
if (highestMonthsLayout.isExpanded()) {
highestMonthsLayout.collapse();
highestMonthMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_more));
} else {
highestMonthsLayout.expand();
highestMonthMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_less));
}
}
break;
case R.id.highest_first_day:
onItemClick(highestDays, highestDays.getChildAt(0), -1, -1);
break;
case R.id.highest_day_more:
if (highestDaysLayout != null) {
if (highestDaysLayout.isExpanded()) {
highestDaysLayout.collapse();
highestDayMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_more));
} else {
highestDaysLayout.expand();
highestDayMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_less));
}
}
break;
case R.id.lowest_first_day:
onItemClick(lowestDays, lowestDays.getChildAt(0), -1, -1);
break;
case R.id.lowest_day_more:
if (lowestDaysLayout != null) {
if (lowestDaysLayout.isExpanded()) {
lowestDaysLayout.collapse();
lowestDayMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_more));
} else {
lowestDaysLayout.expand();
lowestDayMoreText.setText(CoCoinApplication.getAppContext().getResources().getString(R.string.report_view_lowest_tag_show_less));
}
}
break;
case R.id.button:
if (!isEmpty)
showSelectListDataDialog();
break;
}
}
use of lecho.lib.hellocharts.model.SelectedValue 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.model.SelectedValue in project hellocharts-android by lecho.
the class BubbleChartView method callTouchListener.
@Override
public void callTouchListener() {
SelectedValue selectedValue = chartRenderer.getSelectedValue();
if (selectedValue.isSet()) {
BubbleValue value = data.getValues().get(selectedValue.getFirstIndex());
onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), value);
} else {
onValueTouchListener.onValueDeselected();
}
}
Aggregations