Ejemplo n.º 1
0
  void drawGraph(float[] data) {
    int length = data.length;
    String[] labels = new String[length];
    for (int i = 0; i < length; i++) {
      labels[i] = Integer.toString(i);
    }

    LineChartView lView = (LineChartView) findViewById(R.id.linechart);
    lView.reset();
    LineSet dataSet = new LineSet(labels, data);
    //
    dataSet.setDotsRadius(15);
    dataSet.setDotsColor(0xFFFFFF);
    dataSet.setColor(0xBCCACF);

    // dataSet.setGradientFill(new int[]{0xFFFFFF, 0x20CE99}, new float[]{0, 1});
    lView.setBackgroundColor(0x20CE99);
    //        dataSet.setFill(0x20CE99);
    dataSet.setDotsStrokeColor(0xBCCACF);
    dataSet.setDotsStrokeThickness(10);

    Animation anim = new Animation(2000);
    anim.setEasing(new CircEase());
    lView.setYLabels(AxisController.LabelPosition.NONE);
    //        lView.setYAxis(false);

    Paint p = new Paint();

    p.setColor(0xBCCACF);
    //        lView.setValueThreshold(10, 10, p);
    lView.setAxisThickness(5);

    // LineSet threshLower = new LineSet(new String[]{"1", "2", "3", "4", "5", "6"}, new
    // float[]{10,10,10,10,10,10});

    //        LineSet threshLower = new LineSet(new String[]{"1", "2", "3", "4", "5", "6"}, new
    // float[]{10,10,10,10,10,10,});
    //
    //        threshLower.setColor(0x000000);
    //
    //        threshLower.setDashed(new float[]{10, 10, 10, 10, 10, 10});
    //        threshLower.setSmooth(true);
    //        threshLower.setThickness(5);

    lView.addData(createThresh(dataSet, 70));
    lView.addData(createThresh(dataSet, 200));
    lView.addData(dataSet);

    lView.show(anim);

    bGlucose = (TextView) findViewById(R.id.bglucose);

    setGlucoseLevel((int) data[length - 1]);
  }
Ejemplo n.º 2
0
	/**
	 * The method listens chart clicks and checks whether it intercepts
	 * a known Region. It will then use the registered Listener.onClick 
	 * to return the region's index. 
	 */
	@Override
	public boolean onTouchEvent(@NonNull MotionEvent event) {

		if(mAnim == null || !mAnim.isPlaying())

			if(event.getAction() == MotionEvent.ACTION_DOWN &&
					mEntryListener != null&&
					(mTooltip != null ) &&
					mRegions != null){

				//Check if ACTION_DOWN over any ScreenPoint region.
				int nSets = mRegions.size();
				int nEntries = mRegions.get(0).size();
				for(int i = 0; i < nSets ; i++){
					for(int j = 0; j < nEntries; j++){

						if(mRegions.get(i).get(j)
								.contains((int) event.getX(),
										(int) event.getY())){
							mSetClicked = i;
							mIndexClicked = j;
						}
					}
				}

			}else if(event.getAction() == MotionEvent.ACTION_UP){

				if(mSetClicked != -1 &&
						mIndexClicked != -1){
					if(mRegions.get(mSetClicked).get(mIndexClicked)
							.contains((int) event.getX(),
									(int) event.getY())){

						if(mEntryListener != null){
							mEntryListener.onClick(mSetClicked,
									mIndexClicked,
									new Rect(getEntryRect(mRegions.get(mSetClicked).get(mIndexClicked))));
						}

						if(mTooltip != null){
							toggleTooltip(getEntryRect(mRegions.get(mSetClicked).get(mIndexClicked)),
									data.get(mSetClicked).getValue(mIndexClicked));
						}

					}
					mSetClicked = -1;
					mIndexClicked = -1;

				}else{

					if(mChartListener != null)
						mChartListener.onClick(this);

					if(mTooltip != null && mTooltip.on())
						dismissTooltip(mTooltip);
				}
			}

		return true;
	}
Ejemplo n.º 3
0
	/**
	 * Method not expected to be used often. More for testing.
	 * Resets chart state to insert new configuration.
	 */
	public void reset(){

		if(mAnim != null && mAnim.isPlaying())
			mAnim.cancel();

		init();
		if(horController.mandatoryBorderSpacing != 0) {
			horController.reset();
		}

		if(verController.mandatoryBorderSpacing != 0) {
			verController.reset();
		}

		mHasThresholdLabel = false;
		mHasThresholdValue = false;
		style.thresholdPaint = null;

		style.gridPaint = null;
	}
Ejemplo n.º 4
0
	/**
	 * Dismiss chart data with animation.
	 *
	 * @param anim   Animation used to exit
	 */
	public void dismiss(Animation anim){

		if(anim != null) {
			mAnim = anim;

			final Runnable endAction = mAnim.getEndAction();
			mAnim.setEndAction(new Runnable() {
				@Override
				public void run() {
					if (endAction != null)
						endAction.run();
					data.clear();
					invalidate();
				}
			});

			data = mAnim.prepareExitAnimation(this);
		}else{
			data.clear();
		}
		invalidate();
	}
Ejemplo n.º 5
0
	/**
	 * Notify {@link ChartView} about updated values. {@link ChartView} will be validated.
	 */
	public void notifyDataUpdate(){

		ArrayList<float[][]> oldCoords = new ArrayList<>(data.size());
		ArrayList<float[][]> newCoords = new ArrayList<>(data.size());

		for(ChartSet set : data)
			oldCoords.add(set.getScreenPoints());

		digestData();
		for(ChartSet set : data)
			newCoords.add(set.getScreenPoints());

		mRegions = defineRegions(data);
		if(mAnim != null)
			data = mAnim.prepareUpdateAnimation(this, oldCoords, newCoords);

		invalidate();
	}
Ejemplo n.º 6
0
		@SuppressLint("NewApi")
		@Override
		public boolean onPreDraw() {
			ChartView.this.getViewTreeObserver().removeOnPreDrawListener(this);

			style.init();

			// Define chart frame
			mChartTop = getPaddingTop() + verController.getLabelHeight()/2;
			mChartBottom = getMeasuredHeight() - getPaddingBottom()-LABELTEXTMAXLINE*(int)(style.labelsPaint.descent()-style.labelsPaint.ascent());
			mChartLeft = getPaddingLeft();
			mChartRight = getMeasuredWidth() - getPaddingRight();


			// Initialize controllers now that we have the measures
			verController.init();

			if(mHasThresholdValue) {
				mThresholdStartValue = verController.parsePos(0, mThresholdStartValue);
				mThresholdEndValue = verController.parsePos(0, mThresholdEndValue);
			}

			// Mandatory: X axis after Y axis!
			horController.init();

			// Process data to define screen positions
			digestData();

			// Tells view to execute code before starting drawing
			onPreDrawChart(data);

			// Define regions
			mRegions = defineRegions(data);

			// Prepares the animation if needed and gets the first dump 
			// of data to be drawn
			if(mAnim != null)
				data = mAnim.prepareEnterAnimation(ChartView.this);

			if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
				ChartView.this.setLayerType(LAYER_TYPE_SOFTWARE, null);

			return mReadyToDraw = true;
		}