Java Code Examples for lecho.lib.hellocharts.model.PointValue#getX()

The following examples show how to use lecho.lib.hellocharts.model.PointValue#getX() . 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: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {
	
	String filtered = "";
	try {
		PointValueExtended pve = (PointValueExtended) pointValue;
		if(pve.calculatedFilteredValue != -1) {
			filtered = " (" + Math.round(pve.calculatedFilteredValue*10) / 10d +")";
		}
	} catch (ClassCastException e) {
		Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
	}
    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    Long time = ((long)pointValue.getX())*FUZZER;
    if(tooltip!= null){
        tooltip.cancel();
    }
    tooltip = Toast.makeText(context, timeFormat.format(time)+ ": " + Math.round(pointValue.getY()*10)/ 10d + filtered, Toast.LENGTH_LONG);
    tooltip.show();
}
 
Example 2
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {
	
	String filtered = "";
	try {
		PointValueExtended pve = (PointValueExtended) pointValue;
		if(pve.calculatedFilteredValue != -1) {
			filtered = " (" + Math.round(pve.calculatedFilteredValue*10) / 10d +")";
		}
	} catch (ClassCastException e) {
		Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
	}
    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    Long time = ((long)pointValue.getX())*FUZZER;
    if(tooltip!= null){
        tooltip.cancel();
    }
    tooltip = Toast.makeText(context, timeFormat.format(time)+ ": " + Math.round(pointValue.getY()*10)/ 10d + filtered, Toast.LENGTH_LONG);
    tooltip.show();
}
 
Example 3
Source File: BgGraphBuilder.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {
	
	String filtered = "";
	try {
		PointValueExtended pve = (PointValueExtended) pointValue;
		if(pve.calculatedFilteredValue != -1) {
			filtered = " (" + Math.round(pve.calculatedFilteredValue*10) / 10d +")";
		}
	} catch (ClassCastException e) {
		Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
	}
    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    Long time = ((long)pointValue.getX())*FUZZER;
    if(tooltip!= null){
        tooltip.cancel();
    }
    tooltip = Toast.makeText(context, timeFormat.format(time)+ ": " + Math.round(pointValue.getY()*10)/ 10d + filtered, Toast.LENGTH_LONG);
    tooltip.show();
}
 
Example 4
Source File: LineChartRenderer.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private void calculateMaxViewport() {
    tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
    LineChartData data = dataProvider.getLineChartData();

    for (Line line : data.getLines()) {
        // Calculate max and min for viewport.
        for (PointValue pointValue : line.getValues()) {
            if (pointValue.getX() < tempMaximumViewport.left) {
                tempMaximumViewport.left = pointValue.getX();
            }
            if (pointValue.getX() > tempMaximumViewport.right) {
                tempMaximumViewport.right = pointValue.getX();
            }
            if (pointValue.getY() < tempMaximumViewport.bottom) {
                tempMaximumViewport.bottom = pointValue.getY();
            }
            if (pointValue.getY() > tempMaximumViewport.top) {
                tempMaximumViewport.top = pointValue.getY();
            }

        }
    }
}
 
Example 5
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 6
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> filteredLines() {
    ArrayList<Line> line_array = new ArrayList<Line>();
    float last_x_pos = -999999; // bogus mark value
    final float jump_threshold = 15; // in minutes
    List<PointValue> local_points = new ArrayList<PointValue>();

    if (filteredValues.size() > 0) {
        final float end_marker = filteredValues.get(filteredValues.size() - 1).getX();

        for (PointValue current_point : filteredValues) {
            // a jump too far for a line? make it a new one
            if (((last_x_pos != -999999) && (Math.abs(current_point.getX() - last_x_pos) > jump_threshold))
                    || current_point.getX() == end_marker) {
                Line line = new Line(local_points);
                line.setHasPoints(true);
                line.setPointRadius(2);
                line.setStrokeWidth(1);
                line.setColor(Color.parseColor("#a0a0a0"));
                line.setCubic(true);
                line.setHasLines(true);
                line_array.add(line);
                local_points = new ArrayList<PointValue>();
            }
            last_x_pos = current_point.getX();
            local_points.add(current_point); // grow current line list
        }
    }
    return line_array;
}
 
