summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Dubbeld <sven.dubbeld1@gmail.com>2015-03-13 13:28:05 +0100
committerSteve Kondik <steve@cyngn.com>2015-03-21 16:02:34 -0700
commit3906836ed6fabeec3aa812f1aad00015d40942d0 (patch)
tree8f36aa6f88424d031f9cc521c312a94bfa3bd3b9
parenta7bbaf03c3a86081eb0f00da58edcae0b69302ae (diff)
downloadandroid_packages_apps_Dialer-3906836ed6fabeec3aa812f1aad00015d40942d0.tar.gz
android_packages_apps_Dialer-3906836ed6fabeec3aa812f1aad00015d40942d0.tar.bz2
android_packages_apps_Dialer-3906836ed6fabeec3aa812f1aad00015d40942d0.zip
Added Reverse Lookup Gebeld (NL)
Change-Id: Icc69b9aac2f50f54ab2a97365297620ccd547177
-rw-r--r--res/values/cm_arrays.xml2
-rw-r--r--src/com/android/dialer/lookup/LookupSettings.java1
-rw-r--r--src/com/android/dialer/lookup/ReverseLookup.java6
-rw-r--r--src/com/android/dialer/lookup/gebeld/GebeldApi.java96
-rw-r--r--src/com/android/dialer/lookup/gebeld/GebeldReverseLookup.java69
5 files changed, 174 insertions, 0 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml
index 7f8d573eb..6ab20c7e5 100644
--- a/res/values/cm_arrays.xml
+++ b/res/values/cm_arrays.xml
@@ -54,6 +54,7 @@
<string-array name="reverse_lookup_providers" translatable="false">
<item>OpenCnam</item>
<item>DasTelefonbuch</item>
+ <item>Gebeld</item>
<item>WhitePages</item>
<item>WhitePages_CA</item>
<item>YellowPages</item>
@@ -64,6 +65,7 @@
<string-array name="reverse_lookup_provider_names" translatable="false">
<item>OpenCnam (US)</item>
<item>Das Telefonbuch (DE)</item>
+ <item>Gebeld (NL)</item>
<item>WhitePages (US)</item>
<item>WhitePages (CA)</item>
<item>YellowPages (US)</item>
diff --git a/src/com/android/dialer/lookup/LookupSettings.java b/src/com/android/dialer/lookup/LookupSettings.java
index 3d969a32d..68d9bfa26 100644
--- a/src/com/android/dialer/lookup/LookupSettings.java
+++ b/src/com/android/dialer/lookup/LookupSettings.java
@@ -45,6 +45,7 @@ public final class LookupSettings {
public static final String RLP_ZABASEARCH = "ZabaSearch";
public static final String RLP_CYNGN_CHINESE = "CyngnChinese";
public static final String RLP_DASTELEFONBUCH = "DasTelefonbuch";
+ public static final String RLP_GEBELD = "Gebeld";
public static final String RLP_DEFAULT = RLP_OPENCNAM;
private LookupSettings() {
diff --git a/src/com/android/dialer/lookup/ReverseLookup.java b/src/com/android/dialer/lookup/ReverseLookup.java
index 79ee96ebd..32da8ae02 100644
--- a/src/com/android/dialer/lookup/ReverseLookup.java
+++ b/src/com/android/dialer/lookup/ReverseLookup.java
@@ -19,6 +19,7 @@ package com.android.dialer.lookup;
import com.android.dialer.calllog.ContactInfo;
import com.android.dialer.lookup.cyngn.CyngnChineseReverseLookup;
import com.android.dialer.lookup.dastelefonbuch.TelefonbuchReverseLookup;
+import com.android.dialer.lookup.gebeld.GebeldReverseLookup;
import com.android.dialer.lookup.opencnam.OpenCnamReverseLookup;
import com.android.dialer.lookup.whitepages.WhitePagesReverseLookup;
import com.android.dialer.lookup.yellowpages.YellowPagesReverseLookup;
@@ -56,6 +57,8 @@ public abstract class ReverseLookup {
INSTANCE = new CyngnChineseReverseLookup(context);
} else if (provider.equals(LookupSettings.RLP_DASTELEFONBUCH)) {
INSTANCE = new TelefonbuchReverseLookup(context);
+ } else if (provider.equals(LookupSettings.RLP_GEBELD)) {
+ INSTANCE = new GebeldReverseLookup(context);
}
}
@@ -83,6 +86,9 @@ public abstract class ReverseLookup {
} else if (provider.equals(LookupSettings.RLP_DASTELEFONBUCH)
&& INSTANCE instanceof TelefonbuchReverseLookup) {
return true;
+ } else if (provider.equals(LookupSettings.RLP_GEBELD)
+ && INSTANCE instanceof GebeldReverseLookup) {
+ return true;
} else {
return false;
}
diff --git a/src/com/android/dialer/lookup/gebeld/GebeldApi.java b/src/com/android/dialer/lookup/gebeld/GebeldApi.java
new file mode 100644
index 000000000..effeb784b
--- /dev/null
+++ b/src/com/android/dialer/lookup/gebeld/GebeldApi.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed 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.
+ */
+
+package com.android.dialer.lookup.gebeld;
+
+import android.content.Context;
+import android.net.Uri;
+
+import com.android.dialer.lookup.LookupUtils;
+
+import org.apache.http.client.methods.HttpGet;
+
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class GebeldApi {
+ private static final String TAG = GebeldApi.class.getSimpleName();
+
+ private static final String REVERSE_LOOKUP_URL =
+ "http://www.gebeld.nl/zoeken.asp?Page=4,%201" +
+ "&searchfield1=fullnumber&action=Zoeken";
+
+ private static String REGEX = "\n?\\s*(.*)<(?:(?:BR|br)\\s*/?)>";
+
+ private GebeldApi() {
+ }
+
+ public static ContactInfo reverseLookup(Context context, String number)
+ throws IOException {
+ String phoneNumber = number.replace("+31", "0");
+ Uri uri = Uri.parse(REVERSE_LOOKUP_URL)
+ .buildUpon()
+ .appendQueryParameter("queryfield1", phoneNumber)
+ .build();
+ // Cut out everything we're not interested in (scripts etc.) to
+ // speed up the subsequent matching.
+ String output = LookupUtils.firstRegexResult(
+ LookupUtils.httpGet(new HttpGet(uri.toString())),
+ "<div class=\"small-12 large-4 columns information\">(.*?)</div>", true);
+
+ String name = null;
+ String address = null;
+
+ if (output == null) {
+ return null;
+ } else {
+ Pattern pattern = Pattern.compile(REGEX, 0);
+ Matcher m = pattern.matcher(output);
+
+ if (m.find()) {
+ name = LookupUtils.fromHtml(m.group(1).trim());
+
+ if (m.find()) {
+ address = LookupUtils.fromHtml(m.group(1).trim());
+
+ if (m.find()) {
+ address += "\n" + LookupUtils.fromHtml(m.group(1).trim());
+ }
+ }
+ }
+ }
+
+ if (name == null) {
+ return null;
+ }
+
+ ContactInfo info = new ContactInfo();
+ info.name = name;
+ info.address = address;
+ info.formattedNumber = phoneNumber != null ? phoneNumber : number;
+ info.website = uri.toString();
+
+ return info;
+ }
+
+ public static class ContactInfo {
+ String name;
+ String address;
+ String formattedNumber;
+ String website;
+ }
+}
diff --git a/src/com/android/dialer/lookup/gebeld/GebeldReverseLookup.java b/src/com/android/dialer/lookup/gebeld/GebeldReverseLookup.java
new file mode 100644
index 000000000..9f1be2e48
--- /dev/null
+++ b/src/com/android/dialer/lookup/gebeld/GebeldReverseLookup.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed 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.
+ */
+
+package com.android.dialer.lookup.gebeld;
+
+import android.content.Context;
+import android.net.Uri;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
+import android.provider.ContactsContract.CommonDataKinds.Website;
+
+import com.android.dialer.calllog.ContactInfo;
+import com.android.dialer.lookup.ContactBuilder;
+import com.android.dialer.lookup.ReverseLookup;
+
+import java.io.IOException;
+
+public class GebeldReverseLookup extends ReverseLookup {
+ private static final String TAG = GebeldReverseLookup.class.getSimpleName();
+
+ public GebeldReverseLookup(Context context) {
+ }
+
+ /**
+ * Perform phone number lookup.
+ *
+ * @param context The application context
+ * @param normalizedNumber The normalized phone number
+ * @param formattedNumber The formatted phone number
+ * @return The phone number info object
+ */
+ public ContactInfo lookupNumber(Context context,
+ String normalizedNumber, String formattedNumber) throws IOException {
+ if (normalizedNumber.startsWith("+") && !normalizedNumber.startsWith("+31")) {
+ // Only handle Dutch numbers
+ return null;
+ }
+
+ GebeldApi.ContactInfo info = GebeldApi.reverseLookup(context, normalizedNumber);
+ if (info == null) {
+ return null;
+ }
+
+ ContactBuilder builder = new ContactBuilder(
+ ContactBuilder.REVERSE_LOOKUP,
+ normalizedNumber, formattedNumber);
+ builder.setName(ContactBuilder.Name.createDisplayName(info.name));
+ builder.addPhoneNumber(ContactBuilder.PhoneNumber.createMainNumber(info.formattedNumber));
+ builder.addWebsite(ContactBuilder.WebsiteUrl.createProfile(info.website));
+ if (info.address != null) {
+ builder.addAddress(ContactBuilder.Address.createFormattedHome(info.address));
+ }
+
+ return builder.build();
+ }
+}