OSDN Git Service

b/2071368 Switch to use the new fasttrack widget and asset from the framework
authorMichael Chan <mchan@android.com>
Wed, 23 Sep 2009 18:37:38 +0000 (11:37 -0700)
committerMichael Chan <mchan@android.com>
Thu, 24 Sep 2009 05:19:20 +0000 (22:19 -0700)
Removed the user's status from the list because
 1) it doesn't make sense for event without other guests and
 2) there's a response spinner for events with guests.
b/2092806 Eliminate the unneeded badge refreshes after fasttrack goes away

Change-Id: I5a2d7d3265dce97b23e279259ed0541247f7123a

res/drawable/fasttrack_badge.xml [deleted file]
res/drawable/fasttrack_badge_light_normal.9.png [deleted file]
res/drawable/fasttrack_badge_light_pressed.9.png [deleted file]
res/drawable/fasttrack_badge_shadow.9.png [deleted file]
res/layout/contact_item.xml
src/com/android/calendar/EventInfoActivity.java

diff --git a/res/drawable/fasttrack_badge.xml b/res/drawable/fasttrack_badge.xml
deleted file mode 100644 (file)
index 8261e46..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_pressed="true" android:drawable="@drawable/fasttrack_badge_light_pressed" />
-    <item android:state_focused="true" android:drawable="@drawable/fasttrack_badge_light_pressed" />
-    <item android:drawable="@drawable/fasttrack_badge_light_normal" />
-</selector>
diff --git a/res/drawable/fasttrack_badge_light_normal.9.png b/res/drawable/fasttrack_badge_light_normal.9.png
deleted file mode 100644 (file)
index ac0ce56..0000000
Binary files a/res/drawable/fasttrack_badge_light_normal.9.png and /dev/null differ
diff --git a/res/drawable/fasttrack_badge_light_pressed.9.png b/res/drawable/fasttrack_badge_light_pressed.9.png
deleted file mode 100644 (file)
index 9ace1a1..0000000
Binary files a/res/drawable/fasttrack_badge_light_pressed.9.png and /dev/null differ
diff --git a/res/drawable/fasttrack_badge_shadow.9.png b/res/drawable/fasttrack_badge_shadow.9.png
deleted file mode 100644 (file)
index 3ffe043..0000000
Binary files a/res/drawable/fasttrack_badge_shadow.9.png and /dev/null differ
index 766aa9c..5aa76f6 100644 (file)
     android:layout_width="fill_parent"
     android:paddingLeft="0dip"
     android:paddingRight="9dip"
-    android:paddingBottom="4dip"
     android:minHeight="48dip">
 
-    <ImageView
-        android:id="@+id/avatar"
-        android:scaleType="centerInside"
-        android:paddingLeft="4dip"
-        android:paddingRight="4dip"
-        android:paddingTop="4dip"
-        android:paddingBottom="9dip"
-        android:layout_width="35dip"
-        android:layout_height="40dip"
+    <FasttrackBadgeWidget
+        android:id="@+id/badge"
+        android:paddingLeft="3dip"
+        android:paddingRight="3dip"
+        android:paddingTop="3dip"
+        android:paddingBottom="6dip"
+        android:layout_above="@+id/separator"
         android:layout_marginLeft="2dip"
         android:layout_marginRight="14dip"
-        android:layout_marginTop="3dip"
+        android:layout_marginTop="4dip"
         android:layout_marginBottom="3dip"
         android:layout_alignParentLeft="true"
-        android:layout_centerVertical="true"
-        android:focusable="true"
+        android:layout_alignParentTop="true"
         android:src="@drawable/ic_contact_picture"
-        android:background="@drawable/fasttrack_badge" />
+        style="@*android:style/Widget.FasttrackBadgeWidgetSmall.WindowSmall" />
 
     <TextView
         android:id="@+id/name"
@@ -47,7 +43,7 @@
         android:inputType="none"
         android:paddingLeft="2dip"
         android:layout_centerVertical="true"
-        android:layout_toRightOf="@id/avatar"
+        android:layout_toRightOf="@id/badge"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
 
index 714952e..1ca8482 100644 (file)
@@ -66,10 +66,10 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
-import android.view.View.OnClickListener;
 import android.view.View.OnTouchListener;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
+import android.widget.FasttrackBadgeWidget;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -113,7 +113,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         Events.ACCESS_LEVEL,         // 11
         Events.COLOR,                // 12
         Events.GUESTS_CAN_MODIFY,    // 13
