Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d34748f9 authored by Wysie's avatar Wysie
Browse files

Edit contact groups about 60% done. Not finished yet. It displays and checks...

Edit contact groups about 60% done. Not finished yet. It displays and checks the groups the users are in, but it does not commit any changes.
parent 37d1839c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -985,12 +985,12 @@ public final class ContactsListActivity extends ListActivity
            		AlertDialog.Builder alert = new AlertDialog.Builder(this);
            		alert.setTitle(R.string.alert_clear_freq_called);
            		alert.setMessage(R.string.alert_clear_freq_called_msg);
            		alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            		alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
    				public void onClick(DialogInterface dialog, int whichButton) {
    					clearFrequentlyCalled();
    				}
    			});
	    		alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
	    		alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
		    		public void onClick(DialogInterface dialog, int whichButton) {
    				// Canceled.
    			}});
+114 −1
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.provider.Contacts;
import android.provider.Contacts.ContactMethods;
import android.provider.Contacts.Intents.Insert;
import android.provider.Contacts.Groups;
import android.provider.Contacts.GroupMembership;
import android.provider.Contacts.Organizations;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
@@ -105,7 +106,7 @@ import java.util.ArrayList;
 * background while this activity is running, the updates will be overwritten.
 */
public final class EditContactActivity extends Activity implements View.OnClickListener,
        TextWatcher, View.OnFocusChangeListener {
        TextWatcher, View.OnFocusChangeListener, DialogInterface.OnMultiChoiceClickListener, DialogInterface.OnClickListener {
    private static final String TAG = "EditContactActivity";

    private static final int STATE_UNKNOWN = 0;
@@ -193,6 +194,8 @@ public final class EditContactActivity extends Activity implements View.OnClickL
    /* package */ static final int MSG_ADD_EMAIL = 4;
    /* package */ static final int MSG_ADD_POSTAL = 5;
    
    private Context context;

    private static final int[] TYPE_PRECEDENCE_PHONES = new int[] {
            Phones.TYPE_MOBILE, Phones.TYPE_HOME, Phones.TYPE_WORK, Phones.TYPE_OTHER
    };
@@ -351,6 +354,8 @@ public final class EditContactActivity extends Activity implements View.OnClickL
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        
        context = this;

        mResolver = getContentResolver();

        // Build the list of sections
@@ -1557,10 +1562,37 @@ public final class EditContactActivity extends Activity implements View.OnClickL
        buildViewsForSection(layout, mNoteEntries,
                R.string.label_notes, SECTION_NOTE);
                
        buildGroupView(layout, R.string.listSeparatorGroup);
        
        buildOtherViews(layout, mOtherEntries);
    }

	    
    private void buildGroupView(final LinearLayout layout, int separatorResource) {
    	View divider = mInflater.inflate(R.layout.edit_divider, layout, false);
    	layout.addView(divider);
    	
    	ViewGroup header = (ViewGroup) mInflater.inflate(R.layout.edit_separator_group, layout, false);    	    	
    	TextView text = (TextView)header.findViewById(R.id.text);
    	text.setText(getText(separatorResource));
    	header.setOnFocusChangeListener(this);
    	
    	header.setOnClickListener(new View.OnClickListener() {
    		public void onClick(View v) {
    			AlertDialog.Builder builder = new AlertDialog.Builder(context)
                    	.setTitle(R.string.select_group_title)
                    	.setPositiveButton(android.R.string.ok, null)
                    	.setNegativeButton(android.R.string.cancel, null);
                    	
                    	setGroupEntries(builder);
                	builder.show();
    		}    		
    	});
    	
    	layout.addView(header);
    }


    /**
     * Builds the views for a specific section.
     * 
@@ -2290,4 +2322,85 @@ public final class EditContactActivity extends Activity implements View.OnClickL
        // views as they are focused.
        v.setSelected(hasFocus);
    }
    
    private void setGroupEntries(AlertDialog.Builder builder) {
        final String[] GROUPS_PROJECTION = new String[] {
        	Groups.SYSTEM_ID, // 0
        	Groups.NAME, // 1
    	};
    	
    	CharSequence[] groupsCharSeq;
    	Cursor cursor;
        cursor = getContentResolver().query(Groups.CONTENT_URI, GROUPS_PROJECTION,
                    null, null, Groups.DEFAULT_SORT_ORDER);
    	try {
            ArrayList<CharSequence> groups = new ArrayList<CharSequence>();
            ArrayList<CharSequence> prefStrings = new ArrayList<CharSequence>();
            
            if (cursor.moveToFirst()) {
            	while (cursor.moveToNext()) {            
	                String name = cursor.getString(cursor.getColumnIndex(Groups.NAME));
        	        groups.add(name);                
        	}
       	    }
            
            groupsCharSeq = groups.toArray(new CharSequence[groups.size()]);
            
            ArrayList<CharSequence> currentMembership = new ArrayList<CharSequence>();            
                        
            long personId = ContentUris.parseId(mUri);
            final String[] GROUP_MEMBERSHIP_PROJECTION = new String[] {
        	GroupMembership.GROUP_ID,
        	GroupMembership.PERSON_ID
       	    };
            
            Cursor groupCursor = getContentResolver().query(GroupMembership.CONTENT_URI, GROUP_MEMBERSHIP_PROJECTION,
        	GroupMembership.PERSON_ID + "='" + personId + "'", null, null);
            Cursor cur = null;
            
             if (groupCursor != null) {
        	while (groupCursor.moveToNext()) {
        		cur = mResolver.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
        			Contacts.Groups._ID + "='" + groupCursor.getString(groupCursor.getColumnIndex(GroupMembership.GROUP_ID)) + "'",
        			null, null);
        		if (cur != null) {
        			if (cur.moveToFirst()) {
        				currentMembership.add(cur.getString(cur.getColumnIndex(Groups.NAME)));
        			}
        		}
        	}
        	cur.close();
        	groupCursor.close();
    	
             }
             
             boolean[] checkedValues = new boolean[groups.size()];
             
             for (boolean b : checkedValues)
             	b = false;
             	
             for (int i = 0; i < currentMembership.size(); i++) {
             	int j = groups.indexOf(currentMembership.get(i));
             	if (j != -1)
             		checkedValues[j] = true;
             }            
            
            builder.setMultiChoiceItems(groupsCharSeq, checkedValues, this);
            
        } finally {
            cursor.close();
        }
    }
    
    public void onClick(DialogInterface dialogInterface, int which) {
    	if (which == DialogInterface.BUTTON_POSITIVE) {

        } else {            
        	dialogInterface.dismiss();
        }
    }
    
    public void onClick(DialogInterface dialogInterface, int which, boolean isChecked) {

    }
}
+2 −2
Original line number Diff line number Diff line
@@ -1043,12 +1043,12 @@ public class RecentCallsListActivity extends ListActivity
    		AlertDialog.Builder alert = new AlertDialog.Builder(this);
    		alert.setTitle(R.string.alert_clear_call_log_title);
    		alert.setMessage("Are you sure you want to clear all call records of " + label + "?"); //Text, eg. show "Private" instead of -1 :P
    		alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    		alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
    			public void onClick(DialogInterface dialog, int whichButton) {
    				deleteCallLog(t + "='" + v + "'", null);
    			}
    		});
    		alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    		alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

    		public void onClick(DialogInterface dialog, int whichButton) {
    			// Canceled.
+11 −14
Original line number Diff line number Diff line
@@ -1097,8 +1097,10 @@ public class ViewContactActivity extends ListActivity
        	GroupMembership.PERSON_ID + "='" + personId + "'", null, null);
        Cursor cur = null;
        
        if (groupCursor.moveToFirst()) {
        	do {
        groupNamesArray.clear();
        
        if (groupCursor != null) {
        	while (groupCursor.moveToNext()) {
        		cur = mResolver.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
        			Contacts.Groups._ID + "='" + groupCursor.getString(groupCursor.getColumnIndex(GroupMembership.GROUP_ID)) + "'",
        			null, null);
@@ -1107,14 +1109,10 @@ public class ViewContactActivity extends ListActivity
        				groupNamesArray.add(cur.getString(cur.getColumnIndex(Groups.NAME)));
        			}
        		}
        		
        	} while (groupCursor.moveToNext());        
        	
        	}
        	cur.close();
        	
        	//sort group names by alphabetical ascending order
        	groupCursor.close();        	
        	java.util.Collections.sort(groupNamesArray);        	
        	
        	StringBuilder groups = new StringBuilder();
        	
        	for (int i = 0; i < groupNamesArray.size(); i++) {
@@ -1124,6 +1122,8 @@ public class ViewContactActivity extends ListActivity
        			groups.append("\n" + groupNamesArray.get(i));
        	}
        	
        	//Log.d("Testing", groups.toString());
        	
        	ViewEntry entry = new ViewEntry();
        	entry.label = getString(R.string.view_contact_groups);
        	entry.data = groups.toString();
@@ -1131,9 +1131,6 @@ public class ViewContactActivity extends ListActivity
        	entry.maxLines = 10;
		mGroupEntries.add(entry);        	
        }
        
        groupCursor.close();
        
    }

    String buildActionString(int actionResId, CharSequence type, boolean lowerCase) {