fixed bug with creating HttpThread from non-activity thread upon "Download Country" click.

This commit is contained in:
rachytski 2012-06-03 23:53:32 +04:00 committed by Alex Zolotarev
parent ddbf18e650
commit a8c028aede
10 changed files with 94 additions and 37 deletions

View file

@ -49,11 +49,6 @@ namespace android
m_sensors[1].SetCount(measurementsCount);
}
void Framework::SetEmptyModelMessage(string const & emptyModelMsg)
{
m_work.GetInformationDisplay().setEmptyModelMessage(emptyModelMsg.c_str());
}
Framework::~Framework()
{
delete m_videoTimer;
@ -164,6 +159,11 @@ namespace android
return m_work.Storage();
}
::Framework & Framework::GetFramework()
{
return m_work;
}
void Framework::Resize(int w, int h)
{
m_work.OnSize(w, h);

View file

@ -57,9 +57,8 @@ namespace android
Framework();
~Framework();
void SetEmptyModelMessage(string const & emptyModelMsg);
storage::Storage & Storage();
::Framework & GetFramework();
void OnLocationStatusChanged(int/* == location::TLocationStatus*/ newStatus);
void OnLocationUpdated(uint64_t time, double lat, double lon, float accuracy);

View file

@ -7,6 +7,7 @@
#include "../../../nv_event/nv_event.hpp"
#include "../../../../../platform/settings.hpp"
#include "../../../../../map/country_status_display.hpp"
////////////////////////////////////////////////////////////////////////////////////////////
extern "C"
@ -79,6 +80,35 @@ extern "C"
return u;
}
void CallOnDownloadCountryClicked(shared_ptr<jobject> const & obj,
jmethodID methodID)
{
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(*obj.get(), methodID);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeConnectDownloadButton(JNIEnv * env, jobject thiz)
{
shared_ptr<CountryStatusDisplay> display = g_framework->GetFramework().GetInformationDisplay().countryStatusDisplay();
jclass k = env->GetObjectClass(thiz);
ASSERT(k, (jni::DescribeException()));
jmethodID methodID = env->GetMethodID(k, "OnDownloadCountryClicked", "()V");
ASSERT(methodID, (jni::DescribeException()));
display->setDownloadListener(bind(&CallOnDownloadCountryClicked,
jni::make_global_ref(thiz),
methodID));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeDownloadCountry(JNIEnv * env, jobject thiz)
{
g_framework->GetFramework().GetInformationDisplay().countryStatusDisplay()->downloadCountry();
}
//////////////////////////////////////////////////////////////////////////////
JNIEXPORT void JNICALL

View file

@ -20,8 +20,7 @@ extern "C"
jstring storagePath,
jstring tmpPath,
jstring extTmpPath,
jstring settingsPath,
jstring emptyModelMessage)
jstring settingsPath)
{
android::Platform::Instance().Initialize(env,
apkPath,
@ -32,7 +31,5 @@ extern "C"
if (!g_framework)
g_framework = new android::Framework();
g_framework->SetEmptyModelMessage(jni::ToString(emptyModelMessage));
}
}

View file

@ -46,6 +46,18 @@ LocationService.Listener
}
}
public void OnDownloadCountryClicked()
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
nativeDownloadCountry();
}
});
}
@Override
public void OnRenderingInitialized()
{
@ -277,6 +289,8 @@ LocationService.Listener
SharedPreferences prefs = getSharedPreferences(mApplication.getPackageName(), MODE_PRIVATE);
final boolean isMyPositionEnabled = prefs.getBoolean(PREFERENCES_MYPOSITION, false);
findViewById(R.id.map_button_myposition).setSelected(isMyPositionEnabled);
nativeConnectDownloadButton();
}
@Override
@ -446,6 +460,9 @@ LocationService.Listener
private native void nativeStorageConnected();
private native void nativeStorageDisconnected();
private native void nativeConnectDownloadButton();
private native void nativeDownloadCountry();
private native void nativeDestroy();
private native void nativeLocationStatusChanged(int newStatus);
private native void nativeLocationUpdated(long time, double lat, double lon, float accuracy);

View file