Example 7
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) {
    ArrayList<Line> linearray = new ArrayList<>();
    float lastx = -999999;

    List<PointValue> macropoints = macroline.getValues();
    List<PointValue> thesepoints = new ArrayList<>();

    if (macropoints.size() > 0) {
        final float endmarker = macropoints.get(macropoints.size() - 1).getX();
        for (PointValue thispoint : macropoints) {

            // a jump too far for a line? make it a new one
            if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh))
                    || thispoint.getX() == endmarker) {

                if (thispoint.getX() == endmarker) {
                    thesepoints.add(thispoint);
                }
                Line line = (Line) cloneObject(macroline); // aieeee
                try {
                    line.setValues(thesepoints);
                    linearray.add(line);
                } catch (NullPointerException e) {
                //
                }
                    thesepoints = new ArrayList<PointValue>();
            }
            lastx = thispoint.getX();
            thesepoints.add(thispoint); // grow current line list
        }
    }
    return linearray;
}
 
Example 8
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) {
   // if (d) Log.d(TAG, "Enter autoSplit Line");
    ArrayList<Line> linearray = new ArrayList<Line>();
    float lastx = -999999;

    List<PointValue> macropoints = macroline.getValues();
    List<PointValue> thesepoints = new ArrayList<PointValue>();

    if (macropoints.size() > 0) {

        final float endmarker = macropoints.get(macropoints.size() - 1).getX();
        for (PointValue thispoint : macropoints) {

            // a jump too far for a line? make it a new one
            if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh))
                    || thispoint.getX() == endmarker) {

                if (thispoint.getX() == endmarker) {
                    thesepoints.add(thispoint);
                }
                Line line = (Line) JoH.cloneObject(macroline); // aieeee
                line.setValues(thesepoints);
                linearray.add(line);
                thesepoints = new ArrayList<PointValue>();
            }

            lastx = thispoint.getX();
            thesepoints.add(thispoint); // grow current line list
        }
    }
 //   if (d) Log.d(TAG, "Exit autoSplit Line");
    return linearray;
}
 
Example 9
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> filteredLines() {
    ArrayList<Line> linearray = new ArrayList<Line>();
    float lastx = -999999; // bogus mark value
    final float jumpthresh = 15; // in minutes
    List<PointValue> thesepoints = new ArrayList<PointValue>();

    if (filteredValues.size() > 0) {

        final float endmarker = filteredValues.get(filteredValues.size() - 1).getX();

        for (PointValue thispoint : filteredValues) {
            // a jump too far for a line? make it a new one
            if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh))
                    || thispoint.getX() == endmarker) {
                Line line = new Line(thesepoints);
                line.setHasPoints(true);
                line.setPointRadius(2);
                line.setStrokeWidth(1);
                line.setColor(getCol(X.color_filtered));
                line.setCubic(true);
                line.setHasLines(true);
                linearray.add(line);
                thesepoints = new ArrayList<PointValue>();
            }

            lastx = thispoint.getX();
            thesepoints.add(thispoint); // grow current line list
        }
    } else {
        UserError.Log.i(TAG, "Raw points size is zero");
    }


    //UserError.Log.i(TAG, "Returning linearray: " + Integer.toString(linearray.size()));
    return linearray;
}
 
Example 10
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> filteredLines() {
    ArrayList<Line> line_array = new ArrayList<Line>();
    float last_x_pos = -999999; // bogus mark value
    final float jump_threshold = 15; // in minutes
    List<PointValue> local_points = new ArrayList<PointValue>();

    if (filteredValues.size() > 0) {
        final float end_marker = filteredValues.get(filteredValues.size() - 1).getX();

        for (PointValue current_point : filteredValues) {
            // a jump too far for a line? make it a new one
            if (((last_x_pos != -999999) && (Math.abs(current_point.getX() - last_x_pos) > jump_threshold))
                    || current_point.getX() == end_marker) {
                Line line = new Line(local_points);
                line.setHasPoints(true);
                line.setPointRadius(2);
                line.setStrokeWidth(1);
                line.setColor(Color.parseColor("#a0a0a0"));
                line.setCubic(true);
                line.setHasLines(true);
                line_array.add(line);
                local_points = new ArrayList<PointValue>();
            }
            last_x_pos = current_point.getX();
            local_points.add(current_point); // grow current line list
        }
    }
    return line_array;
}
 
Example 11
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) {
    ArrayList<Line> linearray = new ArrayList<>();
    float lastx = -999999;

    List<PointValue> macropoints = macroline.getValues();
    List<PointValue> thesepoints = new ArrayList<>();

    if (macropoints.size() > 0) {
        final float endmarker = macropoints.get(macropoints.size() - 1).getX();
        for (PointValue thispoint : macropoints) {

            // a jump too far for a line? make it a new one
            if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh))
                    || thispoint.getX() == endmarker) {

                if (thispoint.getX() == endmarker) {
                    thesepoints.add(thispoint);
                }
                Line line = (Line) cloneObject(macroline); // aieeee
                try {
                    line.setValues(thesepoints);
                    linearray.add(line);
                } catch (NullPointerException e) {
                //
                }
                    thesepoints = new ArrayList<PointValue>();
            }
            lastx = thispoint.getX();
            thesepoints.add(thispoint); // grow current line list
        }
    }
    return linearray;
}
 
Example 12
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) {
   // if (d) Log.d(TAG, "Enter autoSplit Line");
    ArrayList<Line> linearray = new ArrayList<Line>();
    float lastx = -999999;

    List<PointValue> macropoints = macroline.getValues();
    List<PointValue> thesepoints = new ArrayList<PointValue>();

    if (macropoints.size() > 0) {

        final float endmarker = macropoints.get(macropoints.size() - 1).getX();
        for (PointValue thispoint : macropoints) {

            // a jump too far for a line? make it a new one
            if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh))
                    || thispoint.getX() == endmarker) {

                if (thispoint.getX() == endmarker) {
                    thesepoints.add(thispoint);
                }
                Line line = (Line) JoH.cloneObject(macroline); // aieeee
                line.setValues(thesepoints);
                linearray.add(line);
                thesepoints = new ArrayList<PointValue>();
            }

            lastx = thispoint.getX();
            thesepoints.add(thispoint); // grow current line list
        }
    }
 //   if (d) Log.d(TAG, "Exit autoSplit Line");
    return linearray;
}
 
Example 13
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> filteredLines() {
    ArrayList<Line> linearray = new ArrayList<Line>();
    float lastx = -999999; // bogus mark value
    final float jumpthresh = 15; // in minutes
    List<PointValue> thesepoints = new ArrayList<PointValue>();

    if (filteredValues.size() > 0) {

        final float endmarker = filteredValues.get(filteredValues.size() - 1).getX();

        for (PointValue thispoint : filteredValues) {
            // a jump too far for a line? make it a new one
            if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh))
                    || thispoint.getX() == endmarker) {
                Line line = new Line(thesepoints);
                line.setHasPoints(true);
                line.setPointRadius(2);
                line.setStrokeWidth(1);
                line.setColor(getCol(X.color_filtered));
                line.setCubic(true);
                line.setHasLines(true);
                linearray.add(line);
                thesepoints = new ArrayList<PointValue>();
            }

            lastx = thispoint.getX();
            thesepoints.add(thispoint); // grow current line list
        }
    } else {
        UserError.Log.i(TAG, "Raw points size is zero");
    }


    //UserError.Log.i(TAG, "Returning linearray: " + Integer.toString(linearray.size()));
    return linearray;
}
 
Example 14
Source File: BgGraphBuilder.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public ArrayList<Line> filteredLines() {
    ArrayList<Line> line_array = new ArrayList<Line>();
    float last_x_pos = -999999; // bogus mark value
    final float jump_threshold = 15; // in minutes
    List<PointValue> local_points = new ArrayList<PointValue>();

    if (filteredValues.size() > 0) {
        final float end_marker = filteredValues.get(filteredValues.size() - 1).getX();

        for (PointValue current_point : filteredValues) {
            // a jump too far for a line? make it a new one
            if (((last_x_pos != -999999) && (Math.abs(current_point.getX() - last_x_pos) > jump_threshold))
                    || current_point.getX() == end_marker) {
                Line line = new Line(local_points);
                line.setHasPoints(true);
                line.setPointRadius(2);
                line.setStrokeWidth(1);
                line.setColor(Color.parseColor("#a0a0a0"));
                line.setCubic(true);
                line.setHasLines(true);
                line_array.add(line);
                local_points = new ArrayList<PointValue>();
            }
            last_x_pos = current_point.getX();
            local_points.add(current_point); // grow current line list
        }
    }
    return line_array;
}
 
Example 15
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {

    Log.d(TAG, "onValueSelected pointValue=" + pointValue.getX() + "," + pointValue.getY());
    String filtered = "";
    String alternate = "";
    String uuid = "";
    int type = 0;
    long real_timestamp = 0;
    try {
        PointValueExtended pve = (PointValueExtended) pointValue;
        type = pve.type;
        if (pve.calculatedFilteredValue != -1) {
            filtered = " (" + Math.round(pve.calculatedFilteredValue * 10) / 10d + ")";
        }
        if (pve.note != null) {
            alternate = pve.note;
        }
        if (pve.uuid != null) {
            uuid = pve.uuid;
        }
        real_timestamp = pve.real_timestamp;

    } catch (ClassCastException e) {
        Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
    }

    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    final Long time = (real_timestamp > 0) ? real_timestamp : ((long) pointValue.getX()) * FUZZER;
    final double ypos = pointValue.getY();

    final String message;

    if (alternate.length() > 0) {
        message = timeFormat.format(time) + "    " + alternate;
    } else {
        message = timeFormat.format(time) + "      " + (Math.round(pointValue.getY() * 10) / 10d) + " " + unit() + filtered;
    }
    Log.d(TAG, "onValueSelected message=" + message);
    JoH.static_toast(xdrip.getAppContext(), message, Toast.LENGTH_SHORT);

    /*switch (type) {
        case com.eveningoutpost.dexdrip.UtilityModels.PointValueExtended.BloodTest:
            final String fuuid = uuid;
            final View.OnClickListener mBtOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.BLOOD_TEST_ACTION, time.toString(), fuuid);
                }
            };
            Home.snackBar(R.string.blood_test, message, mBtOnClickListener, callerActivity);
            break;
        default:
            final View.OnClickListener mOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.CREATE_TREATMENT_NOTE, time.toString(), Double.toString(ypos));
                }
            };
            Home.snackBar(R.string.add_note, message, mOnClickListener, callerActivity);
            break;
    }*/
}
 
Example 16
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized void onValueSelected(int i, int i1, PointValue pointValue) {

    Log.d(TAG, "onValueSelected pointValue=" + pointValue.getX() + "," + pointValue.getY());
    String filtered = "";
    String alternate = "";
    String uuid = "";
    int type = 0;
    long real_timestamp = 0;
    try {
        PointValueExtended pve = (PointValueExtended) pointValue;
        type = pve.type;
        if (pve.calculatedFilteredValue != -1) {
            filtered = " (" + Math.round(pve.calculatedFilteredValue * 10) / 10d + ")";
        }
        if (pve.note != null) {
            alternate = pve.note;
        }
        if (pve.uuid != null) {
            uuid = pve.uuid;
        }
        real_timestamp = pve.real_timestamp;

    } catch (ClassCastException e) {
        Log.e(TAG, "Error casting a point from pointValue to PointValueExtended", e);
    }

    final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
    //Won't give the exact time of the reading but the time on the grid: close enough.
    final Long time = (real_timestamp > 0) ? real_timestamp : ((long) pointValue.getX()) * FUZZER;
    final double ypos = pointValue.getY();

    final String message;

    if (alternate.length() > 0) {
        message = timeFormat.format(time) + "    " + alternate;
    } else {
        message = timeFormat.format(time) + "      " + (Math.round(pointValue.getY() * 10) / 10d) + " " + unit() + filtered;
    }
    Log.d(TAG, "onValueSelected message=" + message);
    JoH.static_toast(xdrip.getAppContext(), message, Toast.LENGTH_SHORT);

    /*switch (type) {
        case com.eveningoutpost.dexdrip.UtilityModels.PointValueExtended.BloodTest:
            final String fuuid = uuid;
            final View.OnClickListener mBtOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.BLOOD_TEST_ACTION, time.toString(), fuuid);
                }
            };
            Home.snackBar(R.string.blood_test, message, mBtOnClickListener, callerActivity);
            break;
        default:
            final View.OnClickListener mOnClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Home.startHomeWithExtra(xdrip.getAppContext(), Home.CREATE_TREATMENT_NOTE, time.toString(), Double.toString(ypos));
                }
            };
            Home.snackBar(R.string.add_note, message, mOnClickListener, callerActivity);
            break;
    }*/
}