mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
aa974be567
callback to see if there's already one in the DB. Required passing context into jniutils getter, and passing name into jni dict constructors that previously didn't need it.
120 lines
3.7 KiB
C
120 lines
3.7 KiB
C
/* -*-mode: C; compile-command: "cd ..; ../scripts/ndkbuild.sh -j3"; -*- */
|
|
/*
|
|
* Copyright 2001-2010 by Eric House (xwords@eehouse.org). All rights
|
|
* reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "strutils.h"
|
|
#include "jniutlswrapper.h"
|
|
#include "andutils.h"
|
|
|
|
|
|
struct JNIUtilCtxt {
|
|
JNIEnv** envp;
|
|
jobject jjniutil;
|
|
MPSLOT;
|
|
};
|
|
|
|
JNIUtilCtxt*
|
|
makeJNIUtil( MPFORMAL JNIEnv** envp, jobject jniutls )
|
|
{
|
|
JNIUtilCtxt* ctxt = (JNIUtilCtxt*)XP_CALLOC( mpool, sizeof( *ctxt ) );
|
|
JNIEnv* env = *envp;
|
|
ctxt->envp = envp;
|
|
ctxt->jjniutil = (*env)->NewGlobalRef( env, jniutls );
|
|
MPASSIGN( ctxt->mpool, mpool );
|
|
return ctxt;
|
|
}
|
|
|
|
void
|
|
destroyJNIUtil( JNIUtilCtxt** ctxtp )
|
|
{
|
|
JNIUtilCtxt* ctxt = *ctxtp;
|
|
if ( !!ctxt ) {
|
|
JNIEnv* env = *ctxt->envp;
|
|
(*env)->DeleteGlobalRef( env, ctxt->jjniutil );
|
|
XP_FREE( ctxt->mpool, ctxt );
|
|
*ctxtp = NULL;
|
|
}
|
|
}
|
|
|
|
/* These are called from anddict.c, not via vtable */
|
|
#ifndef DROP_BITMAPS
|
|
jobject
|
|
and_util_makeJBitmap( JNIUtilCtxt* jniutil, int nCols, int nRows,
|
|
const jboolean* colors )
|
|
{
|
|
jobject bitmap;
|
|
JNIEnv* env = *jniutil->envp;
|
|
jmethodID mid
|
|
= getMethodID( env, jniutil->jjniutil, "makeBitmap",
|
|
"(II[Z)Landroid/graphics/drawable/BitmapDrawable;" );
|
|
|
|
jbooleanArray jcolors = makeBooleanArray( env, nCols*nRows, colors );
|
|
|
|
bitmap = (*env)->CallObjectMethod( env, jniutil->jjniutil, mid,
|
|
nCols, nRows, jcolors );
|
|
(*env)->DeleteLocalRef( env, jcolors );
|
|
|
|
return bitmap;
|
|
}
|
|
#endif
|
|
|
|
jobject
|
|
and_util_splitFaces( JNIUtilCtxt* jniutil, const XP_U8* bytes, jsize len,
|
|
XP_Bool isUTF8 )
|
|
{
|
|
jobject strarray = NULL;
|
|
JNIEnv* env = *jniutil->envp;
|
|
jmethodID mid
|
|
= getMethodID( env, jniutil->jjniutil, "splitFaces",
|
|
"([BZ)[Ljava/lang/String;" );
|
|
|
|
jbyteArray jbytes = makeByteArray( env, len, (jbyte*)bytes );
|
|
strarray =
|
|
(*env)->CallObjectMethod( env, jniutil->jjniutil, mid, jbytes, isUTF8 );
|
|
(*env)->DeleteLocalRef( env, jbytes );
|
|
|
|
return strarray;
|
|
}
|
|
|
|
jstring
|
|
and_util_getMD5SumFor( JNIUtilCtxt* jniutil, const XP_UCHAR* name )
|
|
{
|
|
JNIEnv* env = *jniutil->envp;
|
|
jmethodID mid = getMethodID( env, jniutil->jjniutil, "getMD5SumFor",
|
|
"(Ljava/lang/String;)Ljava/lang/String;" );
|
|
jstring jname = (*env)->NewStringUTF( env, name );
|
|
jstring result =
|
|
(*env)->CallObjectMethod( env, jniutil->jjniutil, mid, jname );
|
|
(*env)->DeleteLocalRef( env, jname );
|
|
return result;
|
|
}
|
|
|
|
jstring
|
|
and_util_figureMD5Sum( JNIUtilCtxt* jniutil, const XP_U8* bytes, jsize len )
|
|
{
|
|
JNIEnv* env = *jniutil->envp;
|
|
jmethodID mid = getMethodID( env, jniutil->jjniutil, "figureMD5Sum",
|
|
"([B)Ljava/lang/String;" );
|
|
jbyteArray jbytes = makeByteArray( env, len, (jbyte*)bytes );
|
|
jstring sum =
|
|
(*env)->CallObjectMethod( env, jniutil->jjniutil, mid, jbytes );
|
|
(*env)->DeleteLocalRef( env, jbytes );
|
|
|
|
return sum;
|
|
}
|