[and] read index from assets.

This commit is contained in:
d-kunin 2013-08-08 18:53:17 +03:00
parent 0f72e93ae4
commit 95624c635c
5 changed files with 38 additions and 3 deletions

View file

@ -30,4 +30,6 @@ LOCAL_SRC_FILES += \
../../storage/distance.cpp \
../../storage/storage.cpp \
LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)

View file

@ -19,10 +19,12 @@ class AndStorage
m_handle = AAssetManager_open(manager, name, AASSET_MODE_BUFFER);
CHECK(m_handle, ());
}
~AssetReader()
{
AAsset_close(m_handle);
}
virtual void Read(void * p, size_t size)
{
AAsset_read(m_handle, p, size);
@ -32,9 +34,8 @@ class AndStorage
public:
void Init(JNIEnv * env, jobject manager)
{
//AssetReader reader("index.dat", AAssetManager_fromJava(env, manager));
m_storage.Load("/storage/sdcard0/index.dat");
//m_storage.Load(reader);
AssetReader reader("index.dat", AAssetManager_fromJava(env, manager));
m_storage.Load(reader);
}
static AndStorage & Instance()
@ -123,6 +124,12 @@ JNIEXPORT jobject JNICALL Java_com_example_travelguide_cpp_Storage_getArticleInf
info.m_lon);
}
JNIEXPORT void JNICALL Java_com_example_travelguide_cpp_Storage_nativeInitIndex
(JNIEnv * env, jclass clazz, jobject assetManager)
{
STORAGE.Init(env, assetManager);
}
#ifdef __cplusplus
}

View file

@ -31,6 +31,14 @@ JNIEXPORT jint JNICALL Java_com_example_travelguide_cpp_Storage_getResultSize
JNIEXPORT jobject JNICALL Java_com_example_travelguide_cpp_Storage_getArticleInfoByIndex
(JNIEnv *, jobject, jint);
/*
* Class: com_example_travelguide_cpp_Storage
* Method: nativeInitIndex
* Signature: (Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_com_example_travelguide_cpp_Storage_nativeInitIndex
(JNIEnv *, jclass, jobject);
#ifdef __cplusplus
}
#endif

View file

@ -32,6 +32,7 @@ public class QueryResultLoader extends AsyncTaskLoader<Storage>
@Override
public Storage loadInBackground()
{
Storage.initAssets(getContext());
final Storage storage = new Storage();
storage.query(mQuery, mUseLocation, mLat, mLon);
return storage;

View file

@ -1,18 +1,35 @@
package com.example.travelguide.cpp;
import android.content.Context;
import android.content.res.AssetManager;
import com.example.travelguide.article.ArticleInfo;
public class Storage
{
static
{
System.loadLibrary("tguide");
}
private static boolean sIsAssetsInited = false;
public static void initAssets(Context context)
{
if (sIsAssetsInited)
return;
final AssetManager am = context.getAssets();
nativeInitIndex(am);
sIsAssetsInited = true;
}
public native void query(String query, boolean useLocation, double lat, double lon);
public native int getResultSize();
public native ArticleInfo getArticleInfoByIndex(int index);
native private static void nativeInitIndex(AssetManager am);
}