lecho.lib.hellocharts.view.LineChartView Java Examples

The following examples show how to use lecho.lib.hellocharts.view.LineChartView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BGHistory.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private void setupCharts() {
    dateButton1.setText(dateFormatter.format(date1.getTime()));

    Calendar endDate = (GregorianCalendar) date1.clone();
    endDate.add(Calendar.DATE, noDays);
    int numValues = noDays * (60 / 5) * 24;
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues);

    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
}
 
Example #2
Source File: PreviewLineChartActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.fragment_preview_line_chart, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);
    previewChart = (PreviewLineChartView) rootView.findViewById(R.id.chart_preview);

    // Generate data for previewed chart and copy of that data for preview chart.
    generateDefaultData();

    chart.setLineChartData(data);
    // Disable zoom/scroll for previewed chart, visible chart ranges depends on preview chart viewport so
    // zoom/scroll is unnecessary.
    chart.setZoomEnabled(false);
    chart.setScrollEnabled(false);

    previewChart.setLineChartData(previewData);
    previewChart.setViewportChangeListener(new ViewportListener());

    previewX(false);

    return rootView;
}
 
Example #3
Source File: GoodBadChartActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_good_bad, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);

    generateDefaultData();
    chart.setLineChartData(data);

    // Increase viewport height for better look
    Viewport v = chart.getMaximumViewport();
    float dy = v.height() * 0.2f;
    v.inset(0, -dy);
    chart.setMaximumViewport(v);
    chart.setCurrentViewport(v);

    return rootView;
}
 
Example #4
Source File: LineChartActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.fragment_line_chart, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);
    chart.setOnValueTouchListener(new ValueTouchListener());

    // Generate some random values.
    generateValues();

    generateData();

    // Disable viewport recalculations, see toggleCubic() method for more info.
    chart.setViewportCalculationEnabled(false);

    resetViewport();

    return rootView;
}
 
Example #5
Source File: Home.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);

    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();
}
 
Example #6
Source File: Home.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
public void setupCharts() {
    bgGraphBuilder  = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);

    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();
}
 
Example #7
Source File: Home.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
public void setupCharts() {
    bgGraphBuilder  = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);

    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();
}
 
Example #8
Source File: BGHistory.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void setupCharts() {
    dateButton1.setText(dateFormatter.format(date1.getTime()));

    Calendar endDate = (GregorianCalendar) date1.clone();
    endDate.add(Calendar.DATE, noDays);
    int numValues = noDays * (60 / 2) * 24; // LimiTTer sample rate 1 per 2 minutes
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false);

    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(this));
    previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData()));

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());

    setupStatistics(date1.getTimeInMillis(), endDate.getTimeInMillis());
}
 
Example #9
Source File: BGHistory.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void setupCharts() {
    dateButton1.setText(dateFormatter.format(date1.getTime()));

    Calendar endDate = (GregorianCalendar) date1.clone();
    endDate.add(Calendar.DATE, noDays);
    int numValues = noDays * (60 / 2) * 24; // LimiTTer sample rate 1 per 2 minutes
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false);

    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(this));
    previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData()));

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());

    setupStatistics(date1.getTimeInMillis(), endDate.getTimeInMillis());
}
 
Example #10
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 6 votes vote down vote up
/**
* 初始化视图
* */
protected void initView(LineChartView lineChartView) {
    pointValueList = new ArrayList<>();
    linesList = new ArrayList<>();
    //初始化坐标轴
    axisY = new Axis();
    axisX = new Axis();
    lineChartData = initData(null);
    lineChartView.setLineChartData(lineChartData);
    Viewport port = initViewPort(0, 50,150);
    lineChartView.setCurrentViewportWithAnimation(port);
    lineChartView.setInteractive(false);
    lineChartView.setScrollEnabled(true);
    lineChartView.setValueTouchEnabled(true);
    lineChartView.setFocusableInTouchMode(true);
    lineChartView.setViewportCalculationEnabled(false);
    lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
    lineChartView.startDataAnimation();
    points = new ArrayList<>();
}
 
