Search in sources :

Example 1 with SliceValue

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

the class ShowActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show);
    mContext = this;
    title = (TextView) findViewById(R.id.title);
    CoCoinUtil.init(mContext);
    title.setTypeface(CoCoinUtil.typefaceLatoLight);
    title.setText(mContext.getResources().getString(R.string.app_name));
    mViewPager = (SCViewPager) findViewById(R.id.viewpager_main_activity);
    mDotsView = (DotsView) findViewById(R.id.dotsview_main);
    mDotsView.setDotRessource(R.drawable.dot_selected, R.drawable.dot_unselected);
    mDotsView.setNumberOfPage(NUM_PAGES);
    mPageAdapter = new SCViewPagerAdapter(getSupportFragmentManager());
    mPageAdapter.setNumberOfPage(NUM_PAGES);
    mPageAdapter.setFragmentBackgroundColor(R.color.my_blue);
    mViewPager.setAdapter(mPageAdapter);
    mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            mDotsView.selectDot(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    final Point size = SCViewAnimationUtil.getDisplaySize(this);
    int iconOffsetX = CoCoinUtil.getInstance().dpToPx(28);
    int iconOffsetY = CoCoinUtil.getInstance().dpToPx(28);
    SCViewAnimation sc0 = new SCViewAnimation(findViewById(R.id.icon_4));
    sc0.startToPosition(size.x / 4 - iconOffsetX, size.y * 2 / 7 - iconOffsetY);
    sc0.addPageAnimation(new SCPositionAnimation(this, 0, 0, size.y));
    mViewPager.addAnimation(sc0);
    SCViewAnimation sc1 = new SCViewAnimation(findViewById(R.id.icon_11));
    sc1.startToPosition(size.x * 3 / 4 - iconOffsetX, size.y * 3 / 7 - iconOffsetY);
    sc1.addPageAnimation(new SCPositionAnimation(this, 0, -size.x, 0));
    mViewPager.addAnimation(sc1);
    SCViewAnimation sc2 = new SCViewAnimation(findViewById(R.id.icon_12));
    sc2.startToPosition(size.x / 4 - iconOffsetX, size.y * 4 / 7 - iconOffsetY);
    sc2.addPageAnimation(new SCPositionAnimation(this, 0, size.x, 0));
    mViewPager.addAnimation(sc2);
    SCViewAnimation sc3 = new SCViewAnimation(findViewById(R.id.icon_19));
    sc3.startToPosition(size.x * 3 / 4 - iconOffsetX, size.y * 5 / 7 - iconOffsetY);
    sc3.addPageAnimation(new SCPositionAnimation(this, 0, 0, -size.y));
    mViewPager.addAnimation(sc3);
    ((TextView) findViewById(R.id.text_0)).setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
    SCViewAnimation sc4 = new SCViewAnimation(findViewById(R.id.text_0));
    sc4.addPageAnimation(new SCPositionAnimation(this, 0, -size.x, 0));
    mViewPager.addAnimation(sc4);
    PieChartView pie = (PieChartView) findViewById(R.id.pie);
    List<SliceValue> values = new ArrayList<SliceValue>();
    for (int i = 0; i < 5; ++i) {
        SliceValue sliceValue = new SliceValue((float) Math.random() * 30 + 15, ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.white));
        values.add(sliceValue);
    }
    PieChartData pieData = new PieChartData(values);
    pieData.setHasLabels(false);
    pieData.setHasLabelsOnlyForSelected(false);
    pieData.setHasLabelsOutside(false);
    pieData.setHasCenterCircle(true);
    pie.setPieChartData(pieData);
    pie.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    SCViewAnimation sc5 = new SCViewAnimation(pie);
    sc5.startToPosition(size.x / 2, size.y / 9 - size.y);
    sc5.addPageAnimation(new SCPositionAnimation(this, 0, 0, size.y));
    sc5.addPageAnimation(new SCPositionAnimation(this, 1, 0, size.y));
    mViewPager.addAnimation(sc5);
    LineChartView line = (LineChartView) findViewById(R.id.line);
    List<Line> lines = new ArrayList<Line>();
    for (int i = 0; i < 1; ++i) {
        List<PointValue> pointValues = new ArrayList<PointValue>();
        pointValues.add(new PointValue(0, 50));
        pointValues.add(new PointValue(1, 100));
        pointValues.add(new PointValue(2, 20));
        pointValues.add(new PointValue(3, 0));
        pointValues.add(new PointValue(4, 10));
        pointValues.add(new PointValue(5, 15));
        pointValues.add(new PointValue(6, 40));
        pointValues.add(new PointValue(7, 60));
        pointValues.add(new PointValue(8, 100));
        Line aLine = new Line(pointValues);
        aLine.setColor(ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.white));
        aLine.setShape(ValueShape.CIRCLE);
        aLine.setCubic(false);
        aLine.setFilled(false);
        aLine.setHasLabels(false);
        aLine.setHasLabelsOnlyForSelected(false);
        aLine.setHasLines(true);
        aLine.setHasPoints(true);
        lines.add(aLine);
    }
    LineChartData linedata = new LineChartData(lines);
    linedata.setBaseValue(Float.NEGATIVE_INFINITY);
    line.setLineChartData(linedata);
    line.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    SCViewAnimation sc6 = new SCViewAnimation(line);
    sc6.startToPosition(-size.x, null);
    sc6.addPageAnimation(new SCPositionAnimation(this, 0, size.x, 0));
    sc6.addPageAnimation(new SCPositionAnimation(this, 1, size.x, 0));
    mViewPager.addAnimation(sc6);
    ColumnChartView histogram = (ColumnChartView) findViewById(R.id.histogram);
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> subcolumnValues;
    for (int i = 0; i < 5; ++i) {
        subcolumnValues = new ArrayList<SubcolumnValue>();
        for (int j = 0; j < 1; ++j) {
            subcolumnValues.add(new SubcolumnValue((float) Math.random() * 50f + 5, ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.white)));
        }
        Column column = new Column(subcolumnValues);
        column.setHasLabels(false);
        column.setHasLabelsOnlyForSelected(false);
        columns.add(column);
    }
    ColumnChartData histogramData = new ColumnChartData(columns);
    histogram.setColumnChartData(histogramData);
    histogram.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    SCViewAnimation sc7 = new SCViewAnimation(histogram);
    sc7.startToPosition(size.x / 2 - CoCoinUtil.getInstance().dpToPx(140), size.y * 8 / 9 - CoCoinUtil.getInstance().dpToPx(140) + size.y);
    sc7.addPageAnimation(new SCPositionAnimation(this, 0, 0, -size.y));
    sc7.addPageAnimation(new SCPositionAnimation(this, 1, 0, size.y));
    mViewPager.addAnimation(sc7);
    ((TextView) findViewById(R.id.text_1)).setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
    SCViewAnimation sc8 = new SCViewAnimation(findViewById(R.id.text_1));
    sc8.startToPosition(size.x, null);
    sc8.addPageAnimation(new SCPositionAnimation(this, 0, -size.x, 0));
    sc8.addPageAnimation(new SCPositionAnimation(this, 1, -size.x, 0));
    mViewPager.addAnimation(sc8);
    SCViewAnimation sc9 = new SCViewAnimation(findViewById(R.id.cloud));
    sc9.startToPosition(size.x / 2 - CoCoinUtil.getInstance().dpToPx(100) + size.x, size.y / 7);
    sc9.addPageAnimation(new SCPositionAnimation(this, 1, -size.x, 0));
    sc9.addPageAnimation(new SCPositionAnimation(this, 2, 0, size.y));
    mViewPager.addAnimation(sc9);
    SCViewAnimation sc10 = new SCViewAnimation(findViewById(R.id.mobile));
    sc10.startToPosition(size.x / 2 - size.x, size.y * 6 / 7 - CoCoinUtil.getInstance().dpToPx(100));
    sc10.addPageAnimation(new SCPositionAnimation(this, 1, size.x, 0));
    sc10.addPageAnimation(new SCPositionAnimation(this, 2, 0, -size.y));
    mViewPager.addAnimation(sc10);
    ((TextView) findViewById(R.id.text_2)).setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
    SCViewAnimation sc11 = new SCViewAnimation(findViewById(R.id.text_2));
    sc11.startToPosition(size.x, null);
    sc11.addPageAnimation(new SCPositionAnimation(this, 1, -size.x, 0));
    sc11.addPageAnimation(new SCPositionAnimation(this, 2, -size.x, 0));
    mViewPager.addAnimation(sc11);
    ImageView remind1 = (ImageView) findViewById(R.id.remind_1);
    remind1.getLayoutParams().width = size.x / 3;
    remind1.getLayoutParams().height = size.x / 3 * 653 / 320;
    SCViewAnimation sc12 = new SCViewAnimation(findViewById(R.id.remind_1));
    sc12.startToPosition(size.x / 2 - size.x, size.y / 11);
    sc12.addPageAnimation(new SCPositionAnimation(this, 2, size.x, 0));
    sc12.addPageAnimation(new SCPositionAnimation(this, 3, size.x, 0));
    mViewPager.addAnimation(sc12);
    ImageView remind2 = (ImageView) findViewById(R.id.remind_2);
    remind2.getLayoutParams().width = size.x / 3;
    remind2.getLayoutParams().height = size.x / 3 * 653 / 320;
    SCViewAnimation sc13 = new SCViewAnimation(findViewById(R.id.remind_2));
    sc13.startToPosition(size.x / 2 + size.x - size.x / 3, size.y * 10 / 11 - remind1.getLayoutParams().height);
    sc13.addPageAnimation(new SCPositionAnimation(this, 2, -size.x, 0));
    sc13.addPageAnimation(new SCPositionAnimation(this, 3, -size.x, 0));
    mViewPager.addAnimation(sc13);
    ((TextView) findViewById(R.id.text_3)).setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
    SCViewAnimation sc14 = new SCViewAnimation(findViewById(R.id.text_3));
    sc14.startToPosition(size.x, null);
    sc14.addPageAnimation(new SCPositionAnimation(this, 2, -size.x, 0));
    sc14.addPageAnimation(new SCPositionAnimation(this, 3, -size.x, 0));
    mViewPager.addAnimation(sc14);
    View statusBar = findViewById(R.id.status_bar);
    statusBar.setLayoutParams(new RelativeLayout.LayoutParams(statusBar.getLayoutParams().width, getStatusBarHeight()));
    SCViewAnimation statusBarAnimation = new SCViewAnimation(statusBar);
    statusBarAnimation.startToPosition(null, -getStatusBarHeight());
    statusBarAnimation.addPageAnimation(new SCPositionAnimation(this, 3, 0, getStatusBarHeight()));
    mViewPager.addAnimation(statusBarAnimation);
    toolbarLayout = findViewById(R.id.toolbar_layout);
    SCViewAnimation toolbarLayoutAnimation = new SCViewAnimation(toolbarLayout);
    toolbarLayoutAnimation.startToPosition(null, -size.y / 2);
    toolbarLayoutAnimation.addPageAnimation(new SCPositionAnimation(this, 3, 0, size.y / 2));
    mViewPager.addAnimation(toolbarLayoutAnimation);
    passwordAdapter = new PasswordChangeFragmentAdapter(getSupportFragmentManager());
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setScrollBarFadeDuration(700);
    viewPager.setAdapter(passwordAdapter);
    myGridView = (MyGridView) findViewById(R.id.gridview);
    myGridViewAdapter = new PasswordChangeButtonGridViewAdapter(this);
    myGridView.setAdapter(myGridViewAdapter);
    myGridView.setOnItemClickListener(gridViewClickListener);
    myGridView.setOnItemLongClickListener(gridViewLongClickListener);
    myGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            myGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            View lastChild = myGridView.getChildAt(myGridView.getChildCount() - 1);
            RelativeLayout.LayoutParams relativeLayout = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, lastChild.getBottom());
            relativeLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            myGridView.setLayoutParams(relativeLayout);
            DisplayMetrics displaymetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            int height = displaymetrics.heightPixels;
            RelativeLayout.LayoutParams viewPagerLayoutParams = new RelativeLayout.LayoutParams(viewPager.getLayoutParams().width, 800);
            viewPagerLayoutParams.topMargin = getStatusBarHeight() + CoCoinUtil.getToolBarHeight(mContext) / 2;
            viewPager.setLayoutParams(viewPagerLayoutParams);
        }
    });
    superToast = new SuperToast(this);
    SCViewAnimation gridViewAnimation = new SCViewAnimation(myGridView);
    gridViewAnimation.startToPosition(null, size.y);
    gridViewAnimation.addPageAnimation(new SCPositionAnimation(this, 3, 0, -size.y));
    mViewPager.addAnimation(gridViewAnimation);
    SCViewAnimation viewpagerAnimation = new SCViewAnimation(viewPager);
    viewpagerAnimation.startToPosition(null, -size.y);
    viewpagerAnimation.addPageAnimation(new SCPositionAnimation(this, 3, 0, size.y));
    mViewPager.addAnimation(viewpagerAnimation);
    View background = findViewById(R.id.background);
    SCViewAnimation backgroundAnimation = new SCViewAnimation(background);
    backgroundAnimation.startToPosition(null, -size.y - 100);
    backgroundAnimation.addPageAnimation(new SCPositionAnimation(this, 3, 0, size.y + 100));
    mViewPager.addAnimation(backgroundAnimation);
}
Also used : SuperToast(com.github.johnpersano.supertoasts.SuperToast) ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) SCViewPagerAdapter(com.dev.sacot41.scviewpager.SCViewPagerAdapter) DisplayMetrics(android.util.DisplayMetrics) PasswordChangeButtonGridViewAdapter(com.nightonke.saver.adapter.PasswordChangeButtonGridViewAdapter) Column(lecho.lib.hellocharts.model.Column) LineChartData(lecho.lib.hellocharts.model.LineChartData) SubcolumnValue(lecho.lib.hellocharts.model.SubcolumnValue) TextView(android.widget.TextView) LineChartView(lecho.lib.hellocharts.view.LineChartView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) SCViewAnimation(com.dev.sacot41.scviewpager.SCViewAnimation) PointValue(lecho.lib.hellocharts.model.PointValue) PieChartView(lecho.lib.hellocharts.view.PieChartView) PieChartData(lecho.lib.hellocharts.model.PieChartData) Point(android.graphics.Point) SCViewPager(com.dev.sacot41.scviewpager.SCViewPager) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) MyGridView(com.nightonke.saver.ui.MyGridView) PieChartView(lecho.lib.hellocharts.view.PieChartView) AdapterView(android.widget.AdapterView) DotsView(com.dev.sacot41.scviewpager.DotsView) TextView(android.widget.TextView) LineChartView(lecho.lib.hellocharts.view.LineChartView) ColumnChartView(lecho.lib.hellocharts.view.ColumnChartView) Point(android.graphics.Point) Line(lecho.lib.hellocharts.model.Line) PasswordChangeFragmentAdapter(com.nightonke.saver.adapter.PasswordChangeFragmentAdapter) SCPositionAnimation(com.dev.sacot41.scviewpager.SCPositionAnimation) RelativeLayout(android.widget.RelativeLayout) ColumnChartData(lecho.lib.hellocharts.model.ColumnChartData) ColumnChartView(lecho.lib.hellocharts.view.ColumnChartView)

