OSDN Git Service

b/2126473 Update Calendar Code to handle Back key events when released, not when...
authorMichael Chan <mchan@android.com>
Thu, 17 Sep 2009 06:18:54 +0000 (23:18 -0700)
committerMichael Chan <mchan@android.com>
Thu, 17 Sep 2009 12:45:55 +0000 (05:45 -0700)
src/com/android/calendar/AgendaActivity.java
src/com/android/calendar/CalendarView.java
src/com/android/calendar/EditEvent.java
src/com/android/calendar/MonthActivity.java

index 4e98884..fdcac53 100644 (file)
@@ -216,10 +216,6 @@ public class AgendaActivity extends Activity implements Navigator {
                 // Delete the currently selected event (if any)
                 mAgendaListView.deleteSelectedEvent();
                 break;
-
-            case KeyEvent.KEYCODE_BACK:
-                finish();
-                return true;
         }
         return super.onKeyDown(keyCode, event);
     }
index 0bc8258..3710cc9 100644 (file)
@@ -899,6 +899,13 @@ public class CalendarView extends View
                     performLongClick();
                 }
                 break;
+            case KeyEvent.KEYCODE_BACK:
+                if (event.isTracking() && !event.isCanceled()) {
+                    mPopup.dismiss();
+                    mParentActivity.finish();
+                    return true;
+                }
+                break;
         }
         return super.onKeyUp(keyCode, event);
     }
@@ -948,9 +955,11 @@ public class CalendarView extends View
             switchViews(true /* trackball or keyboard */);
             return true;
         case KeyEvent.KEYCODE_BACK:
-            mPopup.dismiss();
-            mParentActivity.finish();
-            return true;
+            if (event.getRepeatCount() == 0) {
+                event.startTracking();
+                return true;
+            }
+            return super.onKeyDown(keyCode, event);
         case KeyEvent.KEYCODE_DPAD_LEFT:
             if (mSelectedEvent != null) {
                 mSelectedEvent = mSelectedEvent.nextLeft;
index b4ce580..fa4cec4 100644 (file)
@@ -1121,23 +1121,18 @@ public class EditEvent extends Activity implements View.OnClickListener,
     }
 
     @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event) {
-        switch (keyCode) {
-            case KeyEvent.KEYCODE_BACK:
-                // If we are creating a new event, do not create it if the
-                // title, location and description are all empty, in order to
-                // prevent accidental "no subject" event creations.
-                if (mUri != null || !isEmpty()) {
-                    if (!save()) {
-                        // We cannot exit this activity because the calendars
-                        // are still loading.
-                        return true;
-                    }
-                }
-                break;
+    public void onBackPressed() {
+        // If we are creating a new event, do not create it if the
+        // title, location and description are all empty, in order to
+        // prevent accidental "no subject" event creations.
+        if (mUri != null || !isEmpty()) {
+            if (!save()) {
+                // We cannot exit this activity because the calendars
+                // are still loading.
+                return;
+            }
         }
-
-        return super.onKeyDown(keyCode, event);
+        finish();
     }
 
     private void populateWhen() {
index b06aa98..8593456 100644 (file)
@@ -322,16 +322,6 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory,
     }
 
     @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event) {
-        switch (keyCode) {
-            case KeyEvent.KEYCODE_BACK:
-                finish();
-                return true;
-        }
-        return super.onKeyDown(keyCode, event);
-    }
-
-    @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
         MenuHelper.onPrepareOptionsMenu(this, menu);
         return super.onPrepareOptionsMenu(menu);