use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.
the class PieChartFragment method loadData.
private void loadData() {
mPieChart.addPieSlice(new PieModel("Freetime", 15, Color.parseColor("#FE6DA8")));
mPieChart.addPieSlice(new PieModel("Sleep", 25, Color.parseColor("#56B7F1")));
mPieChart.addPieSlice(new PieModel("Work", 35, Color.parseColor("#CDA67F")));
mPieChart.addPieSlice(new PieModel("Eating", 9, Color.parseColor("#FED70E")));
mPieChart.setOnItemFocusChangedListener(new IOnItemFocusChangedListener() {
@Override
public void onItemFocusChanged(int _Position) {
// Log.d("PieChart", "Position: " + _Position);
}
});
}
use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.
the class PieChart method setHighlightStrength.
/**
* Sets the highlight strength for the InnerPaddingOutline.
*
* @param _highlightStrength The highlighting value for the outline.
*/
public void setHighlightStrength(float _highlightStrength) {
mHighlightStrength = _highlightStrength;
for (PieModel model : mPieData) {
highlightSlice(model);
}
invalidateGlobal();
}
use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.
the class PieChart method onDataChanged.
/**
* Should be called after new data is inserted. Will be automatically called, when the view dimensions
* has changed.
*
* Calculates the start- and end-angles for every PieSlice.
*/
@Override
protected void onDataChanged() {
super.onDataChanged();
int currentAngle = 0;
int index = 0;
int size = mPieData.size();
for (PieModel model : mPieData) {
int endAngle = (int) (currentAngle + model.getValue() * 360.f / mTotalValue);
if (index == size - 1) {
endAngle = 360;
}
model.setStartAngle(currentAngle);
model.setEndAngle(endAngle);
currentAngle = model.getEndAngle();
index++;
}
calcCurrentItem();
onScrollFinished();
}
use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.
the class PieChart method onLegendDraw.
@Override
protected void onLegendDraw(Canvas _Canvas) {
super.onLegendDraw(_Canvas);
_Canvas.drawPath(mTriangle, mLegendPaint);
float height = mMaxFontHeight = Utils.calculateMaxTextHeight(mLegendPaint, null);
if (!mPieData.isEmpty()) {
PieModel model = mPieData.get(mCurrentItem);
// center text in view
// TODO: move the boundary calculation out of onDraw
mLegendPaint.getTextBounds(model.getLegendLabel(), 0, model.getLegendLabel().length(), mTextBounds);
_Canvas.drawText(model.getLegendLabel(), (mLegendWidth / 2) - (mTextBounds.width() / 2), mIndicatorSize * 2 + mIndicatorBottomMargin + mIndicatorTopMargin + height, mLegendPaint);
} else {
mLegendPaint.getTextBounds(mEmptyDataText, 0, mEmptyDataText.length(), mTextBounds);
_Canvas.drawText(mEmptyDataText, (mLegendWidth / 2) - (mTextBounds.width() / 2), mIndicatorSize * 2 + mIndicatorBottomMargin + mIndicatorTopMargin + height, mLegendPaint);
}
}
use of org.eazegraph.lib.models.PieModel in project EazeGraph by blackfizz.
the class PieChart method initializeGraph.
/**
* This is the main entry point after the graph has been inflated. Used to initialize the graph
* and its corresponding members.
*/
@Override
protected void initializeGraph() {
super.initializeGraph();
Utils.setLayerToSW(this);
mPieData = new ArrayList<PieModel>();
mTotalValue = 0;
mGraphPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mLegendPaint.setTextSize(mLegendTextSize);
mLegendPaint.setColor(mLegendColor);
mLegendPaint.setStyle(Paint.Style.FILL);
mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mValuePaint.setTextSize(mValueTextSize);
mValuePaint.setColor(mValueTextColor);
mValuePaint.setStyle(Paint.Style.FILL);
mGraph.rotateTo(mPieRotation);
mGraph.decelerate();
mRevealAnimator = ValueAnimator.ofFloat(0, 1);
mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mRevealValue = animation.getAnimatedFraction();
invalidateGlobal();
}
});
mRevealAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
mStartedAnimation = false;
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
if (mUsePieRotation) {
// Set up an animator to animate the PieRotation property. This is used to
// correct the pie's orientation after the user lets go of it.
mAutoCenterAnimator = ObjectAnimator.ofInt(PieChart.this, "PieRotation", 0);
// Add a listener to hook the onAnimationEnd event so that we can do
// some cleanup when the pie stops moving.
mAutoCenterAnimator.addListener(new Animator.AnimatorListener() {
public void onAnimationStart(Animator animator) {
}
public void onAnimationEnd(Animator animator) {
mGraph.decelerate();
}
public void onAnimationCancel(Animator animator) {
}
public void onAnimationRepeat(Animator animator) {
}
});
// Create a Scroller to handle the fling gesture.
if (Build.VERSION.SDK_INT < 11) {
mScroller = new Scroller(getContext());
} else {
mScroller = new Scroller(getContext(), null, true);
}
// The scroller doesn't have any built-in animation functions--it just supplies
// values when we ask it to. So we have to have a way to call it every frame
// until the fling ends. This code (ab)uses a ValueAnimator object to generate
// a callback on every animation frame. We don't use the animated value at all.
mScrollAnimator = ValueAnimator.ofFloat(0, 1);
mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator valueAnimator) {
tickScrollAnimation();
}
});
// Create a gesture detector to handle onTouch messages
mDetector = new GestureDetector(PieChart.this.getContext(), new GestureListener());
// Turn off long press--this control doesn't use it, and if long press is enabled,
// you can't scroll for a bit, pause, then scroll some more (the pause is interpreted
// as a long press, apparently)
mDetector.setIsLongpressEnabled(false);
}
if (this.isInEditMode()) {
addPieSlice(new PieModel("Breakfast", 15, Color.parseColor("#FE6DA8")));
addPieSlice(new PieModel("Lunch", 25, Color.parseColor("#56B7F1")));
addPieSlice(new PieModel("Dinner", 35, Color.parseColor("#CDA67F")));
addPieSlice(new PieModel("Snack", 25, Color.parseColor("#FED70E")));
}
}
Aggregations