Skip to content

Commit

Permalink
new contact select UI
Browse files Browse the repository at this point in the history
  • Loading branch information
defrex committed Nov 1, 2010
1 parent cddac7f commit d438154
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 147 deletions.
2 changes: 1 addition & 1 deletion default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# project structure.

# Project target.
target=Google Inc.:Google APIs:3
target=Google Inc.:Google APIs:7
Binary file added res/drawable-hdpi/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions res/layout/user_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
android:id="@+id/user_list_item_avatar" />

<LinearLayout style="@style/UserListItemMiddle">
<TextView style="@style/UserListItemUsername"
android:id="@+id/user_list_item_username"
android:clickable="true" />
<LinearLayout style="@style/FullWidth"
android:orientation="horizontal">
<TextView style="@style/UserListItemUsername"
android:id="@+id/user_list_item_username"
android:clickable="true" />
<View style="@style/Spring"/>
<ImageView style="@style/WrapAll"
android:src="@drawable/star"
android:visibility="gone"
android:id="@+id/user_list_item_star"/>
</LinearLayout>
<TextView style="@style/UserListItemDetail"
android:id="@+id/user_list_item_detail"
android:visibility="gone"/>
Expand Down
2 changes: 1 addition & 1 deletion res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
<item name="android:orientation">vertical</item>
<item name="android:gravity">center_vertical</item>
</style>
<style name="UserListItemUsername" parent="FullWidth">
<style name="UserListItemUsername" parent="WrapAll">
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/link_blue</item>
<item name="android:textSize">18sp</item>
Expand Down
2 changes: 1 addition & 1 deletion src/com/connectsy/events/EventNew.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.connectsy.events.EventManager.Event;
import com.connectsy.events.attendants.AttendantManager;
import com.connectsy.settings.MainMenu;
import com.connectsy.users.UserManager.Contact;
import com.connectsy.users.ContactCursor.Contact;
import com.connectsy.users.UserManager.User;
import com.connectsy.utils.DateUtils;

Expand Down
14 changes: 2 additions & 12 deletions src/com/connectsy/events/attendants/AttendantManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.connectsy.data.DataManager;
import com.connectsy.data.ApiRequest.ApiRequestListener;
import com.connectsy.data.ApiRequest.Method;
import com.connectsy.users.UserManager.Contact;
import com.connectsy.users.ContactCursor.Contact;
import com.connectsy.users.UserManager.User;

