Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
exhuma committed Sep 1, 2009
1 parent 9502626 commit 60c617a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/lu/albert/android/contactbackup/RestoreThread.java
@@ -1,6 +1,7 @@
package lu.albert.android.contactbackup;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand All @@ -11,14 +12,18 @@
import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.provider.Contacts.Photos;

/**
* The thread which reads the input file and restores the contacts.
Expand Down Expand Up @@ -190,18 +195,20 @@ private void readStream(File in_file) {
*/
private void store_contact(JSONObject contact) throws JSONException {

ContentResolver cr = mParent.getContentResolver();

/*
* Store base values
*/
ContentValues values = new ContentValues();
values.put( People._ID, contact.getString("id") );
values.put( People.NAME, contact.getString("id") );
values.put( People.NAME, contact.getString("name") );
values.put( People.TIMES_CONTACTED, contact.getString("times_contacted") );
//values.put( People.DISPLAY_NAME, contact.getString("display_name") );
// TODO: values.put( People.DISPLAY_NAME, contact.getString("display_name") );
values.put( People.STARRED, contact.getInt("starred") );

Uri uri = Contacts.People
.createPersonInMyContactsGroup(mParent.getContentResolver(), values);
.createPersonInMyContactsGroup(cr, values);

if ( uri == null) {
return;
Expand All @@ -223,7 +230,7 @@ private void store_contact(JSONObject contact) throws JSONException {
values.put(People.Phones.TYPE, phone.getInt( "type" ));
values.put(People.Phones.NUMBER, phone.getString("number"));
values.put(People.Phones.ISPRIMARY, (phone.getBoolean("is_primary") ? 1 : 0));
mParent.getContentResolver().insert(phoneUri, values);
cr.insert(phoneUri, values);
}
phones = null;

Expand All @@ -233,10 +240,10 @@ private void store_contact(JSONObject contact) throws JSONException {
JSONArray photos = contact.getJSONArray("photos");
if ( photos.length() > 0 ) {
String photo = photos.getString(0);
if (photo != null ){
if (photo != null && !photo.equals("") ){
try {
Contacts.People.setPhotoData(mParent.getContentResolver(), uri, Base64.decode(photo));
System.out.println( "Added to " + uri );
Contacts.People.setPhotoData(cr, uri, Base64.decode(photo));
System.out.println( "Added photo to " + uri );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit 60c617a

Please sign in to comment.