@ -2,21 +2,23 @@ package com.mapswithme.maps;
import java.io.File;
import com.mapswithme.maps.location.LocationService;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import com.mapswithme.maps.location.LocationService;
public class MWMApplication extends android.app.Application
{
public final static String PACKAGE_NAME = "com.mapswithme.maps";
private LocationService mLocationService = null;
@Override
public void onCreate()
{
super.onCreate();
super.onCreate();
final String extStoragePath = getDataStoragePath();
final String extTmpPath = getExtAppDirectoryPath("caches");
// Create folders if they don't exist
@ -24,39 +26,38 @@ public class MWMApplication extends android.app.Application
new File(extTmpPath).mkdirs();
nativeInit(getApkPath(),
extStoragePath,
extStoragePath,
getTmpPath(),
extTmpPath,
getSettingsPath(),
getString(R.string.empty_model));
getSettingsPath());
}
public LocationService getLocationService()
{
if (mLocationService == null)
mLocationService = new LocationService(this);
return mLocationService;
return mLocationService;
}
public String getApkPath()
{
try
{
return getPackageManager().getApplicationInfo(PACKAGE_NAME, 0).sourceDir;
}
}
catch (NameNotFoundException e)
{
e.printStackTrace();
return "";
}
}
public String getDataStoragePath()
{
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/MapsWithMe/";
}
public String getExtAppDirectoryPath(String folder)
{
final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
@ -71,22 +72,22 @@ public class MWMApplication extends android.app.Application
private String getSettingsPath()
{
return getFilesDir().getAbsolutePath() + "/";
}
}
@Override
public String getPackageName()
{
return PACKAGE_NAME;
}
static
{
System.loadLibrary("mapswithme");
}
private native void nativeInit(String apkPath,
String storagePath,
String tmpPath,
String extTmpPath,
String settingsPath,
String emptyModelMessage);
String settingsPath);
}

View file

@ -105,7 +105,7 @@ CountryStatusDisplay::CountryStatusDisplay(Params const & p)
bp.m_text = "Download";
m_downloadButton.reset(new gui::Button(bp));
m_downloadButton->setOnClickListener(bind(&CountryStatusDisplay::DownloadCountry, this));
m_downloadButton->setOnClickListener(bind(&CountryStatusDisplay::downloadCountry, this));
m_downloadButton->setIsVisible(false);
m_downloadButton->setPosition(yg::EPosCenter);
m_downloadButton->setFont(gui::Element::EActive, yg::FontDesc(16));
@ -132,11 +132,16 @@ CountryStatusDisplay::~CountryStatusDisplay()
m_storage->Unsubscribe(m_slotID);
}
void CountryStatusDisplay::DownloadCountry()
void CountryStatusDisplay::downloadCountry()
{
m_storage->DownloadCountry(m_countryIdx);
}
void CountryStatusDisplay::setDownloadListener(gui::Button::TOnClickListener const & l)
{
m_downloadButton->setOnClickListener(l);
}
void CountryStatusDisplay::setCountryName(string const & name)
{
if (m_countryName != name)

View file

@ -44,9 +44,6 @@ private:
/// caching resources for fast rendering.
void cache();
/// callback for button click to download country
void DownloadCountry();
public:
struct Params : public gui::Element::Params
@ -57,6 +54,10 @@ public:
CountryStatusDisplay(Params const & p);
~CountryStatusDisplay();
/// start country download
void downloadCountry();
/// set download button listener
void setDownloadListener(gui::Button::TOnClickListener const & l);
/// set current country name
void setCountryName(string const & name);
/// reposition element

View file

@ -458,3 +458,8 @@ void InformationDisplay::doDraw(DrawerYG *drawer)
//if (s_isLogEnabled)
// drawLog(drawer);
}
shared_ptr<CountryStatusDisplay> const & InformationDisplay::countryStatusDisplay() const
{
return m_countryStatusDisplay;
}

View file

@ -137,5 +137,7 @@ public:
void setDownloadListener(gui::Button::TOnClickListener l);
void setEmptyCountryName(char const * country);
shared_ptr<CountryStatusDisplay> const & countryStatusDisplay() const;
static void logMessage(my::LogLevel, my::SrcPoint const &, string const &);
};