diff options
Diffstat (limited to 'src/com/android/calendar')
-rw-r--r-- | src/com/android/calendar/AllInOneActivity.java | 28 | ||||
-rw-r--r-- | src/com/android/calendar/CalendarController.java | 51 | ||||
-rw-r--r-- | src/com/android/calendar/MonthActivity.java | 272 | ||||
-rw-r--r-- | src/com/android/calendar/MonthFragment.java | 246 | ||||
-rw-r--r-- | src/com/android/calendar/MonthView.java | 41 |
5 files changed, 379 insertions, 259 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java new file mode 100644 index 00000000..16cab358 --- /dev/null +++ b/src/com/android/calendar/AllInOneActivity.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calendar; + +import android.app.Activity; +import android.os.Bundle; + +public class AllInOneActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.all_in_one); + } +} diff --git a/src/com/android/calendar/CalendarController.java b/src/com/android/calendar/CalendarController.java new file mode 100644 index 00000000..f04fa2a0 --- /dev/null +++ b/src/com/android/calendar/CalendarController.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calendar; + +import android.text.format.Time; + +public interface CalendarController { + /** + * Returns the time in millis of the selected event in this view. + * @return the selected time in UTC milliseconds. + */ + long getSelectedTime(); + + /** + * Changes the view to include the given time. + * @param time the desired time to view. + * @animate enable animation + */ + void goTo(Time time, boolean animate); + + /** + * Changes the view to include today's date. + */ + void goToToday(); + + /** + * This is called when the user wants to create a new event and returns + * true if the new event should default to an all-day event. + * @return true if the new event should be an all-day event. + */ + boolean getAllDay(); + + /** + * TODO comment + */ + void eventsChanged(); +} diff --git a/src/com/android/calendar/MonthActivity.java b/src/com/android/calendar/MonthActivity.java index ec7c670f..3b35c236 100644 --- a/src/com/android/calendar/MonthActivity.java +++ b/src/com/android/calendar/MonthActivity.java @@ -20,186 +20,49 @@ import static android.provider.Calendar.EVENT_BEGIN_TIME; import dalvik.system.VMRuntime; import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.ContentResolver; -import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.database.ContentObserver; import android.os.Bundle; -import android.os.Handler; -import android.preference.PreferenceManager; -import android.provider.Calendar.Events; -import android.text.format.DateUtils; import android.text.format.Time; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.view.animation.Animation.AnimationListener; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.ViewSwitcher; -import android.widget.Gallery.LayoutParams; -import java.util.Calendar; - -public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, - Navigator, AnimationListener { +public class MonthActivity extends Activity { private static final int INITIAL_HEAP_SIZE = 4 * 1024 * 1024; - private Animation mInAnimationPast; - private Animation mInAnimationFuture; - private Animation mOutAnimationPast; - private Animation mOutAnimationFuture; - private ViewSwitcher mSwitcher; private Time mTime; - - private ContentResolver mContentResolver; - EventLoader mEventLoader; - private int mStartDay; - - private ProgressBar mProgressBar; - - private static final int DAY_OF_WEEK_LABEL_IDS[] = { - R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6 - }; - private static final int DAY_OF_WEEK_KINDS[] = { - Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, - Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY - }; - - protected void startProgressSpinner() { - // start the progress spinner - mProgressBar.setVisibility(View.VISIBLE); - } - - protected void stopProgressSpinner() { - // stop the progress spinner - mProgressBar.setVisibility(View.GONE); - } - - /* ViewSwitcher.ViewFactory interface methods */ - public View makeView() { - MonthView mv = new MonthView(this, this); - mv.setLayoutParams(new ViewSwitcher.LayoutParams( - LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - mv.setSelectedTime(mTime); - return mv; - } - - /* Navigator interface methods */ - public void goTo(Time time, boolean animate) { - TextView title = (TextView) findViewById(R.id.title); - title.setText(Utils.formatMonthYear(this, time)); - - MonthView current = (MonthView) mSwitcher.getCurrentView(); - current.dismissPopup(); - - Time currentTime = current.getTime(); - - // Compute a month number that is monotonically increasing for any - // two adjacent months. - // This is faster than calling getSelectedTime() because we avoid - // a call to Time#normalize(). - if (animate) { - int currentMonth = currentTime.month + currentTime.year * 12; - int nextMonth = time.month + time.year * 12; - if (nextMonth < currentMonth) { - mSwitcher.setInAnimation(mInAnimationPast); - mSwitcher.setOutAnimation(mOutAnimationPast); - } else { - mSwitcher.setInAnimation(mInAnimationFuture); - mSwitcher.setOutAnimation(mOutAnimationFuture); - } - } - - MonthView next = (MonthView) mSwitcher.getNextView(); - next.setSelectionMode(current.getSelectionMode()); - next.setSelectedTime(time); - next.reloadEvents(); - next.animationStarted(); - mSwitcher.showNext(); - next.requestFocus(); - mTime = time; - } - - public void goToToday() { - Time now = new Time(); - now.set(System.currentTimeMillis()); - now.minute = 0; - now.second = 0; - now.normalize(false); - - TextView title = (TextView) findViewById(R.id.title); - title.setText(Utils.formatMonthYear(this, now)); - mTime = now; - - MonthView view = (MonthView) mSwitcher.getCurrentView(); - view.setSelectedTime(now); - view.reloadEvents(); - } - - public long getSelectedTime() { - MonthView mv = (MonthView) mSwitcher.getCurrentView(); - return mv.getSelectedTimeInMillis(); - } - - public boolean getAllDay() { - return false; - } - - int getStartDay() { - return mStartDay; - } - - void eventsChanged() { - MonthView view = (MonthView) mSwitcher.getCurrentView(); - view.reloadEvents(); - } + private MonthFragment mFragment; /** * Listens for intent broadcasts */ - private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (action.equals(Intent.ACTION_TIME_CHANGED) - || action.equals(Intent.ACTION_DATE_CHANGED) - || action.equals(Intent.ACTION_TIMEZONE_CHANGED)) { - eventsChanged(); - } - } - }; +//FRAG_TODO +// private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { +// @Override +// public void onReceive(Context context, Intent intent) { +// String action = intent.getAction(); +// if (action.equals(Intent.ACTION_TIME_CHANGED) +// || action.equals(Intent.ACTION_DATE_CHANGED) +// || action.equals(Intent.ACTION_TIMEZONE_CHANGED)) { +// eventsChanged(); +// } +// } +// }; // Create an observer so that we can update the views whenever a // Calendar event changes. - private ContentObserver mObserver = new ContentObserver(new Handler()) - { - @Override - public boolean deliverSelfNotifications() { - return true; - } - - @Override - public void onChange(boolean selfChange) { - eventsChanged(); - } - }; - - public void onAnimationStart(Animation animation) { - } - - // Notifies the MonthView when an animation has finished. - public void onAnimationEnd(Animation animation) { - MonthView monthView = (MonthView) mSwitcher.getCurrentView(); - monthView.animationFinished(); - } - - public void onAnimationRepeat(Animation animation) { - } +//FRAG_TODO +// private ContentObserver mObserver = new ContentObserver(new Handler()) +// { +// @Override +// public boolean deliverSelfNotifications() { +// return true; +// } +// +// @Override +// public void onChange(boolean selfChange) { +// eventsChanged(); +// } +// }; @Override protected void onCreate(Bundle icicle) { @@ -209,8 +72,8 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, // TODO: We should restore the old heap size once the activity reaches the idle state VMRuntime.getRuntime().setMinimumHeapSize(INITIAL_HEAP_SIZE); - setContentView(R.layout.month_activity); - mContentResolver = getContentResolver(); + mFragment = new MonthFragment(); + openFragmentTransaction().add(android.R.id.content, mFragment).commit(); long time; if (icicle != null) { @@ -222,44 +85,6 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, mTime = new Time(); mTime.set(time); mTime.normalize(true); - - // Get first day of week based on locale and populate the day headers - mStartDay = Calendar.getInstance().getFirstDayOfWeek(); - int diff = mStartDay - Calendar.SUNDAY - 1; - final int startDay = Utils.getFirstDayOfWeek(); - final int sundayColor = getResources().getColor(R.color.sunday_text_color); - final int saturdayColor = getResources().getColor(R.color.saturday_text_color); - - for (int day = 0; day < 7; day++) { - final String dayString = DateUtils.getDayOfWeekString( - (DAY_OF_WEEK_KINDS[day] + diff) % 7 + 1, DateUtils.LENGTH_MEDIUM); - final TextView label = (TextView) findViewById(DAY_OF_WEEK_LABEL_IDS[day]); - label.setText(dayString); - if (Utils.isSunday(day, startDay)) { - label.setTextColor(sundayColor); - } else if (Utils.isSaturday(day, startDay)) { - label.setTextColor(saturdayColor); - } - } - - // Set the initial title - TextView title = (TextView) findViewById(R.id.title); - title.setText(Utils.formatMonthYear(this, mTime)); - - mEventLoader = new EventLoader(this); - mProgressBar = (ProgressBar) findViewById(R.id.progress_circular); - - mSwitcher = (ViewSwitcher) findViewById(R.id.switcher); - mSwitcher.setFactory(this); - mSwitcher.getCurrentView().requestFocus(); - - mInAnimationPast = AnimationUtils.loadAnimation(this, R.anim.slide_down_in); - mOutAnimationPast = AnimationUtils.loadAnimation(this, R.anim.slide_down_out); - mInAnimationFuture = AnimationUtils.loadAnimation(this, R.anim.slide_up_in); - mOutAnimationFuture = AnimationUtils.loadAnimation(this, R.anim.slide_up_out); - - mInAnimationPast.setAnimationListener(this); - mInAnimationFuture.setAnimationListener(this); } @Override @@ -268,24 +93,15 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, if (timeMillis > 0) { Time time = new Time(); time.set(timeMillis); - goTo(time, false); +//FRAG_TODO fragment not initialized mFragment.goTo(time, false); } } @Override protected void onPause() { super.onPause(); - if (isFinishing()) { - mEventLoader.stopBackgroundThread(); - } - mContentResolver.unregisterContentObserver(mObserver); - unregisterReceiver(mIntentReceiver); - - MonthView view = (MonthView) mSwitcher.getCurrentView(); - view.dismissPopup(); - view = (MonthView) mSwitcher.getNextView(); - view.dismissPopup(); - mEventLoader.stopBackgroundThread(); +//FRAG_TODO mContentResolver.unregisterContentObserver(mObserver); +//FRAG_TODO unregisterReceiver(mIntentReceiver); // Record Month View as the (new) start view Utils.setDefaultView(this, CalendarApplication.MONTH_VIEW_ID); @@ -294,16 +110,6 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, @Override protected void onResume() { super.onResume(); - mEventLoader.startBackgroundThread(); - eventsChanged(); - - MonthView view1 = (MonthView) mSwitcher.getCurrentView(); - MonthView view2 = (MonthView) mSwitcher.getNextView(); - SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this); - String str = prefs.getString(CalendarPreferenceActivity.KEY_DETAILED_VIEW, - CalendarPreferenceActivity.DEFAULT_DETAILED_VIEW); - view1.setDetailedView(str); - view2.setDetailedView(str); // Register for Intent broadcasts IntentFilter filter = new IntentFilter(); @@ -311,16 +117,10 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_DATE_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); - registerReceiver(mIntentReceiver, filter); +//FRAG_TODO registerReceiver(mIntentReceiver, filter); - mContentResolver.registerContentObserver(Events.CONTENT_URI, - true, mObserver); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putLong(EVENT_BEGIN_TIME, mTime.toMillis(true)); +//FRAG_TODO mContentResolver.registerContentObserver(Events.CONTENT_URI, +//FRAG_TODO true, mObserver); } @Override @@ -337,7 +137,7 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, @Override public boolean onOptionsItemSelected(MenuItem item) { - MenuHelper.onOptionsItemSelected(this, item, this); +//FRAG_TODO MenuHelper.onOptionsItemSelected(this, item, this); return super.onOptionsItemSelected(item); } } diff --git a/src/com/android/calendar/MonthFragment.java b/src/com/android/calendar/MonthFragment.java new file mode 100644 index 00000000..2649c955 --- /dev/null +++ b/src/com/android/calendar/MonthFragment.java @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calendar; + +import static android.provider.Calendar.EVENT_BEGIN_TIME; + +import android.app.Fragment; +import android.content.SharedPreferences; +import android.content.res.Resources; +import android.os.Bundle; +import android.text.format.DateUtils; +import android.text.format.Time; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.view.animation.Animation.AnimationListener; +import android.widget.TextView; +import android.widget.ViewSwitcher; +import android.widget.Gallery.LayoutParams; +import android.widget.ViewSwitcher.ViewFactory; + +import java.util.Calendar; + +public class MonthFragment extends Fragment implements CalendarController, AnimationListener, ViewFactory { + private static final int DAY_OF_WEEK_LABEL_IDS[] = { + R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6 + }; + private static final int DAY_OF_WEEK_KINDS[] = { + Calendar.SUNDAY, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, + Calendar.THURSDAY, Calendar.FRIDAY, Calendar.SATURDAY + }; + + private Time mTime = new Time(); + + private Animation mInAnimationPast; + private Animation mInAnimationFuture; + private Animation mOutAnimationPast; + private Animation mOutAnimationFuture; + private ViewSwitcher mSwitcher; + + // FRAG_TODO use framework loader + private EventLoader mEventLoader; + + private boolean mShowTitle = false; + + public MonthFragment() { + } + + public MonthFragment(boolean showTitle) { + mShowTitle = showTitle; + } + + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.month_activity, null); + + mSwitcher = (ViewSwitcher) v.findViewById(R.id.switcher); + mSwitcher.setFactory(this); + mSwitcher.getCurrentView().requestFocus(); + + setDayOfWeekHeader(v); + + return v; + } + + private void setDayOfWeekHeader(View v) { + Resources res = getActivity().getResources(); + + // Get first day of week based on locale and populate the day headers + int diff = Calendar.getInstance().getFirstDayOfWeek() - Calendar.SUNDAY - 1; + final int startDay = Utils.getFirstDayOfWeek(); + final int sundayColor = res.getColor(R.color.sunday_text_color); + final int saturdayColor = res.getColor(R.color.saturday_text_color); + + for (int day = 0; day < 7; day++) { + final String dayString = DateUtils.getDayOfWeekString( + (DAY_OF_WEEK_KINDS[day] + diff) % 7 + 1, DateUtils.LENGTH_MEDIUM); + final TextView label = (TextView) v.findViewById(DAY_OF_WEEK_LABEL_IDS[day]); + label.setText(dayString); + if (Utils.isSunday(day, startDay)) { + label.setTextColor(sundayColor); + } else if (Utils.isSaturday(day, startDay)) { + label.setTextColor(saturdayColor); + } + } + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + } + + mEventLoader = new EventLoader(getActivity()); + + mInAnimationPast = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_down_in); + mOutAnimationPast = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_down_out); + mInAnimationFuture = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up_in); + mOutAnimationFuture = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up_out); + + mInAnimationPast.setAnimationListener(this); + mInAnimationFuture.setAnimationListener(this); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putLong(EVENT_BEGIN_TIME, mTime.toMillis(true)); + } + + @Override + public void onResume() { + super.onResume(); + mEventLoader.startBackgroundThread(); + eventsChanged(); + + MonthView current = (MonthView) mSwitcher.getCurrentView(); + current.setSelectedTime(mTime); + + MonthView next = (MonthView) mSwitcher.getNextView(); + SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(getActivity()); + String str = prefs.getString(CalendarPreferenceActivity.KEY_DETAILED_VIEW, + CalendarPreferenceActivity.DEFAULT_DETAILED_VIEW); + current.setDetailedView(str); + next.setDetailedView(str); + } + + @Override + public void onPause() { + super.onPause(); + if (getActivity().isFinishing()) { + mEventLoader.stopBackgroundThread(); + } + + mEventLoader.stopBackgroundThread(); + cleanupMonthView(); + } + + private void cleanupMonthView() { + MonthView mv = (MonthView) mSwitcher.getCurrentView(); + mv.dismissPopup(); + } + + public View makeView() { + MonthView mv = new MonthView(getActivity(), this, mEventLoader); + mv.setLayoutParams(new ViewSwitcher.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + + if (mShowTitle) { + // TODO Probably not the best place for this. Clean up later. + + // Set the initial title + mv.findViewById(R.id.title_bar).setVisibility(View.VISIBLE); + + TextView title = (TextView) mv.findViewById(R.id.title); + title.setText(Utils.formatMonthYear(getActivity(), mTime)); + } + return mv; + } + + // CalendarController interface + public void goTo(Time time, boolean animate) { + MonthView current = (MonthView) mSwitcher.getCurrentView(); + current.dismissPopup(); + Time currentTime = current.getTime(); + + // Compute a month number that is monotonically increasing for any + // two adjacent months. + // This is faster than calling getSelectedTime() because we avoid + // a call to Time#normalize(). + if (animate) { + int currentMonth = currentTime.month + currentTime.year * 12; + int nextMonth = time.month + time.year * 12; + if (nextMonth < currentMonth) { + mSwitcher.setInAnimation(mInAnimationPast); + mSwitcher.setOutAnimation(mOutAnimationPast); + } else { + mSwitcher.setInAnimation(mInAnimationFuture); + mSwitcher.setOutAnimation(mOutAnimationFuture); + } + } + + cleanupMonthView(); + MonthView mv = (MonthView) mSwitcher.getCurrentView(); + mv.dismissPopup(); + mv.setSelectedTime(time); + mv.reloadEvents(); + mv.animationStarted(); + mSwitcher.showNext(); + mv.requestFocus(); + mTime = time; + } + + // CalendarController interface + public void goToToday() { + Time now = new Time(); + now.set(System.currentTimeMillis()); + now.minute = 0; + now.second = 0; + now.normalize(false); + goTo(now, false); + } + + // CalendarController interface + public long getSelectedTime() { + MonthView mv = (MonthView) mSwitcher.getCurrentView(); + return mv.getSelectedTimeInMillis(); + } + + // CalendarController interface + public boolean getAllDay() { + return false; + } + + // CalendarController interface + public void eventsChanged() { + MonthView mv = (MonthView) mSwitcher.getCurrentView(); + mv.reloadEvents(); + } + + public void onAnimationStart(Animation animation) { + } + + public void onAnimationEnd(Animation animation) { + MonthView monthView = (MonthView) mSwitcher.getCurrentView(); + monthView.animationFinished(); + } + + public void onAnimationRepeat(Animation animation) { + } +} diff --git a/src/com/android/calendar/MonthView.java b/src/com/android/calendar/MonthView.java index 18298239..3b11fe8d 100644 --- a/src/com/android/calendar/MonthView.java +++ b/src/com/android/calendar/MonthView.java @@ -102,12 +102,11 @@ public class MonthView extends View implements View.OnCreateContextMenuListener private Drawable mBoxSelected; private Drawable mBoxPressed; private Drawable mBoxLongPressed; - private Drawable mEventDot; private int mCellWidth; private Resources mResources; - private MonthActivity mParentActivity; - private Navigator mNavigator; + private Context mContext; + private CalendarController mNavigator; private final EventGeometry mEventGeometry; // Pre-allocate and reuse @@ -151,9 +150,6 @@ public class MonthView extends View implements View.OnCreateContextMenuListener private static final int SELECTION_SELECTED = 2; private static final int SELECTION_LONGPRESS = 3; - // Modulo used to pack (width,height) into a unique integer - private static final int MODULO_SHIFT = 16; - private int mSelectionMode = SELECTION_HIDDEN; /** @@ -181,7 +177,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener private int mBusybitsColor; private int mMonthBgColor; - public MonthView(MonthActivity activity, Navigator navigator) { + public MonthView(Context activity, CalendarController navigator, EventLoader eventLoader) { super(activity); if (mScale == 0) { mScale = getContext().getResources().getDisplayMetrics().density; @@ -206,7 +202,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener } } - mEventLoader = activity.mEventLoader; + mEventLoader = eventLoader; mNavigator = navigator; mEventGeometry = new EventGeometry(); mEventGeometry.setMinEventHeight(MIN_EVENT_HEIGHT); @@ -214,11 +210,11 @@ public class MonthView extends View implements View.OnCreateContextMenuListener init(activity); } - private void init(MonthActivity activity) { + private void init(Context activity) { setFocusable(true); setClickable(true); setOnCreateContextMenuListener(this); - mParentActivity = activity; + mContext = activity; mViewCalendar = new Time(); long now = System.currentTimeMillis(); mViewCalendar.set(now); @@ -229,7 +225,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener mViewCalendar.set(now); mCursor = new DayOfMonthCursor(mViewCalendar.year, mViewCalendar.month, - mViewCalendar.monthDay, mParentActivity.getStartDay()); + mViewCalendar.monthDay, Calendar.getInstance().getFirstDayOfWeek()); mToday = new Time(); mToday.set(System.currentTimeMillis()); @@ -238,7 +234,6 @@ public class MonthView extends View implements View.OnCreateContextMenuListener mBoxPressed = mResources.getDrawable(R.drawable.month_view_pressed); mBoxLongPressed = mResources.getDrawable(R.drawable.month_view_longpress); - mEventDot = mResources.getDrawable(R.drawable.event_dot); mTodayBackground = mResources.getDrawable(R.drawable.month_view_today_background); // Cache color lookups @@ -294,7 +289,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener time.month -= 1; } time.normalize(true); - mParentActivity.goTo(time, true); + mNavigator.goTo(time, true); return true; } @@ -388,7 +383,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener final int flags = DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH; - final String title = DateUtils.formatDateTime(mParentActivity, startMillis, flags); + final String title = DateUtils.formatDateTime(mContext, startMillis, flags); menu.setHeaderTitle(title); item = menu.add(0, MenuHelper.MENU_DAY, 0, R.string.show_day_view); @@ -412,12 +407,12 @@ public class MonthView extends View implements View.OnCreateContextMenuListener switch (item.getItemId()) { case MenuHelper.MENU_DAY: { long startMillis = getSelectedTimeInMillis(); - Utils.startActivity(mParentActivity, DayActivity.class.getName(), startMillis); + Utils.startActivity(mContext, DayActivity.class.getName(), startMillis); break; } case MenuHelper.MENU_AGENDA: { long startMillis = getSelectedTimeInMillis(); - Utils.startActivity(mParentActivity, AgendaActivity.class.getName(), + Utils.startActivity(mContext, AgendaActivity.class.getName(), startMillis); break; } @@ -425,10 +420,10 @@ public class MonthView extends View implements View.OnCreateContextMenuListener long startMillis = getSelectedTimeInMillis(); long endMillis = startMillis + DateUtils.HOUR_IN_MILLIS; Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setClassName(mParentActivity, EditEventActivity.class.getName()); + intent.setClassName(mContext, EditEventActivity.class.getName()); intent.putExtra(EVENT_BEGIN_TIME, startMillis); intent.putExtra(EVENT_END_TIME, endMillis); - mParentActivity.startActivity(intent); + mContext.startActivity(intent); break; } default: { @@ -451,7 +446,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener int startDay = Time.getJulianDay(millis, monthStart.gmtoff); // Load the days with events in the background - mParentActivity.startProgressSpinner(); +//FRAG_TODO mParentActivity.startProgressSpinner(); final long startMillis; if (PROFILE_LOAD_TIME) { startMillis = SystemClock.uptimeMillis(); @@ -465,7 +460,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener public void run() { mEvents = events; mRedrawScreen = true; - mParentActivity.stopProgressSpinner(); +//FRAG_TODO mParentActivity.stopProgressSpinner(); invalidate(); int numEvents = events.size(); @@ -1056,17 +1051,17 @@ public class MonthView extends View implements View.OnCreateContextMenuListener } } else { flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON_MIDNIGHT; - if (DateFormat.is24HourFormat(mParentActivity)) { + if (DateFormat.is24HourFormat(mContext)) { flags |= DateUtils.FORMAT_24HOUR; } } String timeRange; if (showEndTime) { - timeRange = DateUtils.formatDateRange(mParentActivity, + timeRange = DateUtils.formatDateRange(mContext, event.startMillis, event.endMillis, flags); } else { - timeRange = DateUtils.formatDateRange(mParentActivity, + timeRange = DateUtils.formatDateRange(mContext, event.startMillis, event.startMillis, flags); } |