content: package com.yl.mpandroidchartdemo;
  
  import android.graphics.Color;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import com.github.mikephil.charting.charts.LineChart;
  import com.github.mikephil.charting.data.Entry;
  import com.yl.mpandroidchartdemo.utils.AnimationUtils;
  import com.yl.mpandroidchartdemo.utils.ChartUtils;
  import com.yl.mpandroidchartdemo.utils.ShowUtils;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  /**
   * 主页
   * Created by yangle on 2016/11/25.
   * <p>
   * Website：http://www.yangle.tech
   * GitHub：https://github.com/alidili
   * CSDN：http://blog.csdn.net/kong_gu_you_lan
   * JianShu：http://www.jianshu.com/u/34ece31cd6eb
   */
  
  public class LineChartActivity extends AppCompatActivity implements View.OnClickListener {
  
      private TextView tvDate;
      private ImageView ivDate;
      private LineChart chart;
  
      private static final String[] dates = new String[]{"今日", "本周", "本月"};
      private List<String> dateList = Arrays.asList(dates);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_line_chart);
  
          initView();
      }
  
      private void initView() {
          tvDate = (TextView) findViewById(R.id.tv_date);
          ivDate = (ImageView) findViewById(R.id.iv_date);
          chart = (LineChart) findViewById(R.id.chart);
  
          ivDate.setColorFilter(Color.WHITE);
          tvDate.setOnClickListener(this);
          ivDate.setOnClickListener(this);
  
          ChartUtils.initChart(chart);
          ChartUtils.notifyDataSetChanged(chart, getData(), ChartUtils.dayValue);
      }
  
      @Override
      public void onClick(View v) {
          switch (v.getId()) {
              case R.id.tv_date:
              case R.id.iv_date:
                  String data = tvDate.getText().toString();
  
                  if (!ShowUtils.isPopupWindowShowing()) {
                      AnimationUtils.startModeSelectAnimation(ivDate, true);
                      ShowUtils.showPopupWindow(this, tvDate, 90, 166, dateList,
                              new AdapterView.OnItemClickListener() {
                                  @Override
                                  public void onItemClick(AdapterView<?> parent, View view,
                                                          int position, long id) {
                                      ShowUtils.updatePopupWindow(position);
                                      AnimationUtils.startModeSelectAnimation(ivDate, false);
                                      ShowUtils.popupWindowDismiss();
                                      tvDate.setText(dateList.get(position));
                                      // 更新图表
                                      ChartUtils.notifyDataSetChanged(chart, getData(), position);
                                  }
                              });
                  } else {
                      AnimationUtils.startModeSelectAnimation(ivDate, false);
                      ShowUtils.popupWindowDismiss();
                  }
  
                  if (dateList.get(0).equals(data)) {
                      ShowUtils.updatePopupWindow(0);
                  } else if (dateList.get(1).equals(data)) {
                      ShowUtils.updatePopupWindow(1);
                  } else if (dateList.get(2).equals(data)) {
                      ShowUtils.updatePopupWindow(2);
                  }
                  break;
  
              default:
                  break;
          }
      }
  
      private List<Entry> getData() {
          List<Entry> values = new ArrayList<>();
          values.add(new Entry(0, 15));
          values.add(new Entry(1, 15));
          values.add(new Entry(2, 15));
          values.add(new Entry(3, 20));
          values.add(new Entry(4, 25));
          values.add(new Entry(5, 20));
          values.add(new Entry(6, 20));
          return values;
      }
  }
  