-        // TODO Events.CAN_INVITE_OTHERS is broken. Investigate
+        // TODO Events.GUESTS_CAN_INVITE_OTHERS has not been implemented in calendar provider
         Events.GUESTS_CAN_INVITE_OTHERS, // 14
         Events.ORGANIZER,            // 15
     };
@@ -229,7 +229,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     // TODO This can be removed when the contacts content provider doesn't return duplicates
     private int mUpdateCounts;
     private static class ViewHolder {
-        ImageView avatar;
+        FasttrackBadgeWidget badge;
         ImageView presence;
         int updateCounts;
     }
@@ -254,25 +254,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
     ArrayList<Attendee> mAcceptedAttendees = new ArrayList<Attendee>();
     ArrayList<Attendee> mDeclinedAttendees = new ArrayList<Attendee>();
     ArrayList<Attendee> mTentativeAttendees = new ArrayList<Attendee>();
-    private OnClickListener contactOnClickListener = new OnClickListener() {
-        private Rect getTargetRect(View anchor) {
-            final int[] location = new int[2];
-            anchor.getLocationOnScreen(location);
-
-            final Rect rect = new Rect();
-            rect.left = location[0];
-            rect.top = location[1];
-            rect.right = rect.left + anchor.getWidth();
-            rect.bottom = rect.top + anchor.getHeight();
-            return rect;
-        }
-
-        public void onClick(View avatar) {
-            final Rect target = getTargetRect(avatar);
-            View attendeeItem = (View) avatar.getParent();
-            showContactInfo((Attendee) attendeeItem.getTag(), target);
-        }
-    };
     private int mColor;
 
     // This is called when one of the "remove reminder" buttons is selected.
@@ -331,15 +312,15 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         }
 
         setContentView(R.layout.event_info_activity);
-
-        // Attendees cursor
-        Uri uri = Attendees.CONTENT_URI;
-        String where = String.format(ATTENDEES_WHERE, mEventId);
-        mAttendeesCursor = managedQuery(uri, ATTENDEES_PROJECTION, where, ATTENDEES_SORT_ORDER);
+        mPresenceQueryHandler = new PresenceQueryHandler(this, cr);
+        mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        mRemindersContainer = (LinearLayout) findViewById(R.id.reminders_container);
+        mOrganizerContainer = (LinearLayout) findViewById(R.id.organizer_container);
+        mOrganizerView = (TextView) findViewById(R.id.organizer);
 
         // Calendars cursor
-        uri = Calendars.CONTENT_URI;
-        where = String.format(CALENDARS_WHERE, mEventCursor.getLong(EVENT_INDEX_CALENDAR_ID));
+        Uri uri = Calendars.CONTENT_URI;
+        String where = String.format(CALENDARS_WHERE, mEventCursor.getLong(EVENT_INDEX_CALENDAR_ID));
         mCalendarsCursor = managedQuery(uri, CALENDARS_PROJECTION, where, null);
         mCalendarOwnerAccount = "";
         if (mCalendarsCursor != null) {
@@ -347,6 +328,14 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
             mCalendarOwnerAccount = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT);
         }
 
+        updateView();
+
+        // Attendees cursor
+        uri = Attendees.CONTENT_URI;
+        where = String.format(ATTENDEES_WHERE, mEventId);
+        mAttendeesCursor = managedQuery(uri, ATTENDEES_PROJECTION, where, ATTENDEES_SORT_ORDER);
+        initAttendeesCursor();
+
         String eventOrganizer = mEventCursor.getString(EVENT_INDEX_ORGANIZER);
         mOrganizer = eventOrganizer;
         mCanModifyCalendar =
@@ -374,10 +363,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                 prefs.getString(CalendarPreferenceActivity.KEY_DEFAULT_REMINDER, "0");
         mDefaultReminderMinutes = Integer.parseInt(durationString);
 
-        mRemindersContainer = (LinearLayout) findViewById(R.id.reminders_container);
-        mOrganizerContainer = (LinearLayout) findViewById(R.id.organizer_container);
-        mOrganizerView = (TextView) findViewById(R.id.organizer);
-
         // Reminders cursor
         boolean hasAlarm = mEventCursor.getInt(EVENT_INDEX_HAS_ALARM) != 0;
         if (hasAlarm) {
@@ -406,8 +391,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
             }
         }
 
