This commit is contained in:
ScorpioMiku
2019-08-20 15:29:34 +08:00
parent a4b695f8ef
commit eee362050c
3 changed files with 221 additions and 5 deletions

View File

@@ -1,15 +1,37 @@
package com.scorpiomiku.oldpeoplehome.modules.oldpeople.fragmemt;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.scorpiomiku.oldpeoplehome.R;
import com.scorpiomiku.oldpeoplehome.base.BaseFragment;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
/**
* Created by ScorpioMiku on 2019/8/20.
*/
public class SleepViewPagerItem extends BaseFragment {
@BindView(R.id.pie_chart)
PieChart sleepPie;
Unbinder unbinder;
@Override
protected Handler initHandle() {
return null;
@@ -27,6 +49,55 @@ public class SleepViewPagerItem extends BaseFragment {
@Override
protected void initView() {
initPie();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO: inflate a fragment view
View rootView = super.onCreateView(inflater, container, savedInstanceState);
unbinder = ButterKnife.bind(this, rootView);
return rootView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
/**
* 绘制饼图
*/
private void initPie() {
List<PieEntry> strings = new ArrayList<>();
strings.add(new PieEntry(30f, "深度睡眠"));
strings.add(new PieEntry(70f, "浅度睡眠"));
PieDataSet dataSet = new PieDataSet(strings, "");
ArrayList<Integer> colors = new ArrayList<Integer>();
colors.add(getResources().getColor(R.color.sleep_deep));
colors.add(getResources().getColor(R.color.sleep_shallow));
dataSet.setColors(colors);
dataSet.setValueTextSize(12f);
PieData pieData = new PieData(dataSet);
pieData.setDrawValues(true);
pieData.setValueFormatter(new PercentFormatter());
pieData.setValueTextSize(12f);
pieData.setValueTextColor(getResources().getColor(R.color.place_holder));
sleepPie.setData(pieData);
sleepPie.invalidate();
Description description = new Description();
description.setText("");
sleepPie.setDescription(description);
sleepPie.setHoleRadius(0f);
sleepPie.setTransparentCircleRadius(0f);
Legend legend = sleepPie.getLegend();
legend.setEnabled(false);
}
}

View File

@@ -1,11 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="260dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="星期一"
android:textColor="@color/sleep_bg"
android:textSize="14sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test" />
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pie_chart"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp">
</com.github.mikephil.charting.charts.PieChart>
</RelativeLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="@color/sleep_deep" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="深度睡眠"
android:textColor="@color/sleep_deep" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="00:00"
android:textColor="@color/sleep_deep"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="@color/sleep_shallow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="浅度睡眠"
android:textColor="@color/sleep_shallow" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="00:00"
android:textColor="@color/sleep_shallow"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="@color/sleep_no" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="清醒时间"
android:textColor="@color/sleep_no" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="00:00"
android:textColor="@color/sleep_no"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -12,8 +12,8 @@
<color name="place_holder">#dfdede</color>
<color name="sleep_deep">#38b692</color>
<color name="sleep_shallow">#51e2db</color>
<color name="sleep_no">#ecea70</color>
<color name="sleep_deep">#0a36c1</color>
<color name="sleep_shallow">#4766e4</color>
<color name="sleep_no">#7096cc</color>
<color name="white_text">#FFF</color>
</resources>