Example #11
Source File: LineCharts.java    From MetalDetector with GNU General Public License v3.0 5 votes vote down vote up
protected void makeCharts(final LineChartView lineChartView,float uT){
    //实时添加新的点
    PointValue value1 = new PointValue(position * 5, uT);
    value1.setLabel("00:00");
    pointValueList.add(value1);
    float x = value1.getX();
    float y = uT;
    //根据新的点的集合画出新的线
    Line line = new Line(pointValueList);
    line.setColor(Color.RED);
    line.setShape(ValueShape.CIRCLE);
    line.setCubic(true);//曲线是否平滑
    line.setHasPoints(false);//设置折线是否含点
    linesList.clear();
    linesList.add(line);
    lineChartData = initData(linesList);
    lineChartView.setLineChartData(lineChartData);
    //根据点的横坐实时变换坐标的视图范围
    Viewport port;
    if (x > 500) {
            port = initViewPort(x - 500, x, y);
    } else {
        port = initViewPort(0, 500 ,y);
    }
    lineChartView.setCurrentViewport(port);//当前窗口

    Viewport maxPort = initMaxViewPort(x,y);//更新最大窗口设置
    lineChartView.setMaximumViewport(maxPort);//最大窗口
    position++;
}
 
Example #12
Source File: ExampleChartPreferenceView.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
protected void refreshView(View view) {
    LineChartView chart = (LineChartView) view.findViewById(R.id.example_linechart);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getContext());
    chart.setLineChartData(bgGraphBuilder.lineData());
    Viewport viewport = chart.getMaximumViewport();
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0, 0, 0, 0);
    chart.setLeft(0);
    chart.setTop(0);
    Log.d(TAG, "onBindExampleChart: refreshview " + chart.getHeight());
}
 
Example #13
Source File: ExampleChartPreferenceView.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
protected void refreshView(View view) {
    LineChartView chart = (LineChartView) view.findViewById(R.id.example_linechart);
    BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getContext());
    chart.setLineChartData(bgGraphBuilder.lineData());
    Viewport viewport = chart.getMaximumViewport();
    chart.setViewportCalculationEnabled(false);
    chart.setInteractive(false);
    chart.setCurrentViewport(viewport);
    chart.setPadding(0, 0, 0, 0);
    chart.setLeft(0);
    chart.setTop(0);
    Log.d(TAG, "onBindExampleChart: refreshview " + chart.getHeight());
}
 
Example #14
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_basalvstempbasal_linechart, container, false);
    basalvsTempBasalChart   = (LineChartView) rootView.findViewById(R.id.basalvsTempBasal_LineChart);
    previewChart            = (PreviewLineChartView) getActivity().findViewById(R.id.chart_preview);
    basalvsTempBasalLoading = (ProgressBar) rootView.findViewById(R.id.basalvsTempBasalLoading);

    //setupChart();
    updateChart();

    return rootView;
}
 
Example #15
Source File: MainActivity.java    From MetalDetector with GNU General Public License v3.0 5 votes vote down vote up
private void initFunc(){
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mTextX = (TextView)findViewById(R.id.x);
    mTextY = (TextView)findViewById(R.id.y);
    mTextZ = (TextView)findViewById(R.id.z);
    mTotal = (TextView)findViewById(R.id.total);
    progressView = findViewById(R.id.totalMetalProgress);
    metalState = (TextView) findViewById(R.id.metalDetect);
    lineChart = (LineChartView) findViewById(R.id.chart);
    lineCharts.initView(lineChart);
}
 
Example #16
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_iobcob_linechart, container, false);
    iobcobPastChart         = (LineChartView) rootView.findViewById(R.id.iobcobPast);
    previewChart            = (PreviewLineChartView) getActivity().findViewById(R.id.chart_preview);
    iobcobPastLoading       = (ProgressBar) rootView.findViewById(R.id.iobcobPastLoading);

    //setupChart();
    updateChart();
    return rootView;
}
 
