From 9ba663ab98c4bb258435f180938a7208ab5463a4 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 18 May 2012 07:41:46 -0700 Subject: [PATCH] implement util_phoneNumbersSame in java and call telephony's number compare method. Skip the java call when the numbers are strcmp-identical. --- xwords4/android/XWords4/jni/utilwrapper.c | 11 ++++++++--- .../src/org/eehouse/android/xw4/jni/UtilCtxt.java | 2 ++ .../src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/jni/utilwrapper.c b/xwords4/android/XWords4/jni/utilwrapper.c index 78412dab8..2671f9065 100644 --- a/xwords4/android/XWords4/jni/utilwrapper.c +++ b/xwords4/android/XWords4/jni/utilwrapper.c @@ -462,9 +462,14 @@ and_util_phoneNumbersSame( XW_UtilCtxt* uc, const XP_UCHAR* p1, { XP_Bool same = 0 == strcmp( p1, p2 ); if ( !same ) { - /* If they're same, fine, but if not probably need to call into - platform code for a closer look */ - XP_LOGF( "%s(%s,%s)=>%d", __func__, p1, p2, same ); + UTIL_CBK_HEADER( "phoneNumbersSame", + "(Ljava/lang/String;Ljava/lang/String;)Z" ); + jstring js1 = (*env)->NewStringUTF( env, p1 ); + jstring js2 = (*env)->NewStringUTF( env, p2 ); + same = (*env)->CallBooleanMethod( env, util->jutil, mid, js1, js2 ); + (*env)->DeleteLocalRef( env, js1 ); + (*env)->DeleteLocalRef( env, js2 ); + UTIL_CBK_TAIL(); } return same; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java index 24fd36eb2..c0b151e2f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java @@ -119,4 +119,6 @@ public interface UtilCtxt { boolean warnIllegalWord( String[] words, int turn, boolean turnLost ); void showChat( String msg ); + + boolean phoneNumbersSame( String num1, String num2 ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java index 7818761c2..6ca2c09c2 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java @@ -21,8 +21,11 @@ package org.eehouse.android.xw4.jni; import android.content.Context; +import android.telephony.PhoneNumberUtils; +import junit.framework.Assert; import org.eehouse.android.xw4.DbgUtils; +import org.eehouse.android.xw4.XWApp; import org.eehouse.android.xw4.R; public class UtilCtxtImpl implements UtilCtxt { @@ -238,6 +241,14 @@ public class UtilCtxtImpl implements UtilCtxt { subclassOverride( "showChat" ); } + public boolean phoneNumbersSame( String num1, String num2 ) + { + Assert.assertTrue( XWApp.SMSSUPPORTED ); + boolean same = PhoneNumberUtils.compare( m_context, num1, num2 ); + DbgUtils.logf( "phoneNumbersSame => %b", same ); + return same; + } + private void subclassOverride( String name ) { // DbgUtils.logf( "%s::%s() called", getClass().getName(), name ); }