From 3864be025ed7fa5bcb33c7adaae9267d5b34f17f Mon Sep 17 00:00:00 2001 From: RoboErik Date: Mon, 25 Jul 2011 15:56:50 -0700 Subject: b/3362680 fix up register/deregister for AllInOneActivity Also fixes back stack for up key Change-Id: I8f789db685e352eaf1172bc7e1712c34476e2c4f --- src/com/android/calendar/AllInOneActivity.java | 20 +++++++++---- src/com/android/calendar/CalendarController.java | 37 ++++++++++++++++++++++++ src/com/android/calendar/Utils.java | 6 ++-- 3 files changed, 54 insertions(+), 9 deletions(-) (limited to 'src/com/android/calendar') 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 mToBeRemovedEventHandlers = new LinkedList(); private LinkedHashMap mToBeAddedEventHandlers = new LinkedHashMap< Integer, EventHandler>(); + private Pair mFirstEventHandler; + private Pair mToBeAddedFirstEventHandler; private volatile int mDispatchInProgressCounter = 0; private static WeakHashMap 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> handlers = eventHandlers.entrySet().iterator(); handlers.hasNext();) { Entry 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 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(key, eventHandler); + } else { + mFirstEventHandler = new Pair(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); } -- cgit v1.2.3