cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject git commit: CB-7290 Adds support for universal Windows platform.
Date Wed, 13 Aug 2014 00:51:16 GMT
Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master 6240e88d2 -> d5c112643


CB-7290 Adds support for universal Windows platform.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/d5c11264
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/d5c11264
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/d5c11264

Branch: refs/heads/master
Commit: d5c112643876290b3fc0903237c3ad802ffcbee8
Parents: 6240e88
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Tue Aug 12 16:24:36 2014 +0400
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Tue Aug 12 16:29:07 2014 +0400

----------------------------------------------------------------------
 doc/index.md                |  42 ++++++++
 plugin.xml                  |   7 ++
 src/windows/ContactProxy.js | 219 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 268 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/d5c11264/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 6f9cd54..d48c557 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -58,6 +58,11 @@ __WARNING__: All privileged apps enforce [Content Security Policy](https://devel
 		}
 	}
 
+### Windows Quirks
+
+Any contacts returned from `find` and `pickContact` methods are readonly, so your application
cannot modify them.
+`find` method available only on Windows Phone 8.1 devices.
+
 ### Windows 8 Quirks
 
 Windows 8 Contacts are readonly. Via the Cordova API Contacts are not queryable/searchable,
you should inform the user to pick a contact as a call to contacts.pickContact which will
open the 'People' app where the user must choose a contact.
@@ -143,6 +148,7 @@ parameter to control which contact properties must be returned back.
 - Firefox OS
 - iOS
 - Windows Phone 7 and 8
+- Windows (Windows Phone 8.1 devices only)
 
 ### Example
 
@@ -162,6 +168,10 @@ parameter to control which contact properties must be returned back.
     var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
     navigator.contacts.find(fields, onSuccess, onError, options);
 
+### Windows Quirks
+
+- `__contactFields__` is not supported and will be ignored. `find` method will always attempt
to match the name, email address, or phone number of a contact.
+
 ## navigator.contacts.pickContact
 
 The `navigator.contacts.pickContact` method launches the Contact Picker to select a single
contact.
@@ -180,6 +190,7 @@ function specified by the __contactSuccess__ parameter.
 - iOS
 - Windows Phone 8
 - Windows 8
+- Windows
 
 ### Example
 
@@ -248,6 +259,7 @@ for details.
 - iOS
 - Windows Phone 7 and 8
 - Windows 8
+- Windows
 
 ### Save Example
 
@@ -344,6 +356,14 @@ for details.
 
 - __categories__: Not supported, returning `null`.
 
+### Windows Quirks
+
+- __photos__: Returns a File URL to the image, which is stored in the application's temporary
directory.
+
+- __birthdays__: Not supported, returning `null`.
+
+- __categories__: Not supported, returning `null`.
+
 
 ## ContactAddress
 
@@ -379,6 +399,7 @@ a `ContactAddress[]` array.
 - iOS
 - Windows Phone 7 and 8
 - Windows 8
+- Windows
 
 ### Example
 
@@ -445,6 +466,10 @@ a `ContactAddress[]` array.
 
 - __pref__: Not supported
 
+### Windows Quirks
+
+- __pref__: Not supported
+
 
 ## ContactError
 
@@ -501,6 +526,7 @@ string.
 - iOS
 - Windows Phone 7 and 8
 - Windows 8
+- Windows
 
 ### Example
 
@@ -537,6 +563,10 @@ string.
 
 - __pref__: Not supported, returning `false`.
 
+### Windows Quirks
+
+- __pref__: Not supported, returning `false`.
+
 
 ## ContactName
 
@@ -565,6 +595,7 @@ Contains different kinds of information about a `Contact` object's name.
 - iOS
 - Windows Phone 7 and 8
 - Windows 8
+- Windows
 
 ### Example
 
@@ -629,6 +660,10 @@ Contains different kinds of information about a `Contact` object's name.
 
 - __honorificSuffix__: not supported
 
+### Windows Quirks
+
+- __formatted__: It is identical to `displayName`
+
 
 ## ContactOrganization
 
@@ -656,6 +691,7 @@ properties.  A `Contact` object stores one or more
 - Firefox OS
 - iOS
 - Windows Phone 7 and 8
+- Windows (Windows 8.1 and Windows Phone 8.1 devices only)
 
 ### Example
 
@@ -717,3 +753,9 @@ properties.  A `Contact` object stores one or more
 - __department__: Partially supported.  The first department name is stored in the iOS __kABPersonDepartmentProperty__
field.
 
 - __title__: Partially supported.  The first title is stored in the iOS __kABPersonJobTitleProperty__
