Merge "b/5063456 Fix event changes checks to be less agressive"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 73ef242..19a91ca 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -50,10 +50,6 @@
             android:name="AllInOneActivity"
             android:theme="@style/CalendarTheme.WithActionBar"
             android:launchMode="singleTop">
-        </activity>
-
-        <activity-alias android:name="LaunchActivity"
-            android:targetActivity=".AllInOneActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -71,6 +67,10 @@
                 <category android:name="android.intent.category.DEFAULT" />
                 <data android:mimeType="vnd.android.cursor.item/event" />
             </intent-filter>
+        </activity>
+
+        <activity-alias android:name="LaunchActivity"
+            android:targetActivity=".AllInOneActivity">
         </activity-alias>
 
         <activity android:name="EventInfoActivity"
diff --git a/src/com/android/calendar/EventInfoActivity.java b/src/com/android/calendar/EventInfoActivity.java
index a0f7980..9188a8e 100644
--- a/src/com/android/calendar/EventInfoActivity.java
+++ b/src/com/android/calendar/EventInfoActivity.java
@@ -103,44 +103,44 @@
         }
     }
 
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-
-        // Handles option menu selections:
-        // Home button - close event info activity and start the main calendar one
-        // Edit button - start the event edit activity and close the info activity
-        // Delete button - start a delete query that calls a runnable that close the info activity
-
-        switch (item.getItemId()) {
-            case android.R.id.home:
-                Intent launchIntent = new Intent();
-                launchIntent.setAction(Intent.ACTION_VIEW);
-                launchIntent.setData(Uri.parse(CalendarContract.CONTENT_URI + "/time"));
-                launchIntent.setFlags(
-                        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                startActivity(launchIntent);
-                finish();
-                return true;
-            case R.id.info_action_edit:
-                Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
-                Intent intent = new Intent(Intent.ACTION_EDIT, uri);
-                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis);
-                intent.putExtra(EXTRA_EVENT_END_TIME, mEndMillis);
-                intent.setClass(this, EditEventActivity.class);
-                intent.putExtra(EVENT_EDIT_ON_LAUNCH, true);
-                startActivity(intent);
-                finish ();
-                break;
-            case R.id.info_action_delete:
-                DeleteEventHelper deleteHelper = new DeleteEventHelper(
-                        this, this, true /* exitWhenDone */);
-                deleteHelper.delete(mStartMillis, mEndMillis, mEventId, -1, onDeleteRunnable);
-                break;
-            default:
-                break;
-        }
-        return super.onOptionsItemSelected(item);
-    }
+//    @Override
+//    public boolean onOptionsItemSelected(MenuItem item) {
+//
+//        // Handles option menu selections:
+//        // Home button - close event info activity and start the main calendar one
+//        // Edit button - start the event edit activity and close the info activity
+//        // Delete button - start a delete query that calls a runnable that close the info activity
+//
+//        switch (item.getItemId()) {
+//            case android.R.id.home:
+//                Intent launchIntent = new Intent();
+//                launchIntent.setAction(Intent.ACTION_VIEW);
+//                launchIntent.setData(Uri.parse(CalendarContract.CONTENT_URI + "/time"));
+//                launchIntent.setFlags(
+//                        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//                startActivity(launchIntent);
+//                finish();
+//                return true;
+//            case R.id.info_action_edit:
+//                Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
+//                Intent intent = new Intent(Intent.ACTION_EDIT, uri);
+//                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis);
+//                intent.putExtra(EXTRA_EVENT_END_TIME, mEndMillis);
+//                intent.setClass(this, EditEventActivity.class);
+//                intent.putExtra(EVENT_EDIT_ON_LAUNCH, true);
+//                startActivity(intent);
+//                finish ();
+//                break;
+//            case R.id.info_action_delete:
+//                DeleteEventHelper deleteHelper = new DeleteEventHelper(
+//                        this, this, true /* exitWhenDone */);
+//                deleteHelper.delete(mStartMillis, mEndMillis, mEventId, -1, onDeleteRunnable);
+//                break;
+//            default:
+//                break;
+//        }
+//        return super.onOptionsItemSelected(item);
+//    }
 
     // runs at the end of a delete action and closes the activity
     private Runnable onDeleteRunnable = new Runnable() {
diff --git a/src/com/android/calendar/EventInfoFragment.java b/src/com/android/calendar/EventInfoFragment.java
index 44db258..6de5e3c 100644
--- a/src/com/android/calendar/EventInfoFragment.java
+++ b/src/com/android/calendar/EventInfoFragment.java
@@ -16,11 +16,16 @@
 
 package com.android.calendar;
 
+import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
+import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
+import static com.android.calendar.CalendarController.EVENT_EDIT_ON_LAUNCH;
+
 import com.android.calendar.CalendarController.EventInfo;
 import com.android.calendar.CalendarController.EventType;
 import com.android.calendar.CalendarEventModel.Attendee;
 import com.android.calendar.CalendarEventModel.ReminderEntry;
 import com.android.calendar.event.AttendeesView;
+import com.android.calendar.event.EditEventActivity;
 import com.android.calendar.event.EditEventHelper;
 import com.android.calendarcommon.EventRecurrence;
 import com.android.calendar.event.EventViewUtils;
@@ -249,7 +254,7 @@
     private TextView mWhat;
     private TextView mAttendees;
     private AttendeesView mLongAttendees;
-    private Menu mMenu;
+    private Menu mMenu = null;
     private View mHeadlines;
     private ScrollView mScrollView;
 
@@ -346,8 +351,6 @@
                 updateCalendar(mView);
                 // FRAG_TODO fragments shouldn't set the title anymore
                 updateTitle();
-                // update the action bar since our option set might have changed
-                activity.invalidateOptionsMenu();
 
                 if (!mIsBusyFreeCalendar) {
                     args = new String[] { Long.toString(mEventId) };
@@ -738,10 +741,58 @@
         // Show edit/delete buttons only in non-dialog configuration on a phone
         if (!mIsDialog && !mIsTabletConfig) {
             inflater.inflate(R.menu.event_info_title_bar, menu);
-                mMenu = menu;
+            mMenu = menu;
+            updateMenu();
         }
     }
 
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+
+        // If we're a dialog or part of a tablet display we don't want to handle
+        // menu buttons
+        if (mIsDialog || mIsTabletConfig) {
+            return false;
+        }
+        // Handles option menu selections:
+        // Home button - close event info activity and start the main calendar
+        // one
+        // Edit button - start the event edit activity and close the info
+        // activity
+        // Delete button - start a delete query that calls a runnable that close
+        // the info activity
+
+        switch (item.getItemId()) {
+            case android.R.id.home:
+                Intent launchIntent = new Intent();
+                launchIntent.setAction(Intent.ACTION_VIEW);
+                launchIntent.setData(Uri.parse(CalendarContract.CONTENT_URI + "/time"));
+                launchIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
+                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                launchIntent.setClass(mActivity, AllInOneActivity.class);
+                startActivity(launchIntent);
+                mActivity.finish();
+                return true;
+            case R.id.info_action_edit:
+                Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
+                Intent intent = new Intent(Intent.ACTION_EDIT, uri);
+                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis);
+                intent.putExtra(EXTRA_EVENT_END_TIME, mEndMillis);
+                intent.setClass(mActivity, EditEventActivity.class);
+                intent.putExtra(EVENT_EDIT_ON_LAUNCH, true);
+                startActivity(intent);
+                mActivity.finish();
+                break;
+            case R.id.info_action_delete:
+                DeleteEventHelper deleteHelper =
+                        new DeleteEventHelper(mActivity, mActivity, true /* exitWhenDone */);
+                deleteHelper.delete(mStartMillis, mEndMillis, mEventId, -1, onDeleteRunnable);
+                break;
+            default:
+                break;
+        }
+        return super.onOptionsItemSelected(item);
+    }
 
     @Override
     public void onDestroyView() {
@@ -1133,12 +1184,9 @@
                 if (mIsDialog) {
                     mView.findViewById(R.id.delete).setEnabled(false);
                 }
-                else {
-                    MenuItem item = mMenu.findItem(R.id.info_action_delete);
-                    if (item != null) {
-                        item.setVisible(false);
-                    }
-                }
+            }
+            if (mMenu != null) {
+                mActivity.invalidateOptionsMenu();
             }
         } else {
             setVisibilityCommon(view, R.id.calendar, View.GONE);
@@ -1146,6 +1194,25 @@
         }
     }
 
+    /**
+     *
+     */
+    private void updateMenu() {
+        if (mMenu == null) {
+            return;
+        }
+        MenuItem delete = mMenu.findItem(R.id.info_action_delete);
+        MenuItem edit = mMenu.findItem(R.id.info_action_edit);
+        if (delete != null) {
+            delete.setVisible(mCanModifyCalendar);
+            delete.setEnabled(mCanModifyCalendar);
+        }
+        if (edit != null) {
+            edit.setVisible(mCanModifyCalendar);
+            edit.setEnabled(mCanModifyCalendar);
+        }
+    }
+
     private void updateAttendees(View view) {
 
         if (mAcceptedAttendees.size() + mDeclinedAttendees.size() +