Example 2 with SliceValue

use of lecho.lib.hellocharts.model.SliceValue 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 3 with SliceValue

use of lecho.lib.hellocharts.model.SliceValue 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();
}
Also used : PieChartOnValueSelectListener(lecho.lib.hellocharts.listener.PieChartOnValueSelectListener) PointValue(lecho.lib.hellocharts.model.PointValue) Calendar(java.util.Calendar) SliceValue(lecho.lib.hellocharts.model.SliceValue) ActionClickListener(com.nispok.snackbar.listeners.ActionClickListener) Snackbar(com.nispok.snackbar.Snackbar) LineChartOnValueSelectListener(lecho.lib.hellocharts.listener.LineChartOnValueSelectListener)

Example 4 with SliceValue

use of lecho.lib.hellocharts.model.SliceValue 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();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) SliceValue(lecho.lib.hellocharts.model.SliceValue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SelectedValue(lecho.lib.hellocharts.model.SelectedValue) PieChartData(lecho.lib.hellocharts.model.PieChartData) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) PieChartView(lecho.lib.hellocharts.view.PieChartView) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) CoCoinRecord(com.nightonke.saver.model.CoCoinRecord) PieChartOnValueSelectListener(lecho.lib.hellocharts.listener.PieChartOnValueSelectListener) FragmentActivity(android.support.v4.app.FragmentActivity) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Snackbar(com.nispok.snackbar.Snackbar)

