Improved contacts performances
This commit is contained in:
parent
1a29c5ac72
commit
35bbf884ab
3 changed files with 71 additions and 30 deletions
|
@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,21 +31,31 @@ public class Contact implements Serializable {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private transient Uri photo;
|
private transient Uri photoUri;
|
||||||
|
private transient Bitmap photo;
|
||||||
private List<String> numerosOrAddresses;
|
private List<String> numerosOrAddresses;
|
||||||
|
|
||||||
public Contact(String id, String name) {
|
public Contact(String id, String name) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.photo = null;
|
this.photoUri = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact(String id, String name, Uri photo) {
|
public Contact(String id, String name, Uri photo) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.photo = photo;
|
this.photoUri = photo;
|
||||||
|
this.photo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Contact(String id, String name, Uri photo, Bitmap picture) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.photoUri = photo;
|
||||||
|
this.photo = picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
|
@ -55,7 +66,11 @@ public class Contact implements Serializable {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri getPhoto() {
|
public Uri getPhotoUri() {
|
||||||
|
return photoUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getPhoto() {
|
||||||
return photo;
|
return photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ContactFragment extends Fragment {
|
||||||
|
|
||||||
ImageView contactPicture = (ImageView) view.findViewById(R.id.contactPicture);
|
ImageView contactPicture = (ImageView) view.findViewById(R.id.contactPicture);
|
||||||
if (contact.getPhoto() != null) {
|
if (contact.getPhoto() != null) {
|
||||||
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, contact.getPhoto(), R.drawable.unknown_small);
|
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, contact.getPhotoUri(), R.drawable.unknown_small);
|
||||||
}
|
}
|
||||||
|
|
||||||
chatListener = getChatListener();
|
chatListener = getChatListener();
|
||||||
|
@ -81,7 +81,7 @@ public class ContactFragment extends Fragment {
|
||||||
return new OnClickListener() {
|
return new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LinphoneActivity.instance().setAddressAndGoToDialer(v.getTag().toString(), contact.getName(), contact.getPhoto());
|
LinphoneActivity.instance().setAddressAndGoToDialer(v.getTag().toString(), contact.getName(), contact.getPhotoUri());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -53,6 +55,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
private boolean onlyDisplayLinphoneCalls;
|
private boolean onlyDisplayLinphoneCalls;
|
||||||
private int lastKnownPosition;
|
private int lastKnownPosition;
|
||||||
private Cursor cursor;
|
private Cursor cursor;
|
||||||
|
private List<Contact> contacts;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -114,10 +117,45 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
contactsList.setAdapter(new ContactsListAdapter());
|
contactsList.setAdapter(new ContactsListAdapter());
|
||||||
contactsList.setFastScrollEnabled(true);
|
contactsList.setFastScrollEnabled(true);
|
||||||
}
|
}
|
||||||
|
contacts = new ArrayList<Contact>();
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (int i = 0; i < cursor.getCount(); i++) {
|
||||||
|
Contact contact = getContact(i);
|
||||||
|
contacts.add(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Contact getContact(int position) {
|
||||||
|
cursor.moveToFirst();
|
||||||
|
boolean success = cursor.move(position);
|
||||||
|
if (!success)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
|
||||||
|
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
||||||
|
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
|
||||||
|
Uri photo = Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
|
||||||
|
|
||||||
|
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getActivity().getContentResolver(), person);
|
||||||
|
Contact contact;
|
||||||
|
if (input == null) {
|
||||||
|
contact = new Contact(id, name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
contact = new Contact(id, name, photo, BitmapFactory.decodeStream(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
contact.setNumerosOrAddresses(ContactHelper.extractContactNumbersAndAddresses(contact.getID(), getActivity().getContentResolver()));
|
||||||
|
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
|
||||||
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
||||||
private AlphabetIndexer indexer;
|
private AlphabetIndexer indexer;
|
||||||
private int margin;
|
private int margin;
|
||||||
|
@ -134,28 +172,11 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
cursor.moveToFirst();
|
if (position >= contacts.size()) {
|
||||||
boolean success = cursor.move(position);
|
return getContact(position);
|
||||||
if (!success)
|
} else {
|
||||||
return null;
|
return contacts.get(position);
|
||||||
|
}
|
||||||
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
|
|
||||||
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
|
||||||
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
|
|
||||||
Uri photo = Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
|
|
||||||
|
|
||||||
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getActivity().getContentResolver(), person);
|
|
||||||
Contact contact;
|
|
||||||
if (input == null) {
|
|
||||||
contact = new Contact(id, name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
contact = new Contact(id, name, photo);
|
|
||||||
}
|
|
||||||
|
|
||||||
contact.setNumerosOrAddresses(ContactHelper.extractContactNumbersAndAddresses(contact.getID(), getActivity().getContentResolver()));
|
|
||||||
|
|
||||||
return contact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
|
@ -171,7 +192,10 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
view = mInflater.inflate(R.layout.contact_cell, parent, false);
|
view = mInflater.inflate(R.layout.contact_cell, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact contact = (Contact) getItem(position);
|
Contact contact = null;
|
||||||
|
do {
|
||||||
|
contact = (Contact) getItem(position);
|
||||||
|
} while (contact == null);
|
||||||
|
|
||||||
TextView name = (TextView) view.findViewById(R.id.name);
|
TextView name = (TextView) view.findViewById(R.id.name);
|
||||||
name.setText(contact.getName());
|
name.setText(contact.getName());
|
||||||
|
@ -189,7 +213,9 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
|
|
||||||
ImageView icon = (ImageView) view.findViewById(R.id.icon);
|
ImageView icon = (ImageView) view.findViewById(R.id.icon);
|
||||||
if (contact.getPhoto() != null) {
|
if (contact.getPhoto() != null) {
|
||||||
icon.setImageURI(contact.getPhoto());
|
icon.setImageBitmap(contact.getPhoto());
|
||||||
|
} else if (contact.getPhotoUri() != null) {
|
||||||
|
icon.setImageURI(contact.getPhotoUri());
|
||||||
} else {
|
} else {
|
||||||
icon.setImageBitmap(bitmapUnknown);
|
icon.setImageBitmap(bitmapUnknown);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue