diff options
author | Michael Chan <mchan@android.com> | 2009-05-04 16:15:40 -0700 |
---|---|---|
committer | Michael Chan <mchan@android.com> | 2009-05-04 18:54:32 -0700 |
commit | b3866cbd69a2688d0cb165f18f133e73f0243c8e (patch) | |
tree | cf0f8629ec879c00e72f7274a9fc0caab0019543 | |
parent | 405626ac892f2ceee19ba1a6ff696287641ef171 (diff) | |
download | android_packages_apps_Calendar-b3866cbd69a2688d0cb165f18f133e73f0243c8e.tar.gz android_packages_apps_Calendar-b3866cbd69a2688d0cb165f18f133e73f0243c8e.tar.bz2 android_packages_apps_Calendar-b3866cbd69a2688d0cb165f18f133e73f0243c8e.zip |
Flatten the Agenda view hierarchy down to one level deep. b/1791496
-rw-r--r-- | res/layout/agenda_item.xml | 90 | ||||
-rw-r--r-- | src/com/android/calendar/AgendaAdapter.java | 37 | ||||
-rw-r--r-- | src/com/android/calendar/AgendaItemView.java | 57 |
3 files changed, 116 insertions, 68 deletions
diff --git a/res/layout/agenda_item.xml b/res/layout/agenda_item.xml index 5cae9888..95419172 100644 --- a/res/layout/agenda_item.xml +++ b/res/layout/agenda_item.xml @@ -14,59 +14,47 @@ limitations under the License. --> - -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" +<com.android.calendar.AgendaItemView + xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/content" android:layout_height="wrap_content" - android:layout_width="fill_parent"> + android:layout_width="fill_parent" + android:gravity="center_vertical" + android:minHeight="?android:attr/listPreferredItemHeight"> - <LinearLayout - android:orientation="horizontal" + <TextView + android:id="@+id/title" + android:layout_width="fill_parent" android:layout_height="wrap_content" + android:layout_marginLeft="10dip" + android:ellipsize="end" + android:maxLines="2" + android:textStyle="bold" + android:textColor="?android:attr/textColorSecondary" + style="?android:attr/textAppearanceMediumInverse" /> + + <TextView + android:id="@+id/when" android:layout_width="fill_parent" - android:gravity="center_vertical" - android:minHeight="?android:attr/listPreferredItemHeight" - > - - <View android:id="@+id/vertical_stripe" - android:layout_width="5dip" - android:layout_height="fill_parent" - android:layout_marginRight="5dip" /> - - <LinearLayout - android:orientation="vertical" - android:layout_height="wrap_content" - android:layout_width="fill_parent" - android:layout_weight="1"> - - <TextView android:id="@+id/title" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:ellipsize="end" - android:maxLines="2" - android:textStyle="bold" - android:textColor="?android:attr/textColorSecondary" - style="?android:attr/textAppearanceMediumInverse" - /> - - <TextView android:id="@+id/when" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:ellipsize="end" - android:maxLines="2" - android:textStyle="bold" - android:textColor="?android:attr/textColorSecondary" - style="?android:attr/textAppearanceSmallInverse" - /> - - <TextView android:id="@+id/where" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:ellipsize="end" - android:maxLines="2" - android:textColor="?android:attr/textColorSecondary" - style="?android:attr/textAppearanceSmallInverse" - /> - </LinearLayout> - </LinearLayout> -</FrameLayout> + android:layout_height="wrap_content" + android:layout_below="@+id/title" + android:layout_alignLeft="@+id/title" + android:ellipsize="end" + android:maxLines="2" + android:textStyle="bold" + android:textColor="?android:attr/textColorSecondary" + style="?android:attr/textAppearanceSmallInverse" /> + + <TextView + android:id="@+id/where" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_below="@+id/when" + android:layout_alignLeft="@+id/title" + android:layout_alignParentRight="true" + android:ellipsize="end" + android:maxLines="2" + android:textColor="?android:attr/textColorSecondary" + style="?android:attr/textAppearanceSmallInverse" /> + +</com.android.calendar.AgendaItemView> diff --git a/src/com/android/calendar/AgendaAdapter.java b/src/com/android/calendar/AgendaAdapter.java index 1bce5acc..1b93b7e2 100644 --- a/src/com/android/calendar/AgendaAdapter.java +++ b/src/com/android/calendar/AgendaAdapter.java @@ -23,26 +23,29 @@ import android.provider.Calendar.Attendees; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.view.View; -import android.widget.FrameLayout; import android.widget.ResourceCursorAdapter; import android.widget.TextView; public class AgendaAdapter extends ResourceCursorAdapter { static private String mNoTitleLabel; // todo update on locale change. private Resources mResources; + private int mDeclinedColor; + + static class ViewHolder { + int overLayColor; // Used by AgendaItemView to gray out the entire item if so desired - private static class ViewHolder { /* Event */ - View stripe; TextView title; TextView when; TextView where; + int calendarColor; // Used by AgendaItemView to color the vertical stripe } public AgendaAdapter(Context context, int resource) { super(context, resource, null); mResources = context.getResources(); mNoTitleLabel = mResources.getString(R.string.no_title_label); + mDeclinedColor = mResources.getColor(R.drawable.agenda_item_declined); } @Override @@ -52,7 +55,6 @@ public class AgendaAdapter extends ResourceCursorAdapter { if (holder == null) { holder = new ViewHolder(); view.setTag(holder); - holder.stripe = view.findViewById(R.id.vertical_stripe); holder.title = (TextView) view.findViewById(R.id.title); holder.when = (TextView) view.findViewById(R.id.when); holder.where = (TextView) view.findViewById(R.id.where); @@ -60,19 +62,20 @@ public class AgendaAdapter extends ResourceCursorAdapter { // Fade text if event was declined. int selfAttendeeStatus = cursor.getInt(AgendaActivity.INDEX_SELF_ATTENDEE_STATUS); - boolean declined = (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED); + if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED) { + holder.overLayColor = mDeclinedColor; + } else { + holder.overLayColor = 0; + } - View stripe = holder.stripe; TextView title = holder.title; TextView when = holder.when; TextView where = holder.where; + /* Calendar Color */ int color = cursor.getInt(AgendaActivity.INDEX_COLOR); - ((FrameLayout) view).setForeground(declined ? - mResources.getDrawable(R.drawable.agenda_item_declined) : null); + holder.calendarColor = color; - stripe.setBackgroundColor(color); - // What String titleString = cursor.getString(AgendaActivity.INDEX_TITLE); if (titleString == null || titleString.length() == 0) { @@ -80,7 +83,7 @@ public class AgendaAdapter extends ResourceCursorAdapter { } title.setText(titleString); title.setTextColor(color); - + // When long begin = cursor.getLong(AgendaActivity.INDEX_BEGIN); long end = cursor.getLong(AgendaActivity.INDEX_END); @@ -97,16 +100,16 @@ public class AgendaAdapter extends ResourceCursorAdapter { } whenString = DateUtils.formatDateRange(context, begin, end, flags); when.setText(whenString); - + String rrule = cursor.getString(AgendaActivity.INDEX_RRULE); if (rrule != null) { - when.setCompoundDrawablesWithIntrinsicBounds(null, null, + when.setCompoundDrawablesWithIntrinsicBounds(null, null, context.getResources().getDrawable(R.drawable.ic_repeat_dark), null); when.setCompoundDrawablePadding(5); } else { when.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } - + /* // Repeating info View repeatContainer = view.findViewById(R.id.repeat_icon); @@ -117,7 +120,7 @@ public class AgendaAdapter extends ResourceCursorAdapter { repeatContainer.setVisibility(View.GONE); } */ - + /* // Reminder boolean hasAlarm = cursor.getInt(AgendaActivity.INDEX_HAS_ALARM) != 0; @@ -125,7 +128,7 @@ public class AgendaAdapter extends ResourceCursorAdapter { updateReminder(view, context, begin, cursor.getLong(AgendaActivity.INDEX_EVENT_ID)); } */ - + // Where String whereString = cursor.getString(AgendaActivity.INDEX_EVENT_LOCATION); if (whereString != null && whereString.length() > 0) { @@ -141,7 +144,7 @@ public class AgendaAdapter extends ResourceCursorAdapter { ContentResolver cr = context.getContentResolver(); Uri uri = Reminders.CONTENT_URI; String where = String.format(REMINDERS_WHERE, eventId); - + Cursor remindersCursor = cr.query(uri, REMINDERS_PROJECTION, where, null, null); if (remindersCursor != null) { LayoutInflater inflater = diff --git a/src/com/android/calendar/AgendaItemView.java b/src/com/android/calendar/AgendaItemView.java new file mode 100644 index 00000000..7419e1ad --- /dev/null +++ b/src/com/android/calendar/AgendaItemView.java @@ -0,0 +1,57 @@ +/* + * 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. + */ + +package com.android.calendar; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +import com.android.calendar.AgendaAdapter.ViewHolder; + +/** + * A custom layout for each item in the Agenda list view. + */ +public class AgendaItemView extends RelativeLayout { + Paint mPaint = new Paint(); + + public AgendaItemView(Context context) { + super(context); + } + + public AgendaItemView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void dispatchDraw(Canvas canvas) { + super.dispatchDraw(canvas); + ViewHolder holder = (ViewHolder) getTag(); + if (holder != null) { + /* Draw vertical color stripe */ + mPaint.setColor(holder.calendarColor); + canvas.drawRect(0, 0, 5, getHeight(), mPaint); + + /* Gray out item if the event was declined */ + if (holder.overLayColor != 0) { + mPaint.setColor(holder.overLayColor); + canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint); + } + } + } +} |