forked from organicmaps/organicmaps
[android]
- Fix bug with files moving. - Settings.ini should be in a one place always (default external path). - Add AlertDialog in files moving.
This commit is contained in:
parent
5d1ece2c3e
commit
9119ae9daa
16 changed files with 146 additions and 34 deletions
|
@ -26,13 +26,13 @@ extern "C"
|
|||
g_framework->RemoveLocalMaps();
|
||||
|
||||
Platform & pl = GetPlatform();
|
||||
char const * arrExt[] = { DATA_FILE_EXTENSION, ".ttf", ".ini" };
|
||||
char const * arrMask[] = { "*" DATA_FILE_EXTENSION, "*.ttf" };
|
||||
|
||||
// Copy all needed files.
|
||||
for (size_t i = 0; i < ARRAY_SIZE(arrExt); ++i)
|
||||
for (size_t i = 0; i < ARRAY_SIZE(arrMask); ++i)
|
||||
{
|
||||
Platform::FilesList files;
|
||||
pl.GetFilesInDir(from, "*" DATA_FILE_EXTENSION, files);
|
||||
pl.GetFilesInDir(from, arrMask[i], files);
|
||||
|
||||
for (size_t j = 0; j < files.size(); ++j)
|
||||
if (!my::CopyFile((from + files[j]).c_str(), (to + files[j]).c_str()))
|
||||
|
|
|
@ -88,9 +88,12 @@ namespace android
|
|||
|
||||
m_resourcesDir = jni::ToNativeString(env, apkPath);
|
||||
|
||||
// Settings file should always be in one place (default external storage).
|
||||
// It stores path to current maps storage.
|
||||
m_settingsDir = jni::ToNativeString(env, storagePath);
|
||||
|
||||
if (!Settings::Get("StoragePath", m_writableDir))
|
||||
m_writableDir = jni::ToNativeString(env, storagePath);
|
||||
m_settingsDir = m_writableDir;
|
||||
m_writableDir = m_settingsDir;
|
||||
|
||||
m_localTmpPath = jni::ToNativeString(env, tmpPath);
|
||||
m_externalTmpPath = jni::ToNativeString(env, extTmpPath);
|
||||
|
@ -127,7 +130,7 @@ namespace android
|
|||
|
||||
void Platform::SetStoragePath(string const & path)
|
||||
{
|
||||
m_writableDir = m_settingsDir = path;
|
||||
m_writableDir = path;
|
||||
Settings::Set("StoragePath", m_writableDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -186,4 +186,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -190,4 +190,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -186,4 +186,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -182,4 +182,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -188,4 +188,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -184,4 +184,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -194,4 +194,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -194,4 +194,8 @@
|
|||
<string name="settings">Настройки</string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage">Хранилище карт</string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps">Переместить карты?</string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes">Это может занять несколько минут.\nПожалуйста, подождите ...</string>
|
||||
</resources>
|
||||
|
|
|
@ -182,4 +182,8 @@
|
|||
<string name="settings"></string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage"></string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps"></string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes"></string>
|
||||
</resources>
|
||||
|
|
|
@ -198,4 +198,8 @@
|
|||
<string name="settings">Settings</string>
|
||||
<!-- Header of settings activity where user defines storage path -->
|
||||
<string name="maps_storage">Maps storage</string>
|
||||
<!-- Question dialog for transferring maps from one storage to another -->
|
||||
<string name="move_maps">Move maps?</string>
|
||||
<!-- Ask to wait user several minutes (some long process in modal dialog). -->
|
||||
<string name="wait_several_minutes">This can take several minutes.\nPlease wait ...</string>
|
||||
</resources>
|
||||
|
|
|
@ -7,7 +7,9 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.StatFs;
|
||||
import android.util.Log;
|
||||
|
@ -136,15 +138,20 @@ public class SettingsActivity extends ListActivity
|
|||
return m_pathes.get(position) + "/MapsWithMe/";
|
||||
}
|
||||
|
||||
private void deleteRecursive(File file)
|
||||
// delete all files (except settings.ini) in directory
|
||||
private void deleteFiles(File dir)
|
||||
{
|
||||
if (file.isDirectory())
|
||||
for (File child : file.listFiles())
|
||||
deleteRecursive(child);
|
||||
|
||||
if (!file.delete())
|
||||
assert(dir.isDirectory());
|
||||
for (File file : dir.listFiles())
|
||||
{
|
||||
Log.w(TAG, "Can't delete file: " + file.getName());
|
||||
assert(file.isFile());
|
||||
|
||||
// skip settings.ini - this file should be always in one place
|
||||
if (file.getName().equalsIgnoreCase("settings.ini"))
|
||||
continue;
|
||||
|
||||
if (!file.delete())
|
||||
Log.w(TAG, "Can't delete file: " + file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +183,7 @@ public class SettingsActivity extends ListActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id)
|
||||
protected void onListItemClick(final ListView l, View v, final int position, long id)
|
||||
{
|
||||
if (position != m_checked)
|
||||
{
|
||||
|
@ -189,23 +196,48 @@ public class SettingsActivity extends ListActivity
|
|||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Transfer data to storage: " + path);
|
||||
if (nativeSetStoragePath(path))
|
||||
new AlertDialog.Builder(this)
|
||||
.setCancelable(false)
|
||||
.setTitle(R.string.move_maps)
|
||||
.setMessage(R.string.wait_several_minutes)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
|
||||
{
|
||||
if (m_checked != -1)
|
||||
deleteRecursive(new File(getFullPath(m_checked)));
|
||||
@Override
|
||||
public void onClick(DialogInterface dlg, int which)
|
||||
{
|
||||
Log.i(TAG, "Transfer data to storage: " + path);
|
||||
if (nativeSetStoragePath(path))
|
||||
{
|
||||
if (m_checked != -1)
|
||||
deleteFiles(new File(getFullPath(m_checked)));
|
||||
|
||||
l.setItemChecked(position, true);
|
||||
l.setItemChecked(position, true);
|
||||
|
||||
/*
|
||||
final CheckedTextView old = getViewByPos(l, m_checked);
|
||||
if (old != null)
|
||||
old.setChecked(false);
|
||||
((CheckedTextView) v).setChecked(true);
|
||||
*/
|
||||
m_checked = position;
|
||||
}
|
||||
else if (m_checked != -1)
|
||||
{
|
||||
// set check state back to m_checked item
|
||||
l.setItemChecked(m_checked, true);
|
||||
}
|
||||
|
||||
m_checked = position;
|
||||
}
|
||||
dlg.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dlg, int which)
|
||||
{
|
||||
// set check state back to m_checked item
|
||||
if (m_checked != -1)
|
||||
l.setItemChecked(m_checked, true);
|
||||
|
||||
dlg.dismiss();
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,14 +237,28 @@ bool CopyFile(string const & fOld, string const & fNew)
|
|||
ifstream ifs(fOld.c_str());
|
||||
ofstream ofs(fNew.c_str());
|
||||
|
||||
ofs << ifs.rdbuf();
|
||||
return true;
|
||||
if (ifs.is_open() && ofs.is_open())
|
||||
{
|
||||
ofs << ifs.rdbuf();
|
||||
|
||||
if (ofs.bad() || ofs.fail())
|
||||
{
|
||||
// Well, specification says that exception is thrown for critical errors.
|
||||
// So just log stream fail state and continue.
|
||||
LOG(LWARNING, ("Bad or Fail bit is set while writing file:", fNew));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
LOG(LERROR, ("Can't open files:", fOld, fNew));
|
||||
}
|
||||
catch (exception const & ex)
|
||||
{
|
||||
LOG(LERROR, ("Copy file error: ", ex.what()));
|
||||
return false;
|
||||
LOG(LERROR, ("Copy file error:", ex.what()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -271,9 +271,6 @@ void Framework::UpdateAfterDownload(string const & file)
|
|||
|
||||
void Framework::AddLocalMaps()
|
||||
{
|
||||
// initializes model with locally downloaded maps
|
||||
LOG(LDEBUG, ("Initializing storage"));
|
||||
|
||||
// add maps to the model
|
||||
Platform::FilesList maps;
|
||||
GetLocalMaps(maps);
|
||||
|
|
26
strings.txt
26
strings.txt
|
@ -1256,3 +1256,29 @@
|
|||
ko =
|
||||
cs =
|
||||
nl =
|
||||
[move_maps]
|
||||
en = Move maps?
|
||||
tags = android
|
||||
comment = Question dialog for transferring maps from one storage to another
|
||||
ru = Переместить карты?
|
||||
de =
|
||||
uk =
|
||||
es =
|
||||
fr =
|
||||
ja =
|
||||
ko =
|
||||
cs =
|
||||
nl =
|
||||
[wait_several_minutes]
|
||||
en = This can take several minutes.\nPlease wait ...
|
||||
tags = android
|
||||
comment = Ask to wait user several minutes (some long process in modal dialog).
|
||||
ru = Это может занять несколько минут.\nПожалуйста, подождите ...
|
||||
de =
|
||||
uk =
|
||||
es =
|
||||
fr =
|
||||
ja =
|
||||
ko =
|
||||
cs =
|
||||
nl =
|
||||
|
|
Loading…
Add table
Reference in a new issue