1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| package com.geyek.widget;
import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast;
import java.util.ArrayList; import java.util.List; import java.util.Random;
/** * Created by LiHuan on 10/09/16. */ public class MainActivity extends AppCompatActivity { Random random = new Random(); int i = 0;
@ Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
LeftChart left = (LeftChart) findViewById(R.id.left); final SimpleChart chart = (SimpleChart) findViewById(R.id.chart); Button add = (Button) findViewById(R.id.add); Button addAll = (Button) findViewById(R.id.addAll); Button clear = (Button) findViewById(R.id.clear);
chart.setColumn(8); chart.setRow(6); chart.setBackgroundColor(Color.parseColor("#10000000")); chart.setHintSize(30); chart.setHintColor(Color.GREEN); chart.setLineColor(Color.RED); chart.setLineWidth(3); chart.setPointColor(Color.GRAY); chart.setPointRadius(12); chart.setWaveColor(Color.GRAY); chart.setWaveWidth(1); chart.setXLableColor(Color.BLACK); chart.setXlablePadding(5); chart.setXLableSize(30); chart.setMaxY(1000);
left.bindSimpleChar(chart);
add.setOnClickListener(new View.OnClickListener() {@ Override public void onClick(View v) { chart.add(getChartPoint()); } });
addAll.setOnClickListener(new View.OnClickListener() {@ Override public void onClick(View v) { List & lt; ChartPoint & gt; chartPointList = new ArrayList & lt; & gt; (); for (int j = 0; j & lt; 10; j++) { chartPointList.add(getChartPoint()); } chart.addAll(chartPointList); } });
clear.setOnClickListener(new View.OnClickListener() {@ Override public void onClick(View v) { chart.clear(); } });
chart.setStatusListener(new SimpleChart.StatusListener() {@ Override public void status(int status) { switch (status) { case SimpleChart.LEFT: toast("已经到最左了..."); break; case SimpleChart.CENTER: toast("在滑动中..."); break; case SimpleChart.RIGHT: toast("已经到最右了..."); break; default: toast("迷路了..."); break; } } }); }
public ChartPoint getChartPoint() { ChartPoint chartPoint = new ChartPoint(); chartPoint.lableX = ++i + ""; chartPoint.pointColor = -random.nextInt(Integer.MAX_VALUE); chartPoint.valueY = random.nextInt(1000); chartPoint.lableY = chartPoint.valueY + ""; return chartPoint; }
public void toast(String toast) { Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show(); } }
|