Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new methods for changing bar background foreground text colors #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions AndroidCharts/src/main/java/im/dacer/androidcharts/BarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import java.util.ArrayList;

/**
Expand All @@ -16,9 +17,9 @@ public class BarView extends View {
private final int MINI_BAR_WIDTH;
private final int BAR_SIDE_MARGIN;
private final int TEXT_TOP_MARGIN;
private final int TEXT_COLOR = Color.parseColor("#9B9A9B");
private final int BACKGROUND_COLOR = Color.parseColor("#F6F6F6");
private final int FOREGROUND_COLOR = Color.parseColor("#FC496D");
private int TEXT_COLOR = Color.parseColor("#9B9A9B");
private int BACKGROUND_COLOR = Color.parseColor("#F6F6F6");
private int FOREGROUND_COLOR = Color.parseColor("#FC496D");
private ArrayList<Float> percentList;
private ArrayList<Float> targetPercentList;
private Paint textPaint;
Expand All @@ -32,7 +33,8 @@ public class BarView extends View {
private int bottomTextHeight;
private ArrayList<String> bottomTextList = new ArrayList<String>();
private Runnable animator = new Runnable() {
@Override public void run() {
@Override
public void run() {
boolean needNewFrame = false;
for (int i = 0; i < targetPercentList.size(); i++) {
if (percentList.get(i) < targetPercentList.get(i)) {
Expand Down Expand Up @@ -134,7 +136,8 @@ public void setDataList(ArrayList<Integer> list, int max) {
post(animator);
}

@Override protected void onDraw(Canvas canvas) {
@Override
protected void onDraw(Canvas canvas) {
int i = 1;
if (percentList != null && !percentList.isEmpty()) {
for (Float f : percentList) {
Expand Down Expand Up @@ -171,7 +174,8 @@ public void setDataList(ArrayList<Integer> list, int max) {
}
}

@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mViewWidth = measureWidth(widthMeasureSpec);
int mViewHeight = measureHeight(heightMeasureSpec);
setMeasuredDimension(mViewWidth, mViewHeight);
Expand Down Expand Up @@ -206,4 +210,19 @@ private int getMeasurement(int measureSpec, int preferred) {
}
return measurement;
}

public void setBarColorEmptyPart(int color) {
BACKGROUND_COLOR = color;
bgPaint.setColor(color);
}

public void setBarColorValuePart(int color) {
FOREGROUND_COLOR = color;
fgPaint.setColor(color);
}

public void setTextColor(int color) {
TEXT_COLOR = color;
textPaint.setColor(color);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package com.dacer.androidchartsexample;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import im.dacer.androidcharts.BarView;

import java.util.ArrayList;

import im.dacer.androidcharts.BarView;

/**
* Created by Dacer on 11/15/13.
*/
public class BarFragment extends Fragment {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_bar, container, false);
final BarView barView = (BarView) rootView.findViewById(R.id.bar_view);
// barView.setBarColorEmptyPart(Color.parseColor("#4CAF50"));
barView.setBarColorValuePart(Color.parseColor("#4CAF50"));
barView.setTextColor(Color.parseColor("#009688"));
Button button = (Button) rootView.findViewById(R.id.bar_button);
button.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
@Override
public void onClick(View view) {
randomSet(barView);
}
});
Expand Down