public class AttendantManager extends DataManager implements ApiRequestListener {
Expand Down Expand Up @@ -170,20 +170,10 @@ public void bulkInvite(ArrayList<User> users, ArrayList<Contact> contacts,
kwargs.put("users", "friends");
}
if (contacts != null && contacts.size() > 0){
Log.d(TAG, "formatting contacts: "+contacts);
JSONArray jsonContacts = new JSONArray();
for (int i=0;i<contacts.size();i++){
String number = contacts.get(i).keyNumber;
if (number.length() == 10)
number += "1";
if (number.charAt(number.length()-1) != '+')
number += "+";
String revNumber = "";
for (int n=number.length()-1;n>=0;n--)
revNumber += number.charAt(n);

JSONObject c = new JSONObject();
c.put("number", revNumber);
c.put("number", contacts.get(i).normalizedNumber());
c.put("name", contacts.get(i).displayName);
jsonContacts.put(c);
}
Expand Down
171 changes: 171 additions & 0 deletions src/com/connectsy/users/ContactCursor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
*
*/
package com.connectsy.users;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Phone;

public class ContactCursor {

public static class Contact{
public String number;
public String displayNumber;
public String displayName;
public String lookupKey;
//public Long dbID;
public int type;
public String customType;
public String displayType;
public boolean stared;

public String normalizedNumber(){
String cleanNumber = "";
for (int n=0;n<number.length();n++){
char c = number.charAt(n);
if (Character.isDigit(c))
cleanNumber += c;
}
return cleanNumber;
}

public String toString(){
return "Contact: "+displayName+" number:"+number;
}

public static String serializeList(ArrayList<Contact> contacts){
JSONArray jsonContacts = new JSONArray();
try {
for (Contact contact: contacts){
JSONObject jsonContact = new JSONObject();
jsonContact.put("key_number", contact.number);
jsonContact.put("display_number", contact.displayNumber);
jsonContact.put("display_name", contact.displayName);
jsonContact.put("lookup_key", contact.lookupKey);
//jsonContact.put("db_id", contact.dbID);
jsonContact.put("type", contact.type);
jsonContact.put("custom_type", contact.customType);
jsonContact.put("display_type", contact.displayType);
jsonContact.put("stared", contact.stared);
jsonContacts.put(jsonContact);
}
} catch (JSONException e) {
e.printStackTrace();
}
return jsonContacts.toString();
}

public static ArrayList<Contact> deserializeList(String sContacts)
throws JSONException{
ArrayList<Contact> contacts = new ArrayList<Contact>();
JSONArray jsonContacts = new JSONArray(sContacts);
for(int i=0;i<jsonContacts.length();i++){
JSONObject jsonContact = jsonContacts.getJSONObject(i);
Contact contact = new Contact();
contact.number = jsonContact.getString("key_number");
contact.displayNumber = jsonContact.getString("display_number");
contact.displayName = jsonContact.getString("display_name");
contact.lookupKey = jsonContact.getString("lookup_key");
//contact.dbID = jsonContact.getLong("db_id");
contact.type = jsonContact.getInt("type");
contact.customType = jsonContact.getString("custom_type");
contact.displayType = jsonContact.getString("display_type");
contact.stared = jsonContact.getBoolean("stared");
contacts.add(contact);
}
return contacts;
}

public static Contact fromCursor(Context context, Cursor cursor){
Contact contact = new Contact();
contact.displayName = cursor.getString(
cursor.getColumnIndex(Data.DISPLAY_NAME));
contact.stared = (cursor.getInt(
cursor.getColumnIndex(Data.STARRED)) == 1);
contact.lookupKey = cursor.getString(
cursor.getColumnIndex(Data.LOOKUP_KEY));
// contact.dbID = cursor.getLong(
// cursor.getColumnIndex(Data._ID));
contact.number = cursor.getString(
cursor.getColumnIndex(Data.DATA1));
contact.type = cursor.getInt(
cursor.getColumnIndex(Data.DATA2));
contact.customType = cursor.getString(
cursor.getColumnIndex(Data.DATA3));
contact.displayNumber = formatNumber(contact);
contact.displayType = CommonDataKinds.Phone.getTypeLabel(
context.getResources(), contact.type, contact.customType)
.toString();
return contact;
}
}


@SuppressWarnings("unused")
private final static String TAG = "ContactCursor";
protected Cursor cursor;
protected Context context;

protected ContactCursor(Activity activity){
this.context = activity;
cursor = activity.managedQuery(Data.CONTENT_URI,
new String[]{
Data._ID,
Data.LOOKUP_KEY,
Data.DISPLAY_NAME,
Data.STARRED,
Data.MIMETYPE,
Data.DATA1,
Data.DATA2,
Data.DATA3,
},
Data.MIMETYPE+"='"+Phone.CONTENT_ITEM_TYPE+"'",
null,
Data.STARRED +" DESC, "+ Data.DISPLAY_NAME + " ASC");
}

public int getCount(){
return cursor.getCount();
}

public Contact next(){
cursor.moveToNext();
return getCurrentContact();
}

public Contact getAt(int position){
if (cursor.getCount() > position){
int curpos = cursor.getPosition();
cursor.moveToPosition(position);
Contact c = getCurrentContact();
cursor.moveToPosition(curpos);
return c;
}else{
return null;
}
}

protected Contact getCurrentContact(){
return Contact.fromCursor(context, cursor);
}

public static String formatNumber(Contact contact){
String resp = contact.normalizedNumber();
if (resp.length() == 11 && resp.charAt(0) == '1')
resp = resp.substring(1);
if (resp.length() == 10)
resp = new StringBuffer(resp).insert(3, "-").insert(7, "-").toString();

return resp;
}
}
44 changes: 0 additions & 44 deletions src/com/connectsy/users/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,48 +199,4 @@ public void onApiRequestFinish(int status, String response, int code) {
Log.d(TAG, "uploading avatar returned "+status+" with response "+response);
listener.onDataUpdate(returnCode, response);
}

public static class Contact{
public String keyNumber;
public String displayNumber;
public String displayName;
public Long personID;

public String toString(){
return "Contact: "+displayName+" k:"+keyNumber+" d:"+displayNumber;
}

public static String serializeList(ArrayList<Contact> contacts){
JSONArray jsonContacts = new JSONArray();
try {
for (Contact contact: contacts){
JSONObject jsonContact = new JSONObject();
jsonContact.put("key_number", contact.keyNumber);
jsonContact.put("display_number", contact.displayNumber);
jsonContact.put("display_name", contact.displayName);
jsonContact.put("person_id", contact.personID);
jsonContacts.put(jsonContact);
}
} catch (JSONException e) {
e.printStackTrace();
}
return jsonContacts.toString();
}

public static ArrayList<Contact> deserializeList(String sContacts)
throws JSONException{
ArrayList<Contact> contacts = new ArrayList<Contact>();
JSONArray jsonContacts = new JSONArray(sContacts);
for(int i=0;i<jsonContacts.length();i++){
JSONObject jsonContact = jsonContacts.getJSONObject(i);
Contact contact = new Contact();
contact.keyNumber = jsonContact.getString("key_number");
contact.displayNumber = jsonContact.getString("display_number");
contact.displayName = jsonContact.getString("display_name");
contact.personID = jsonContact.getLong("person_id");
contacts.add(contact);
}
return contacts;
}
}
}
Loading

0 comments on commit d438154

Please sign in to comment.