Example #17
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingChartViewport) {
        updatingPreviewViewport = true;
        bgChart.setZoomType(ZoomType.HORIZONTAL);
        bgChart.setCurrentViewport(newViewport);
        tempViewport = newViewport;
        updatingPreviewViewport = false;

        if (iobcobFragmentObject.getView() != null) {                                       //Fragment is loaded
            LineChartView iobcobPastChart = (LineChartView) findViewById(R.id.iobcobPast);
            iobcobPastChart.setCurrentViewport(newViewport);
            Viewport iobv = new Viewport(iobcobPastChart.getMaximumViewport());             //Update the IOB COB Line Chart Viewport to stay inline with the preview
            iobv.left   = newViewport.left;
            iobv.right  = newViewport.right;
            iobv.top    = iobcobPastChart.getMaximumViewport().top;
            iobv.bottom = iobcobPastChart.getMaximumViewport().bottom;
            iobcobPastChart.setMaximumViewport(iobv);
            iobcobPastChart.setCurrentViewport(iobv);
        }
        if (basalvsTempBasalObject.getView() != null){
            LineChartView bvbChart = (LineChartView) findViewById(R.id.basalvsTempBasal_LineChart);
            Viewport bvbv = new Viewport(bgChart.getMaximumViewport());
            bvbv.left = newViewport.left;
            bvbv.right = newViewport.right;
            bvbv.top    = bvbChart.getMaximumViewport().top;
            bvbv.bottom = bvbChart.getMaximumViewport().bottom;
            bvbChart.setMaximumViewport(bvbv);
            bvbChart.setCurrentViewport(bvbv);

        }
    }
    if (updateStuff) {
        holdViewport.set(newViewport.left, newViewport.top, newViewport.right, newViewport.bottom);
    }
}
 
Example #18
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewportChanged(Viewport newViewport) {
    if (!updatingPreviewViewport) {
        updatingChartViewport = true;
        bgPreviewChart.setZoomType(ZoomType.HORIZONTAL);
        bgPreviewChart.setCurrentViewport(newViewport);
        updatingChartViewport = false;

        if (iobcobFragmentObject.getView() != null) {                                       //Fragment is loaded
            LineChartView iobcobPastChart = (LineChartView) findViewById(R.id.iobcobPast);
            Viewport iobv = new Viewport(bgChart.getMaximumViewport());                       //Update the IOB COB Line Chart Viewport to stay inline with the preview
            iobv.left   = newViewport.left;
            iobv.right  = newViewport.right;
            iobv.top    = iobcobPastChart.getMaximumViewport().top;
            iobv.bottom = iobcobPastChart.getMaximumViewport().bottom;
            iobcobPastChart.setMaximumViewport(iobv);
            iobcobPastChart.setCurrentViewport(iobv);
        }
        if (basalvsTempBasalObject.getView() != null){
            LineChartView bvbChart = (LineChartView) findViewById(R.id.basalvsTempBasal_LineChart);
            Viewport bvbv = new Viewport(bgChart.getMaximumViewport());
            bvbv.left   = newViewport.left;
            bvbv.right  = newViewport.right;
            bvbv.top    = bvbChart.getMaximumViewport().top;
            bvbv.bottom = bvbChart.getMaximumViewport().bottom;
            bvbChart.setMaximumViewport(bvbv);
            bvbChart.setCurrentViewport(bvbv);
        }
    }
}
 
Example #19
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
BgSparklineBuilder(Context context) {
    mContext = context;
    chart = new LineChartView(mContext);
    width = convertDpToPixel(NOTIFICATION_WIDTH_DP);
    height = convertDpToPixel(NOTIFICATION_HEIGHT_DP);
}
 
Example #20
Source File: LineColumnDependencyActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_line_column_dependency, container, false);

    // *** TOP LINE CHART ***
    chartTop = (LineChartView) rootView.findViewById(R.id.chart_top);

    // Generate and set data for line chart
    generateInitialLineData();

    // *** BOTTOM COLUMN CHART ***

    chartBottom = (ColumnChartView) rootView.findViewById(R.id.chart_bottom);

    generateColumnData();

    return rootView;
}
 
Example #21
Source File: MainActivity.java    From healthgo with GNU General Public License v3.0 4 votes vote down vote up
public void drawChart() {

        // WeatherChartView mCharView = (WeatherChartView) findViewById(R.id.line_char);
        Date[] days = DateTimeHelper.get6days();

        Realm realm = Realm.getDefaultInstance();

        int[] data = new int[]{0, 0, 0, 0, 0, 0};
        int i = 0;
        for (Date d : days) {
            Log.d("eee","date "+d);
            if (i == 5) {
                data[i] = Integer.parseInt(String.valueOf(numSteps));
            }
            else {
                StepModel result = realm.where(StepModel.class)
                        .equalTo("date", d)
                        .findFirst();
                if (result != null) {
                    Log.d("eee","r !null  ");
                    data[i] = Integer.parseInt(String.valueOf(result.getNumSteps()));
                }
            }
            i++;
        }

        realm.close();

        String[] xValues = DateTimeHelper.get6days(true);


        lineChart = (LineChartView) findViewById(R.id.line_chart);
        for (i = 0; i < xValues.length; i++) {
            mAxisXValues.add(new AxisValue(i).setLabel(xValues[i]));
        }

        for (i = 0; i < data.length; i++) {
            mPointValues.add(new PointValue(i, data[i]));
        }
        initLineChart();//初始化

    }
 
