├── Calendar Widget
├── .classpath
├── .project
├── AndroidManifest.xml
├── bin
│ ├── Calendar Widget.apk
│ ├── classes.dex
│ ├── in
│ │ └── dharmin
│ │ │ └── calendar
│ │ │ ├── DBHelper$toDoDBOpenHelper.class
│ │ │ ├── DBHelper.class
│ │ │ ├── Main.class
│ │ │ ├── MonthView$1.class
│ │ │ ├── MonthView$2.class
│ │ │ ├── MonthView.class
│ │ │ ├── R$attr.class
│ │ │ ├── R$drawable.class
│ │ │ ├── R$id.class
│ │ │ ├── R$layout.class
│ │ │ ├── R$string.class
│ │ │ └── R.class
│ └── resources.ap_
├── default.properties
├── gen
│ └── in
│ │ └── dharmin
│ │ └── calendar
│ │ └── R.java
├── proguard.cfg
├── res
│ ├── drawable-hdpi
│ │ ├── calheader.xml
│ │ ├── current_day.xml
│ │ ├── dayinmonth.xml
│ │ ├── event.png
│ │ ├── icon.png
│ │ ├── left_arrow.png
│ │ ├── rectgrad.xml
│ │ ├── right_arrow.png
│ │ └── selectedgrad.xml
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── layout
│ │ ├── main.xml
│ │ └── monthtop.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── in
│ └── dharmin
│ └── calendar
│ ├── DBHelper.java
│ ├── Main.java
│ └── MonthView.java
└── README.txt
/Calendar Widget/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Calendar Widget/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Calendar Widget
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Calendar Widget/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Calendar Widget/bin/Calendar Widget.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/Calendar Widget.apk
--------------------------------------------------------------------------------
/Calendar Widget/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/classes.dex
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/DBHelper$toDoDBOpenHelper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/DBHelper$toDoDBOpenHelper.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/DBHelper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/DBHelper.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/Main.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/MonthView$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/MonthView$1.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/MonthView$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/MonthView$2.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/MonthView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/MonthView.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/R$attr.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/R$drawable.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/R$id.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/R$layout.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/R$string.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/in/dharmin/calendar/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/in/dharmin/calendar/R.class
--------------------------------------------------------------------------------
/Calendar Widget/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/bin/resources.ap_
--------------------------------------------------------------------------------
/Calendar Widget/default.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 use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-4
12 |
--------------------------------------------------------------------------------
/Calendar Widget/gen/in/dharmin/calendar/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package in.dharmin.calendar;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int calheader=0x7f020000;
15 | public static final int current_day=0x7f020001;
16 | public static final int dayinmonth=0x7f020002;
17 | public static final int event=0x7f020003;
18 | public static final int icon=0x7f020004;
19 | public static final int left_arrow=0x7f020005;
20 | public static final int rectgrad=0x7f020006;
21 | public static final int right_arrow=0x7f020007;
22 | public static final int selectedgrad=0x7f020008;
23 | }
24 | public static final class id {
25 | public static final int imgLeft=0x7f050000;
26 | public static final int imgRight=0x7f050003;
27 | public static final int txtDay=0x7f050001;
28 | public static final int txtYear=0x7f050002;
29 | }
30 | public static final class layout {
31 | public static final int main=0x7f030000;
32 | public static final int monthtop=0x7f030001;
33 | }
34 | public static final class string {
35 | public static final int app_name=0x7f040013;
36 | public static final int april=0x7f04000a;
37 | public static final int august=0x7f04000e;
38 | public static final int december=0x7f040012;
39 | public static final int february=0x7f040008;
40 | public static final int friday=0x7f040005;
41 | public static final int january=0x7f040007;
42 | public static final int july=0x7f04000d;
43 | public static final int june=0x7f04000c;
44 | public static final int march=0x7f040009;
45 | public static final int may=0x7f04000b;
46 | public static final int monday=0x7f040001;
47 | public static final int november=0x7f040011;
48 | public static final int october=0x7f040010;
49 | public static final int saturday=0x7f040006;
50 | public static final int september=0x7f04000f;
51 | public static final int sunday=0x7f040000;
52 | public static final int thursday=0x7f040004;
53 | public static final int tuesday=0x7f040002;
54 | public static final int wednesday=0x7f040003;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Calendar Widget/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembernames class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembernames class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers enum * {
30 | public static **[] values();
31 | public static ** valueOf(java.lang.String);
32 | }
33 |
34 | -keep class * implements android.os.Parcelable {
35 | public static final android.os.Parcelable$Creator *;
36 | }
37 |
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/calheader.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/current_day.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
10 |
11 |
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/dayinmonth.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/event.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/res/drawable-hdpi/event.png
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/left_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/res/drawable-hdpi/left_arrow.png
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/rectgrad.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/right_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/res/drawable-hdpi/right_arrow.png
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-hdpi/selectedgrad.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/Calendar Widget/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dharmin007/Android-Calendar-Widget/acf8ea676ba221e02056917317e362f5c404daee/Calendar Widget/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/Calendar Widget/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/Calendar Widget/res/layout/monthtop.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
19 |
27 |
35 |
36 |
43 |
--------------------------------------------------------------------------------
/Calendar Widget/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Sunday
4 | Monday
5 | Tuesday
6 | Wednesday
7 | Thursday
8 | Friday
9 | Saturday
10 | January
11 | February
12 | March
13 | April
14 | May
15 | June
16 | July
17 | August
18 | September
19 | October
20 | November
21 | December
22 | Calendar Widget
23 |
24 |
--------------------------------------------------------------------------------
/Calendar Widget/src/in/dharmin/calendar/DBHelper.java:
--------------------------------------------------------------------------------
1 |
2 | package in.dharmin.calendar;
3 |
4 | import android.content.ContentValues;
5 | import android.content.Context;
6 | import android.content.SharedPreferences;
7 | import android.database.Cursor;
8 | import android.database.sqlite.SQLiteDatabase;
9 | import android.database.sqlite.SQLiteException;
10 | import android.database.sqlite.SQLiteOpenHelper;
11 | import android.database.sqlite.SQLiteDatabase.CursorFactory;
12 | import android.preference.PreferenceManager;
13 |
14 | public class DBHelper {
15 | private static final String DATABASE_NAME = "mycal.db";
16 | private static final String TABLE_NAME = "mainTable";
17 | private static final String KEY_ID = "_id";
18 | private toDoDBOpenHelper dbHelper;
19 | private SQLiteDatabase db;
20 | private final Context context;
21 |
22 | public DBHelper(Context _context)
23 | {
24 | context = _context;
25 | dbHelper = new toDoDBOpenHelper(context,DATABASE_NAME,null,1);
26 | }
27 | public void open() throws SQLiteException{
28 |
29 | try
30 | {
31 | db = dbHelper.getWritableDatabase();
32 | }catch(SQLiteException e)
33 | {
34 | e.printStackTrace();
35 | db = dbHelper.getReadableDatabase();
36 | }
37 | }
38 | public void dropDatabase(){
39 | context.deleteDatabase(DATABASE_NAME);
40 | }
41 | public Cursor queryDatabase()
42 | {
43 | String[] result_columns = new String[]{KEY_ID,"_dtstart","_dtend","_dtmodified","_attendee",
44 | "_uid","_dtcreated","_dtstamp","_desc","_location","_status","_schoolid","_summary","_allday"};
45 | Cursor allRows = db.query(true,TABLE_NAME, result_columns, null, null, null,
46 | null,null,null);
47 |
48 | return allRows;
49 | }
50 | public Cursor queryRow(String where)
51 | {
52 | String id="";
53 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
54 | if(prefs.getBoolean("cal1", false))
55 | id = "'"+prefs.getString("cal1ID", "")+"'";
56 | if(prefs.getBoolean("cal2", false))
57 | id += ",'"+prefs.getString("cal2ID", "")+"'";
58 | if(prefs.getBoolean("cal3", false))
59 | id += ",'"+prefs.getString("cal3ID", "")+"'";
60 |
61 | if(id.startsWith(","))
62 | id=id.substring(1);
63 |
64 | if(id.length()<1)
65 | id="''";
66 |
67 | where += " AND _schoolid IN ("+id+")";
68 |
69 | String[] result_columns = new String[]{KEY_ID,"_dtstart","_dtend","_dtmodified","_attendee",
70 | "_uid","_dtcreated","_dtstamp","_desc","_location","_status","_summary","_schoolid","_allday"};
71 | Cursor allRows = db.query(true,TABLE_NAME, result_columns, where, null,
72 | null, null,"_dtstart",null);
73 | return allRows;
74 | }
75 |
76 | public long insert(ContentValues contentValues)
77 | {
78 | return db.insert(TABLE_NAME, null, contentValues);
79 | }
80 | public boolean update(ContentValues contentValues,String where)
81 | {
82 | return db.update(TABLE_NAME, contentValues, where, null)>0;
83 | }
84 |
85 | public boolean remove(String where)
86 | {
87 | where = KEY_ID+"="+where;
88 | return db.delete(TABLE_NAME, where, null)>0;
89 | }
90 | public boolean removeSchool(String where)
91 | {
92 | where = "_schoolid='"+where+"'";
93 | return db.delete(TABLE_NAME, where, null)>0;
94 | }
95 | public void close()
96 | {
97 | db.close();
98 | }
99 | private static class toDoDBOpenHelper extends SQLiteOpenHelper{
100 |
101 | private static final String DATABASE_CREATE = "create table if not exists "+TABLE_NAME+" " +
102 | "("+KEY_ID+" integer primary key autoincrement, _dtstart integer not null, _dtend integer not null," +
103 | "_dtmodified integer, _uid text,_dtcreated integer,_dtstamp integer," +
104 | "_desc text,_location text,_status text,_schoolid text,_attendee text,_summary text,_allday boolean DEFAULT 0);";
105 |
106 | public toDoDBOpenHelper(Context context, String name,
107 | CursorFactory factory, int version) {
108 | super(context, name, factory, version);
109 | // TODO Auto-generated constructor stub
110 | }
111 |
112 | @Override
113 | public void onCreate(SQLiteDatabase db) {
114 | // TODO Auto-generated method stub
115 | db.execSQL(DATABASE_CREATE);
116 | }
117 |
118 | @Override
119 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
120 | // TODO Auto-generated method stub
121 | db.execSQL("DROP TABLE IF EXISTS "+DATABASE_NAME);
122 | onCreate(db);
123 | }
124 |
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/Calendar Widget/src/in/dharmin/calendar/Main.java:
--------------------------------------------------------------------------------
1 | package in.dharmin.calendar;
2 |
3 | import java.util.Calendar;
4 |
5 | import android.app.Activity;
6 | import android.os.Bundle;
7 |
8 | public class Main extends Activity {
9 | @Override
10 | public void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 |
13 | // One way to use the calendar widget is putting it in the xml file is shown in main.xml
14 | // setContentView(R.layout.main);
15 |
16 | /*
17 | Other way is to add is using the java code as follows.
18 | */
19 | MonthView mv = new MonthView(this);
20 | setContentView(mv);
21 | // Calendar cal = Calendar.getInstance();
22 | // cal.set(2012, Calendar.DECEMBER,12);
23 | // mv.GoToDate(cal.getTime());
24 | }
25 | }
--------------------------------------------------------------------------------
/Calendar Widget/src/in/dharmin/calendar/MonthView.java:
--------------------------------------------------------------------------------
1 | package in.dharmin.calendar;
2 |
3 | import java.util.Calendar;
4 | import java.util.Date;
5 |
6 | import android.content.Context;
7 | import android.content.res.Resources;
8 | import android.database.Cursor;
9 | import android.graphics.Color;
10 | import android.text.Html;
11 | import android.util.AttributeSet;
12 | import android.util.TypedValue;
13 | import android.view.Gravity;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.animation.TranslateAnimation;
17 | import android.widget.ImageView;
18 | import android.widget.RelativeLayout;
19 | import android.widget.TableLayout;
20 | import android.widget.TableRow;
21 | import android.widget.TextView;
22 |
23 | public class MonthView extends TableLayout{
24 |
25 |
26 | int day=0,month=0,year=0;
27 | public int firstDay=Calendar.SUNDAY;
28 | private TextView btn;
29 | private TranslateAnimation animSet1,animSet2;
30 | private Context context;
31 | private TableRow tr;
32 | private Boolean[] isEvent = new Boolean[32];
33 | private int[] resDaysSun = {R.string.sunday,R.string.monday,R.string.tuesday,R.string.wednesday,
34 | R.string.thursday,R.string.friday,R.string.saturday};
35 | private int[] resDaysMon = {R.string.monday,R.string.tuesday,R.string.wednesday,
36 | R.string.thursday,R.string.friday,R.string.saturday,R.string.sunday};
37 | private String[] days;
38 |
39 | private int[] monthIds = {R.string.january,R.string.february,R.string.march,R.string.april,R.string.may,R.string.june,
40 | R.string.july,R.string.august,R.string.september,R.string.october,R.string.november,R.string.december};
41 |
42 | private String[] months = new String[12];
43 |
44 | Calendar cal,prevCal,today; //today will be used for setting a box around today's date
45 | //prevCal will be used to display last few dates of previous month in the calendar
46 | public MonthView(Context context, AttributeSet attrs) {
47 | super(context, attrs);
48 | init(context);
49 | }
50 | public MonthView(Context context){
51 | super(context);
52 | init(context);
53 | }
54 |
55 | private void init(Context contxt)
56 | {
57 | context = contxt; //initializing the context variable
58 | Resources res = getResources();
59 | for(int i=0;i<12;i++)
60 | months[i] = res.getString(monthIds[i]);
61 |
62 | days = new String[7];
63 | setStretchAllColumns(true); //stretch all columns so that calendar's width fits the screen
64 | today = Calendar.getInstance();//get current date and time's instance
65 | today.clear(Calendar.HOUR);//remove the hour,minute,second and millisecond from the today variable
66 | today.clear(Calendar.MINUTE);
67 | today.clear(Calendar.SECOND);
68 | today.clear(Calendar.MILLISECOND);
69 | if(firstDay==Calendar.MONDAY)
70 | today.setFirstDayOfWeek(Calendar.MONDAY);
71 | cal = (Calendar) today.clone();//create exact copy as today for dates display purpose.
72 |
73 |
74 | DisplayMonth(true);//uses cal and prevCal to display the month
75 | }
76 | public void GoToDate(Date date)
77 | {
78 | cal.setTime(date);
79 | DisplayMonth(true);
80 | }
81 | private boolean animFlag=false;
82 | //Change month listener called when the user clicks to show next or prev month.
83 | private OnClickListener ChangeMonthListener = new OnClickListener(){
84 |
85 | @Override
86 | public void onClick(View v) {
87 | ImageView tv = (ImageView)v;
88 | //If previous month is to be displayed subtract one from current month.
89 | if(tv.getTag().equals("<"))
90 | {
91 | cal.add(Calendar.MONTH, -1);
92 | animFlag = false;
93 | }
94 | //If next month is to be displayed add one to the current month
95 | else
96 | {
97 | cal.add(Calendar.MONTH, 1);
98 | animFlag = true;
99 | }
100 | selected_day = 0;
101 | DisplayMonth(true);
102 | }};
103 | //Main function for displaying the current selected month
104 | private void checkForEvents()
105 | {
106 | DBHelper db = new DBHelper(context);
107 |
108 | for(int i=0;i<32;i++)
109 | isEvent[i]=false;
110 |
111 | Calendar tempcal = (Calendar) cal.clone();
112 | tempcal.set(Calendar.DATE, 1);
113 | tempcal.clear(Calendar.HOUR);
114 | tempcal.clear(Calendar.MINUTE);
115 | tempcal.clear(Calendar.SECOND);
116 | Calendar tempcal1 = (Calendar)tempcal.clone();
117 | tempcal1.set(Calendar.DATE, tempcal.getActualMaximum(Calendar.DATE));
118 | db.open();
119 | Cursor c = db.queryRow("_dtstart >= "+tempcal.getTimeInMillis()+" AND _dtstart <= "+tempcal1.getTimeInMillis());
120 | if(c.moveToFirst())
121 | do{
122 | try {
123 | isEvent[new Date(c.getLong(c.getColumnIndexOrThrow("_dtstart"))).getDate()]=true;
124 | } catch (Exception e) {
125 | e.printStackTrace();
126 | }
127 | }while(c.moveToNext());
128 | c.close();
129 | db.close();
130 | }
131 | int selected_day=0;
132 | void DisplayMonth(boolean animationEnabled)
133 | {
134 | checkForEvents();
135 | if(animationEnabled)
136 | {
137 | animSet1 = new TranslateAnimation(0,getWidth(),1,1);
138 | animSet1.setDuration(300);
139 |
140 | animSet2 = new TranslateAnimation(0,-getWidth(),1,1);
141 | animSet2.setDuration(300);
142 | }
143 | Resources r = getResources();
144 | String tempDay;
145 | for(int i=0;i<7;i++)
146 | {
147 | if(firstDay == Calendar.MONDAY)
148 | tempDay = r.getString(resDaysMon[i]);
149 | else
150 | tempDay = r.getString(resDaysSun[i]);
151 | days[i] = tempDay.substring(0,3);
152 | }
153 |
154 | removeAllViews();//Clears the calendar so that a new month can be displayed, removes all child elements (days,week numbers, day labels)
155 |
156 | int firstDayOfWeek,prevMonthDay,nextMonthDay,week;
157 | cal.set(Calendar.DAY_OF_MONTH, 1); //Set date = 1st of current month so that we can know in next step which day is the first day of the week.
158 | firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1; //get which day is on the first date of the month
159 | if(firstDay==Calendar.MONDAY)
160 | {
161 | firstDayOfWeek--;
162 | if(firstDayOfWeek==-1)
163 | firstDayOfWeek=6;
164 | }
165 | week = cal.get(Calendar.WEEK_OF_YEAR)-1; //get which week is the current week.
166 | if(firstDayOfWeek==0 && cal.get(Calendar.MONTH)==Calendar.JANUARY) //adjustment for week number when january starts with first day of month as sunday
167 | week = 1;
168 | if(week==0)
169 | week = 52;
170 |
171 | prevCal = (Calendar) cal.clone(); //create a calendar item for the previous month by subtracting
172 | prevCal.add(Calendar.MONTH, -1); //1 from the current month
173 |
174 | //get the number of days in the previous month to display last few days of previous month
175 | prevMonthDay = prevCal.getActualMaximum(Calendar.DAY_OF_MONTH)-firstDayOfWeek+1;
176 | nextMonthDay = 1; //set the next month counter to date 1
177 | android.widget.TableRow.LayoutParams lp;
178 |
179 | RelativeLayout rl = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.monthtop, null);
180 |
181 | //create the left arrow button for displaying the previous month
182 | ImageView btn1 = (ImageView) rl.findViewById(R.id.imgLeft);
183 | btn1.setTag("<");
184 | btn1.setOnClickListener(ChangeMonthListener);
185 |
186 | btn = (TextView) rl.findViewById(R.id.txtDay);
187 | btn.setText(months[cal.get(Calendar.MONTH)]);
188 |
189 | ((TextView)rl.findViewById(R.id.txtYear)).setText(""+cal.get(Calendar.YEAR));
190 |
191 | //create the right arrow button for displaying the next month
192 | btn1 = (ImageView) rl.findViewById(R.id.imgRight);
193 | btn1.setTag(">");
194 | btn1.setOnClickListener(ChangeMonthListener);
195 | //add the tablerow containing the next and prev views to the calendar
196 | addView(rl);
197 |
198 | tr = new TableRow(context); //create a new row to add to the tablelayout
199 | tr.setWeightSum(0.7f);
200 | lp = new TableRow.LayoutParams();
201 | lp.weight = 0.1f;
202 | //Create the day labels on top of the calendar
203 | for(int i=0;i<7;i++)
204 | {
205 | btn = new TextView(context);
206 | btn.setBackgroundResource(R.drawable.calheader);
207 | btn.setPadding(10, 3,10, 3);
208 | btn.setLayoutParams(lp);
209 | btn.setTextColor(Color.parseColor("#9C9A9D"));
210 | btn.setText(days[i]);
211 | btn.setTextSize(TypedValue.COMPLEX_UNIT_SP,13);
212 | btn.setGravity(Gravity.CENTER);
213 | tr.addView(btn); //add the day label to the tablerow
214 | }
215 | if(animationEnabled)
216 | {
217 | if(animFlag)
218 | tr.startAnimation(animSet2);
219 | else
220 | tr.startAnimation(animSet1);
221 | }
222 | addView(tr); //add the tablerow to the tablelayout (first row of the calendar)
223 |
224 | tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
225 | /*initialize the day counter to 1, it will be used to display the dates of the month*/
226 | int day=1;
227 | lp = new TableRow.LayoutParams();
228 | lp.weight = 0.1f;
229 | for(int i=0;i<6;i++)
230 | {
231 | if(day>cal.getActualMaximum(Calendar.DAY_OF_MONTH))
232 | break;
233 | tr = new TableRow(context);
234 | tr.setWeightSum(0.7f);
235 | //this loop is used to fill out the days in the i-th row in the calendar
236 | for(int j=0;j<7;j++)
237 | {
238 | btn = new TextView(context);
239 | btn.setLayoutParams(lp);
240 | btn.setBackgroundResource(R.drawable.rectgrad);
241 | btn.setGravity(Gravity.CENTER);
242 | btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
243 | btn.setTextColor(Color.GRAY);
244 | if(j"+prevMonthDay+++"")));
246 | else if(day>cal.getActualMaximum(Calendar.DAY_OF_MONTH)) //checks to see whether to print next month's date
247 | {
248 | btn.setText(Html.fromHtml(""+nextMonthDay+++""));
249 | }
250 | else //day counter is in the current month
251 | {
252 | try{
253 | if(isEvent[day])
254 | btn.setBackgroundResource(R.drawable.dayinmonth);
255 | else
256 | btn.setBackgroundResource(R.drawable.rectgrad);
257 | }catch(Exception ex)
258 | {
259 | btn.setBackgroundResource(R.drawable.rectgrad);
260 | }
261 | cal.set(Calendar.DAY_OF_MONTH, day);
262 | btn.setTag(day); //tag to be used when closing the calendar view
263 | btn.setOnClickListener(dayClickedListener);
264 | if(cal.equals(today))//if the day is today then set different background and text color
265 | {
266 | tv = btn;
267 | btn.setBackgroundResource(R.drawable.current_day);
268 | btn.setTextColor(Color.BLACK);
269 | }
270 | else if(selected_day==day)
271 | {
272 | tv = btn;
273 | btn.setBackgroundResource(R.drawable.selectedgrad);
274 | btn.setTextColor(Color.WHITE);
275 | }
276 | else
277 | btn.setTextColor(Color.WHITE);
278 |
279 | //set the text of the day
280 | btn.setText(Html.fromHtml(""+String.valueOf(day++)+""));
281 | if(j==0)
282 | btn.setTextColor(Color.parseColor("#D73C10"));
283 | else if(j==6)
284 | btn.setTextColor(Color.parseColor("#009EF7"));
285 |
286 | if((day==this.day+1)&&(this.month==cal.get(Calendar.MONTH)+1)&&(this.year==cal.get(Calendar.YEAR)))
287 | btn.setBackgroundColor(Color.GRAY);
288 | }
289 | btn.setPadding(8,8,8,8); //maintains proper distance between two adjacent days
290 | tr.addView(btn);
291 | }
292 | if(animationEnabled)
293 | {
294 | if(animFlag)
295 | tr.startAnimation(animSet2);
296 | else
297 | tr.startAnimation(animSet1);
298 | }
299 | //this adds a table row for six times for six different rows in the calendar
300 | addView(tr);
301 | }
302 | }
303 | private TextView tv;
304 |
305 | //Called when a day is clicked.
306 | private OnClickListener dayClickedListener = new OnClickListener(){
307 | @Override
308 | public void onClick(View v) {
309 | if(tv!=null)
310 | {
311 | try{
312 | if(isEvent[day])
313 | {
314 | tv.setBackgroundResource(R.drawable.dayinmonth);
315 | }
316 | else
317 | tv.setBackgroundResource(R.drawable.rectgrad);
318 |
319 | }catch(Exception ex)
320 | {
321 | tv.setBackgroundResource(R.drawable.rectgrad);
322 | }
323 | tv.setPadding(8,8,8,8);
324 | }
325 | if(tv.getText().toString().trim().equals(String.valueOf(today.get(Calendar.DATE))))
326 | {
327 | tv.setBackgroundResource(R.drawable.selectedgrad);
328 | }
329 | day = Integer.parseInt(v.getTag().toString());
330 | selected_day = day;
331 | tv = (TextView)v;
332 | tv.setBackgroundResource(R.drawable.selectedgrad);
333 | DisplayMonth(false);
334 | /*save the day,month and year in the public int variables day,month and year
335 | so that they can be used when the calendar is closed */
336 |
337 | cal.set(Calendar.DAY_OF_MONTH, day);
338 | }
339 | };
340 | }
341 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | This is a calendar widget that can be used in your android app to display month view.
2 |
3 | Months can be switched and days clicked to generate click event.
4 |
5 | Days having events associated with them can be displayed with different marking.
6 |
7 | Check out more details at
8 |
9 | http://dharmin007.wordpress.com/android-calendar-widget-month-view/
--------------------------------------------------------------------------------