ChipsUtil.java revision 7537f840506bcb642bed9dc1c2bdcf6d31c6b2a7
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.ex.chips; 18 19import android.content.ContentResolver; 20import android.content.ContentUris; 21import android.content.ContentValues; 22import android.content.Context; 23import android.net.Uri; 24import android.os.Build; 25import android.provider.ContactsContract.Contacts; 26import android.provider.ContactsContract.Data; 27import android.text.TextUtils; 28 29import java.util.Collection; 30 31public class ChipsUtil { 32 33 /** 34 * @return true when the caller can use Chips UI in its environment. 35 */ 36 public static boolean supportsChipsUi() { 37 // TODO: should use Build.VERSION_SDK_INT when it is determined. 38 return TextUtils.equals("IceCreamSandwich", Build.VERSION.RELEASE); 39 } 40 41 // TODO: check this works 42 public static void updateRecencyInfo(RecipientEditTextView view) { 43 final Context context = view.getContext(); 44 final ContentResolver resolver = context.getContentResolver(); 45 final long currentTimeMillis = System.currentTimeMillis(); 46 47 final Collection<Integer> contactIds = view.getContactIds(); 48 if (contactIds != null) { 49 for (Integer contactId : contactIds) { 50 final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 51 final ContentValues values = new ContentValues(); 52 values.put(Contacts.LAST_TIME_CONTACTED, currentTimeMillis); 53 resolver.update(uri, values, null, null); 54 } 55 } 56 57 /* Not effective yet. 58 final Collection<Integer> dataIds = view.getDataIds(); 59 if (dataIds != null) { 60 for (Integer dataId : dataIds) { 61 Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, dataId); 62 final ContentValues values = new ContentValues(); 63 values.put("last_time_contacted", currentTimeMillis); 64 resolver.update(uri, values, null, null); 65 } 66 }*/ 67 } 68}