Example #22
Source File: BgSparklineBuilder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public BgSparklineBuilder(Context context) {
    mContext = context;
    chart = new LineChartView(mContext);
    width = convertDpToPixel(NOTIFICATION_WIDTH_DP);
    height = convertDpToPixel(NOTIFICATION_HEIGHT_DP);
}
 
Example #23
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
BgSparklineBuilder(Context context) {
    mContext = context;
    chart = new LineChartView(mContext);
    width = convertDpToPixel(NOTIFICATION_WIDTH_DP);
    height = convertDpToPixel(NOTIFICATION_HEIGHT_DP);
}
 
Example #24
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
public BgSparklineBuilder(Context context) {
    mContext = context;
    chart = new LineChartView(mContext);
    width = convertDpToPixel(NOTIFICATION_WIDTH_DP);
    height = convertDpToPixel(NOTIFICATION_HEIGHT_DP);
}
 
Example #25
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    activity = this;
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    ins = this;

    //Sets default Preferences
    PreferenceManager.setDefaultValues(this, R.xml.pref_aps, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_notification, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_integration, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_misc, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_pump, false);

    checkEula();

    //Make sure BackgroundService is running, as this maybe first run
    startService(new Intent(this, BackgroundService.class));

    setContentView(R.layout.activity_main);

    realmManager = new RealmManager();
    realmManager.getRealm().setAutoRefresh(true); //so we pickup updates from other threads

    setupMenuAndToolbar();

    // Create the adapter that will return a fragment for each of the 4 primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager      =   (ViewPager) this.findViewById(R.id.pager);
    bgChart =   (LineChartView) findViewById(R.id.chart);
    bgChartLoading = (ProgressBar) findViewById(R.id.bgChartLoading);
    bgPreviewChart =   (PreviewLineChartView) findViewById(R.id.chart_preview);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    //Build Fragments
    openAPSFragmentObject       = new openAPSFragment();
    iobcobActiveFragmentObject  = new iobcobActiveFragment();
    iobcobFragmentObject        = new iobcobFragment();
    basalvsTempBasalObject      = new basalvsTempBasalFragment();
}
 
Example #26
Source File: BgSparklineBuilder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public BgSparklineBuilder(Context context) {
    mContext = context;
    chart = new LineChartView(mContext);
    width = convertDpToPixel(NOTIFICATION_WIDTH_DP);
    height = convertDpToPixel(NOTIFICATION_HEIGHT_DP);
}
 
Example #27
Source File: BgSparklineBuilder.java    From NightWatch with GNU General Public License v3.0 4 votes vote down vote up
public BgSparklineBuilder(Context context) {
    mContext = context;
    chart = new LineChartView(mContext);
    width = convertDpToPixel(NOTIFICATION_WIDTH_DP);
    height = convertDpToPixel(NOTIFICATION_HEIGHT_DP);
}
 
