Fix for 2148982: Keyboard freezes while typing

Contacts dictionary code was being triggered too frequently during sync and
during presence updates and this seems expensive for accounts with a lot of
contacts.

Throttling the contacts read to every 30 minutes.
diff --git a/src/com/android/inputmethod/latin/ContactsDictionary.java b/src/com/android/inputmethod/latin/ContactsDictionary.java
index e8faf45..6f7f4b6 100644
--- a/src/com/android/inputmethod/latin/ContactsDictionary.java
+++ b/src/com/android/inputmethod/latin/ContactsDictionary.java
@@ -16,16 +16,11 @@
 
 package com.android.inputmethod.latin;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.provider.ContactsContract.Contacts;
-import android.util.Log;
 
 public class ContactsDictionary extends ExpandableDictionary {
 
@@ -40,6 +35,8 @@
 
     private boolean mRequiresReload;
 
+    private long mLastLoadedContacts;
+
     public ContactsDictionary(Context context) {
         super(context);
         // Perform a managed query. The Activity will handle closing and requerying the cursor
@@ -64,12 +61,17 @@
     }
 
     private synchronized void loadDictionary() {
-        Cursor cursor = getContext().getContentResolver()
-                .query(Contacts.CONTENT_URI, PROJECTION, null, null, null);
-        if (cursor != null) {
-            addWords(cursor);
+        long now = android.os.SystemClock.uptimeMillis();
+        if (mLastLoadedContacts == 0
+                || now - mLastLoadedContacts > 30 * 60 * 1000 /* 30 minutes */) {
+            Cursor cursor = getContext().getContentResolver()
+                    .query(Contacts.CONTENT_URI, PROJECTION, null, null, null);
+            if (cursor != null) {
+                addWords(cursor);
+            }
+            mRequiresReload = false;
+            mLastLoadedContacts = now;
         }
-        mRequiresReload = false;
     }
 
     @Override