mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
implement load/store on android
This commit is contained in:
parent
e898dc509c
commit
a9769efe1c
2 changed files with 51 additions and 8 deletions
|
@ -26,6 +26,7 @@ import android.telephony.PhoneNumberUtils;
|
|||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.XWApp;
|
||||
import org.eehouse.android.xw4.DBUtils;
|
||||
import org.eehouse.android.xw4.DevID;
|
||||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.Log;
|
||||
|
@ -210,7 +211,28 @@ public class DUtilCtxt {
|
|||
return same;
|
||||
}
|
||||
|
||||
// SET_DPROC(getCurSeconds);
|
||||
// SET_DPROC(md5sum);
|
||||
public void store( String key, byte[] data )
|
||||
{
|
||||
Log.d( TAG, "store(key=%s)", key );
|
||||
|
||||
if ( null == data ) {
|
||||
} else {
|
||||
DBUtils.setBytesFor( m_context, key, data );
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] load( String key )
|
||||
{
|
||||
byte[] result = null;
|
||||
int resultLen = 0;
|
||||
Log.d( TAG, "load(key=%s)", key );
|
||||
|
||||
result = DBUtils.getBytesFor( m_context, key );
|
||||
if ( result != null ) {
|
||||
resultLen = result.length;
|
||||
}
|
||||
|
||||
Log.d( TAG, "load(%s) returning %d bytes", key, resultLen );
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,17 +459,38 @@ and_dutil_getUserQuantityString( XW_DUtilCtxt* duc, XP_U16 stringCode, XP_U16 qu
|
|||
}
|
||||
|
||||
static void
|
||||
and_dutil_store( XW_DUtilCtxt* duc, const XP_UCHAR* key, XWStreamCtxt* data )
|
||||
and_dutil_store( XW_DUtilCtxt* duc, const XP_UCHAR* key, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_LOGF( "%s() NOT IMPLEMENTED", __func__ );
|
||||
// XP_ASSERT(0);
|
||||
DUTIL_CBK_HEADER( "store", "(Ljava/lang/String;[B)V" );
|
||||
|
||||
JNIEnv* env = ENVFORME( dutil->ti );
|
||||
jbyteArray jdata = streamToBArray( env, stream );
|
||||
jstring jkey = (*env)->NewStringUTF( env, key );
|
||||
|
||||
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jkey, jdata );
|
||||
|
||||
deleteLocalRefs( env, jdata, jkey, DELETE_NO_REF );
|
||||
|
||||
DUTIL_CBK_TAIL();
|
||||
}
|
||||
|
||||
static void
|
||||
and_dutil_load( XW_DUtilCtxt* duc, const XP_UCHAR* key,XWStreamCtxt* inOut )
|
||||
and_dutil_load( XW_DUtilCtxt* duc, const XP_UCHAR* key, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_LOGF( "%s() NOT IMPLEMENTED", __func__ );
|
||||
// XP_ASSERT(0);
|
||||
DUTIL_CBK_HEADER("load", "(Ljava/lang/String;)[B");
|
||||
|
||||
jstring jkey = (*env)->NewStringUTF( env, key );
|
||||
jbyteArray jvalue = (*env)->CallObjectMethod( env, dutil->jdutil,
|
||||
mid, jkey );
|
||||
if ( jvalue != NULL ) {
|
||||
jbyte* jelems = (*env)->GetByteArrayElements( env, jvalue, NULL );
|
||||
jsize len = (*env)->GetArrayLength( env, jvalue );
|
||||
stream_putBytes( stream, jelems, len );
|
||||
(*env)->ReleaseByteArrayElements( env, jvalue, jelems, 0 );
|
||||
}
|
||||
deleteLocalRefs( env, jkey, jvalue, DELETE_NO_REF );
|
||||
|
||||
DUTIL_CBK_TAIL();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue