Skip to content

Commit

Permalink
#259 Added sample code for PhoneLookupQuery into cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
vestrel00 committed Sep 6, 2022
1 parent 7d9173e commit 8b5943a
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
58 changes: 58 additions & 0 deletions docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,64 @@ heading explore each API in full detail. You may also find these samples in the
}
```

### [Query contacts by phone number or SIP address](./basics/query-contacts-by-phone-or-sip.md)

=== "Kotlin"

```kotlin
import android.app.Activity
import contacts.core.*
import contacts.core.entities.Contact

class QueryContactsByPhoneOrSipActivity : Activity() {

fun getContactsWithPhoneNumberThatExactlyMatches(text: String?): List<Contact> =
Contacts(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.PHONE_NUMBER)
.whereExactlyMatches(text)
.find()

fun getContactsWithSipAddressThatExactlyMatches(text: String?): List<Contact> =
Contacts(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.SIP_ADDRESS)
.whereExactlyMatches(text)
.find()
}
```

=== "Java"

```java
import android.app.Activity;

import java.util.List;

import contacts.core.ContactsFactory;
import contacts.core.PhoneLookupQuery;
import contacts.core.entities.Contact;

public class QueryContactsByPhoneOrSipActivity extends Activity {

List<Contact> getContactsWithPhoneNumberThatExactlyMatches(String text) {
return ContactsFactory.create(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.PHONE_NUMBER)
.whereExactlyMatches(text)
.find();
}

List<Contact> getContactsWithEmailOrDisplayNameThatPartiallyMatches(String text) {
return ContactsFactory.create(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.SIP_ADDRESS)
.whereExactlyMatches(text)
.find();
}
}
```

### [Insert contacts](./basics/insert-contacts.md)

=== "Kotlin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package contacts.sample.cheatsheet.basics.java;

import android.app.Activity;

import java.util.List;

import contacts.core.ContactsFactory;
import contacts.core.PhoneLookupQuery;
import contacts.core.entities.Contact;

public class QueryContactsByPhoneOrSipActivity extends Activity {

List<Contact> getContactsWithPhoneNumberThatExactlyMatches(String text) {
return ContactsFactory.create(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.PHONE_NUMBER)
.whereExactlyMatches(text)
.find();
}

List<Contact> getContactsWithEmailOrDisplayNameThatPartiallyMatches(String text) {
return ContactsFactory.create(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.SIP_ADDRESS)
.whereExactlyMatches(text)
.find();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package contacts.sample.cheatsheet.basics.kotlin

import android.app.Activity
import contacts.core.*
import contacts.core.entities.Contact

class QueryContactsByPhoneOrSipActivity : Activity() {

fun getContactsWithPhoneNumberThatExactlyMatches(text: String?): List<Contact> =
Contacts(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.PHONE_NUMBER)
.whereExactlyMatches(text)
.find()

fun getContactsWithSipAddressThatExactlyMatches(text: String?): List<Contact> =
Contacts(this)
.phoneLookupQuery()
.match(PhoneLookupQuery.Match.SIP_ADDRESS)
.whereExactlyMatches(text)
.find()
}

0 comments on commit 8b5943a

Please sign in to comment.