diff --git a/AndroidTimetableView/.idea/caches/build_file_checksums.ser b/AndroidTimetableView/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..542884d Binary files /dev/null and b/AndroidTimetableView/.idea/caches/build_file_checksums.ser differ diff --git a/AndroidTimetableView/.idea/codeStyles/Project.xml b/AndroidTimetableView/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/AndroidTimetableView/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AndroidTimetableView/.idea/misc.xml b/AndroidTimetableView/.idea/misc.xml index d4e6701..7aa454e 100644 --- a/AndroidTimetableView/.idea/misc.xml +++ b/AndroidTimetableView/.idea/misc.xml @@ -1,7 +1,7 @@ - - + diff --git a/AndroidTimetableView/TimetableView/build.gradle b/AndroidTimetableView/TimetableView/build.gradle index 705517e..f46a54a 100644 --- a/AndroidTimetableView/TimetableView/build.gradle +++ b/AndroidTimetableView/TimetableView/build.gradle @@ -55,7 +55,7 @@ publish { repoName='Maven' groupId = 'com.zhuangfei'//jcenter上的路径 artifactId = 'TimetableView'//项目名称 - publishVersion = '2.0.2'//版本号 + publishVersion = '2.0.3'//版本号 desc = 'A beautiful Android based curriculum schedule widget'//描述,不重要 website = 'https://github.com/zfman/TimetableView'//网站,不重要;尽量模拟github上的地址,例如我这样的;当然你有地址最好了 } diff --git a/AndroidTimetableView/TimetableView/res/layout/view_content.xml b/AndroidTimetableView/TimetableView/res/layout/view_content.xml index 83ec502..1eeca9e 100644 --- a/AndroidTimetableView/TimetableView/res/layout/view_content.xml +++ b/AndroidTimetableView/TimetableView/res/layout/view_content.xml @@ -12,9 +12,8 @@ android:orientation="horizontal"> @@ -25,7 +24,7 @@ android:id="@+id/weekPanel_1" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> @@ -33,7 +32,7 @@ android:id="@+id/weekPanel_2" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> @@ -41,7 +40,7 @@ android:id="@+id/weekPanel_3" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> @@ -49,7 +48,7 @@ android:id="@+id/weekPanel_4" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> @@ -57,7 +56,7 @@ android:id="@+id/weekPanel_5" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> @@ -65,7 +64,7 @@ android:id="@+id/weekPanel_6" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> @@ -73,7 +72,7 @@ android:id="@+id/weekPanel_7" android:layout_width="0dp" android:layout_height="match_parent" - android:layout_weight="1.5" + android:layout_weight="1" android:layout_marginBottom="5dp" android:orientation="vertical"> diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/TimetableView.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/TimetableView.java index ad061fc..b121d68 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/TimetableView.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/TimetableView.java @@ -1,19 +1,11 @@ package com.zhuangfei.timetable; import android.content.Context; -import android.content.res.TypedArray; import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; import android.util.AttributeSet; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; -import android.widget.FrameLayout; import android.widget.LinearLayout; -import android.widget.TextView; -import com.zhuangfei.android_timetableview.sample.R; import com.zhuangfei.timetable.listener.ISchedule; import com.zhuangfei.timetable.listener.OnDateBuildAapter; import com.zhuangfei.timetable.listener.OnFlaglayoutClickAdapter; @@ -27,49 +19,54 @@ import com.zhuangfei.timetable.model.Schedule; import com.zhuangfei.timetable.model.ScheduleColorPool; import com.zhuangfei.timetable.model.ScheduleEnable; +import com.zhuangfei.timetable.operater.AbsOperater; import com.zhuangfei.timetable.model.ScheduleSupport; -import com.zhuangfei.timetable.utils.ColorUtils; +import com.zhuangfei.timetable.operater.SimpleOperater; import com.zhuangfei.timetable.utils.ScreenUtils; -import java.sql.Time; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** - * 课程表控件 + * 课程表控件,该类主要负责属性的设置,业务逻辑由{@link SimpleOperater}处理 + * 虽然这个类代码很多,但是都是属性设置,除了属性设置的方法: + * {@link #showView()} + * {@link #changeWeek(int, boolean)} + * {@link #changeWeekOnly(int)} + * {@link #changeWeekForce(int)} + * {@link #updateView()} + * {@link #updateSlideView()} + * {@link #updateDateView()} + * {@link #updateView()} * + * 文档参考 https://github.com/zfman/TimetableView/wiki/%E6%9C%80%E6%96%B0%E6%96%87%E6%A1%A3 * @author Administrator + * @see AbsOperater + * @see SimpleOperater */ public class TimetableView extends LinearLayout { private static final String TAG = "TimetableView"; + //业务逻辑 + private AbsOperater operater; private Context context; - // 当前周、学期 + // 当前周、学期、课程数据源 private int curWeek = 1; private String curTerm = "Term"; - - // 课程数据源 private List dataSource = null; - //布局转换器 - private LayoutInflater inflater; - private LinearLayout weekPanel;//侧边栏 - private List[] data = new ArrayList[7];//每天的课程 - private LinearLayout[] panels = new LinearLayout[7];//每天的面板 - private LinearLayout containerLayout;//根布局 - private LinearLayout dateLayout;//根布局、日期栏容器 - - //点击空白格子显示的布局:旗标布局 - private LinearLayout flagLayout; - private int flagBgcolor=Color.rgb(220,230,239);//背景颜色 - private boolean isShowFlaglayout=true; - //上边距、左边距、项高度 private int marTop, marLeft, itemHeight; + //侧边栏宽度 + private int monthWidth; + + //旗标布局背景颜色 + private int flagBgcolor = Color.rgb(220, 230, 239);//背景颜色 + private boolean isShowFlaglayout = true; + //本周、非本周的弧度 private int thisWeekCorner; private int nonThisWeekCorner; @@ -86,13 +83,13 @@ public class TimetableView extends LinearLayout { //课程项、侧边栏、日期栏的透明度,1:不透明,0:透明 private float itemAlpha = 1, slideAlpha = 1, dateAlpha = 1; - //保存点击的坐标 - private float x, y; - //课程项文本颜色 private int itemTextColorWithThisWeek = Color.WHITE;//本周 private int itemTextColorWithNotThis = Color.WHITE;//非本周 + private boolean isShowWeekends=true; + + //监听器 private ISchedule.OnWeekChangedListener onWeekChangedListener;//周次改变监听 private ISchedule.OnScrollViewBuildListener onScrollViewBuildListener;//替换滚动布局构建监听 private ISchedule.OnDateBuildListener onDateBuildListener;//日期栏构建监听 @@ -103,6 +100,61 @@ public class TimetableView extends LinearLayout { private ISchedule.OnSpaceItemClickListener onSpaceItemClickListener;//空白格子点击监听 private ISchedule.OnFlaglayoutClickListener onFlaglayoutClickListener;//旗标布局点击监听 + /** + * 是否显示周末 + * @param isShowWeekends + * @return + */ + public TimetableView isShowWeekends(boolean isShowWeekends) { + this.isShowWeekends = isShowWeekends; + return this; + } + + public boolean isShowWeekends() { + return isShowWeekends; + } + + public AbsOperater operater(){ + if(operater==null) operater=new SimpleOperater(); + return operater; + } + + public TimetableView operater(AbsOperater operater) { + this.operater = operater; + return this; + } + + /** + * 设置侧边栏宽度dp + * + * @param monthWidthDp + * @return + */ + public TimetableView monthWidthDp(int monthWidthDp) { + this.monthWidth = ScreenUtils.dip2px(context, monthWidthDp); + return this; + } + + /** + * 设置侧边栏宽度px + * + * @param monthWidthPx + * @return + */ + public TimetableView monthWidthPx(int monthWidthPx) { + this.monthWidth = monthWidthPx; + return this; + } + + /** + * 获取侧边栏宽度px + * + * @return + */ + public int monthWidth() { + return this.monthWidth; + } + /** * 课程项文本颜色 * @@ -191,55 +243,61 @@ public TimetableView alpha(float allAlpha) { /** * 设置旗标布局背景颜色 + * * @param color * @return */ - public TimetableView flagBgcolor(int color){ - this.flagBgcolor=color; + public TimetableView flagBgcolor(int color) { + this.flagBgcolor = color; return this; } /** * 重置旗标布局背景色 + * * @return */ - public TimetableView resetFlagBgcolor(){ - flagBgcolor(Color.rgb(220,230,239)); + public TimetableView resetFlagBgcolor() { + flagBgcolor(Color.rgb(220, 230, 239)); return this; } /** * 获取是否显示旗标布局 + * * @return */ - public boolean isShowFlaglayout(){ + public boolean isShowFlaglayout() { return isShowFlaglayout; } /** * 设置是否显示旗标布局 + * * @param isShowFlaglayout * @return */ - public TimetableView isShowFlaglayout(boolean isShowFlaglayout){ - this.isShowFlaglayout=isShowFlaglayout; + public TimetableView isShowFlaglayout(boolean isShowFlaglayout) { + this.isShowFlaglayout = isShowFlaglayout; return this; } /** * 获取旗标布局背景颜色 + * * @return */ - public int flagBgcolor(){ + public int flagBgcolor() { return flagBgcolor; } /** * 获取旗标布局 + * * @return */ - public LinearLayout flagLayout(){ - return flagLayout; + public LinearLayout flagLayout() { + return operater().getFlagLayout(); } /** @@ -255,10 +313,11 @@ public TimetableView callback(ISchedule.OnItemLongClickListener onItemLongClickL /** * 获取课程项长按监听器 + * * @return */ public ISchedule.OnItemLongClickListener onItemLongClickListener() { - if(onItemLongClickListener==null) onItemLongClickListener=new OnItemLongClickAdapter(); + if (onItemLongClickListener == null) onItemLongClickListener = new OnItemLongClickAdapter(); return onItemLongClickListener; } @@ -382,15 +441,18 @@ public TimetableView callback(ISchedule.OnSpaceItemClickListener onSpaceItemClic /** * 获取空白格子点击监听器 + * * @return */ public ISchedule.OnSpaceItemClickListener onSpaceItemClickListener() { - if (onSpaceItemClickListener == null) onSpaceItemClickListener = new OnSpaceItemClickAdapter(); + if (onSpaceItemClickListener == null) + onSpaceItemClickListener = new OnSpaceItemClickAdapter(); return onSpaceItemClickListener; } /** * 设置旗标布局点击监听器 + * * @param onFlaglayoutClickListener * @return */ @@ -401,10 +463,12 @@ public TimetableView callback(ISchedule.OnFlaglayoutClickListener onFlaglayoutCl /** * 获取旗标布局点击监听器 + * * @return */ public ISchedule.OnFlaglayoutClickListener onFlaglayoutClickListener() { - if (onFlaglayoutClickListener == null) onFlaglayoutClickListener = new OnFlaglayoutClickAdapter(); + if (onFlaglayoutClickListener == null) + onFlaglayoutClickListener = new OnFlaglayoutClickAdapter(); return onFlaglayoutClickListener; } @@ -703,347 +767,7 @@ public int marTop() { public TimetableView(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; - inflater = LayoutInflater.from(context); - inflater.inflate(R.layout.timetable_layout, this); - containerLayout = findViewById(R.id.id_container); - dateLayout = findViewById(R.id.id_datelayout); - initAttr(attrs); - } - - /** - * 获取自定义属性 - * - * @param attrs - */ - private void initAttr(AttributeSet attrs) { - TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TimetableView); - int curWeek = ta.getInteger(R.styleable.TimetableView_cur_week, 1); - String curTerm = ta.getString(R.styleable.TimetableView_cur_term); - - int defMarTop = (int) context.getResources().getDimension(R.dimen.weekItemMarTop); - int defMarLeft = (int) context.getResources().getDimension(R.dimen.weekItemMarLeft); - int defItemHeight = (int) context.getResources().getDimension(R.dimen.weekItemHeight); - - int marTop = (int) ta.getDimension(R.styleable.TimetableView_mar_top, defMarTop); - int marLeft = (int) ta.getDimension(R.styleable.TimetableView_mar_left, defMarLeft); - int itemHeight = (int) ta.getDimension(R.styleable.TimetableView_item_height, defItemHeight); - int thisWeekCorner = (int) ta.getDimension(R.styleable.TimetableView_thisweek_corner, 5); - int nonWeekCorner = (int) ta.getDimension(R.styleable.TimetableView_nonweek_corner, 5); - int maxSlideItem = ta.getInteger(R.styleable.TimetableView_max_slide_item, 12); - boolean isShowNotWeek = ta.getBoolean(R.styleable.TimetableView_show_notcurweek, true); - - ta.recycle(); - - curWeek(curWeek) - .curTerm(curTerm) - .marTop(marTop) - .marLeft(marLeft) - .itemHeight(itemHeight) - .corner(thisWeekCorner, true) - .corner(nonWeekCorner, false) - .maxSlideItem(maxSlideItem) - .isShowNotCurWeek(isShowNotWeek); - } - - /** - * 构建侧边栏 - * - * @param slidelayout 侧边栏的容器 - */ - private void newSlideView(LinearLayout slidelayout) { - if (slidelayout == null) return; - slidelayout.removeAllViews(); - - ISchedule.OnSlideBuildListener listener = onSlideBuildListener(); - listener.onInit(slidelayout, slideAlpha()); - for (int i = 0; i < maxSlideItem(); i++) { - View view = listener.getView(i, inflater, itemHeight(), marTop()); - slidelayout.addView(view); - } - } - - /** - * 构建课程项 - * - * @param data 某一天的数据集合 - * @param subject 当前的课程数据 - * @param pre 上一个课程数据 - * @param i 构建的索引 - * @param curWeek 当前周 - * @return View - */ - private View newItemView(final List data, final Schedule subject, Schedule pre, int i, int curWeek) { - //宽高 - int width = LinearLayout.LayoutParams.MATCH_PARENT; - int height = itemHeight() * subject.getStep() + marTop() * (subject.getStep() - 1); - - //边距 - int left = marLeft() / 2, right = marLeft() / 2; - int top = (subject.getStart() - (pre.getStart() + pre.getStep())) - * (itemHeight() + marTop()) + marTop(); - - if (i != 0 && top < 0) return null; - - // 设置Params - View view = inflater.inflate(R.layout.item_timetable, null, false); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height); - if (i == 0) { - top = (subject.getStart() - 1) * (itemHeight() + marTop()) + marTop(); - } - lp.setMargins(left, top, right, 0); - - view.setBackgroundColor(Color.TRANSPARENT); - view.setTag(subject); - FrameLayout layout = view.findViewById(R.id.id_course_item_framelayout); - TextView textView = view.findViewById(R.id.id_course_item_course); - layout.setLayoutParams(lp); - - boolean isThisWeek = ScheduleSupport.isThisWeek(subject, curWeek); - textView.setText(onItemBuildListener().getItemText(subject, isThisWeek)); - - GradientDrawable gd = new GradientDrawable(); - if (isThisWeek) { - gd.setColor(colorPool().getColorAuto(subject.getColorRandom())); - gd.setCornerRadius(corner(true)); - } else { - gd.setColor(colorPool().getUselessColor()); - gd.setCornerRadius(corner(false)); - } - textView.setBackgroundDrawable(gd); - - textView.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - List result = ScheduleSupport.findSubjects(subject, data); - onItemClickListener().onItemClick(v, result); - } - }); - - textView.setOnLongClickListener(new OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - onItemLongClickListener().onLongClick(view,subject.getDay(),subject.getStart()); - return true; - } - }); - - return view; - } - - /** - * 将数据data添加到layout的布局上 - * - * @param layout 容器 - * @param data 某一天的数据集合 - * @param curWeek 当前周 - */ - private void addToLayout(LinearLayout layout, final List data, int curWeek) { - if (layout == null || data == null || data.size() < 1) return; - layout.removeAllViews(); - - //遍历 - Schedule pre = data.get(0); - for (int i = 0; i < data.size(); i++) { - final Schedule subject = data.get(i); - boolean isIgnore = filterSubject(subject, pre, i, curWeek); - if (!isIgnore) { - View view = newItemView(data, subject, pre, i, curWeek); - if (view != null) { - layout.addView(view); - pre = subject; - } - } - } - } - - /** - * 简单过滤课程 - * - * @param subject - * @param pre - * @param index - * @param curWeek - * @return - */ - private boolean filterSubject(Schedule subject, Schedule pre, int index, int curWeek) { - - if (index != 0 && ScheduleSupport.isThisWeek(subject, curWeek)) { - if (ScheduleSupport.isThisWeek(pre, curWeek)) { - if (subject.getStart() == pre.getStart()) return true; - } - } - return false; - } - - /** - * 更新课程项的视图 - * - * @param courses - * @param view - * @param preView - * @param isChange - * @param j - * @param curWeek - * @return - */ - private boolean updateItemView(final List courses, View view, View preView, boolean isChange, int j, int curWeek) { - FrameLayout layout = (FrameLayout) view.findViewById(R.id.id_course_item_framelayout); - Schedule tag = (Schedule) view.getTag(); - Schedule subject = ScheduleSupport.findRealSubject(tag.getStart(), curWeek, courses); - - boolean isThisWeek = ScheduleSupport.isThisWeek(subject, curWeek); - if (!isThisWeek && !isShowNotCurWeek()) { - view.setVisibility(View.INVISIBLE); - } else { - view.setVisibility(View.VISIBLE); - } - - int height = itemHeight() * subject.getStep() + - marTop() * (subject.getStep() - 1); - int leftOrRight = marLeft() / 2; - int top = 0; - - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, height); - - if (isChange || tag.getStart() != subject.getStart() || tag.getStep() != subject.getStep()) { - if (j > 0) { - Schedule pre = (Schedule) preView.getTag(); - top = (subject.getStart() - (pre.getStart() + pre.getStep())) * (itemHeight() - + marTop()) + marTop(); - } else { - top = (subject.getStart() - 1) * (itemHeight() + marTop()) + marTop(); - } - lp.setMargins(leftOrRight, top, leftOrRight, 0); - layout.setLayoutParams(lp); - view.setTag(subject); - isChange = true; - } - - if (top < 0) view.setVisibility(View.GONE); - TextView textView = (TextView) view.findViewById(R.id.id_course_item_course); - TextView countTextView = (TextView) view.findViewById(R.id.id_course_item_count); - textView.setText(onItemBuildListener().getItemText(subject, isThisWeek)); - - countTextView.setText(""); - countTextView.setVisibility(View.GONE); - - GradientDrawable gd = new GradientDrawable(); - if (isThisWeek) { - textView.setTextColor(itemTextColorWithThisWeek()); - gd.setColor(colorPool().getColorAutoWithAlpha(subject.getColorRandom(), itemAlpha())); - gd.setCornerRadius(corner(true)); - - int count = 0; - List result = ScheduleSupport.findSubjects(subject, courses); - for (Schedule bean : result) { - if (ScheduleSupport.isThisWeek(bean, curWeek)) { - count++; - } - } - if (count > 1) { - countTextView.setVisibility(View.VISIBLE); - countTextView.setText(count + ""); - } - } else { - textView.setTextColor(itemTextColorWithNotThis()); - gd.setColor(colorPool().getUselessColorWithAlpha(itemAlpha())); - gd.setCornerRadius(corner(false)); - } - - textView.setBackgroundDrawable(gd); - onItemBuildListener().onItemUpdate(layout, textView, countTextView, subject, gd); - return isChange; - } - - - /** - * 周次切换 - */ - private void changeWeek(LinearLayout[] panels, List[] data, int curWeek) { - for (int i = 0; i < panels.length; i++) { - List courses = data[i]; - boolean isChange = false; - for (int j = 0; j < panels[i].getChildCount(); j++) { - View view = panels[i].getChildAt(j); - View preView; - if (j > 0) preView = panels[i].getChildAt(j - 1); - else preView = null; - isChange = updateItemView(courses, view, preView, isChange, j, curWeek); - } - } - } - - /** - * 点击panel时的事件响应 - */ - private void onPanelClicked(View view, float y) { - if(isShowFlaglayout()){ - flagLayout.setVisibility(VISIBLE); - }else{ - flagLayout.setVisibility(GONE); - } - - //周几,0:周一,6:周日 - int day = 0; - - // 先找到点击的是周几的panel - for (int i = 0; i < panels.length; i++) { - if (view == panels[i]) { - day = i; - break; - } - } - - if (day == -1) - return; - - // 判断点击的是第几节课,1:第1节 - final int start = (int) Math.ceil((y / (itemHeight + marTop))); - onSpaceItemClickListener().onSpaceItemClick(day,start); - final int finalDay = day; - flagLayout.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - onFlaglayoutClickListener().onFlaglayoutClick(finalDay,start); - } - }); - } - - /** - * 初始化panel并为panel设置事件监听 - */ - private void initPanel() { - for (int i = 0; i < panels.length; i++) { - panels[i] = findViewById(R.id.weekPanel_1 + i); - data[i] = new ArrayList<>(); - - /** - * 点击空白格子时才会触发这个事件 - */ - panels[i].setOnTouchListener(new OnTouchListener() { - - @Override - public boolean onTouch(View arg0, MotionEvent arg1) { - switch (arg1.getAction()) { - case MotionEvent.ACTION_DOWN: - x = arg1.getX(); - y = arg1.getY(); - - break; - case MotionEvent.ACTION_UP: - float x2 = arg1.getX(); - float y2 = arg1.getY(); - if (x2 == x && y2 == y) - onPanelClicked(arg0, arg1.getY()); - break; - default: - break; - } - return true; - } - }); - } + operater().init(context,attrs,this); } /** @@ -1059,16 +783,17 @@ public void updateView() { * 隐藏旗标布局,立即生效 */ public TimetableView hideFlaglayout() { - flagLayout.setVisibility(GONE); + flagLayout().setVisibility(GONE); return this; } /** * 显示旗标布局,立即生效 + * * @return */ public TimetableView showFlaglayout() { - flagLayout.setVisibility(VISIBLE); + flagLayout().setVisibility(VISIBLE); return this; } @@ -1079,7 +804,7 @@ public TimetableView showFlaglayout() { * @return */ public void hideDateView() { - dateLayout.setVisibility(View.GONE); + operater().getDateLayout().setVisibility(View.GONE); } /** @@ -1088,81 +813,21 @@ public void hideDateView() { * @return */ public void showDateView() { - dateLayout.setVisibility(View.VISIBLE); - } - - /** - * 绘制课程表 - */ - public void showView() { - if (dataSource() == null) return; - - //实现ScrollView的替换,只有在初始化时替换一次 - if (findViewById(R.id.id_scrollview) == null) { - View view = onScrollViewBuildListener().getScrollView(inflater); - containerLayout.addView(view); - //初始化 - weekPanel = findViewById(R.id.weekPanel_0); - flagLayout=findViewById(R.id.id_flaglayout); - initPanel(); - } - - flagLayout.setBackgroundColor(flagBgcolor()); - float perWidth = ScreenUtils.getWidthInPx(context) / 11.5f; - onSpaceItemClickListener().onInit(flagLayout, Math.round(perWidth), - Math.round(perWidth*1.5f),itemHeight(),marTop(), - Math.round(marLeft()/2.0f)); - - //更新日期 - updateDateView(); - updateSlideView(); - - //清空、拆分数据 - for (int i = 0; i < 7; i++) { - data[i].clear(); - } - List source = dataSource(); - for (int i = 0; i < source.size(); i++) { - Schedule bean = source.get(i); - if (bean.getDay() != -1) - data[bean.getDay() - 1].add(bean); - } - - //排序、填充课程 - ScheduleSupport.sortList(data); - for (int i = 0; i < panels.length; i++) { - panels[i].removeAllViews(); - addToLayout(panels[i], data[i], curWeek()); - } - //周次切换,保证重叠时显示角标 - changeWeek(curWeek(), false); + operater().getDateLayout().setVisibility(View.VISIBLE); } /** * 更新日期栏 */ public void updateDateView() { - dateLayout.removeAllViews(); - float perWidth = ScreenUtils.getWidthInPx(context) / 11.5f; - int height = context.getResources().getDimensionPixelSize(R.dimen.headHeight); -// //日期栏 - ISchedule.OnDateBuildListener listener = onDateBuildListener(); - listener.onInit(dateLayout, dateAlpha()); - View[] views = onDateBuildListener().getDateViews(inflater, perWidth, height); - for (View v : views) { - if (v != null) { - dateLayout.addView(v); - } - } - onDateBuildListener().onUpdateDate(curWeek(), curWeek()); - onDateBuildListener().onHighLight(); + operater().updateDateView(); } /** * 侧边栏更新 */ public void updateSlideView() { - newSlideView(weekPanel); + operater().updateSlideView(); } /** @@ -1172,8 +837,7 @@ public void updateSlideView() { * @param isCurWeek 是否强制设置为本周 */ public void changeWeek(int week, boolean isCurWeek) { - if (isCurWeek) changeWeekForce(week); - else changeWeekOnly(week); + operater().changeWeek(week,isCurWeek); } /** @@ -1182,8 +846,7 @@ public void changeWeek(int week, boolean isCurWeek) { * @param week */ public void changeWeekOnly(int week) { - changeWeek(panels, data, week); - onWeekChangedListener().onWeekChanged(week); + operater().changeWeek(week,false); } /** @@ -1192,15 +855,18 @@ public void changeWeekOnly(int week) { * @param week */ public void changeWeekForce(int week) { - changeWeek(panels, data, week); - curWeek(week); + operater().changeWeek(week,true); } /** * 更新旗标布局的背景色 */ - public void updateFlaglayout(){ - flagLayout.setBackgroundColor(flagBgcolor()); - if(!isShowFlaglayout()) hideFlaglayout(); + public void updateFlaglayout() { + flagLayout().setBackgroundColor(flagBgcolor()); + if (!isShowFlaglayout()) hideFlaglayout(); + } + + public void showView(){ + operater().showView(); } } diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/ISchedule.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/ISchedule.java index 181b27b..eb87d30 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/ISchedule.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/ISchedule.java @@ -176,13 +176,15 @@ interface OnDateBuildListener { /** * 获取View数组 + * 被废弃,自v2.0.3起该方法无效 * * @param mInflate 转换器 - * @param perWidth 每个单位的宽度,月份占1个单位,其余为1.5个单位 + * @param monthWidth 月份宽度px + * @param perWidth 日期每项宽度px * @param height 默认的日期栏高度 * @return */ - View[] getDateViews(LayoutInflater mInflate, float perWidth, int height); + View[] getDateViews(LayoutInflater mInflate, float monthWidth,float perWidth, int height); /** * 为日期栏设置高亮时回调 diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnDateBuildAapter.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnDateBuildAapter.java index 82bc993..0d6a694 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnDateBuildAapter.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnDateBuildAapter.java @@ -30,7 +30,7 @@ public class OnDateBuildAapter implements ISchedule.OnDateBuildListener { protected TextView[] textViews = new TextView[8]; protected LinearLayout[] layouts = new LinearLayout[8]; - private int background = Color.parseColor("#F4F8F8"); + protected int background = Color.parseColor("#F4F8F8"); protected float alpha = 1; protected String[] dateArray; @@ -45,23 +45,20 @@ public OnDateBuildAapter setBackground(int background) { @Override public void onInit(LinearLayout layout, float alpha) { this.alpha = alpha; - this.layout=layout; + this.layout = layout; //星期设置 - dateArray=getStringArray(); + dateArray = getStringArray(); weekDates = ScheduleSupport.getWeekDate(); int alphaColor = ColorUtils.alphaColor(background, alpha); if (layout != null) layout.setBackgroundColor(alphaColor); } @Override - public View[] getDateViews(LayoutInflater mInflate, float perWidth, int height) { + public View[] getDateViews(LayoutInflater mInflate, float monthWidth, float perWidth, int height) { View[] views = new View[8]; - - //月份占1份的宽度 - views[0] = onBuildMonthLayout(mInflate,(int)perWidth,height); - + views[0] = onBuildMonthLayout(mInflate, (int) monthWidth, height); for (int i = 1; i < 8; i++) { - views[i]=onBuildDayLayout(mInflate,i,(int)(perWidth*1.5),height); + views[i] = onBuildDayLayout(mInflate, i, (int) perWidth, height); } return views; } @@ -87,16 +84,15 @@ public void onHighLight() { } - @Override - public void onUpdateDate(int curWeek,int targetWeek) { + public void onUpdateDate(int curWeek, int targetWeek) { if (textViews == null || textViews.length < 8) return; - weekDates = ScheduleSupport.getDateStringFromWeek(curWeek,targetWeek); + weekDates = ScheduleSupport.getDateStringFromWeek(curWeek, targetWeek); int month = Integer.parseInt(weekDates.get(0)); textViews[0].setText(month + "\n月"); for (int i = 1; i < 8; i++) { - if(textViews[i]!=null){ + if (textViews[i] != null) { textViews[i].setText(weekDates.get(i) + "日"); } } @@ -111,7 +107,7 @@ public void onUpdateDate(int curWeek,int targetWeek) { * @param height 默认高度 * @return */ - public View onBuildMonthLayout(LayoutInflater mInflate, int width, int height) { + protected View onBuildMonthLayout(LayoutInflater mInflate, int width, int height) { View first = mInflate.inflate(R.layout.item_dateview_first, null, false); //月份设置 textViews[0] = first.findViewById(R.id.id_week_month); @@ -125,7 +121,7 @@ public View onBuildMonthLayout(LayoutInflater mInflate, int width, int height) { return first; } - public View onBuildDayLayout(LayoutInflater mInflate,int pos, int width, int height) { + protected View onBuildDayLayout(LayoutInflater mInflate, int pos, int width, int height) { View v = mInflate.inflate(R.layout.item_dateview, null, false); TextView dayTextView = v.findViewById(R.id.id_week_day); dayTextView.setText(dateArray[pos]); @@ -142,20 +138,23 @@ public View onBuildDayLayout(LayoutInflater mInflate,int pos, int width, int hei /** * 返回一个长度为8的数组,第0个位置为null + * * @return */ - public String[] getStringArray(){ - return new String[]{null,"周一", "周二", "周三", "周四", "周五", "周六", "周日"}; + public String[] getStringArray() { + return new String[]{null, "周一", "周二", "周三", "周四", "周五", "周六", "周日"}; } - public void initDateBackground(){ + protected void initDateBackground() { for (int i = 1; i < 8; i++) { - layouts[i].setBackgroundColor(Color.TRANSPARENT); + if (layouts[i] != null) layouts[i].setBackgroundColor(Color.TRANSPARENT); } } - private void activeDateBackground(int weekDay) { - layouts[weekDay].setBackgroundColor( - ColorUtils.alphaColor(Color.parseColor("#BFF6F4"), alpha)); + protected void activeDateBackground(int weekDay) { + if (layouts.length > weekDay && layouts[weekDay] != null) { + layouts[weekDay].setBackgroundColor( + ColorUtils.alphaColor(Color.parseColor("#BFF6F4"), alpha)); + } } } diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemBuildAdapter.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemBuildAdapter.java index 8737b7e..899785c 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemBuildAdapter.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemBuildAdapter.java @@ -14,10 +14,16 @@ public class OnItemBuildAdapter implements ISchedule.OnItemBuildListener { @Override public String getItemText(Schedule schedule, boolean isThisWeek) { - if(schedule==null||schedule.getName()==null||schedule.getRoom()==null) return "default"; - String r=schedule.getName()+"@"+schedule.getRoom(); - if(!isThisWeek){ - r="[非本周]"+r; + if (schedule == null || TextUtils.isEmpty(schedule.getName())) return "未命名"; + if (schedule.getRoom() == null) { + if (!isThisWeek) + return "[非本周]" + schedule.getName(); + return schedule.getName(); + } + + String r = schedule.getName() + "@" + schedule.getRoom(); + if (!isThisWeek) { + r = "[非本周]" + r; } return r; } diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemClickAdapter.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemClickAdapter.java index 437e18a..3401af6 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemClickAdapter.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnItemClickAdapter.java @@ -15,6 +15,5 @@ public class OnItemClickAdapter implements ISchedule.OnItemClickListener { private static final String TAG = "OnItemClickAdapter"; @Override public void onItemClick(View v, List scheduleList) { - Log.d(TAG, "onItemClick: "); } } diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnSlideBuildAdapter.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnSlideBuildAdapter.java index 0847fa1..be3c2e0 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnSlideBuildAdapter.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/listener/OnSlideBuildAdapter.java @@ -18,15 +18,15 @@ public class OnSlideBuildAdapter implements ISchedule.OnSlideBuildListener { //时刻,每个元素保存每节课的开始时间 - private String[] times; + protected String[] times; //节次文本的颜色、字号 - private int textColor= Color.BLACK; - private float textSize=14; + protected int textColor= Color.BLACK; + protected float textSize=14; //时刻文本的颜色、字号 - private float timeTextSize=12; - private int timeTextColor=Color.GRAY; + protected float timeTextSize=12; + protected int timeTextColor=Color.GRAY; //侧边栏背景色 protected int background=Color.WHITE; diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/Schedule.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/Schedule.java index 09de7da..3ec866f 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/Schedule.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/Schedule.java @@ -12,7 +12,7 @@ * @author Administrator 刘壮飞 * */ -public class Schedule implements Serializable{ +public class Schedule implements Serializable,Comparable{ /** * 课程名 @@ -154,4 +154,14 @@ public Schedule() { super(); } + @Override + public int compareTo(Schedule o) { + if(getStart() getDateStringFromCalendar(Calendar calendar) { calendar.add(Calendar.DAY_OF_MONTH, -1); } calendar.setFirstDayOfWeek(Calendar.MONDAY); - dateList.add((calendar.get(Calendar.MONTH) + 1)+""); + dateList.add((calendar.get(Calendar.MONTH) + 1) + ""); for (int i = 0; i < 7; i++) { - dateList.add(calendar.get(Calendar.DAY_OF_MONTH)+""); + dateList.add(calendar.get(Calendar.DAY_OF_MONTH) + ""); calendar.add(Calendar.DAY_OF_MONTH, 1); } return dateList; @@ -167,6 +174,7 @@ public static List getColorReflect(List schedules) { /** * 内部使用的是:context.getResources().getDimensionPixelSize(dp); + * * @param context * @param dp * @return @@ -298,17 +306,23 @@ public static void sortList(List[] data) { int min; Schedule tmp; for (int i = 0; i < data.length; i++) - for (int m = 0; m < data[i].size() - 1; m++) { - min = m; - for (int k = m + 1; k < data[i].size(); k++){ - if (data[i].get(min).getStart() > data[i].get(k).getStart()) { - min = k; - } + sortList(data[i]); + } + + public static void sortList(List data) { + int min; + Schedule tmp; + for (int m = 0; m < data.size() - 1; m++) { + min = m; + for (int k = m + 1; k < data.size(); k++) { + if (data.get(min).getStart() > data.get(k).getStart()) { + min = k; } - tmp = data[i].get(m); - data[i].set(m, data[i].get(min)); - data[i].set(min, tmp); } + tmp = data.get(m); + data.set(m, data.get(min)); + data.set(min, tmp); + } } /** @@ -322,4 +336,61 @@ public static boolean isThisWeek(Schedule subject, int cur_week) { if (weekList.indexOf(cur_week) != -1) return true; return false; } + + /** + * 根据当前周过滤课程,获取本周有效的课程(忽略重叠的) + * + * @param data + * @param curWeek + * @return + */ + public static List fliterSchedule(List data, int curWeek, boolean isShowNotCurWeek) { + List filterData = new ArrayList<>(); + if (data == null) return filterData; + + if (isShowNotCurWeek) filterData = data; + else { + for (Schedule schedule : data) { + if (ScheduleSupport.isThisWeek(schedule, curWeek)) { + filterData.add(schedule); + } + } + } + Set result = new HashSet<>(); + for (int i = 0; i < filterData.size(); i++) { + Schedule s = filterData.get(i); + if (s != null) { + s.putExtras("zfman_count", 0); + } + } + + if (data.size() >= 1) { + result.add(data.get(0)); + } + + for (int i = 1; i < data.size(); i++) { + Schedule s = data.get(i); + for (int j = 0; j < i; j++) { + Schedule s2 = data.get(j); + if (s.getStart() <= (s2.getStart() + s2.getStep() - 1)) { + if (!ScheduleSupport.isThisWeek(s2, curWeek)) { + if (ScheduleSupport.isThisWeek(s, curWeek)) { + result.remove(s2); + result.add(s); + } + } else { + if (ScheduleSupport.isThisWeek(s, curWeek)) { + s.putExtras("zfman_count", (int) (s.getExtras().get("zfman_count")) + 1); + s2.putExtras("zfman_count", (int) (s2.getExtras().get("zfman_count")) + 1); + } + } + } else { + result.add(s); + } + } + } + List list = new ArrayList<>(result); + sortList(list); + return list; + } } \ No newline at end of file diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/WeekViewEnable.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/WeekViewEnable.java index 93bdcde..71b0585 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/WeekViewEnable.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/model/WeekViewEnable.java @@ -1,18 +1,5 @@ package com.zhuangfei.timetable.model; -import android.content.Context; -import android.util.AttributeSet; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.zhuangfei.android_timetableview.sample.R; -import com.zhuangfei.timetable.view.PerWeekView; -import com.zhuangfei.timetable.view.WeekView; - -import java.util.ArrayList; import java.util.List; /** @@ -77,7 +64,7 @@ public interface WeekViewEnable { * 设置控件的可见性 * @param isShow true:显示,false:隐藏 */ - WeekView isShow(boolean isShow); + T isShow(boolean isShow); /** * 判断该控件是否显示 diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/AbsOperater.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/AbsOperater.java new file mode 100644 index 0000000..204c7b8 --- /dev/null +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/AbsOperater.java @@ -0,0 +1,29 @@ +package com.zhuangfei.timetable.operater; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.LinearLayout; + +import com.zhuangfei.timetable.TimetableView; + +/** + * 抽象的业务逻辑 + * Created by Liu ZhuangFei on 2018/9/2. + */ +public abstract class AbsOperater { + public void init(Context context, AttributeSet attrs, TimetableView view){}; + + public void showView(){}; + + public void updateDateView(){}; + + public void updateSlideView(){}; + + public void changeWeek(int week, boolean isCurWeek){}; + + public LinearLayout getFlagLayout(){return null;}; + + public LinearLayout getDateLayout(){return null;}; + + public void setWeekendsVisiable(boolean isShow){}; +} diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/SimpleOperater.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/SimpleOperater.java new file mode 100644 index 0000000..4d28355 --- /dev/null +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/SimpleOperater.java @@ -0,0 +1,462 @@ +package com.zhuangfei.timetable.operater; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; +import android.graphics.drawable.GradientDrawable; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.zhuangfei.android_timetableview.sample.R; +import com.zhuangfei.timetable.TimetableView; +import com.zhuangfei.timetable.listener.ISchedule; +import com.zhuangfei.timetable.model.Schedule; +import com.zhuangfei.timetable.model.ScheduleSupport; +import com.zhuangfei.timetable.utils.ScreenUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * 课表业务操作者,TimetableView中只涉及属性的设置,方法的具体实现在这里. + * 常用的方法也就四个,如下 + * + * @see SimpleOperater#changeWeek(int, boolean) + * @see SimpleOperater#showView() + * @see SimpleOperater#updateDateView() + * @see SimpleOperater#updateSlideView() + * + * Created by Liu ZhuangFei on 2018/9/1. + */ +public class SimpleOperater extends AbsOperater{ + + private TimetableView mView; + private Context context; + + //保存点击的坐标 + private float x, y; + + //布局转换器 + private LayoutInflater inflater; + private LinearLayout weekPanel;//侧边栏 + private List[] data = new ArrayList[7];//每天的课程 + private LinearLayout[] panels = new LinearLayout[7];//每天的面板 + private LinearLayout containerLayout;//根布局 + private LinearLayout dateLayout;//根布局、日期栏容器 + private LinearLayout flagLayout;//旗标布局 + + @Override + public void init(Context context, AttributeSet attrs, TimetableView view) { + this.context = context; + mView = view; + inflater = LayoutInflater.from(context); + inflater.inflate(R.layout.timetable_layout, mView); + containerLayout = mView.findViewById(R.id.id_container); + dateLayout = mView.findViewById(R.id.id_datelayout); + mView.monthWidthDp(40); + initAttr(attrs); + } + + /** + * 获取自定义属性 + * + * @param attrs + */ + protected void initAttr(AttributeSet attrs) { + TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TimetableView); + int curWeek = ta.getInteger(R.styleable.TimetableView_cur_week, 1); + String curTerm = ta.getString(R.styleable.TimetableView_cur_term); + + int defMarTop = (int) context.getResources().getDimension(R.dimen.weekItemMarTop); + int defMarLeft = (int) context.getResources().getDimension(R.dimen.weekItemMarLeft); + int defItemHeight = (int) context.getResources().getDimension(R.dimen.weekItemHeight); + + int marTop = (int) ta.getDimension(R.styleable.TimetableView_mar_top, defMarTop); + int marLeft = (int) ta.getDimension(R.styleable.TimetableView_mar_left, defMarLeft); + int itemHeight = (int) ta.getDimension(R.styleable.TimetableView_item_height, defItemHeight); + int thisWeekCorner = (int) ta.getDimension(R.styleable.TimetableView_thisweek_corner, 5); + int nonWeekCorner = (int) ta.getDimension(R.styleable.TimetableView_nonweek_corner, 5); + int maxSlideItem = ta.getInteger(R.styleable.TimetableView_max_slide_item, 12); + boolean isShowNotWeek = ta.getBoolean(R.styleable.TimetableView_show_notcurweek, true); + + ta.recycle(); + + mView.curWeek(curWeek) + .curTerm(curTerm) + .marTop(marTop) + .marLeft(marLeft) + .itemHeight(itemHeight) + .corner(thisWeekCorner, true) + .corner(nonWeekCorner, false) + .maxSlideItem(maxSlideItem) + .isShowNotCurWeek(isShowNotWeek); + } + + @Override + public LinearLayout getDateLayout() { + return dateLayout; + } + + /** + * 获取旗标布局 + * @return + */ + @Override + public LinearLayout getFlagLayout(){ + return flagLayout; + } + + /** + * 构建侧边栏 + * + * @param slidelayout 侧边栏的容器 + */ + public void newSlideView(LinearLayout slidelayout) { + if (slidelayout == null) return; + slidelayout.removeAllViews(); + + ISchedule.OnSlideBuildListener listener = mView.onSlideBuildListener(); + listener.onInit(slidelayout, mView.slideAlpha()); + for (int i = 0; i < mView.maxSlideItem(); i++) { + View view = listener.getView(i, inflater, mView.itemHeight(), mView.marTop()); + slidelayout.addView(view); + } + } + + /** + * 构建课程项 + * + * @param data 某一天的数据集合 + * @param subject 当前的课程数据 + * @param pre 上一个课程数据 + * @param i 构建的索引 + * @param curWeek 当前周 + * @return View + */ + private View newItemView(final List data, final Schedule subject, Schedule pre, int i, int curWeek) { + //宽高 + int width = LinearLayout.LayoutParams.MATCH_PARENT; + int height = mView.itemHeight() * subject.getStep() + mView.marTop() * (subject.getStep() - 1); + + //边距 + int left = mView.marLeft() / 2, right = mView.marLeft() / 2; + int top = (subject.getStart() - (pre.getStart() + pre.getStep())) + * (mView.itemHeight() + mView.marTop()) + mView.marTop(); + + if (i != 0 && top < 0) return null; + + // 设置Params + View view = inflater.inflate(R.layout.item_timetable, null, false); + + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height); + if (i == 0) { + top = (subject.getStart() - 1) * (mView.itemHeight() + mView.marTop()) + mView.marTop(); + } + lp.setMargins(left, top, right, 0); + + view.setBackgroundColor(Color.TRANSPARENT); + view.setTag(subject); + FrameLayout layout = view.findViewById(R.id.id_course_item_framelayout); + layout.setLayoutParams(lp); + + boolean isThisWeek = ScheduleSupport.isThisWeek(subject, curWeek); + TextView textView = (TextView) view.findViewById(R.id.id_course_item_course); + TextView countTextView = (TextView) view.findViewById(R.id.id_course_item_count); + textView.setText(mView.onItemBuildListener().getItemText(subject, isThisWeek)); + + countTextView.setText(""); + countTextView.setVisibility(View.GONE); + + GradientDrawable gd = new GradientDrawable(); + if (isThisWeek) { + textView.setTextColor(mView.itemTextColorWithThisWeek()); + gd.setColor(mView.colorPool().getColorAutoWithAlpha(subject.getColorRandom(), mView.itemAlpha())); + gd.setCornerRadius(mView.corner(true)); + + int count = (int) subject.getExtras().get("zfman_count"); + if (count > 1) { + countTextView.setVisibility(View.VISIBLE); + countTextView.setText(count + ""); + } + } else { + textView.setTextColor(mView.itemTextColorWithNotThis()); + gd.setColor(mView.colorPool().getUselessColorWithAlpha(mView.itemAlpha())); + gd.setCornerRadius(mView.corner(false)); + } + + textView.setBackgroundDrawable(gd); + mView.onItemBuildListener().onItemUpdate(layout, textView, countTextView, subject, gd); + + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + List result = ScheduleSupport.findSubjects(subject, data); + mView.onItemClickListener().onItemClick(v, result); + } + }); + + textView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + mView.onItemLongClickListener().onLongClick(view, subject.getDay(), subject.getStart()); + return true; + } + }); + + return view; + } + + /** + * 将数据data添加到layout的布局上 + * + * @param layout 容器 + * @param data 某一天的数据集合 + * @param curWeek 当前周 + */ + private void addToLayout(LinearLayout layout, final List data, int curWeek) { + if (layout == null || data == null || data.size() < 1) return; + layout.removeAllViews(); + + //遍历 + Schedule pre = data.get(0); + List filter = ScheduleSupport.fliterSchedule(data, curWeek,mView.isShowNotCurWeek()); + layout.setTag(filter.size()); + for (int i = 0; i < filter.size(); i++) { + final Schedule subject = filter.get(i); + View view = newItemView(filter, subject, pre, i, curWeek); + if (view != null) { + layout.addView(view); + pre = subject; + } + } + } + + + /** + * 点击panel时的事件响应 + */ + protected void onPanelClicked(View view, float y) { + if(mView.isShowFlaglayout()){ + flagLayout.setVisibility(View.VISIBLE); + }else{ + flagLayout.setVisibility(View.GONE); + } + + //周几,0:周一,6:周日 + int day = 0; + + // 先找到点击的是周几的panel + for (int i = 0; i < panels.length; i++) { + if (view == panels[i]) { + day = i; + break; + } + } + + if (day == -1) + return; + + // 判断点击的是第几节课,1:第1节 + final int start = (int) Math.ceil((y / (mView.itemHeight() + mView.marTop()))); + if(!checkPosition(day,start)){ + mView.onSpaceItemClickListener().onSpaceItemClick(day,start); + } + final int finalDay = day; + flagLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mView.onFlaglayoutClickListener().onFlaglayoutClick(finalDay,start); + } + }); + } + + /** + * 判断位置是否有课 + * @param day + * @param start + * @return true:有课,false:无课 + */ + protected boolean checkPosition(int day,int start){ + List list; + if(mView.isShowNotCurWeek()){ + list= ScheduleSupport.getAllSubjectsWithDay(mView.dataSource(),day); + }else{ + list= ScheduleSupport.getHaveSubjectsWithDay(mView.dataSource(),mView.curWeek(),day); + } + boolean isHave=false; + for(Schedule item:list){ + if(start==item.getStart()||(start>=item.getStart()&&start<=(item.getStart()+item.getStep()-1))){ + isHave=true; + } + } + return isHave; + } + + /** + * 初始化panel并为panel设置事件监听 + */ + protected void initPanel() { + for (int i = 0; i < panels.length; i++) { + panels[i] = mView.findViewById(R.id.weekPanel_1 + i); + data[i] = new ArrayList<>(); + + /** + * 点击空白格子时才会触发这个事件 + */ + panels[i].setOnTouchListener(new View.OnTouchListener() { + + @Override + public boolean onTouch(View arg0, MotionEvent arg1) { + switch (arg1.getAction()) { + case MotionEvent.ACTION_DOWN: + x = arg1.getX(); + y = arg1.getY(); + + break; + case MotionEvent.ACTION_UP: + float x2 = arg1.getX(); + float y2 = arg1.getY(); + if (x2 == x && y2 == y) + onPanelClicked(arg0, arg1.getY()); + break; + default: + break; + } + return true; + } + }); + } + } + + /** + * 绘制课程表 + */ + @Override + public void showView() { + if (mView.dataSource() == null) return; + + //实现ScrollView的替换,只有在初始化时替换一次 + if (mView.findViewById(R.id.id_scrollview) == null) { + View view = mView.onScrollViewBuildListener().getScrollView(inflater); + containerLayout.addView(view); + //初始化 + weekPanel = mView.findViewById(R.id.weekPanel_0); + flagLayout=mView.findViewById(R.id.id_flaglayout); + initPanel(); + } + + LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(mView.monthWidth(), LinearLayout.LayoutParams.MATCH_PARENT); + weekPanel.setLayoutParams(lp); + flagLayout.setBackgroundColor(mView.flagBgcolor()); + float perWidth=getPerWidth(); + + mView.onSpaceItemClickListener().onInit(flagLayout, mView.monthWidth(), + Math.round(perWidth),mView.itemHeight(),mView.marTop(), + Math.round(mView.marLeft()/2.0f)); + + + setWeekendsVisiable(mView.isShowWeekends()); + + //更新日期 + updateDateView(); + updateSlideView(); + + //清空、拆分数据 + for (int i = 0; i < 7; i++) { + data[i].clear(); + } + List source = mView.dataSource(); + for (int i = 0; i < source.size(); i++) { + Schedule bean = source.get(i); + if (bean.getDay() != -1) + data[bean.getDay() - 1].add(bean); + } + + //排序、填充课程 + ScheduleSupport.sortList(data); + for (int i = 0; i < panels.length; i++) { + panels[i].removeAllViews(); + addToLayout(panels[i], data[i], mView.curWeek()); + } + } + + /** + * 切换周次 + * @param week + * @param isCurWeek 是否强制设置为当前周 + */ + @Override + public void changeWeek(int week, boolean isCurWeek) { + for (int i = 0; i < panels.length; i++) { + addToLayout(panels[i], data[i], week); + } + if (isCurWeek){ + mView.curWeek(week); + }else{ + mView.onWeekChangedListener().onWeekChanged(week); + } + } + + protected float getPerWidth(){ + float perWidth = 0; + if(mView.isShowWeekends()){ + perWidth=(ScreenUtils.getWidthInPx(context) -mView.monthWidth())/7; + }else{ + perWidth=(ScreenUtils.getWidthInPx(context) -mView.monthWidth())/5; + } + return perWidth; + } + /** + * 更新日期栏 + */ + public void updateDateView() { + dateLayout.removeAllViews(); + + float perWidth=getPerWidth(); + + int height = context.getResources().getDimensionPixelSize(R.dimen.headHeight); +// //日期栏 + ISchedule.OnDateBuildListener listener = mView.onDateBuildListener(); + listener.onInit(dateLayout, mView.dateAlpha()); + View[] views = mView.onDateBuildListener().getDateViews(inflater, mView.monthWidth(),perWidth, height); + for (View v : views) { + if (v != null) { + dateLayout.addView(v); + } + } + mView.onDateBuildListener().onUpdateDate(mView.curWeek(), mView.curWeek()); + mView.onDateBuildListener().onHighLight(); + } + + /** + * 侧边栏更新 + */ + @Override + public void updateSlideView() { + + newSlideView(weekPanel); + } + + /** + * 设置周末的可见性 + */ + public void setWeekendsVisiable(boolean isShow) { + if(isShow){ + if(panels!=null&&panels.length>6){ + panels[5].setVisibility(View.VISIBLE); + panels[6].setVisibility(View.VISIBLE); + } + }else{ + if(panels!=null&&panels.length>6){ + panels[5].setVisibility(View.GONE); + panels[6].setVisibility(View.GONE); + } + } + } +} diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/package-info.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/package-info.java new file mode 100644 index 0000000..c7efb3e --- /dev/null +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/operater/package-info.java @@ -0,0 +1,4 @@ +/** + * 该包存放与ScheduleOperater有关的类 + */ +package com.zhuangfei.timetable.operater; \ No newline at end of file diff --git a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/view/WeekView.java b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/view/WeekView.java index fbdedac..308fdf8 100644 --- a/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/view/WeekView.java +++ b/AndroidTimetableView/TimetableView/src/com/zhuangfei/timetable/view/WeekView.java @@ -25,7 +25,6 @@ /** * 周次选择栏自定义View. * 每一项均为PerWeekView
- * 懒加载机制:在使用时再绘制 */ public class WeekView extends LinearLayout implements WeekViewEnable{ diff --git a/AndroidTimetableView/app/release/app-release.apk b/AndroidTimetableView/app/release/app-release.apk new file mode 100644 index 0000000..1980f13 Binary files /dev/null and b/AndroidTimetableView/app/release/app-release.apk differ diff --git a/AndroidTimetableView/app/release/output.json b/AndroidTimetableView/app/release/output.json new file mode 100644 index 0000000..5897f44 --- /dev/null +++ b/AndroidTimetableView/app/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.zhuangfei.android_timetableview","split":"","minSdkVersion":"15"}}] \ No newline at end of file diff --git a/AndroidTimetableView/app/src/main/AndroidManifest.xml b/AndroidTimetableView/app/src/main/AndroidManifest.xml index 8edcab4..7e0408a 100644 --- a/AndroidTimetableView/app/src/main/AndroidManifest.xml +++ b/AndroidTimetableView/app/src/main/AndroidManifest.xml @@ -34,7 +34,8 @@ - + + \ No newline at end of file diff --git a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/MainActivity.java b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/MainActivity.java index a13dd3d..a166c69 100644 --- a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/MainActivity.java +++ b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/MainActivity.java @@ -10,6 +10,7 @@ import com.zhuangfei.android_timetableview.views.BaseFuncActivity; import com.zhuangfei.android_timetableview.views.ColorPoolActivity; import com.zhuangfei.android_timetableview.views.DateActivity; +import com.zhuangfei.android_timetableview.views.DateDelayActivity; import com.zhuangfei.android_timetableview.views.ElasticActivity; import com.zhuangfei.android_timetableview.views.ExtrasActivity; import com.zhuangfei.android_timetableview.views.FlaglayoutActivity; @@ -37,6 +38,7 @@ private void initView() { Button button8=findViewById(R.id.id_btn8); Button button9=findViewById(R.id.id_btn9); Button button10=findViewById(R.id.id_btn10); + Button button11=findViewById(R.id.id_btn11); button1.setOnClickListener(this); button2.setOnClickListener(this); @@ -48,6 +50,7 @@ private void initView() { button8.setOnClickListener(this); button9.setOnClickListener(this); button10.setOnClickListener(this); + button11.setOnClickListener(this); } public void toTarget(Class cla){ @@ -88,6 +91,9 @@ public void onClick(View view) { case R.id.id_btn10: toTarget(FlaglayoutActivity.class); break; + case R.id.id_btn11: + toTarget(DateDelayActivity.class); + break; } } diff --git a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/adapter/OnDateDelayAdapter.java b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/adapter/OnDateDelayAdapter.java new file mode 100644 index 0000000..2bf59c8 --- /dev/null +++ b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/adapter/OnDateDelayAdapter.java @@ -0,0 +1,128 @@ +package com.zhuangfei.android_timetableview.adapter; + +import android.text.TextUtils; +import android.widget.LinearLayout; +import com.zhuangfei.timetable.listener.OnDateBuildAapter; +import com.zhuangfei.timetable.model.ScheduleSupport; + +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * 自定义日期栏 + * Created by Liu ZhuangFei on 2018/8/24. + */ +public class OnDateDelayAdapter extends OnDateBuildAapter { + + /** + * 阈值,即超过这个时间戳后开始更新日期 + * 否则将一直显示initDates中的日期 + */ + protected long startTime; + protected String startTimeStr; + + protected SimpleDateFormat sdf; + + /** + * 日期集合,8个元素,当前时间小于等于阈值时使用 + */ + List initDates=null; + + public OnDateDelayAdapter(){ + sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm"); + } + + /** + * 设置日期集合 + * @param dates 元素个数必须大于等于8,第一个为月份数值,第2-8为周一至周日的日期数值(不带中文) + */ + public void setDateList(List dates){ + if(dates.size()>=8){ + this.initDates=dates; + } + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + this.startTimeStr=sdf.format(startTime); + } + + @Override + public void onInit(LinearLayout layout, float alpha) { + super.onInit(layout, alpha); + + //增加的 + long curTime=System.currentTimeMillis(); + if(curTime<=startTime){ + weekDates=initDates; + } + } + + @Override + public void onUpdateDate(int curWeek,int targetWeek) { + if (textViews == null || textViews.length < 8) return; + + if(whenBeginSchool()<=0){ + weekDates = ScheduleSupport.getDateStringFromWeek(curWeek,targetWeek); + } + + int month = Integer.parseInt(weekDates.get(0)); + textViews[0].setText(month + "\n月"); + for (int i = 1; i < 8; i++) { + if(textViews[i]!=null){ + textViews[i].setText(weekDates.get(i) + "日"); + } + } + } + + //这段代码可以禁止在开学前自动更新日期栏上的星期高亮 + //它会使用开学那天的星期作为高亮 + //你可以根据自己的需求使用 +// @Override +// public void onHighLight() { +// if(whenBeginSchool()<=0){ +// super.onHighLight(); +// return; +// } +// +// initDateBackground(); +// //获取周几,1->7 +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(new Date(startTime)); +// //一周第一天是否为星期天 +// boolean isFirstSunday = (calendar.getFirstDayOfWeek() == Calendar.SUNDAY); +// int weekDay = calendar.get(Calendar.DAY_OF_WEEK); +// //若一周第一天为星期天,则-1 +// if (isFirstSunday) { +// weekDay = weekDay - 1; +// if (weekDay == 0) { +// weekDay = 7; +// } +// } +// activeDateBackground(weekDay); +// } +// +// private void activeDateBackground(int weekDay) { +// layouts[weekDay].setBackgroundColor( +// ColorUtils.alphaColor(Color.parseColor("#BFF6F4"), alpha)); +// } + + /** + * 计算距离开学的天数 + * + * @return 返回值2种类型,-1:没有开学时间,无法计算;0:已经开学;>0:天数 + */ + public long whenBeginSchool(){ + if(!TextUtils.isEmpty(startTimeStr)){ + int calWeek= ScheduleSupport.timeTransfrom(startTimeStr); + if(calWeek>0){//开学 + return 0; + }else { + long seconds=(startTime-System.currentTimeMillis())/1000; + long day = seconds / (24 * 3600); + return day; + } + } + return -1; + } +} diff --git a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/model/SubjectRepertory.java b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/model/SubjectRepertory.java index 48630af..4013d02 100644 --- a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/model/SubjectRepertory.java +++ b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/model/SubjectRepertory.java @@ -22,6 +22,14 @@ public static List loadDefaultSubjects(){ return parse(json); } + public static List loadDefaultSubjects2() { + //json转义 + String json = "[[\"2017-2018学年秋\", \"\", \"\", \"计算机组成原理\", \"\", \"\", \"\", \"\", \"刘静\", \"\", \"\", \"1,2,3,4,5\", 1, 1, 4, \"\", \"计算机综合楼106\", \"\"]," + + "[\"2017-2018学年秋\", \"\", \"\", \"高等数学\", \"\", \"\", \"\", \"\", \"壮飞\", \"\", \"\", \"1,2,3,7,8\", 1, 2, 2, \"\", \"计算机综合楼106\", \"\"]," + + "[\"2017-2018学年秋\", \"\", \"\", \"算法分析与设计\", \"\", \"\", \"\", \"\", \"王静\", \"\", \"\", \"1,3,5,9,10\", 1, 5, 2, \"\", \"计算机综合楼205\", \"\"]]"; + return parse(json); + } + /** * 对json字符串进行解析 * @param parseString diff --git a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/BaseFuncActivity.java b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/BaseFuncActivity.java index 25d17ed..f0cc333 100644 --- a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/BaseFuncActivity.java +++ b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/BaseFuncActivity.java @@ -20,7 +20,9 @@ import com.zhuangfei.timetable.listener.ISchedule; import com.zhuangfei.timetable.listener.IWeekView; import com.zhuangfei.timetable.listener.OnSlideBuildAdapter; +import com.zhuangfei.timetable.listener.OnSpaceItemClickAdapter; import com.zhuangfei.timetable.model.Schedule; +import com.zhuangfei.timetable.model.ScheduleSupport; import com.zhuangfei.timetable.view.WeekView; import java.util.List; @@ -66,7 +68,8 @@ public void onClick(View view) { } }); - mySubjects = SubjectRepertory.loadDefaultSubjects(); + mySubjects = SubjectRepertory.loadDefaultSubjects2(); + mySubjects.addAll(SubjectRepertory.loadDefaultSubjects()); titleTextView = findViewById(R.id.id_title); layout = findViewById(R.id.id_layout); layout.setOnClickListener(this); @@ -107,10 +110,11 @@ public void onWeekLeftClicked() { .curWeek(1) .curTerm("大三下学期") .maxSlideItem(10) + .monthWidthDp(30) //透明度 //日期栏0.1f、侧边栏0.1f,周次选择栏0.6f //透明度范围为0->1,0为全透明,1为不透明 - .alpha(0.3f, 0.1f, 0.6f) +// .alpha(0.1f, 0.1f, 0.6f) .callback(new ISchedule.OnItemClickListener() { @Override public void onItemClick(View v, List scheduleList) { @@ -243,6 +247,18 @@ public boolean onMenuItemClick(MenuItem item) { case R.id.top12: hideWeekView(); break; + case R.id.top13: + setMonthWidth(); + break; + case R.id.top16: + resetMonthWidth(); + break; + case R.id.top14: + hideWeekends(); + break; + case R.id.top15: + showWeekends(); + break; default: break; } @@ -371,4 +387,32 @@ protected void showWeekView() { protected void hideWeekView() { mWeekView.isShow(false); } + + /** + * 设置月份宽度 + */ + private void setMonthWidth() { + mTimetableView.monthWidthDp(50).updateView(); + } + + /** + * 设置月份宽度,默认40dp + */ + private void resetMonthWidth() { + mTimetableView.monthWidthDp(40).updateView(); + } + + /** + * 隐藏周末 + */ + private void hideWeekends() { + mTimetableView.isShowWeekends(false).updateView(); + } + + /** + * 显示周末 + */ + private void showWeekends() { + mTimetableView.isShowWeekends(true).updateView(); + } } diff --git a/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/DateDelayActivity.java b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/DateDelayActivity.java new file mode 100644 index 0000000..0466a90 --- /dev/null +++ b/AndroidTimetableView/app/src/main/java/com/zhuangfei/android_timetableview/views/DateDelayActivity.java @@ -0,0 +1,118 @@ +package com.zhuangfei.android_timetableview.views; + +import android.content.DialogInterface; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; + +import com.zhuangfei.android_timetableview.R; +import com.zhuangfei.android_timetableview.adapter.OnDateDelayAdapter; +import com.zhuangfei.android_timetableview.model.MySubject; +import com.zhuangfei.android_timetableview.model.SubjectRepertory; +import com.zhuangfei.timetable.TimetableView; +import com.zhuangfei.timetable.listener.ISchedule; +import com.zhuangfei.timetable.listener.IWeekView; +import com.zhuangfei.timetable.listener.OnDateBuildAapter; +import com.zhuangfei.timetable.listener.OnSpaceItemClickAdapter; +import com.zhuangfei.timetable.model.Schedule; +import com.zhuangfei.timetable.model.ScheduleSupport; +import com.zhuangfei.timetable.view.WeekView; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * 日期延迟案例: + * 需求:设定一个开学时间,在开学时间到来之前,一直显示开学时的第一周的日期 + */ +public class DateDelayActivity extends AppCompatActivity { + + //控件 + TimetableView mTimetableView; + + TextView titleTextView; + List mySubjects; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_date_delay); + mySubjects = SubjectRepertory.loadDefaultSubjects(); + titleTextView = findViewById(R.id.id_title); + initTimetableView(); + } + + @Override + protected void onStart() { + super.onStart(); + + //用于更正日期的显示 + int cur=mTimetableView.curWeek(); + mTimetableView.onDateBuildListener().onUpdateDate(cur,cur); + + //更新文本 + OnDateDelayAdapter adapter= (OnDateDelayAdapter) mTimetableView.onDateBuildListener(); + long when=adapter.whenBeginSchool(); + if(when>0){ + titleTextView.setText("距离开学还有"+when+"天"); + } + } + + /** + * 初始化课程控件 + */ + private void initTimetableView() { + mTimetableView = findViewById(R.id.id_timetableView); + + mTimetableView.source(mySubjects) + .curWeek(1) + .curTerm("大三下学期") + .maxSlideItem(10) + .callback(new ISchedule.OnWeekChangedListener() { + @Override + public void onWeekChanged(int curWeek) { + OnDateDelayAdapter adapter= (OnDateDelayAdapter) mTimetableView.onDateBuildListener(); + long when=adapter.whenBeginSchool(); + if(when>0){ + titleTextView.setText("距离开学还有"+when+"天"); + }else{ + titleTextView.setText("第" + curWeek + "周"); + } + } + }) + .callback(getDateDelayAdapter()) + .showView(); + } + + /** + * 配置OnDateDelayAdapter + */ + public OnDateDelayAdapter getDateDelayAdapter(){ + OnDateDelayAdapter onDateDelayAdapter=new OnDateDelayAdapter(); + + //计算开学时间戳 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm"); + long startTime=0; + try { + startTime=sdf.parse("2018-09-03 00:00").getTime(); + } catch (ParseException e) { + e.printStackTrace(); + } + + //计算开学时的一周日期,我这里模拟一下 + List dateList= Arrays.asList("9","03","04","05","06","07","08","09"); + + //设置 + onDateDelayAdapter.setStartTime(startTime); + onDateDelayAdapter.setDateList(dateList); + return onDateDelayAdapter; + } +} diff --git a/AndroidTimetableView/app/src/main/res/layout/activity_base_func.xml b/AndroidTimetableView/app/src/main/res/layout/activity_base_func.xml index 81cbefe..01bbdde 100644 --- a/AndroidTimetableView/app/src/main/res/layout/activity_base_func.xml +++ b/AndroidTimetableView/app/src/main/res/layout/activity_base_func.xml @@ -17,7 +17,7 @@ android:id="@+id/id_timetableView" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@drawable/bg3"> + android:background="@color/app_white"> diff --git a/AndroidTimetableView/app/src/main/res/layout/activity_date_delay.xml b/AndroidTimetableView/app/src/main/res/layout/activity_date_delay.xml new file mode 100644 index 0000000..7431f82 --- /dev/null +++ b/AndroidTimetableView/app/src/main/res/layout/activity_date_delay.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/AndroidTimetableView/app/src/main/res/layout/activity_main.xml b/AndroidTimetableView/app/src/main/res/layout/activity_main.xml index 04a4cc2..4069693 100644 --- a/AndroidTimetableView/app/src/main/res/layout/activity_main.xml +++ b/AndroidTimetableView/app/src/main/res/layout/activity_main.xml @@ -65,5 +65,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="旗标布局(空白格子点击)" /> +