Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquarg committed Jun 26, 2015
1 parent 6548326 commit 32e8a5c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 133 deletions.
41 changes: 4 additions & 37 deletions src/android/ContactAccessorSdk5.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
dbMap.put("birthday", ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE);
dbMap.put("note", ContactsContract.CommonDataKinds.Note.NOTE);
dbMap.put("photos.value", ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
//dbMap.put("categories.value", null);
dbMap.put("urls", ContactsContract.CommonDataKinds.Website.URL);
dbMap.put("urls.value", ContactsContract.CommonDataKinds.Website.URL);

Expand Down Expand Up @@ -188,10 +187,6 @@ public JSONArray search(JSONArray fields, JSONObject options) {
}


// Log.d(LOG_TAG, "Search Term = " + searchTerm);
//Log.d(LOG_TAG, "Field Length = " + fields.length());
//Log.d(LOG_TAG, "Fields = " + fields.toString());

// Loop through the fields the user provided to see what data should be returned.
HashMap<String, Boolean> populate = buildPopulationSet(options);

Expand Down Expand Up @@ -331,13 +326,10 @@ public JSONObject getContactById(String id) throws JSONException {
public JSONObject getContactById(String id, JSONArray desiredFields) throws JSONException {
// Do the id query
Cursor c = mApp.getActivity().getContentResolver().query(
// ContactsContract.Data.CONTENT_URI,
RawContactsEntity.CONTENT_URI,
null,
// ContactsContract.Data.RAW_CONTACT_ID + " = ? ",
ContactsContract.RawContacts._ID + " = ? ",
new String[] { id },
// ContactsContract.Data.RAW_CONTACT_ID + " ASC");
ContactsContract.RawContacts.Data._ID + " ASC");

HashMap<String, Boolean> populate = buildPopulationSet(
Expand Down Expand Up @@ -390,7 +382,6 @@ private JSONArray populateContactArray(int limit,

// Column indices
int colContactId = c.getColumnIndex(ContactsContract.Data.CONTACT_ID);
// int colRawContactId = c.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID);
int colRawContactId = c.getColumnIndex(ContactsContract.RawContacts._ID);
int colMimetype = c.getColumnIndex(ContactsContract.Data.MIMETYPE);
int colDisplayName = c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME);
Expand Down Expand Up @@ -436,7 +427,6 @@ private JSONArray populateContactArray(int limit,
emails, ims, websites, photos));



// Clean up the objects
contact = new JSONObject();
organizations = new JSONArray();
Expand Down Expand Up @@ -687,7 +677,6 @@ private WhereOptions buildWhereClause(JSONArray fields, String searchTerm, Strin

String key;
try {
//Log.d(LOG_TAG, "How many fields do we have = " + fields.length());
for (int i = 0; i < fields.length(); i++) {
key = fields.getString(i);

Expand Down Expand Up @@ -1034,23 +1023,12 @@ private JSONObject photoQuery(Cursor cursor, String rawContactId) {

byte[] photoBlob = cursor.getBlob(cursor.getColumnIndex(
ContactsContract.CommonDataKinds.Photo.PHOTO));
if (photoBlob == null) {
return null;
}

photo.put("value", Base64.encodeToString(photoBlob, Base64.DEFAULT));

// photo.put("type", "url");
// Uri person = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, (Long.valueOf(rawContactId)));
// Uri photoUri = Uri.withAppendedPath(person, ContactsContract.RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
// photo.put("value", photoUri.toString());

// // Query photo existance
// Cursor photoCursor = mApp.getActivity().getContentResolver().query(photoUri, new String[] {ContactsContract.Contacts.Photo.PHOTO}, null, null, null);
// if (photoCursor == null) {
// return null;
// } else {
// if (!photoCursor.moveToFirst()) {
// photoCursor.close();
// return null;
// }
// }
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
Expand Down Expand Up @@ -1151,17 +1129,6 @@ private String modifyContact(String id, JSONObject contact, String accountType,
// Create a list of attributes to add to the contact database
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();


// TODO: really dangerous : move all contact to accountYpe, accountName.
// May come from examples in android doc, useless (unless change account
// of a app).
//
//Add contact type
// ops.add(ContentProviderOperation.newUpdate(ContactsContract.RawContacts.CONTENT_URI)
// .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, accountType)
// .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, accountName)
// .build());

// Modify name
JSONObject name;
try {
Expand Down
40 changes: 26 additions & 14 deletions src/android/ContactManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ public void run() {
else if (action.equals("pickContact")) {
pickContactAsync();
}
// TODO : cleanup !
else if (action.equals("createAccount")) {
createAccount();
final String accountName = args.getString(0);
final String accountType = args.getString(1);
createAccount(accountName, accountType);

callbackContext.success();
// listAccounts();
}
else if (action.equals("listAccounts")) {
JSONArray accounts = listAccounts();
callbackContext.success(accounts);
}

else {
Expand All @@ -160,29 +165,36 @@ else if (action.equals("createAccount")) {
return true;
}

// TODO !!
private void createAccount() {

private void createAccount(String accountName, String accountType) {
AccountManager accountManager = AccountManager.get(ContactManager.this.cordova.getActivity());

// Create account if not exist.
for (Account c: accountManager.getAccounts()) {
Log.d("CordovaContacts", c.type + ", " + c.name);
if ("io.cozy".equals(c.type) && "myCozy".equals(c.name)) {
if (accountType.equals(c.type) && accountName.equals(c.name)) {
return; // skip creation.
}
}

Account account = new Account("myCozy", "io.cozy");

// ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
// ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
Account account = new Account(accountName, accountType);
accountManager.addAccountExplicitly(account, null, null);
}

private void listAccounts() {
private JSONArray listAccounts() {
AccountManager accountManager = AccountManager.get(ContactManager.this.cordova.getActivity());
for (Account c: accountManager.getAccounts()) {
Log.d("CordovaContacts", c.type + ", " + c.name);
JSONArray accounts = new JSONArray();
try {
for (Account c: accountManager.getAccounts()) {
JSONObject account = new JSONObject();
account.put("type", c.type);
account.put("name", c.name);

accounts.put(account);
}
} catch (JSONException e) {
Log.e(LOG_TAG, "JSON fail.", e);
}
return accounts;
}

/**
Expand Down
81 changes: 1 addition & 80 deletions src/android/syncadapter/SyncAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,86 +107,7 @@ private static long ensureSampleGroupExists(Context context, Account account) {
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
Log.d(TAG, "onPerformSync: do nothing !");
// try {
// // see if we already have a sync-state attached to this account. By handing
// // This value to the server, we can just get the contacts that have
// // been updated on the server-side since our last sync-up
// long lastSyncMarker = getServerSyncMarker(account);

// // By default, contacts from a 3rd party provider are hidden in the contacts
// // list. So let's set the flag that causes them to be visible, so that users
// // can actually see these contacts.
// if (lastSyncMarker == 0) {
// ContactManager.setAccountContactsVisibility(getContext(), account, true);
// }

// List<RawContact> dirtyContacts;
// List<RawContact> updatedContacts;

// // Use the account manager to request the AuthToken we'll need
// // to talk to our sample server. If we don't have an AuthToken
// // yet, this could involve a round-trip to the server to request
// // and AuthToken.
// final String authtoken = mAccountManager.blockingGetAuthToken(account,
// Constants.AUTHTOKEN_TYPE, NOTIFY_AUTH_FAILURE);

// // Make sure that the sample group exists
final long groupId = ensureSampleGroupExists(mContext, account);



// // Find the local 'dirty' contacts that we need to tell the server about...
// // Find the local users that need to be sync'd to the server...
// dirtyContacts = ContactManager.getDirtyContacts(mContext, account);

// // Send the dirty contacts to the server, and retrieve the server-side changes
// updatedContacts = NetworkUtilities.syncContacts(account, authtoken,
// lastSyncMarker, dirtyContacts);

// // Update the local contacts database with the changes. updateContacts()
// // returns a syncState value that indicates the high-water-mark for
// // the changes we received.
// Log.d(TAG, "Calling contactManager's sync contacts");
// long newSyncState = ContactManager.updateContacts(mContext,
// account.name,
// updatedContacts,
// groupId,
// lastSyncMarker);

// // This is a demo of how you can update IM-style status messages
// // for contacts on the client. This probably won't apply to
// // 2-way contact sync providers - it's more likely that one-way
// // sync providers (IM clients, social networking apps, etc) would
// // use this feature.

// ContactManager.updateStatusMessages(mContext, updatedContacts);

// // Save off the new sync marker. On our next sync, we only want to receive
// // contacts that have changed since this sync...
// setServerSyncMarker(account, newSyncState);

// if (dirtyContacts.size() > 0) {
// ContactManager.clearSyncFlags(mContext, dirtyContacts);
// }

// } catch (final AuthenticatorException e) {
// Log.e(TAG, "AuthenticatorException", e);
// syncResult.stats.numParseExceptions++;
// } catch (final OperationCanceledException e) {
// Log.e(TAG, "OperationCanceledExcetpion", e);
// } catch (final IOException e) {
// Log.e(TAG, "IOException", e);
// syncResult.stats.numIoExceptions++;
// } catch (final AuthenticationException e) {
// Log.e(TAG, "AuthenticationException", e);
// syncResult.stats.numAuthExceptions++;
// } catch (final ParseException e) {
// Log.e(TAG, "ParseException", e);
// syncResult.stats.numParseExceptions++;
// } catch (final JSONException e) {
// Log.e(TAG, "JSONException", e);
// syncResult.stats.numParseExceptions++;
// }
final long groupId = ensureSampleGroupExists(mContext, account);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions www/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var argscheck = require('cordova/argscheck'),
* Currently only used for Date fields
*/
function convertIn(contact) {
// Wrong on android !
// var value = contact.birthday;
// try {
// // contact.birthday = new Date(parseFloat(value));
Expand All @@ -45,6 +46,7 @@ function convertIn(contact) {
**/

function convertOut(contact) {
// Wrong on android !
// var value = contact.birthday;
// if (value !== null) {
// // try to make it a Date object if it is not already
Expand Down
10 changes: 8 additions & 2 deletions www/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ var contacts = {
return contact;
},

// TODO

createAccount: function(accountType, accountName, successCB, errorCB) {
argscheck.checkArgs('ssfF', 'contacts.createAccount', arguments);
exec(successCB, errorCB, 'Contacts', 'createAccount', [accountName, accountType]);
exec(successCB, errorCB, 'Contacts', 'createAccount',
[accountName, accountType]);

},

listAccounts: function(successCB, errorCB) {
argscheck.checkArgs('fF', 'contacts.listAccounts', arguments);
exec(successCB, errorCB, "Contacts", "listAccounts", []);
},
};

Expand Down

0 comments on commit 32e8a5c

Please sign in to comment.