integrate chips ui into calendar.

Makes edit event display chips UI. We still need final design
to decide if we're going to display a full list of guests in
tablets like we currently do or just the chips. Leaving with
current behavior but showing chips in the edit box for now.

Change-Id: Ia045bbdc3326dca9056070ae0ebc75a7a5b2f5ba
This commit is contained in:
Mindy Pereira 2011-06-09 18:31:23 -07:00 committed by RoboErik
parent 4573e93f0d
commit 18cabd263b
7 changed files with 124 additions and 11 deletions

View File

@ -1,6 +1,10 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# Include res dir from chips
chips_dir := ../../../frameworks/ex/chips/res
res_dirs := $(chips_dir) res
LOCAL_EMMA_COVERAGE_FILTER := +com.android.calendar.*
LOCAL_MODULE_TAGS := optional
@ -8,16 +12,19 @@ LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under,src)
# bundled
LOCAL_STATIC_JAVA_LIBRARIES += android-common
LOCAL_STATIC_JAVA_LIBRARIES += android-common android-common-chips
# unbundled
#LOCAL_STATIC_JAVA_LIBRARIES := android-common
#LOCAL_STATIC_JAVA_LIBRARIES := android-common android-common-chips
#LOCAL_SDK_VERSION := current
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))
LOCAL_PACKAGE_NAME := Calendar
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.

View File

@ -82,7 +82,7 @@
android:id="@+id/add_attendees_group"
android:orientation="horizontal">
<!-- ATTENDEES INPUT -->
<MultiAutoCompleteTextView
<com.android.ex.chips.RecipientEditTextView
android:id="@+id/attendees"
android:layout_width="0dip"
android:layout_height="wrap_content"

View File

@ -103,7 +103,7 @@
android:layout_width="match_parent"
android:orientation="horizontal">
<!-- ATTENDEES INPUT -->
<MultiAutoCompleteTextView
<com.android.ex.chips.RecipientEditTextView
android:id="@+id/attendees"
android:layout_width="0dip"
android:layout_height="wrap_content"

View File