Example 5 with SliceValue

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

the class PieChartRenderer method drawSlices.

/**
     * Draw all slices for this PieChart, if mode == {@link #MODE_HIGHLIGHT} currently selected slices will be redrawn
     * and
     * highlighted.
     *
     * @param canvas
     */
private void drawSlices(Canvas canvas) {
    final PieChartData data = dataProvider.getPieChartData();
    final float sliceScale = 360f / maxSum;
    float lastAngle = rotation;
    int sliceIndex = 0;
    for (SliceValue sliceValue : data.getValues()) {
        final float angle = Math.abs(sliceValue.getValue()) * sliceScale;
        if (isTouched() && selectedValue.getFirstIndex() == sliceIndex) {
            drawSlice(canvas, sliceValue, lastAngle, angle, MODE_HIGHLIGHT);
        } else {
            drawSlice(canvas, sliceValue, lastAngle, angle, MODE_DRAW);
        }
        lastAngle += angle;
        ++sliceIndex;
    }
}
Also used : PieChartData(lecho.lib.hellocharts.model.PieChartData) SliceValue(lecho.lib.hellocharts.model.SliceValue) Paint(android.graphics.Paint)

Aggregations

SliceValue (lecho.lib.hellocharts.model.SliceValue)13 PieChartData (lecho.lib.hellocharts.model.PieChartData)10 Paint (android.graphics.Paint)5 ArrayList (java.util.ArrayList)5 View (android.view.View)4 TextView (android.widget.TextView)4 SelectedValue (lecho.lib.hellocharts.model.SelectedValue)4 PieChartView (lecho.lib.hellocharts.view.PieChartView)4 Snackbar (com.nispok.snackbar.Snackbar)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 PieChartOnValueSelectListener (lecho.lib.hellocharts.listener.PieChartOnValueSelectListener)3 Column (lecho.lib.hellocharts.model.Column)3 ColumnChartData (lecho.lib.hellocharts.model.ColumnChartData)3 SubcolumnValue (lecho.lib.hellocharts.model.SubcolumnValue)3 ColumnChartView (lecho.lib.hellocharts.view.ColumnChartView)3 MaterialIconView (net.steamcrafted.materialiconlib.MaterialIconView)3 FragmentActivity (android.support.v4.app.FragmentActivity)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ImageView (android.widget.ImageView)2