/**
 * ZRTP.org is a ZRTP protocol implementation  
 * Copyright (C) 2012 - PrivateWave Italia S.p.A.
 * 
 * This  program  is free software:  you can  redistribute it and/or
 * modify  it  under  the terms  of  the  GNU Affero  General Public
 * License  as  published  by the  Free Software Foundation,  either 
 * version 3 of the License,  or (at your option) any later version.
 * 
 * This program is  distributed in  the hope that it will be useful,
 * but WITHOUT ANY WARRANTY;  without even  the implied  warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 * Affero General Public License for more details.
 * 
 * You should have received a copy of the  GNU Affero General Public
 * License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information, please contact PrivateWave Italia S.p.A. at
 * address zorg@privatewave.com or http://www.privatewave.com 
 */
package zorg.platform.j2se;

import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract.PhoneLookup;

public class ContactLookup {

	String name;
	String number;
	Boolean isOnUserAddressBook = false;

	/**
	 * Search for a phone number on the Android AddressBook
	 * 
	 * @param number PhoneNumber
	 */
	public ContactLookup(String number) {
		this.name = number;
		this.number = number;

		if (!number.equals("")) {
			if (number.startsWith("+"))
				number = number.substring(1);
			Cursor c = ((PlatformImpl) PlatformImpl.getInstance()).getApplication()
					.getApplicationContext()
					.getContentResolver()
					.query(Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
							Uri.encode(number)),
							new String[] { PhoneLookup.DISPLAY_NAME }, null, null,
							null);
			
			if (c.getCount() > 0) {
				isOnUserAddressBook = true;
			}
	
	
			while (c.moveToNext())
				this.name = c.getString(c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
			
			c.close();
		}
		
		
	}

	/**
	 * Returns the contact name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the contact phone number
	 */
	public String getNumber() {
		return number;
	}
	
	/**
	 * Returns true if the contact is on the user address book
	 */
	public boolean isOnUserAddressBook() {
		return isOnUserAddressBook;
	}

}

@@ -991,123 +991,8 @@
 %0D%0A%0D%0A
-import android.database.Cursor;%0D%0Aimport android.net.Uri;%0D%0Aimport android.provider.ContactsContract.PhoneLookup;%0D%0A%0D%0A
 publ
@@ -1290,633 +1290,8 @@
 er;%0D
-%0A%0D%0A%09%09if (!number.equals(%22%22)) %7B%0D%0A%09%09%09if (number.startsWith(%22+%22))%0D%0A%09%09%09%09number = number.substring(1);%0D%0A%09%09%09Cursor c = ((PlatformImpl) PlatformImpl.getInstance()).getApplication()%0D%0A%09%09%09%09%09.getApplicationContext()%0D%0A%09%09%09%09%09.getContentResolver()%0D%0A%09%09%09%09%09.query(Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,%0D%0A%09%09%09%09%09%09%09Uri.encode(number)),%0D%0A%09%09%09%09%09%09%09new String%5B%5D %7B PhoneLookup.DISPLAY_NAME %7D, null, null,%0D%0A%09%09%09%09%09%09%09null);%0D%0A%09%09%09%0D%0A%09%09%09if (c.getCount() %3E 0) %7B%0D%0A%09%09%09%09isOnUserAddressBook = true;%0D%0A%09%09%09%7D%0D%0A%09%0D%0A%09%0D%0A%09%09%09while (c.moveToNext())%0D%0A%09%09%09%09this.name = c.getString(c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));%0D%0A%09%09%09%0D%0A%09%09%09c.close();%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09%0D
 %0A%09%7D%0D

Remove Android-specific contact support (no longer supports any contact backend)