-        updateView();
-
         // Setup the + Add Reminder Button
         View.OnClickListener addReminderOnClickListener = new View.OnClickListener() {
             public void onClick(View v) {
@@ -422,9 +405,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
 
         mDeleteEventHelper = new DeleteEventHelper(this, true /* exit when done */);
         mEditResponseHelper = new EditResponseHelper(this);
-
-        mPresenceQueryHandler = new PresenceQueryHandler(this, cr);
-        mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     }
 
     @Override
@@ -435,7 +415,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
             finish();
             return;
         }
-        initAttendeesCursor();
         initCalendarsCursor();
         updateResponse();
         updateTitle();
@@ -505,17 +484,20 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                     if (mCalendarOwnerAttendeeId == -1 && mCalendarOwnerAccount.equals(email)) {
                         mCalendarOwnerAttendeeId = mAttendeesCursor.getInt(ATTENDEES_INDEX_ID);
                         mOriginalAttendeeResponse = mAttendeesCursor.getInt(ATTENDEES_INDEX_STATUS);
-                    }
-
-                    switch(status) {
-                        case Attendees.ATTENDEE_STATUS_ACCEPTED:
-                            mAcceptedAttendees.add(new Attendee(name, email));
-                            break;
-                        case Attendees.ATTENDEE_STATUS_DECLINED:
-                            mDeclinedAttendees.add(new Attendee(name, email));
-                            break;
-                        default:
-                            mTentativeAttendees.add(new Attendee(name, email));
+                    } else {
+                        // Don't show your own status in the list because:
+                        //  1) it doesn't make sense for event without other guests.
+                        //  2) there's a spinner for that for events with guests.
+                        switch(status) {
+                            case Attendees.ATTENDEE_STATUS_ACCEPTED:
+                                mAcceptedAttendees.add(new Attendee(name, email));
+                                break;
+                            case Attendees.ATTENDEE_STATUS_DECLINED:
+                                mDeclinedAttendees.add(new Attendee(name, email));
+                                break;
+                            default:
+                                mTentativeAttendees.add(new Attendee(name, email));
+                        }
                     }
                 } while (mAttendeesCursor.moveToNext());
                 mAttendeesCursor.moveToFirst();
@@ -691,7 +673,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                 updateResponse(cr, mEventId, mCalendarOwnerAttendeeId, status);
                 return true;
             default:
-                Log.e("Calendar", "Unexpected choice for updating invitation response");
+                Log.e(TAG, "Unexpected choice for updating invitation response");
                 break;
         }
         return false;
@@ -775,10 +757,10 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         if (mEventCursor == null) {
             return;
         }
-        Resources res = getResources();
 
         String eventName = mEventCursor.getString(EVENT_INDEX_TITLE);
         if (eventName == null || eventName.length() == 0) {
+            Resources res = getResources();
             eventName = res.getString(R.string.no_title_label);
         }
 
@@ -912,7 +894,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
         ContentResolver cr = getContentResolver();
         // Yes/No/Maybe Title
         View titleView = mLayoutInflater.inflate(R.layout.contact_item, null);
-        titleView.findViewById(R.id.avatar).setVisibility(View.GONE);
+        titleView.findViewById(R.id.badge).setVisibility(View.GONE);
         View divider = titleView.findViewById(R.id.separator);
         divider.getBackground().setColorFilter(mColor, PorterDuff.Mode.SRC_IN);
 
@@ -945,8 +927,8 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
             tv.setText(name);
 
             ViewHolder vh = new ViewHolder();
-            vh.avatar = (ImageView) v.findViewById(R.id.avatar);
-            vh.avatar.setOnClickListener(contactOnClickListener);
+            vh.badge = (FasttrackBadgeWidget) v.findViewById(R.id.badge);
+            vh.badge.assignContactFromEmail(attendee.mEmail, true);
             vh.presence = (ImageView) v.findViewById(R.id.presence);
             mViewHolders.put(attendee.mEmail, vh);
 
@@ -984,7 +966,6 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
             }
 
             try {
-
                 cursor.moveToPosition(-1);
                 while (cursor.moveToNext()) {
                     String email = cursor.getString(PRESENCE_PROJECTION_EMAIL_INDEX);
@@ -1008,7 +989,7 @@ public class EventInfoActivity extends Activity implements View.OnClickListener,
                     if (photoId > 0 && vh.updateCounts < queryIndex) {
                         vh.updateCounts = queryIndex;
                         Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
-                        ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, vh.avatar,
+                        ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, vh.badge,
                                 personUri, R.drawable.ic_contact_picture);
                     }
                 }