@ -16,6 +16,9 @@
package com.android.calendar;
import com.android.calendar.event.EditEventHelper;
import com.android.common.Rfc822Validator;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -24,11 +27,14 @@ import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Reminders;
import android.text.TextUtils;
import android.text.util.Rfc822Token;
import android.widget.AutoCompleteTextView;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.TimeZone;
/**
@ -409,6 +415,20 @@ public class CalendarEventModel implements Serializable {
mAttendeesList.put(attendee.mEmail, attendee);
}
public void addAttendees(String attendees, Rfc822Validator validator) {
final LinkedHashSet<Rfc822Token> addresses = EditEventHelper.getAddressesFromList(
attendees, validator);
synchronized (this) {
for (final Rfc822Token address : addresses) {
final Attendee attendee = new Attendee(address.getName(), address.getAddress());
if (TextUtils.isEmpty(attendee.mName)) {
attendee.mName = attendee.mEmail;
}
addAttendee(attendee);
}
}
}
public void removeAttendee(Attendee attendee) {
mAttendeesList.remove(attendee.mEmail);
}

View File

@ -17,6 +17,7 @@
package com.android.calendar;
import com.android.common.contacts.BaseEmailAddressAdapter;
import com.android.ex.chips.AccountSpecifier;
import android.content.Context;
import android.text.TextUtils;
@ -30,7 +31,7 @@ import android.widget.TextView;
* purpose of the class is to bind the generic implementation to the resources
* defined locally: strings and layouts.
*/
public class EmailAddressAdapter extends BaseEmailAddressAdapter {
public class EmailAddressAdapter extends BaseEmailAddressAdapter implements AccountSpecifier {
private LayoutInflater mInflater;

View File

@ -0,0 +1,60 @@
/*
* Copyright (C) 2011 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 com.android.ex.chips.BaseRecipientAdapter;
import android.accounts.Account;
import android.content.Context;
public class RecipientAdapter extends BaseRecipientAdapter {
public RecipientAdapter(Context context) {
super(context);
}
/**
* Set the account when known. Causes the search to prioritize contacts from
* that account.
*/
public void setAccount(Account account) {
if (account != null) {
// TODO: figure out how to infer the contacts account
// type from the email account
super.setAccount(new android.accounts.Account(account.name, "unknown"));
}
}
@Override
protected int getDefaultPhotoResource() {
return R.drawable.ic_contact_picture;
}
@Override
protected int getItemLayout() {
return R.layout.chips_recipient_dropdown_item;
}
@Override
protected int getSeparatorLayout() {
return R.layout.chips_separator;
}
@Override
protected int getSeparatorWithinGroupLayout() {
return R.layout.chips_separator_within_group;
}
}

View File

@ -23,12 +23,17 @@ import com.android.calendar.EmailAddressAdapter;
import com.android.calendar.EventInfoFragment;
import com.android.calendar.GeneralPreferences;
import com.android.calendar.R;
import com.android.calendar.RecipientAdapter;
import com.android.calendar.TimezoneAdapter;
import com.android.calendar.TimezoneAdapter.TimezoneRow;
import com.android.calendar.Utils;
import com.android.calendar.event.EditEventHelper.EditDoneRunnable;
import com.android.common.Rfc822InputFilter;
import com.android.common.Rfc822Validator;
import com.android.ex.chips.AccountSpecifier;
import com.android.ex.chips.BaseRecipientAdapter;
import com.android.ex.chips.ChipsUtil;
import com.android.ex.chips.RecipientEditTextView;
import android.app.Activity;
import android.app.AlertDialog;
@ -44,6 +49,8 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.pim.EventRecurrence;
import android.provider.CalendarContract.Attendees;
@ -153,7 +160,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
private View mView;
private CalendarEventModel mModel;
private Cursor mCalendarsCursor;
private EmailAddressAdapter mAddressAdapter;
private AccountSpecifier mAddressAdapter;
private Rfc822Validator mEmailValidator;
private TimezoneAdapter mTimezoneAdapter;
@ -977,8 +984,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
mModel = model;
// Need to close the autocomplete adapter to prevent leaking cursors.
if (mAddressAdapter != null) {
mAddressAdapter.close();
if (mAddressAdapter != null && mAddressAdapter instanceof EmailAddressAdapter) {
((EmailAddressAdapter)mAddressAdapter).close();
mAddressAdapter = null;
}
@ -1033,7 +1040,6 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
domain = ownerDomain;
}
}
mAddressAdapter = new EmailAddressAdapter(mActivity);
mEmailValidator = new Rfc822Validator(domain);
mAttendeesList = initMultiAutoCompleteTextView(R.id.attendees);
mAttendeesList.addTextChangedListener(this);
@ -1456,8 +1462,27 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
// From com.google.android.gm.ComposeActivity
private MultiAutoCompleteTextView initMultiAutoCompleteTextView(int res) {
MultiAutoCompleteTextView list = (MultiAutoCompleteTextView) mView.findViewById(res);
list.setAdapter(mAddressAdapter);
RecipientEditTextView list = (RecipientEditTextView) mView.findViewById(res);
if (ChipsUtil.supportsChipsUi()) {
mAddressAdapter = new RecipientAdapter(mActivity);
list.setAdapter((BaseRecipientAdapter) mAddressAdapter);
Resources r = mActivity.getResources();
Bitmap def = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture);
list.setChipDimensions(
r.getDrawable(R.drawable.chip_background),
r.getDrawable(R.drawable.chip_background_selected),
r.getDrawable(R.drawable.chip_background_invalid),
r.getDrawable(R.drawable.chip_delete),
def,
R.string.more_string,
R.layout.chips_alternate_item,
r.getDimension(R.dimen.chip_height),
r.getDimension(R.dimen.chip_padding),
r.getDimension(R.dimen.chip_text_size));
} else {
mAddressAdapter = new EmailAddressAdapter(mActivity);
list.setAdapter((EmailAddressAdapter)mAddressAdapter);
}
list.setTokenizer(new Rfc822Tokenizer());
list.setValidator(mEmailValidator);