Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package com.github.tlaabs.timetableview;

import android.widget.TextView;


import android.view.View;

import java.io.Serializable;
import java.util.ArrayList;

public class Sticker implements Serializable {
private ArrayList<TextView> view;
private ArrayList<View> view;
private ArrayList<Schedule> schedules;

public Sticker() {
this.view = new ArrayList<TextView>();
this.view = new ArrayList<View>();
this.schedules = new ArrayList<Schedule>();
}

public void addTextView(TextView v){
public void addView(View v){
view.add(v);
}

public void addSchedule(Schedule schedule){
schedules.add(schedule);
}

public ArrayList<TextView> getView() {
public ArrayList<View> getView() {
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,69 @@ public void add(ArrayList<Schedule> schedules) {
}

private void add(final ArrayList<Schedule> schedules, int specIdx) {
final int count = specIdx < 0 ? ++stickerCount : specIdx;
int count = specIdx < 0 ? ++stickerCount : specIdx;
Sticker sticker = new Sticker();
for (Schedule schedule : schedules) {
RelativeLayout rl = new RelativeLayout(context);
RelativeLayout.LayoutParams rlp = createStickerParam(schedule);
rl.setLayoutParams(rlp);

//start
TextView tv_start = new TextView(context);
RelativeLayout.LayoutParams start_lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
tv_start.setLayoutParams(start_lp);
tv_start.setPadding(0, 0, 0, 0);
tv_start.setText((schedule.getStartTime().getMinute() > 9 ? "" : "0") + schedule.getStartTime().getMinute());
tv_start.setTextColor(Color.parseColor("#FFFFFF"));
tv_start.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
tv_start.setTypeface(null, Typeface.BOLD);
rl.addView(tv_start);

// description
TextView tv = new TextView(context);

RelativeLayout.LayoutParams param = createStickerParam(schedule);
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
param.addRule(RelativeLayout.CENTER_IN_PARENT);
tv.setLayoutParams(param);
tv.setPadding(10, 0, 10, 0);
tv.setText(schedule.getClassTitle() + "\n" + schedule.getClassPlace());
tv.setTextColor(Color.parseColor("#FFFFFF"));
tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_STICKER_FONT_SIZE_DP);
tv.setTypeface(null, Typeface.BOLD);

tv.setOnClickListener(new OnClickListener() {
rl.addView(tv);

//stop
TextView tv_stop = new TextView(context);
RelativeLayout.LayoutParams stop_lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
stop_lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
stop_lp.addRule(RelativeLayout.ALIGN_PARENT_END);
tv_stop.setLayoutParams(stop_lp);
tv_stop.setPadding(0, 0, 0, 0);
tv_stop.setText((schedule.getEndTime().getMinute() > 9 ? "" : "0") + schedule.getEndTime().getMinute());
tv_stop.setTextColor(Color.parseColor("#FFFFFF"));
tv_stop.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
tv_stop.setTypeface(null, Typeface.BOLD);
rl.addView(tv_stop);

final int no = count;
rl.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(stickerSelectedListener != null)
stickerSelectedListener.OnStickerSelected(count, schedules);
stickerSelectedListener.OnStickerSelected(no, schedules);
}
});

sticker.addTextView(tv);
sticker.addView(rl);
sticker.addSchedule(schedule);
stickers.put(count, sticker);
stickerBox.addView(tv);
stickerBox.addView(rl);
count++;
}
setStickerColor();
}
Expand All @@ -199,7 +237,7 @@ public void load(String data) {
public void removeAll() {
for (int key : stickers.keySet()) {
Sticker sticker = stickers.get(key);
for (TextView tv : sticker.getView()) {
for (View tv : sticker.getView()) {
stickerBox.removeView(tv);
}
}
Expand All @@ -213,7 +251,7 @@ public void edit(int idx, ArrayList<Schedule> schedules) {

public void remove(int idx) {
Sticker sticker = stickers.get(idx);
for (TextView tv : sticker.getView()) {
for (View tv : sticker.getView()) {
stickerBox.removeView(tv);
}
stickers.remove(idx);
Expand Down Expand Up @@ -263,7 +301,7 @@ private void setStickerColor() {
int colorSize = stickerColors.length;

for (i = 0; i < size; i++) {
for (TextView v : stickers.get(orders[i]).getView()) {
for (View v : stickers.get(orders[i]).getView()) {
v.setBackgroundColor(Color.parseColor(stickerColors[i % (colorSize)]));
}
}
Expand Down