forked from organicmaps/organicmaps-tmp
[android] Closed #294 - Add/Remove maps when external storage is connected/disconnected
This commit is contained in:
parent
ad954d64c8
commit
366339be12
5 changed files with 98 additions and 31 deletions
|
@ -62,6 +62,9 @@ namespace android
|
|||
void SaveState();
|
||||
|
||||
void SetupMeasurementSystem();
|
||||
|
||||
void AddLocalMaps() { m_work.AddLocalMaps(); }
|
||||
void RemoveLocalMaps() { m_work.RemoveLocalMaps(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -96,4 +96,18 @@ extern "C"
|
|||
return u;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_nativeStorageConnected(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
g_framework->AddLocalMaps();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_nativeStorageDisconnected(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
g_framework->RemoveLocalMaps();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
|
|
@ -305,8 +305,6 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
|
||||
int ic_location_old = m_ic_location;
|
||||
int ic_menu_location_old = m_ic_menu_location;
|
||||
|
||||
|
@ -318,13 +316,13 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
updateButtonIcons();
|
||||
|
||||
stopWatchingExternalStorage();
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
m_ic_download = R.drawable.ic_download;
|
||||
m_ic_menu_download = R.drawable.ic_menu_download;
|
||||
|
||||
|
@ -334,6 +332,8 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
m_locationService.startUpdate(this, this);
|
||||
|
||||
startWatchingExternalStorage();
|
||||
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -369,11 +369,13 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
// Initialized to invalid combination to force update on the first check
|
||||
private boolean m_storageAvailable = false;
|
||||
private boolean m_storageWriteable = true;
|
||||
|
||||
private void updateExternalStorageState()
|
||||
{
|
||||
boolean available = false;
|
||||
boolean writeable = false;
|
||||
|
||||
boolean available, writeable;
|
||||
final String state = Environment.getExternalStorageState();
|
||||
if (Environment.MEDIA_MOUNTED.equals(state))
|
||||
{
|
||||
|
@ -384,23 +386,37 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
writeable = false;
|
||||
} else
|
||||
available = writeable = false;
|
||||
handleExternalStorageState(available, writeable);
|
||||
|
||||
if (m_storageAvailable != available || m_storageWriteable != writeable)
|
||||
{
|
||||
m_storageAvailable = available;
|
||||
m_storageWriteable = writeable;
|
||||
handleExternalStorageState(available, writeable);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleExternalStorageState(boolean available, boolean writeable)
|
||||
{
|
||||
Log.d("COUNTRY", "USB State changed:" + available + " " + writeable);
|
||||
|
||||
if (available && writeable)
|
||||
{ // enable downloader button and dismiss blocking popup
|
||||
{ // Add local maps to the model
|
||||
nativeStorageConnected();
|
||||
// enable downloader button and dismiss blocking popup
|
||||
m_btnDownloadMaps.setVisibility(View.VISIBLE);
|
||||
if (m_storageDisconnectedDialog != null)
|
||||
m_storageDisconnectedDialog.dismiss();
|
||||
} else if (available)
|
||||
{ // disable downloader button and dismiss blocking popup
|
||||
{ // Add local maps to the model
|
||||
nativeStorageConnected();
|
||||
// disable downloader button and dismiss blocking popup
|
||||
m_btnDownloadMaps.setVisibility(View.INVISIBLE);
|
||||
if (m_storageDisconnectedDialog != null)
|
||||
m_storageDisconnectedDialog.dismiss();
|
||||
} else
|
||||
{ // enable downloader button and show blocking popup
|
||||
{ // Remove local maps from the model
|
||||
nativeStorageDisconnected();
|
||||
// enable downloader button and show blocking popup
|
||||
m_btnDownloadMaps.setVisibility(View.VISIBLE);
|
||||
if (m_storageDisconnectedDialog == null)
|
||||
{
|
||||
|
@ -429,6 +445,10 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
filter.addAction(Intent.ACTION_MEDIA_EJECT);
|
||||
filter.addAction(Intent.ACTION_MEDIA_SHARED);
|
||||
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
|
||||
filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
|
||||
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
|
||||
filter.addAction(Intent.ACTION_MEDIA_CHECKING);
|
||||
filter.addAction(Intent.ACTION_MEDIA_NOFS);
|
||||
filter.addDataScheme("file");
|
||||
registerReceiver(m_externalStorageReceiver, filter);
|
||||
updateExternalStorageState();
|
||||
|
@ -448,13 +468,11 @@ public class MWMActivity extends NvEventQueueActivity implements
|
|||
System.loadLibrary("mapswithme");
|
||||
}
|
||||
|
||||
private native void nativeStorageConnected();
|
||||
private native void nativeStorageDisconnected();
|
||||
|
||||
private native void nativeInit(String apkPath, String storagePath);
|
||||
|
||||
private native void nativeLocationStatusChanged(int newStatus);
|
||||
|
||||
private native void nativeLocationUpdated(long time, double lat, double lon,
|
||||
float accuracy);
|
||||
|
||||
private native void nativeCompassUpdated(long time, double magneticNorth,
|
||||
double trueNorth, float accuracy);
|
||||
private native void nativeLocationUpdated(long time, double lat, double lon, float accuracy);
|
||||
private native void nativeCompassUpdated(long time, double magneticNorth, double trueNorth, float accuracy);
|
||||
}
|
||||
|
|
|
@ -84,6 +84,12 @@ InformationDisplay & Framework::GetInformationDisplay()
|
|||
return m_informationDisplay;
|
||||
}
|
||||
|
||||
static void GetResourcesMaps(vector<string> & outMaps)
|
||||
{
|
||||
Platform & pl = GetPlatform();
|
||||
pl.GetFilesInDir(pl.ResourcesDir(), "*" DATA_FILE_EXTENSION, outMaps);
|
||||
}
|
||||
|
||||
Framework::Framework()
|
||||
: m_hasPendingInvalidate(false),
|
||||
m_doForceUpdate(false),
|
||||
|
@ -125,6 +131,37 @@ Framework::Framework()
|
|||
|
||||
m_model.InitClassificator();
|
||||
|
||||
vector<string> maps;
|
||||
GetResourcesMaps(maps);
|
||||
#ifndef OMIM_OS_ANDROID
|
||||
// On Android, local maps are added and removed when external storage
|
||||
// is connected/disconnected
|
||||
GetLocalMaps(maps);
|
||||
#endif
|
||||
// Remove duplicate maps if they're both present in resources and in WritableDir
|
||||
sort(maps.begin(), maps.end());
|
||||
maps.erase(unique(maps.begin(), maps.end()), maps.end());
|
||||
try
|
||||
{
|
||||
for_each(maps.begin(), maps.end(), bind(&Framework::AddMap, this, _1));
|
||||
}
|
||||
catch (RootException const & e)
|
||||
{
|
||||
LOG(LERROR, ("Can't add map: ", e.what()));
|
||||
}
|
||||
|
||||
|
||||
m_storage.Init(bind(&Framework::AddMap, this, _1),
|
||||
bind(&Framework::RemoveMap, this, _1),
|
||||
bind(&Framework::InvalidateRect, this, _1, true));
|
||||
LOG(LDEBUG, ("Storage initialized"));
|
||||
}
|
||||
|
||||
Framework::~Framework()
|
||||
{}
|
||||
|
||||
void Framework::AddLocalMaps()
|
||||
{
|
||||
// initializes model with locally downloaded maps
|
||||
LOG(LDEBUG, ("Initializing storage"));
|
||||
// add maps to the model
|
||||
|
@ -138,25 +175,17 @@ Framework::Framework()
|
|||
{
|
||||
LOG(LERROR, ("Can't add map: ", e.what()));
|
||||
}
|
||||
|
||||
m_storage.Init(bind(&Framework::AddMap, this, _1),
|
||||
bind(&Framework::RemoveMap, this, _1),
|
||||
bind(&Framework::InvalidateRect, this, _1, true));
|
||||
LOG(LDEBUG, ("Storage initialized"));
|
||||
}
|
||||
|
||||
Framework::~Framework()
|
||||
{}
|
||||
void Framework::RemoveLocalMaps()
|
||||
{
|
||||
m_model.RemoveAllCountries();
|
||||
}
|
||||
|
||||
void Framework::GetLocalMaps(vector<string> & outMaps)
|
||||
{
|
||||
outMaps.clear();
|
||||
|
||||
Platform & pl = GetPlatform();
|
||||
pl.GetFilesInDir(pl.ResourcesDir(), "*" DATA_FILE_EXTENSION, outMaps);
|
||||
pl.GetFilesInDir(pl.WritableDir(), "*" DATA_FILE_EXTENSION, outMaps);
|
||||
sort(outMaps.begin(), outMaps.end());
|
||||
outMaps.erase(unique(outMaps.begin(), outMaps.end()), outMaps.end());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -317,7 +346,7 @@ void Framework::DoPaint(shared_ptr<PaintEvent> const & e)
|
|||
DrawerYG * pDrawer = e->drawer();
|
||||
|
||||
m_informationDisplay.setScreen(m_navigator.Screen());
|
||||
|
||||
|
||||
m_informationDisplay.enableEmptyModelMessage(m_renderPolicy->IsEmptyModel());
|
||||
|
||||
m_informationDisplay.setDebugInfo(0/*m_renderQueue.renderState().m_duration*/, my::rounds(GetCurrentScale()));
|
||||
|
|
|
@ -116,6 +116,9 @@ public:
|
|||
void DeleteOldMaps();
|
||||
//@}
|
||||
|
||||
void AddLocalMaps();
|
||||
void RemoveLocalMaps();
|
||||
|
||||
storage::Storage & Storage() { return m_storage; }
|
||||
|
||||
void OnLocationStatusChanged(location::TLocationStatus newStatus);
|
||||
|
|
Loading…
Add table
Reference in a new issue