├── README.md ├── example.png ├── library ├── res │ ├── drawable │ │ ├── icon.png │ │ ├── event_count_bg.xml │ │ └── side_cell_bg.xml │ ├── values │ │ ├── strings.xml │ │ ├── dimens.xml │ │ ├── styles.xml │ │ └── colors.xml │ └── layout │ │ ├── day_timeline_eventlist.xml │ │ ├── week.xml │ │ ├── week_body.xml │ │ ├── day_timeline_event.xml │ │ ├── week_side.xml │ │ ├── week_cell.xml │ │ └── day_timeline.xml ├── project.properties ├── AndroidManifest.xml └── src │ └── cc │ └── linktime │ └── TimeLineCalendar │ └── library │ ├── ui │ ├── CalendarHour.java │ ├── CalendarWeekCell.java │ ├── CalendarTimeLineEvent.java │ ├── CalendarWeekSideCursor.java │ ├── CalendarTimeLineEventList.java │ ├── CalendarWeek.java │ ├── CalendarDayTimeLine.java │ ├── CalendarWeekBody.java │ └── CalendarWeekSide.java │ └── util │ ├── EventBuilder.java │ └── CalendarWeekBuilder.java ├── sample ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── values │ │ └── strings.xml │ └── layout │ │ └── main.xml ├── project.properties ├── ant.properties ├── AndroidManifest.xml ├── proguard-project.txt ├── src │ └── cc │ │ └── linktime │ │ └── TimeLineCalendar │ │ └── sample │ │ └── sample.java └── build.xml ├── .gitignore └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # 时间线日历 2 | UI组件Demo样图 3 | ![Screenshot](./example.png) 4 | 5 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linktime/TimeLineCalendar/HEAD/example.png -------------------------------------------------------------------------------- /library/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linktime/TimeLineCalendar/HEAD/library/res/drawable/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linktime/TimeLineCalendar/HEAD/sample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linktime/TimeLineCalendar/HEAD/sample/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linktime/TimeLineCalendar/HEAD/sample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Linktime/TimeLineCalendar/HEAD/sample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | library 4 | -------------------------------------------------------------------------------- /sample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | sample 4 | 5 | -------------------------------------------------------------------------------- /library/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by IntelliJ IDEA 2 | # Project target. 3 | target=android-18 4 | android.library=true 5 | -------------------------------------------------------------------------------- /library/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 3 | 40dp 4 | 20dp 5 | 40dp 6 | -------------------------------------------------------------------------------- /library/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /library/res/drawable/event_count_bg.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 8 | 9 | -------------------------------------------------------------------------------- /library/res/drawable/side_cell_bg.xml: -------------------------------------------------------------------------------- 1 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /library/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /library/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 3 | #FF3300 4 | #FF4C17 5 | #FF6532 6 | #FF7E4B 7 | #FF9D64 8 | #FFBB7D 9 | #FFCC9C 10 | -------------------------------------------------------------------------------- /sample/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /library/res/layout/day_timeline_eventlist.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /library/res/layout/week.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # 6 | *.*~ 7 | 8 | # files for the dex VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # generated files 15 | bin/ 16 | gen/ 17 | 18 | # Local configuration file (sdk path, etc) 19 | local.properties 20 | 21 | # Eclipse project files 22 | .classpath 23 | .project 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Intellij project files 29 | *.iml 30 | *.ipr 31 | *.iws 32 | .idea/ 33 | .gradle 34 | .DS_Store 35 | -------------------------------------------------------------------------------- /library/res/layout/week_body.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Linktime 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /sample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-18 15 | android.library.reference.1=../library 16 | -------------------------------------------------------------------------------- /sample/ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /library/res/layout/day_timeline_event.xml: -------------------------------------------------------------------------------- 1 | 7 | 14 | 20 | -------------------------------------------------------------------------------- /sample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /library/res/layout/week_side.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 18 | 22 | > 23 | 28 | -------------------------------------------------------------------------------- /library/res/layout/week_cell.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 14 | 24 | 37 | 38 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarHour.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.ViewGroup; 6 | 7 | /** 8 | * Created with IntelliJ IDEA. 9 | * User: freedom 10 | * Date: 2/26/14 11 | * Time: 4:44 PM 12 | * To change this template use File | Settings | File Templates. 13 | */ 14 | public class CalendarHour extends ViewGroup { 15 | 16 | public CalendarHour(Context context) { 17 | super(context); 18 | } 19 | 20 | public CalendarHour(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | } 23 | 24 | public CalendarHour(Context context, AttributeSet attrs, int defStyle) { 25 | super(context, attrs, defStyle); 26 | } 27 | 28 | @Override 29 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 30 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 31 | int totalWidth = MeasureSpec.getSize(widthMeasureSpec); 32 | int totalHeight = MeasureSpec.getSize(heightMeasureSpec); 33 | getChildAt(0).measure(totalWidth,totalHeight); 34 | setMeasuredDimension(totalWidth,totalHeight); 35 | } 36 | 37 | @Override 38 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 39 | //To change body of implemented methods use File | Settings | File Templates. 40 | getChildAt(0).layout(l,t,r,b); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/util/EventBuilder.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.util; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import cc.linktime.TimeLineCalendar.library.ui.CalendarTimeLineEvent; 6 | import cc.linktime.TimeLineCalender.library.R; 7 | 8 | /** 9 | * Created with IntelliJ IDEA. 10 | * User: freedom 11 | * Date: 3/3/14 12 | * Time: 11:20 PM 13 | * To change this template use File | Settings | File Templates. 14 | */ 15 | public class EventBuilder { 16 | private Context context; 17 | private LayoutInflater layoutInflater; 18 | private int start; 19 | private int end; 20 | private String info; 21 | public EventBuilder(Context context) { 22 | this.context = context; 23 | layoutInflater = LayoutInflater.from(context); 24 | } 25 | 26 | public EventBuilder setStart(int start){ 27 | this.start = start; 28 | return this; 29 | } 30 | 31 | public EventBuilder setEnd(int end) { 32 | this.end = end; 33 | return this; 34 | } 35 | 36 | public EventBuilder setDuring(int start,int end) { 37 | this.start = start; 38 | this.end = end; 39 | return this; 40 | } 41 | 42 | public EventBuilder setInfo(String info) { 43 | this.info = info; 44 | return this; 45 | } 46 | 47 | public CalendarTimeLineEvent builder(){ 48 | CalendarTimeLineEvent event = (CalendarTimeLineEvent)layoutInflater.inflate(R.layout.day_timeline_event,null); 49 | event.setDuring(start,end); 50 | event.setEventInfo(info); 51 | return event; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/util/CalendarWeekBuilder.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.util; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import cc.linktime.TimeLineCalendar.library.ui.CalendarTimeLineEvent; 6 | import cc.linktime.TimeLineCalendar.library.ui.CalendarWeek; 7 | import cc.linktime.TimeLineCalender.library.R; 8 | 9 | import java.util.ArrayList; 10 | 11 | /** 12 | * Created with IntelliJ IDEA. 13 | * User: freedom 14 | * Date: 3/3/14 15 | * Time: 11:42 PM 16 | * To change this template use File | Settings | File Templates. 17 | */ 18 | public class CalendarWeekBuilder { 19 | private Context context; 20 | private LayoutInflater layoutInflater; 21 | private ArrayList> eventList; 22 | public CalendarWeekBuilder(Context context) { 23 | this.context = context; 24 | layoutInflater = LayoutInflater.from(context); 25 | eventList = new ArrayList>(); 26 | for (int i=0;i<7;i++) { 27 | eventList.add(new ArrayList()); 28 | } 29 | } 30 | 31 | public CalendarWeekBuilder setEventList(ArrayList> eventList) { 32 | this.eventList = eventList; 33 | return this; 34 | } 35 | 36 | public ArrayList> getEventList() { 37 | return eventList; 38 | } 39 | 40 | public CalendarWeek builder() { 41 | CalendarWeek week = (CalendarWeek)layoutInflater.inflate(R.layout.week,null); 42 | week.setEventList(eventList); 43 | return week; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sample/src/cc/linktime/TimeLineCalendar/sample/sample.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.sample; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.LinearLayout; 6 | import cc.linktime.TimeLineCalendar.library.ui.CalendarTimeLineEvent; 7 | import cc.linktime.TimeLineCalendar.library.ui.CalendarWeek; 8 | import cc.linktime.TimeLineCalendar.library.util.CalendarWeekBuilder; 9 | import cc.linktime.TimeLineCalendar.library.util.EventBuilder; 10 | 11 | 12 | import java.util.ArrayList; 13 | 14 | public class sample extends Activity { 15 | /** 16 | * Called when the activity is first created. 17 | */ 18 | @Override 19 | public void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.main); 22 | LinearLayout root = (LinearLayout)findViewById(R.id.root); 23 | 24 | CalendarWeekBuilder weekBuilder = new CalendarWeekBuilder(this); //首先生成一个周视图builder 25 | CalendarWeek week = weekBuilder.builder(); //用builder生产一个周试图 26 | 27 | ArrayList> eventList = weekBuilder.getEventList(); // 获取事件列表 28 | 29 | EventBuilder eventBuilder = new EventBuilder(this); 30 | CalendarTimeLineEvent event = eventBuilder.setDuring(2, 5).setInfo("我没空").builder(); //使用事件builder生成事件 31 | 32 | (eventList.get(3)).add(event); //添加到对应某一天中,其中eventlist内部有7个ArrayList,对应7天 33 | 34 | (eventList.get(1)).add(event); 35 | (eventList.get(1)).add(eventBuilder.setDuring(6,7).builder()); 36 | 37 | 38 | week.setEventList(eventList); 39 | 40 | 41 | root.addView(week); //添加到布局中 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarWeekCell.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.ViewGroup; 7 | 8 | /** 9 | * Created with IntelliJ IDEA. 10 | * User: freedom 11 | * Date: 2/26/14 12 | * Time: 11:41 AM 13 | * To change this template use File | Settings | File Templates. 14 | */ 15 | public class CalendarWeekCell extends ViewGroup { 16 | 17 | 18 | private int totalWidth; 19 | private int totalHeight; 20 | private int weekday; 21 | 22 | public CalendarWeekCell(Context context) { 23 | super(context); 24 | } 25 | 26 | public CalendarWeekCell(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public CalendarWeekCell(Context context, AttributeSet attrs, int defStyle) { 31 | super(context, attrs, defStyle); 32 | } 33 | 34 | public void setWeekDay(int weekday) { 35 | this.weekday = weekday; 36 | } 37 | 38 | public int getWeekDay() { 39 | return weekday; 40 | } 41 | 42 | @Override 43 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 44 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 45 | totalWidth = MeasureSpec.getSize(widthMeasureSpec); 46 | totalHeight = MeasureSpec.getSize(heightMeasureSpec); 47 | 48 | getChildAt(0).measure(totalWidth,totalHeight/3); 49 | getChildAt(1).measure(totalWidth,totalHeight*2/3); 50 | getChildAt(2).measure(24,24); 51 | setMeasuredDimension(totalWidth,totalHeight); 52 | 53 | 54 | } 55 | 56 | @Override 57 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 58 | //To change body of implemented methods use File | Settings | File Templates. 59 | getChildAt(0).layout(0,0,totalWidth,totalHeight/3); 60 | getChildAt(1).layout(0,totalHeight/3,totalWidth,totalHeight); 61 | Log.i("Cell", "onLayout --- " + String.valueOf(getRight())); 62 | getChildAt(2).layout(getRight()-49,(getBottom()-getTop())/2-12,getRight()-25,(getBottom()-getTop())/2+12); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarTimeLineEvent.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.ViewGroup; 6 | import android.widget.TextView; 7 | import cc.linktime.TimeLineCalender.library.R; 8 | 9 | /** 10 | * Created with IntelliJ IDEA. 11 | * User: freedom 12 | * Date: 2/26/14 13 | * Time: 3:20 PM 14 | * To change this template use File | Settings | File Templates. 15 | */ 16 | public class CalendarTimeLineEvent extends ViewGroup { 17 | 18 | private int totalWidth; 19 | private int totalHeight; 20 | private int start; 21 | private int end; 22 | 23 | public CalendarTimeLineEvent(Context context) { 24 | super(context); 25 | } 26 | 27 | public CalendarTimeLineEvent(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public CalendarTimeLineEvent(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | } 34 | 35 | @Override 36 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 37 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 38 | totalHeight = MeasureSpec.getSize(heightMeasureSpec); 39 | totalWidth = MeasureSpec.getSize(widthMeasureSpec); 40 | 41 | findViewById(R.id.event_during).measure(totalWidth,20); 42 | findViewById(R.id.event_info).measure(totalWidth,totalHeight-20); 43 | 44 | setMeasuredDimension(totalWidth,totalHeight); 45 | 46 | } 47 | 48 | @Override 49 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 50 | //To change body of implemented methods use File | Settings | File Templates. 51 | findViewById(R.id.event_during).layout(0,0,totalWidth,20); 52 | findViewById(R.id.event_info).layout(0,20,totalWidth,totalHeight); 53 | } 54 | 55 | public void setDuring(int start,int end){ 56 | this.start = start; 57 | this.end = end; 58 | TextView textView = (TextView)findViewById(R.id.event_during); 59 | textView.setText(String.valueOf(start) + ":00-" + String.valueOf(end) + ":00"); 60 | } 61 | 62 | public int getStart() { 63 | return start; 64 | } 65 | 66 | public int getEnd() { 67 | return end; 68 | } 69 | 70 | public int getDuring() { 71 | return end - start; 72 | } 73 | 74 | public void setEventInfo(String info) { 75 | TextView textView = (TextView)findViewById(R.id.event_info); 76 | textView.setText(info); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarWeekSideCursor.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.graphics.*; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import cc.linktime.TimeLineCalender.library.R; 9 | 10 | /** 11 | * Created with IntelliJ IDEA. 12 | * User: freedom 13 | * Date: 2/26/14 14 | * Time: 6:56 PM 15 | * To change this template use File | Settings | File Templates. 16 | */ 17 | public class CalendarWeekSideCursor extends View implements ValueAnimator.AnimatorUpdateListener { 18 | private int weekday=0; 19 | private int lastWeekday = 0; 20 | private int colorIndex=0; 21 | private int cursorHeight; 22 | 23 | private final int [] colors = {getResources().getColor(R.color.sun_bg), 24 | getResources().getColor(R.color.mon_bg), 25 | getResources().getColor(R.color.tue_bg), 26 | getResources().getColor(R.color.wed_bg), 27 | getResources().getColor(R.color.thu_bg), 28 | getResources().getColor(R.color.fri_bg), 29 | getResources().getColor(R.color.sat_bg),}; 30 | 31 | public CalendarWeekSideCursor(Context context) { 32 | super(context); 33 | } 34 | 35 | public CalendarWeekSideCursor(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | } 38 | 39 | public CalendarWeekSideCursor(Context context, AttributeSet attrs, int defStyle) { 40 | super(context, attrs, defStyle); 41 | } 42 | 43 | @Override 44 | protected void onDraw(Canvas canvas) { 45 | super.onDraw(canvas); //To change body of overridden methods use File | Settings | File Templates. 46 | int cursorHeight = getBottom() - getTop(); 47 | int cursorWidth = getRight() - getLeft(); 48 | Paint paint = new Paint(); 49 | paint.setColor(colors[colorIndex]); 50 | // LinearGradient lg = new LinearGradient(cursorHeight*3/4,cursorHeight/2,cursorHeight,cursorHeight/2,Color.rgb(204,204,204),Color.rgb(153,255,153), Shader.TileMode.MIRROR); 51 | // paint.setShader(lg); 52 | paint.setStyle(Paint.Style.FILL); 53 | Path path = new Path(); 54 | 55 | 56 | 57 | path.moveTo(cursorWidth,cursorHeight/4); 58 | path.lineTo(0, cursorHeight / 2); 59 | path.lineTo(cursorWidth, cursorHeight*3/4); 60 | path.close(); 61 | canvas.drawPath(path,paint); 62 | //canvas.drawLine(0,0,50,50,paint); 63 | } 64 | 65 | public void setCursorColor(int weekday){ 66 | this.lastWeekday = this.weekday; 67 | this.weekday = weekday; 68 | } 69 | 70 | public void setCursorHeight(int cursorHeight) { 71 | this.cursorHeight = cursorHeight; 72 | } 73 | 74 | public int getCursorHeight() { 75 | return cursorHeight; 76 | } 77 | 78 | @Override 79 | public void onAnimationUpdate(ValueAnimator animation) { 80 | //To change body of implemented methods use File | Settings | File Templates. 81 | //FIXME 82 | colorIndex = lastWeekday + (int)((float)(animation.getDuration()-animation.getStartDelay())/animation.getDuration()*(weekday-lastWeekday)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarTimeLineEventList.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.content.Context; 4 | import android.graphics.*; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import cc.linktime.TimeLineCalender.library.R; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created with IntelliJ IDEA. 14 | * User: freedom 15 | * Date: 2/26/14 16 | * Time: 1:49 PM 17 | * To change this template use File | Settings | File Templates. 18 | */ 19 | public class CalendarTimeLineEventList extends ViewGroup implements CalendarWeekSide.EventListListener { 20 | 21 | private int totalWidth; 22 | private int totalHeight; 23 | private int weekday; 24 | 25 | private ArrayList> evenList; 26 | private int hour_height = getResources().getDimensionPixelSize(R.dimen.hour_height); 27 | 28 | 29 | public CalendarTimeLineEventList(Context context) { 30 | super(context); 31 | } 32 | 33 | public CalendarTimeLineEventList(Context context, AttributeSet attrs) { 34 | super(context, attrs); 35 | } 36 | 37 | public CalendarTimeLineEventList(Context context, AttributeSet attrs, int defStyle) { 38 | super(context, attrs, defStyle); 39 | } 40 | 41 | @Override 42 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { 43 | boolean ret = super.drawChild(canvas, child, drawingTime); //To change body of overridden methods use File | Settings | File Templates. 44 | int borderWidth = 5; 45 | Paint d = new Paint(); 46 | LinearGradient lg = new LinearGradient(0,child.getBottom()-5,0,child.getBottom(),Color.rgb(204,204,204),Color.rgb(255,255,255), Shader.TileMode.MIRROR); 47 | d.setShader(lg); 48 | d.setStyle(Paint.Style.FILL_AND_STROKE); 49 | canvas.drawRect(child.getLeft(),child.getBottom()-borderWidth,child.getRight(),child.getBottom(),d); 50 | return ret; 51 | } 52 | 53 | @Override 54 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 55 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 56 | totalHeight = MeasureSpec.getSize(heightMeasureSpec); 57 | totalWidth = MeasureSpec.getSize(widthMeasureSpec); 58 | for (int i=0;i> evenList){ 78 | this.evenList = evenList; 79 | updateEventList(weekday); 80 | } 81 | 82 | public ArrayList> getEvenList() { 83 | return evenList; 84 | } 85 | 86 | @Override 87 | public int updateEventList(int weekday){ 88 | this.weekday = weekday; 89 | removeAllViews(); 90 | for (CalendarTimeLineEvent event : evenList.get(weekday)) { 91 | addView(event); 92 | } 93 | return evenList.get(weekday).size(); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarWeek.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import cc.linktime.TimeLineCalender.library.R; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created with IntelliJ IDEA. 14 | * User: freedom 15 | * Date: 2/26/14 16 | * Time: 11:51 AM 17 | * To change this template use File | Settings | File Templates. 18 | */ 19 | public class CalendarWeek extends ViewGroup { 20 | private int totalWidth; 21 | private int totalHeight; 22 | private int bodyWidth; 23 | private int sideWidth; 24 | private int bodyHeight; 25 | private int hour_height = getResources().getDimensionPixelSize(R.dimen.hour_height); 26 | 27 | private View weekbody; 28 | private View weekside; 29 | 30 | public CalendarWeek(Context context) { 31 | super(context); 32 | } 33 | 34 | public CalendarWeek(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | // LayoutInflater layoutInflater = ((Activity)context).getLayoutInflater(); 37 | // weekbody = layoutInflater.inflate(R.layout.week_body,null); 38 | // weekside = layoutInflater.inflate(R.layout.week_side,null); 39 | // this.addView(weekbody); 40 | // this.addView(weekside); 41 | } 42 | 43 | public CalendarWeek(Context context, AttributeSet attrs, int defStyle) { 44 | super(context, attrs, defStyle); 45 | } 46 | 47 | @Override 48 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 49 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 50 | totalWidth = MeasureSpec.getSize(widthMeasureSpec); 51 | totalHeight = MeasureSpec.getSize(heightMeasureSpec); 52 | 53 | Log.i("Week", "Week --- onMeasure " + totalHeight + " " + totalWidth); 54 | 55 | sideWidth = totalWidth / 5 + totalHeight/36; 56 | bodyWidth = totalWidth /5 * 4; 57 | 58 | bodyHeight = hour_height*25 + getResources().getDimensionPixelSize(R.dimen.timeline_padding)*2; 59 | 60 | CalendarWeekSide weekside = (CalendarWeekSide)findViewById(R.id.weekside); 61 | CalendarWeekBody weekBody = (CalendarWeekBody)findViewById(R.id.weekbody); 62 | 63 | Log.i("Week", "Week --- onMeasure sideWidth " + sideWidth); 64 | weekside.measure(sideWidth, totalHeight); 65 | weekBody.measure(bodyWidth, bodyHeight); 66 | weekBody.setScreenHeight(totalHeight); 67 | weekside.setEventListListener((CalendarTimeLineEventList)weekBody.findViewById(R.id.timeline_eventlist)); 68 | 69 | setMeasuredDimension(totalWidth, bodyHeight); 70 | 71 | } 72 | 73 | @Override 74 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 75 | //To change body of implemented methods use File | Settings | File Templates. 76 | findViewById(R.id.weekbody).layout(0,0,bodyWidth,bodyHeight); 77 | findViewById(R.id.weekside).layout(bodyWidth-totalHeight/36,0,totalWidth,bodyHeight); 78 | } 79 | 80 | public ArrayList> getEventList() { 81 | return ((CalendarTimeLineEventList)findViewById(R.id.weekbody).findViewById(R.id.timeline_eventlist)).getEvenList(); 82 | } 83 | 84 | public void setEventList(ArrayList> eventList){ 85 | /** 86 | * 事件列表向量数组必须等于7,对应一周七天 87 | */ 88 | ((CalendarTimeLineEventList)findViewById(R.id.weekbody).findViewById(R.id.timeline_eventlist)).setEvenList(eventList); 89 | int [] counts = new int[7]; 90 | for (int i=0;i<7;i++) { 91 | counts[i] = eventList.get(i).size(); 92 | } 93 | ((CalendarWeekSide)findViewById(R.id.weekside)).initEventCount(counts); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /sample/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarDayTimeLine.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.content.Context; 4 | import android.graphics.*; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | import cc.linktime.TimeLineCalender.library.R; 11 | 12 | /** 13 | * Created with IntelliJ IDEA. 14 | * User: freedom 15 | * Date: 2/26/14 16 | * Time: 1:35 PM 17 | * To change this template use File | Settings | File Templates. 18 | */ 19 | public class CalendarDayTimeLine extends ViewGroup { 20 | 21 | private int totalWidth; 22 | private int totalHeight; 23 | private int halfWidth; 24 | private int middle; 25 | private final int HOUR_HEIGHT = (int)getResources().getDimensionPixelSize(R.dimen.hour_height); 26 | 27 | public CalendarDayTimeLine(Context context) { 28 | super(context); 29 | } 30 | 31 | public CalendarDayTimeLine(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | } 34 | 35 | public CalendarDayTimeLine(Context context, AttributeSet attrs, int defStyle) { 36 | super(context, attrs, defStyle); 37 | } 38 | 39 | @Override 40 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { 41 | boolean ret = super.drawChild(canvas, child, drawingTime); //To change body of overridden methods use File | Settings | File Templates. 42 | Paint point = new Paint(); 43 | // point.setColor(Color.rgb(204,102,51)); 44 | point.setColor(Color.rgb(0,153,255)); 45 | int middle = (child.getLeft() + child.getRight())/2; 46 | int center = (child.getTop()+child.getBottom())/2; 47 | // canvas.drawCircle((child.getLeft()+child.getRight())/2,(child.getTop()+child.getBottom())/2,5,point); 48 | canvas.drawRect(middle-4,center-2,middle+4,center+2,point); 49 | return ret; 50 | } 51 | 52 | @Override 53 | protected void dispatchDraw(Canvas canvas) { 54 | Paint paint = new Paint(); 55 | 56 | halfWidth = 6/2; 57 | Log.i("TimeLine", "TimeLine --- dispatchDraw middle " + middle); 58 | int padding = getResources().getDimensionPixelSize(R.dimen.timeline_padding); 59 | int [] colors = {Color.rgb(240,240,240),Color.rgb(0,153,255),Color.rgb(240,240,240)}; 60 | LinearGradient lg = new LinearGradient(middle-halfWidth,(getTop()+getBottom())/2,middle+halfWidth,(getTop()+getBottom())/2,colors,null, Shader.TileMode.MIRROR); 61 | paint.setShader(lg); 62 | paint.setStyle(Paint.Style.FILL_AND_STROKE); 63 | canvas.drawRect( middle - halfWidth, getTop() + padding, middle + halfWidth,getBottom() - padding,paint); 64 | 65 | paint.setShader(null); 66 | paint.setColor(Color.rgb(0,153,255)); 67 | canvas.drawCircle(middle,getTop() + padding,15,paint); 68 | canvas.drawCircle(middle,totalHeight - padding,15,paint); 69 | super.dispatchDraw(canvas); //To change body of overridden methods use File | Settings | File Templates. 70 | } 71 | 72 | @Override 73 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 74 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 75 | 76 | totalWidth = MeasureSpec.getSize(widthMeasureSpec); 77 | totalHeight = MeasureSpec.getSize(heightMeasureSpec); 78 | middle = totalWidth/2; 79 | 80 | int textMarginTop = HOUR_HEIGHT - 24; 81 | textMarginTop = textMarginTop / 2; 82 | 83 | 84 | Log.i("TimeLine", "TimeLine --- onMeasure textHeight " + ((TextView)getChildAt(0)).getLineHeight()); 85 | 86 | for (int i=0;itotalHeight-getScreenHeight() + hour_height) { 98 | scrollTo(0,totalHeight-getScreenHeight() + hour_height); 99 | } else { 100 | scrollTo(0,temp); 101 | } 102 | break; 103 | case MotionEvent.ACTION_UP: 104 | lastY += startY - ev.getY(); 105 | break; 106 | default: 107 | break; 108 | } 109 | return true; 110 | } 111 | 112 | public void setScreenHeight(int screenHeight) { 113 | this.screenHeight = screenHeight; 114 | } 115 | 116 | public int getScreenHeight() { 117 | return screenHeight; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /library/res/layout/day_timeline.xml: -------------------------------------------------------------------------------- 1 | 7 | 13 | 19 | 25 | 31 | 37 | 43 | 49 | 55 | 61 | 67 | 73 | 79 | 85 | 91 | 97 | 103 | 109 | 115 | 121 | 127 | 133 | 139 | 145 | 151 | 152 | -------------------------------------------------------------------------------- /library/src/cc/linktime/TimeLineCalendar/library/ui/CalendarWeekSide.java: -------------------------------------------------------------------------------- 1 | package cc.linktime.TimeLineCalendar.library.ui; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.graphics.*; 6 | import android.util.AttributeSet; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.view.animation.TranslateAnimation; 11 | import android.widget.TextView; 12 | import cc.linktime.TimeLineCalender.library.R; 13 | 14 | /** 15 | * Created with IntelliJ IDEA. 16 | * User: freedom 17 | * Date: 2/26/14 18 | * Time: 11:41 AM 19 | * To change this template use File | Settings | File Templates. 20 | */ 21 | public class CalendarWeekSide extends ViewGroup { 22 | 23 | public interface EventListListener{ 24 | public int updateEventList(int weekday); 25 | } 26 | 27 | private int totalWidth; 28 | private int totalHeight; 29 | private int cellHeight; 30 | private int cellWidth; 31 | private int cursorHeight; 32 | private EventListListener eventListListener; 33 | private int weekday=0; 34 | 35 | private final String [] WEEKDAY = {"Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat."}; 36 | private final int [] colors = {getResources().getColor(R.color.sun_bg), 37 | getResources().getColor(R.color.mon_bg), 38 | getResources().getColor(R.color.tue_bg), 39 | getResources().getColor(R.color.wed_bg), 40 | getResources().getColor(R.color.thu_bg), 41 | getResources().getColor(R.color.fri_bg), 42 | getResources().getColor(R.color.sat_bg)}; 43 | 44 | public CalendarWeekSide(Context context) { 45 | super(context); 46 | } 47 | 48 | public CalendarWeekSide(Context context, AttributeSet attrs) { 49 | super(context, attrs); 50 | } 51 | 52 | public CalendarWeekSide(Context context, AttributeSet attrs, int defStyle) { 53 | super(context, attrs, defStyle); 54 | } 55 | 56 | @Override 57 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { 58 | boolean ret = super.drawChild(canvas, child, drawingTime); //To change body of overridden methods use File | Settings | File Templates. 59 | // Paint whitePaint = new Paint(); 60 | // whitePaint.setColor(Color.WHITE); 61 | // Paint blackPaint = new Paint(); 62 | // blackPaint.setColor(Color.BLACK); 63 | // canvas.drawRect(child.getLeft()+5,child.getBottom()-2,child.getRight()-5,child.getBottom()+2,whitePaint); 64 | // canvas.drawCircle(child.getRight()-15,(child.getBottom()+child.getTop())/2,10,whitePaint); 65 | // canvas.drawText("1",child.getRight()-15,(child.getBottom()+child.getTop())/2,blackPaint); 66 | 67 | return ret; 68 | } 69 | 70 | @Override 71 | protected void dispatchDraw(Canvas canvas) { 72 | Paint d = new Paint(); 73 | int borderWidth = 5; 74 | LinearGradient lg = new LinearGradient(0,totalHeight/2,borderWidth,totalHeight/2,Color.rgb(204,204,204),Color.rgb(255,255,255), Shader.TileMode.MIRROR); 75 | d.setShader(lg); 76 | d.setStyle(Paint.Style.FILL_AND_STROKE); 77 | canvas.drawRect(cursorHeight/4,getTop(),cursorHeight/4+borderWidth,getBottom(),d); 78 | super.dispatchDraw(canvas); //To change body of overridden methods use File | Settings | File Templates. 79 | 80 | } 81 | 82 | @Override 83 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 84 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); //To change body of overridden methods use File | Settings | File Templates. 85 | totalWidth = MeasureSpec.getSize(widthMeasureSpec); 86 | totalHeight = MeasureSpec.getSize(heightMeasureSpec); 87 | cellHeight = totalHeight/9; 88 | cellWidth = totalWidth-cursorHeight/4; 89 | 90 | CalendarWeekSideCursor cursor = (CalendarWeekSideCursor)findViewById(R.id.cursor); 91 | cursor.setCursorHeight(cellHeight); 92 | cursorHeight = cellHeight; 93 | 94 | refresh(); 95 | 96 | for (int i=0;i