field.
+
+### Windows Quirks
+
+- __pref__: Not supported, returning `false`.
+
+- __type__: Not supported, returning `null`.

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/d5c11264/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 30eb0eb..f54f80f 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -220,4 +220,11 @@
         </js-module>
     </platform>
 
+    <!-- Windows -->
+    <platform name="windows">
+        <js-module src="src/windows/ContactProxy.js" name="ContactProxy">
+            <merges target="" />
+        </js-module>
+    </platform>
+
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/d5c11264/src/windows/ContactProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/ContactProxy.js b/src/windows/ContactProxy.js
new file mode 100644
index 0000000..455ff53
--- /dev/null
+++ b/src/windows/ContactProxy.js
@@ -0,0 +1,219 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+var ContactField = require('./ContactField'),
+    ContactAddress = require('./ContactAddress'),
+    ContactOrganization = require('./ContactOrganization'),
+    ContactName = require('./ContactName'),
+    ContactError = require('./ContactError'),
+    Contact = require('./Contact');
+
+
+function convertToContact(windowsContact) {
+    var contact = new Contact();
+
+    // displayName & nickname
+    contact.displayName = windowsContact.name || windowsContact.displayName;
+    contact.nickname = windowsContact.name;
+
+    // name
+    // Additional fields like lastName, middleName etc. available on windows8.1/wp8.1 only
+    contact.name = new ContactName(
+        windowsContact.name || windowsContact.displayName,
+        windowsContact.lastName,
+        windowsContact.middleName,
+        windowsContact.honorificPrefix,
+        windowsContact.honorificSuffix);
+
+    // phoneNumbers
+    contact.phoneNumbers = [];
+    var phoneSource = windowsContact.phoneNumbers || windowsContact.phones;
+    for (var i = 0; i < phoneSource.size; i++) {
+        var rawPhone = phoneSource[i];
+        var phone = new ContactField(rawPhone.category || rawPhone.kind, rawPhone.value ||
rawPhone.number);
+        contact.phoneNumbers.push(phone);
+    }
+
+    // emails
+    contact.emails = [];
+    var emailSource = windowsContact.emails;
+    for (var i = 0; i < emailSource.size; i++) {
+        var rawEmail = emailSource[i];
+        var email = new ContactField(rawEmail.category || rawEmail.kind, rawEmail.value ||
rawEmail.address);
+        contact.emails.push(email);
+    }
+
+    // addressres
+    contact.addresses = [];
+    var addressSource = windowsContact.locations || windowsContact.addresses;
+    for (var i = 0; i < addressSource.size; i++) {
+        var rawAddress = addressSource[i];
+        var address = new ContactAddress(
+            null,
+            rawAddress.category || rawAddress.kind,
+            rawAddress.unstructuredAddress,
+            rawAddress.street || rawAddress.streetAddress,
+            rawAddress.city || rawAddress.locality,
+            rawAddress.region,
+            rawAddress.postalCode,
+            rawAddress.country);
+        contact.addresses.push(address);
+    }
+
+    // ims
+    contact.ims = [];
+    var imSource = windowsContact.instantMessages || windowsContact.connectedServiceAccounts;
+    for (var i = 0; i < imSource.size; i++) {
+        var rawIm = imSource[i];
+        var im = new ContactField(rawIm.category || rawIm.serviceName, rawIm.userName ||
rawIm.id);
+        contact.ims.push(im);
+    }
+
+    // jobInfo field available on Windows 8.1/WP8.1 only
+    var jobInfo = windowsContact.jobInfo;
+    if (jobInfo) {
+        contact.organizations = [];
+        for (var j = 0; j < jobInfo.size; j++) {
+            var rawJob = jobInfo[i];
+            contact.organizations.push(new ContactOrganization(false, null,
+                rawJob.companyName, rawJob.department, rawJob.title));
+        }
+    }
+
+    // note field available on Windows 8.1/WP8.1 only
+    var contactNotes = windowsContact.notes;
+    if (contactNotes) {
+        contact.note = contactNotes;
+    }
+
+    // thumbnail field available on Windows 8.1/WP8.1 only
+    var contactPhoto = windowsContact.thumbnail;
+    if (contactPhoto && contactPhoto.path) {
+        contact.photos = [new ContactField(null, contactPhoto.path , false)];
+    }
+
+    return contact;
+}
+
+// Win API Contacts namespace
+var contactsNS = Windows.ApplicationModel.Contacts;
+
+module.exports = {
+
+    pickContact: function (win, fail, args) {
+
+        // ContactPicker class works differently on Windows8/8.1 and Windows Phone 8.1
+        // so we need to detect when we are running on phone
+        var runningOnPhone = navigator.userAgent.indexOf('Windows Phone') !== -1;
+
+        var picker = new contactsNS.ContactPicker();
+        if (runningOnPhone) {
+            // TODO: Windows Phone 8.1 requires this specification. This should be noted
in quirks
+            // See http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.contacts.contactpicker.desiredfieldswithcontactfieldtype.aspx
for details
+            // Multiple ContactFieldType items, appended to array causes `Request not suported`
error.
+            picker.desiredFieldsWithContactFieldType.append(Windows.ApplicationModel.Contacts.ContactFieldType.phoneNumber);
+        }
+
+        // pickContactAsync is available on Windows 8.1 or later, instead of
+        // pickSingleContactAsync, which is deprecated in Windows 8.1,
+        // so try to use newer method, if available.
+        // see http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.contacts.contactpicker.picksinglecontactasync.aspx
+
+        var pickRequest = picker.pickContactAsync ? picker.pickContactAsync() : picker.pickSingleContactAsync();
+        pickRequest.done(function (contact) {
+            // if contact was not picked
+            if (!contact) {
+                fail && fail(new Error("User did not pick a contact."));
+                return;
+            }
+            // If we are on desktop, just send em back
+            if (!runningOnPhone) {
+                win(convertToContact(contact));
+                return;
+            }
+            // On WP8.1 fields set in resulted Contact object depends on desiredFieldsWithContactFieldType
property of contact picker
+            // so we retrieve full contact by its' Id
+            contactsNS.ContactManager.requestStoreAsync().done(function (contactStore) {
+                contactStore.getContactAsync(contact.id).done(function(con) {
+                    win(convertToContact(con));
+                }, function() {
+                    fail(new ContactError(ContactError.PENDING_OPERATION_ERROR));
+                });
+            }, function () {
+                fail(new ContactError(ContactError.PENDING_OPERATION_ERROR));
+            });
+        });
+    },
+
+    save: function (win, fail, args) {
+        // Not supported yet since WinJS API do not provide methods to manage contactStore
+        // On Windows Phone 8.1 this can be implemented using native class library 
+        // See Windows.Phone.PersonalInformation namespace
+        // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.phone.personalinformation.aspx
+        fail && fail(new ContactError(ContactError.NOT_SUPPORTED_ERROR));
+    },
+
+    search: function (win, fail, options) {
+
+        // searchFields is not supported yet due to WP8.1 API limitations.
+        // findContactsAsync(String) method will attempt to match the name, email address,
or phone number of a contact. 
+        // see http://msdn.microsoft.com/en-us/library/windows/apps/dn624861.aspx for details
+        var searchFields = options[0],
+            searchOptions = options[1],
+            searchFilter = searchOptions.filter,
+            searchMultiple = searchOptions && searchOptions.multiple;
+
+        // Check if necessary API is available.
+        // If not available, we are running on desktop, which doesn't support searching for
contacts
+        if (!(contactsNS.ContactManager && contactsNS.ContactManager.requestStoreAsync))
{
+            fail(new ContactError(ContactError.NOT_SUPPORTED_ERROR));
+            return;
+        }
+
+        // Retrieve contact store instance
+        var contactStoreRequest = contactsNS.ContactManager.requestStoreAsync();
+
+        // When contact store retrieved
+        contactStoreRequest.done(function (contactStore) {
+            // determine, which function we use depending on whether searchOptions.filter
specified or not
+            var contactsRequest = searchFilter ? contactStore.findContactsAsync(searchFilter)
: contactStore.findContactsAsync();
+            // request contacts and resolve either with success or error callback
+            contactsRequest.done(function (contacts) {
+                var result = [];
+                if (contacts.size !== 0) {
+                    // Depending on searchOptions we should return all contacts found or
only first 
+                    var outputContactsArray = searchMultiple ? contacts : [contacts[0]];
+                    outputContactsArray.forEach(function (contact) {
+                        // Convert windows contacts to plugin's contact objects
+                        result.push(convertToContact(contact));
+                    });
+                }
+                win(result);
+            }, function() {
+                fail(new ContactError(ContactError.PENDING_OPERATION_ERROR));
+            });
+        }, function() {
+            fail(new ContactError(ContactError.PENDING_OPERATION_ERROR));
+        });
+    }
+};
+
+require("cordova/exec/proxy").add("Contacts", module.exports);


Mime
View raw message