summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2011-07-26 11:35:24 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-26 11:35:24 -0700
commit17fb0a88a1d3a72a33b6653bb0c47daa8c94c0be (patch)
treeb0617c2f2a9cf258ea3583deb8bf2bfa6e82cc10 /src/com/android/calendar
parent21bd42039c92232647f54461cd20708224cc7eb6 (diff)
parent3864be025ed7fa5bcb33c7adaae9267d5b34f17f (diff)
downloadandroid_packages_apps_Calendar-17fb0a88a1d3a72a33b6653bb0c47daa8c94c0be.tar.gz
android_packages_apps_Calendar-17fb0a88a1d3a72a33b6653bb0c47daa8c94c0be.tar.bz2
android_packages_apps_Calendar-17fb0a88a1d3a72a33b6653bb0c47daa8c94c0be.zip
Merge "b/3362680 fix up register/deregister for AllInOneActivity"
Diffstat (limited to 'src/com/android/calendar')
-rw-r--r--src/com/android/calendar/AllInOneActivity.java20
-rw-r--r--src/com/android/calendar/CalendarController.java37
-rw-r--r--src/com/android/calendar/Utils.java6
3 files changed, 54 insertions, 9 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java
index 9ce3b445..25f037f4 100644
--- a/src/com/android/calendar/AllInOneActivity.java
+++ b/src/com/android/calendar/AllInOneActivity.java
@@ -201,6 +201,8 @@ public class AllInOneActivity extends Activity implements EventHandler,
// This needs to be created before setContentView
mController = CalendarController.getInstance(this);
+
+
// Get time from intent or icicle
long timeMillis = -1;
int viewType = -1;
@@ -268,17 +270,17 @@ public class AllInOneActivity extends Activity implements EventHandler,
// overwrite us
configureActionBar(viewType);
- // Must be the first to register because this activity can modify the
- // list of event handlers in it's handle method. This affects who the
- // rest of the handlers the controller dispatches to are.
- mController.registerEventHandler(HANDLER_KEY, this);
-
mHomeTime = (TextView) findViewById(R.id.home_time);
mMiniMonth = findViewById(R.id.mini_month);
mCalendarsList = findViewById(R.id.calendar_list);
mMiniMonthContainer = findViewById(R.id.mini_month_container);
mSecondaryPane = findViewById(R.id.secondary_pane);
+ // Must register as the first activity because this activity can modify
+ // the list of event handlers in it's handle method. This affects who
+ // the rest of the handlers the controller dispatches to are.
+ mController.registerFirstEventHandler(HANDLER_KEY, this);
+
initFragments(timeMillis, viewType, icicle);
// Listen for changes that would require this to be refreshed
@@ -394,6 +396,12 @@ public class AllInOneActivity extends Activity implements EventHandler,
@Override
protected void onResume() {
super.onResume();
+
+ // Must register as the first activity because this activity can modify
+ // the list of event handlers in it's handle method. This affects who
+ // the rest of the handlers the controller dispatches to are.
+ mController.registerFirstEventHandler(HANDLER_KEY, this);
+
mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
true, mObserver);
if (mUpdateOnResume) {
@@ -430,6 +438,8 @@ public class AllInOneActivity extends Activity implements EventHandler,
@Override
protected void onPause() {
super.onPause();
+
+ mController.deregisterEventHandler(HANDLER_KEY);
mPaused = true;
mHomeTime.removeCallbacks(mHomeTimeUpdater);
if (mActionBarMenuSpinnerAdapter != null) {
diff --git a/src/com/android/calendar/CalendarController.java b/src/com/android/calendar/CalendarController.java
index 0fa41b49..fd144bc4 100644
--- a/src/com/android/calendar/CalendarController.java
+++ b/src/com/android/calendar/CalendarController.java
@@ -40,6 +40,7 @@ import android.provider.CalendarContract.Events;
import android.text.TextUtils;
import android.text.format.Time;
import android.util.Log;
+import android.util.Pair;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -75,6 +76,8 @@ public class CalendarController {
private LinkedList<Integer> mToBeRemovedEventHandlers = new LinkedList<Integer>();
private LinkedHashMap<Integer, EventHandler> mToBeAddedEventHandlers = new LinkedHashMap<
Integer, EventHandler>();
+ private Pair<Integer, EventHandler> mFirstEventHandler;
+ private Pair<Integer, EventHandler> mToBeAddedFirstEventHandler;
private volatile int mDispatchInProgressCounter = 0;
private static WeakHashMap<Context, CalendarController> instances =
@@ -407,10 +410,23 @@ public class CalendarController {
Log.d(TAG, "sendEvent: Dispatching to " + eventHandlers.size() + " handlers");
}
// Dispatch to event handler(s)
+ if (mFirstEventHandler != null) {
+ // Handle the 'first' one before handling the others
+ EventHandler handler = mFirstEventHandler.second;
+ if (handler != null && (handler.getSupportedEventTypes() & event.eventType) != 0
+ && !mToBeRemovedEventHandlers.contains(mFirstEventHandler.first)) {
+ handler.handleEvent(event);
+ handled = true;
+ }
+ }
for (Iterator<Entry<Integer, EventHandler>> handlers =
eventHandlers.entrySet().iterator(); handlers.hasNext();) {
Entry<Integer, EventHandler> entry = handlers.next();
int key = entry.getKey();
+ if (mFirstEventHandler != null && key == mFirstEventHandler.first) {
+ // If this was the 'first' handler it was already handled
+ continue;
+ }
EventHandler eventHandler = entry.getValue();
if (eventHandler != null
&& (eventHandler.getSupportedEventTypes() & event.eventType) != 0) {
@@ -430,10 +446,17 @@ public class CalendarController {
if (mToBeRemovedEventHandlers.size() > 0) {
for (Integer zombie : mToBeRemovedEventHandlers) {
eventHandlers.remove(zombie);
+ if (mFirstEventHandler != null && zombie.equals(mFirstEventHandler.first)) {
+ mFirstEventHandler = null;
+ }
}
mToBeRemovedEventHandlers.clear();
}
// Add new handlers
+ if (mToBeAddedFirstEventHandler != null) {
+ mFirstEventHandler = mToBeAddedFirstEventHandler;
+ mToBeAddedFirstEventHandler = null;
+ }
if (mToBeAddedEventHandlers.size() > 0) {
for (Entry<Integer, EventHandler> food : mToBeAddedEventHandlers.entrySet()) {
eventHandlers.put(food.getKey(), food.getValue());
@@ -496,6 +519,17 @@ public class CalendarController {
}
}
+ public void registerFirstEventHandler(int key, EventHandler eventHandler) {
+ synchronized (this) {
+ registerEventHandler(key, eventHandler);
+ if (mDispatchInProgressCounter > 0) {
+ mToBeAddedFirstEventHandler = new Pair<Integer, EventHandler>(key, eventHandler);
+ } else {
+ mFirstEventHandler = new Pair<Integer, EventHandler>(key, eventHandler);
+ }
+ }
+ }
+
public void deregisterEventHandler(Integer key) {
synchronized (this) {
if (mDispatchInProgressCounter > 0) {
@@ -503,6 +537,9 @@ public class CalendarController {
mToBeRemovedEventHandlers.add(key);
} else {
eventHandlers.remove(key);
+ if (mFirstEventHandler != null && mFirstEventHandler.first == key) {
+ mFirstEventHandler = null;
+ }
}
}
}
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index 467a121d..60d63e3f 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -1002,12 +1002,10 @@ public class Utils {
* @param context
*/
public static void returnToCalendarHome(Context context) {
- Intent launchIntent = new Intent();
+ Intent launchIntent = new Intent(context, AllInOneActivity.class);
launchIntent.setAction(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse("content://com.android.calendar/time"));
- launchIntent.setClass(context, AllInOneActivity.class);
- launchIntent.setFlags(
- Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(launchIntent);
}