Example #28
Source File: LibreTrendGraph.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public void setupCharts() {
    
   final TextView trendView = (TextView) findViewById(R.id.textLibreHeader);
     
    chart = (LineChartView) findViewById(R.id.libre_chart);
    List<Line> lines = new ArrayList<Line>();

    List<PointValue> lineValues = new ArrayList<PointValue>();
    final float conversion_factor_mmol = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL);

    LibreBlock libreBlock= LibreBlock.getLatestForTrend();
    if(libreBlock == null) {
        trendView.setText("No libre data to display");
        setupEmptyCharts();
        return;
    }
    String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) libreBlock.timestamp));

    ArrayList<Float> bg_data = getLatestBgForXMinutes(MINUTES_TO_DISPLAY);
    
    if(bg_data == null) {
        trendView.setText("Error displaying data for " + time);
        setupEmptyCharts();
        return;
    }
    
    trendView.setText("Scan from " + time);
    float min = 1000;
    float max = 0;
    int i = 0;
    for(float bg : bg_data ) {
        if(bg <= 0) {
            i++;
            continue;   
        }
        if(min > bg) {
            min = bg;
        }
        if(max < bg) {
            max = bg;
        }
        
        lineValues.add(new PointValue(-i, bg * conversion_factor_mmol));
        i++;
    }

    Line trendLine = new Line(lineValues);
    trendLine.setColor(ChartUtils.COLOR_RED);
    trendLine.setHasLines(false);
    trendLine.setHasPoints(true);
    trendLine.setPointRadius(3);
    lines.add(trendLine);
    
    final int MIN_GRAPH = 20;
    if(max - min < MIN_GRAPH)
    {
        // On relative flat trend the graph can look very noise althouth with the right resolution it is not that way.
        // I will add two dummy invisible points that will cause the graph to look with bigger Y range.
        float average = (max + min) /2;
        List<PointValue> dummyPointValues = new ArrayList<PointValue>();
        Line dummyPointLine = new Line(dummyPointValues);
        dummyPointValues.add(new PointValue(0, (average - MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointValues.add(new PointValue(0, (average + MIN_GRAPH / 2) * conversion_factor_mmol));
        dummyPointLine.setColor(ChartUtils.COLOR_RED);
        dummyPointLine.setHasLines(false);
        dummyPointLine.setHasPoints(false);
        lines.add(dummyPointLine);
    }

    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);
    axisX.setTextSize(16);
    axisY.setTextSize(16);
    axisX.setName("Time from last scan");
    axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l"));

    data = new LineChartData(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setLineChartData(data);

}
 
Example #29
Source File: CalibrationGraph.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
public void setupCharts() {
    chart = (LineChartView) findViewById(R.id.chart);
    List<Line> lines = new ArrayList<Line>();

    Calibration calibration = Calibration.last();
    if(calibration != null) {
        //set header
        DecimalFormat df = new DecimalFormat("#");
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);
        String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept);
        GraphHeader.setText(Header);

        //red line
        List<PointValue> lineValues = new ArrayList<PointValue>();
        lineValues.add(new PointValue((float) start_x, (float) (start_x * calibration.slope + calibration.intercept)));
        lineValues.add(new PointValue((float) end_x, (float) (end_x * calibration.slope + calibration.intercept)));
        Line calibrationLine = new Line(lineValues);
        calibrationLine.setColor(ChartUtils.COLOR_RED);
        calibrationLine.setHasLines(true);
        calibrationLine.setHasPoints(false);

        //calibration values
        List<Calibration> calibrations = Calibration.allForSensor();
        Line greyLine = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF"));
        calibrations = Calibration.allForSensorInLastFourDays();
        Line blueLine = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE);

        //add lines in order
        lines.add(greyLine);
        lines.add(blueLine);
        lines.add(calibrationLine);

    }
    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);
    axisX.setName("Raw Value");
    axisY.setName("BG");


    data = new LineChartData(lines);
    data.setAxisXBottom(axisX);
    data.setAxisYLeft(axisY);
    chart.setLineChartData(data);

}
 
Example #30
Source File: Home.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
private void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);

    chart.setZoomType(ZoomType.HORIZONTAL);

    //Transmitter Battery Level
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null && sensor.latest_battery_level != 0 && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW && ! mPreferences.getBoolean("disable_battery_warning", false)) {
        Drawable background = new Drawable() {

            @Override
            public void draw(Canvas canvas) {

                DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
                int px = (int) (30 * (metrics.densityDpi / 160f));
                Paint paint = new Paint();
                paint.setTextSize(px);
                paint.setAntiAlias(true);
                paint.setColor(Color.parseColor("#FFFFAA"));
                paint.setStyle(Paint.Style.STROKE);
                paint.setAlpha(100);
                canvas.drawText("transmitter battery", 10, chart.getHeight() / 3 - (int) (1.2 * px), paint);
                if(sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY){
                    paint.setTextSize((int)(px*1.5));
                    canvas.drawText("VERY LOW", 10, chart.getHeight() / 3, paint);
                } else {
                    canvas.drawText("low", 10, chart.getHeight() / 3, paint);
                }
            }

            @Override
            public void setAlpha(int alpha) {}
            @Override
            public void setColorFilter(ColorFilter cf) {}
            @Override
            public int getOpacity() {return 0;}
        };
        chart.setBackground(background);
    }
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();
}