Initial checkin of AOSP Messaging app.

b/23110861

Change-Id: I9aa980d7569247d6b2ca78f5dcb4502e1eaadb8a
This commit is contained in:
Mike Dodd
2015-08-12 08:58:28 -07:00
parent 8b3e2b9c1b
commit 461a34b466
1645 changed files with 186271 additions and 0 deletions
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2015 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.messaging.ui.contact;
import android.content.Context;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.support.v4.text.BidiFormatter;
import android.support.v4.text.TextDirectionHeuristicsCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.android.ex.chips.DropdownChipLayouter;
import com.android.ex.chips.RecipientEntry;
import com.android.messaging.R;
import com.android.messaging.datamodel.data.ContactListItemData;
import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.ui.ContactIconView;
import com.android.messaging.util.Assert;
import com.android.messaging.util.AvatarUriUtil;
import com.android.messaging.util.ContactRecipientEntryUtils;
/**
* An implementation for {@link DropdownChipLayouter}. Layouts the dropdown
* list in the ContactRecipientAutoCompleteView in Material style.
*/
public class ContactDropdownLayouter extends DropdownChipLayouter {
private final ContactListItemView.HostInterface mClivHostInterface;
public ContactDropdownLayouter(final LayoutInflater inflater, final Context context,
final ContactListItemView.HostInterface clivHostInterface) {
super(inflater, context);
mClivHostInterface = new ContactListItemView.HostInterface() {
@Override
public void onContactListItemClicked(final ContactListItemData item,
final ContactListItemView view) {
// The chips UI will handle auto-complete item click events, so No-op here.
}
@Override
public boolean isContactSelected(final ContactListItemData item) {
// In chips drop down we don't show any selected checkmark per design.
return false;
}
};
}
/**
* Bind a drop down view to a RecipientEntry. We'd like regular dropdown items (BASE_RECIPIENT)
* to behave the same as regular ContactListItemViews, while using the chips library's
* item styling for alternates dropdown items (happens when you click on a chip).
*/
@Override
public View bindView(final View convertView, final ViewGroup parent, final RecipientEntry entry,
final int position, AdapterType type, final String substring,
final StateListDrawable deleteDrawable) {
if (type != AdapterType.BASE_RECIPIENT) {
if (type == AdapterType.SINGLE_RECIPIENT) {
// Treat single recipients the same way as alternates. The base implementation of
// single recipients would try to simplify the destination by tokenizing. We'd
// like to always show the full destination address per design request.
type = AdapterType.RECIPIENT_ALTERNATES;
}
return super.bindView(convertView, parent, entry, position, type, substring,
deleteDrawable);
}
// Default to show all the information
// RTL : To format contact name and detail if they happen to be phone numbers.
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
final String displayName = bidiFormatter.unicodeWrap(
ContactRecipientEntryUtils.getDisplayNameForContactList(entry),
TextDirectionHeuristicsCompat.LTR);
final String destination = bidiFormatter.unicodeWrap(
ContactRecipientEntryUtils.formatDestination(entry),
TextDirectionHeuristicsCompat.LTR);
final View itemView = reuseOrInflateView(convertView, parent, type);
// Bold the string that is matched.
final CharSequence[] styledResults =
getStyledResults(substring, displayName, destination);
Assert.isTrue(itemView instanceof ContactListItemView);
final ContactListItemView contactListItemView = (ContactListItemView) itemView;
contactListItemView.setImageClickHandlerDisabled(true);
contactListItemView.bind(entry, styledResults[0], styledResults[1],
mClivHostInterface, (type == AdapterType.SINGLE_RECIPIENT));
return itemView;
}
@Override
protected void bindIconToView(boolean showImage, RecipientEntry entry, ImageView view,
AdapterType type) {
if (showImage && view instanceof ContactIconView) {
final ContactIconView contactView = (ContactIconView) view;
// These show contact cards by default, but that isn't what we want here
contactView.setImageClickHandlerDisabled(true);
final Uri avatarUri = AvatarUriUtil.createAvatarUri(
ParticipantData.getFromRecipientEntry(entry));
contactView.setImageResourceUri(avatarUri);
} else {
super.bindIconToView(showImage, entry, view, type);
}
}
@Override
protected int getItemLayoutResId(AdapterType type) {
switch (type) {
case BASE_RECIPIENT:
return R.layout.contact_list_item_view;
case RECIPIENT_ALTERNATES:
return R.layout.chips_alternates_dropdown_item;
default:
return R.layout.chips_alternates_dropdown_item;
}
}
@Override
protected int getAlternateItemLayoutResId(AdapterType type) {
return getItemLayoutResId(type);
}
}