mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
add static to cache phone->name mapping
This commit is contained in:
parent
3af20f1d5a
commit
a72dbdd8dd
1 changed files with 25 additions and 12 deletions
|
@ -41,6 +41,7 @@ import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import java.util.HashMap;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.jni.*;
|
import org.eehouse.android.xw4.jni.*;
|
||||||
|
@ -52,6 +53,8 @@ public class Utils {
|
||||||
|
|
||||||
private static Boolean s_isFirstBootThisVersion = null;
|
private static Boolean s_isFirstBootThisVersion = null;
|
||||||
private static Boolean s_isFirstBootEver = null;
|
private static Boolean s_isFirstBootEver = null;
|
||||||
|
private static HashMap<String,String> s_phonesHash =
|
||||||
|
new HashMap<String,String>();
|
||||||
|
|
||||||
private Utils() {}
|
private Utils() {}
|
||||||
|
|
||||||
|
@ -140,19 +143,29 @@ public class Utils {
|
||||||
// http://stackoverflow.com/questions/2174048/how-to-look-up-a-contacts-name-from-their-phone-number-on-android
|
// http://stackoverflow.com/questions/2174048/how-to-look-up-a-contacts-name-from-their-phone-number-on-android
|
||||||
public static String phoneToContact( Context context, String phone )
|
public static String phoneToContact( Context context, String phone )
|
||||||
{
|
{
|
||||||
String name = null;
|
// I'm assuming that since context is passed this needn't
|
||||||
ContentResolver contentResolver = context.getContentResolver();
|
// worry about synchronization -- will always be called from
|
||||||
Cursor cursor =
|
// UI thread.
|
||||||
contentResolver
|
String name;
|
||||||
.query( Uri.withAppendedPath( PhoneLookup.CONTENT_FILTER_URI,
|
if ( s_phonesHash.containsKey( phone ) ) {
|
||||||
Uri.encode( phone )),
|
name = s_phonesHash.get( phone );
|
||||||
new String[] { PhoneLookup.DISPLAY_NAME },
|
} else {
|
||||||
null, null, null );
|
name = null;
|
||||||
if ( cursor.moveToNext() ) {
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
int indx = cursor.getColumnIndex( PhoneLookup.DISPLAY_NAME );
|
Cursor cursor =
|
||||||
name = cursor.getString( indx );
|
contentResolver
|
||||||
|
.query( Uri.withAppendedPath( PhoneLookup.CONTENT_FILTER_URI,
|
||||||
|
Uri.encode( phone )),
|
||||||
|
new String[] { PhoneLookup.DISPLAY_NAME },
|
||||||
|
null, null, null );
|
||||||
|
if ( cursor.moveToNext() ) {
|
||||||
|
int indx = cursor.getColumnIndex( PhoneLookup.DISPLAY_NAME );
|
||||||
|
name = cursor.getString( indx );
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
|
s_phonesHash.put( phone, name );
|
||||||
}
|
}
|
||||||
cursor.close();
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue