第二阶段冲刺-08

昨天对饼状图的绘制进行了改进,对其增加了更多的消费类型,和相关的颜色。

遇到的问题:在界面显示比较模糊

今天准备做:写一个方法调用数据库的方法,获取数据库中的数据,将数据赋值给每个对应的消费类型中。

private void initView() {
        mLny = findViewById(R.id.lnyOut);
//        etCanyin = findViewById(R.id.etCanyin);
//        etYule = findViewById(R.id.etWenjiao);
//        etCHuxing = findViewById(R.id.etChuxing);
//        etFushi = findViewById(R.id.etFushi);
//        etShenghuo = findViewById(R.id.etShenghuo);

        btnUpdate = findViewById(R.id.btnUpdate);
        btnUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                uodatePieChart();
            }
        });

    }


    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onResume() {
        super.onResume();
        myDataView = new MyDataView(this, DataDegree(), DataColor());
        params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);

        mLny.addView(myDataView, params);
    }

    private HashMap<String , Float> DataDegree(){
        dataDegee.put("餐饮消费", 32f);
        dataDegee.put("文教娱乐", 42f);
        dataDegee.put("服饰美容", 52f);
        dataDegee.put("出行交通", 92f);
        dataDegee.put("其它",142f);
        dataDegee.put("1212",32f);
        return dataDegee;
    }


    @RequiresApi(api = Build.VERSION_CODES.O)
    private HashMap<String , String> DataColor(){

        dataColor.put("餐饮消费", "#6600ff");
        dataColor.put("文教娱乐", "#cc00ff");
        dataColor.put("服饰美容","#9933ff");
        dataColor.put("出行交通", "#ff9900");
        dataColor.put("其它","#9999ff");
        dataColor.put("1212","#ffff00");
        dataColor.put("","#0000ff");
        dataColor.put("","#00ff00");
        dataColor.put("","#800000");
//        dataColor.put("","#800080");
//        dataColor.put("","");
        return dataColor;
    }

    private void uodatePieChart(){
        month = (TextView)findViewById(R.id.month);
        String n = month.getText().toString();
        String[] a = n.split("[^0-9]");

        String year2 = a[0];
        String month2 = a[1];

        float canyin = Query(year2,month2,"餐饮");
        float yule = Query(year2,month2,"娱乐");
        float gouwu = Query(year2,month2,"购物");
        float chuxing = 50;
        float fushi = 86;
        float s = 58;

        float total = canyin +yule +fushi +gouwu +chuxing + 58;

        if(total>0){

            dataDegee.put("餐饮", getDegree(canyin,total));
            dataDegee.put("服饰美容", getDegree(fushi,total));
            dataDegee.put("其它", getDegree(gouwu,total));
            dataDegee.put("出行交通", getDegree(chuxing,total));
            dataDegee.put("娱乐", getDegree(yule,total));
            dataDegee.put("1212",total);
            mLny.removeView(myDataView);
            mLny.addView(myDataView, params);
            Log.i("test draw", "remove view ; add view");
            Toast.makeText(this,"哇,你居然在"+getMaxinumType()+"上花了这么多",Toast.LENGTH_SHORT).show();

        }else {
            Toast.makeText(this,"输入您的消费额度",Toast.LENGTH_SHORT).show();
        }
    }

    private float getDegree(float number, float total){
        return  number/total * 360;
    }


    private String getMaxinumType(){
        String type="";
        float money = Float.MIN_VALUE;
        for(String key : dataDegee.keySet()){
            if(dataDegee.get(key) > money){
                type = key;
                money = dataDegee.get(key);
            }
        }
        return type;
    }