Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
added custom colors
Browse files Browse the repository at this point in the history
  • Loading branch information
flxholle committed Apr 30, 2020
1 parent 77aadb3 commit 801268a
Showing 1 changed file with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class CourseTableLayout extends LinearLayout {
private StudentCourse studentCourse = new StudentCourse();
private OnTouchListener onTouchListener;

private int[] colorArray = null;

public CourseTableLayout(Context context) {
super(context);
inflate(context, R.layout.course_table_layout, this);
Expand Down Expand Up @@ -235,18 +237,41 @@ public void setStudentCourse(StudentCourse studentCourse) {
this.studentCourse = studentCourse;
}

public void setColorArray(int[] colorArray) {
this.colorArray = colorArray;
}

private int[] getColorArray(int color_count) {
int[] colorArray = new int[color_count];
int[] ints = getContext().getResources().getIntArray(R.array.course_table);
List<Integer> defaoultColor = new ArrayList<>();
for (int i : ints) {
defaoultColor.add(i);
}
for (int i = 0; i < color_count; i++) {
int random = (int) (Math.random() * defaoultColor.size());
colorArray[i] = defaoultColor.remove(random);
if (colorArray == null) {
int[] colorArray = new int[color_count];
int[] ints = getContext().getResources().getIntArray(R.array.course_table);
List<Integer> defaoultColor = new ArrayList<>();
for (int i : ints) {
defaoultColor.add(i);
}
for (int i = 0; i < color_count; i++) {
int random = (int) (Math.random() * defaoultColor.size());
colorArray[i] = defaoultColor.remove(random);
}
return colorArray;
} else {
if (colorArray.length < color_count) {
int[] colArray = colorArray;
colorArray = null;
int[] randomColor = getColorArray(color_count - colArray.length);
colorArray = colArray;

int[] colors = new int[color_count];
for (int i = 0; i < colors.length; i++) {
if (i < colorArray.length)
colors[i] = colorArray[i];
else
colors[i] = randomColor[i - colorArray.length + 1];
}
return colors;
} else
return colorArray;
}
return colorArray;
}

private void setTableCell(int row, int col, int color, CourseInfo course) {
Expand Down

0 comments on commit 801268a

Please sign in to comment.