Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-04-27 22:39:19 +02:00
commit 31577a9a44
5 changed files with 429 additions and 354 deletions

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="application_dir_change_warning3">Do you want OsmAnd to also copy its data files to the new destination?</string>
<string name="specified_directiory_not_writeable">Maps could not be created in specified directory</string>
<string name="copying_osmand_file_failed">Copying files failed</string>
<string name="storage_directory_external">External storage</string>
@ -16,6 +17,7 @@
<string name="storage_directory_internal_app">Internal application memory</string>
<string name="storage_directory_manual">Manually specified</string>
<string name="storage_directory_default">Internal memory</string>
<string name="application_dir">Data storage folder</string>
<string name="storage_directory">Map Storage</string>
<string name="shared_string_copy">Copy</string>
<string name="filter_poi_hint">Filter by name</string>
@ -241,7 +243,7 @@
<string name="dash_download_manage">Manage</string>
<string name="map_locale">Map language</string>
<string name="rendering_attr_transportStops_name">Transport stops</string>
<string name="application_dir_change_warning2">Do you want OsmAnd to also copy its data files to the new destination? Select \'No\' for OsmAnd to just create and use the new folder.</string>
<string name="navigate_point_zone">Zone</string>
<string name="navigate_point_northing">Northing</string>
<string name="navigate_point_easting">Easting</string>
@ -1799,7 +1801,7 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="use_osmand_routing_service_descr">Use OsmAnd offline navigation applies only to routes &gt; 20 km (experimental)</string>
<string name="osmand_routing_experimental">OsmAnd offline navigation is an experimental feature and it does not work for distances of more than about 20 km.\n\nNavigation service is temporarily switched to online CloudMade.</string>
<string name="specified_dir_doesnt_exist">Can not find the specified folder.</string>
<string name="application_dir">Data storage folder</string>
<string name="osmand_net_previously_installed">A previous OsmAnd version is installed. All offline data will be supported by the new application. But Favorite points should be exported in the old application and later imported by the new one.</string>
<string name="build_installed">Build {0} successfully installed ({1}).</string>

View file

@ -64,6 +64,7 @@ import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@ -802,6 +803,9 @@ public class MapActivity extends AccessibleActivity {
}
public void checkExternalStorage() {
if(Build.VERSION.SDK_INT >= 19) {
return;
}
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// ok

View file

@ -1,9 +1,6 @@
package net.osmand.plus.activities;
import java.io.File;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
@ -13,21 +10,14 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ScrollView;

View file

@ -7,7 +7,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import net.osmand.CallbackWithObject;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
@ -20,6 +19,7 @@ import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment;
import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
@ -29,6 +29,7 @@ import net.osmand.plus.voice.CommandPlayer;
import net.osmand.render.RenderingRulesStorage;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
@ -36,6 +37,7 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@ -304,6 +306,42 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
}
});
}
public void showAppDirDialog(){
if(Build.VERSION.SDK_INT >= 19) {
showAppDirDialogV19();
return;
}
AlertDialog.Builder editalert = new AlertDialog.Builder(SettingsGeneralActivity.this);
editalert.setTitle(R.string.application_dir);
final EditText input = new EditText(SettingsGeneralActivity.this);
input.setText(settings.getExternalStorageDirectory().getAbsolutePath());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp.leftMargin = lp.rightMargin = 5;
lp.bottomMargin = lp.topMargin = 5;
input.setLayoutParams(lp);
settings.getExternalStorageDirectory().getAbsolutePath();
editalert.setView(input);
editalert.setNegativeButton(R.string.shared_string_cancel, null);
editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
warnAboutChangingStorage(input.getText().toString());
}
});
editalert.show();
}
private void showAppDirDialogV19() {
Builder bld = new AlertDialog.Builder(this);
ChooseAppDirFragment frg = new DashChooseAppDirFragment.ChooseAppDirFragment(this, (Dialog) null);
bld.setView(frg.initView(getLayoutInflater(), null));
AlertDialog dlg = bld.show();
frg.setDialog(dlg);
}
@ -314,30 +352,9 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
applicationDir.setKey("external_storage_dir");
applicationDir.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public void showOtherDialog(){
AlertDialog.Builder editalert = new AlertDialog.Builder(SettingsGeneralActivity.this);
editalert.setTitle(R.string.application_dir);
final EditText input = new EditText(SettingsGeneralActivity.this);
input.setText(settings.getExternalStorageDirectory().getAbsolutePath());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp.leftMargin = lp.rightMargin = 5;
lp.bottomMargin = lp.topMargin = 5;
input.setLayoutParams(lp);
settings.getExternalStorageDirectory().getAbsolutePath();
editalert.setView(input);
editalert.setNegativeButton(R.string.shared_string_cancel, null);
editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
warnAboutChangingStorage(input.getText().toString());
}
});
editalert.show();
}
@Override
public boolean onPreferenceClick(Preference preference) {
showOtherDialog();
showAppDirDialog();
return false;
}
});
@ -444,7 +461,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
return;
}
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.application_dir_change_warning2));
builder.setMessage(getString(R.string.application_dir_change_warning3));
builder.setPositiveButton(R.string.shared_string_yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

View file

@ -22,7 +22,9 @@ import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.util.Algorithms;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -31,9 +33,11 @@ import android.os.Build;
import android.os.Bundle;
import android.os.StatFs;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
@ -46,342 +50,371 @@ import android.widget.Toast;
public class DashChooseAppDirFragment extends DashBaseFragment {
public static final String TAG = "DASH_CHOOSE_APP_DIR_FRAGMENT";
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
private TextView locationPath;
private TextView locationDesc;
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
private View copyMapsBtn;
private ImageView editBtn;
private View confirmBtn;
private boolean mapsCopied = false;
private TextView warningReadonly;
private int type = -1;
private File selectedFile = new File("/");
private File currentAppFile;
private OsmandSettings settings;
private ChooseAppDirFragment fragment;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
fragment = new ChooseAppDirFragment(activity, this);
}
@Override
public void onOpenDash() {
}
private String getFreeSpace(File dir) {
if(dir.canRead()){
StatFs fs = new StatFs(dir.getAbsolutePath());
return formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
}
return "";
}
public void updateView() {
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT ) {
locationPath.setText(R.string.storage_directory_default);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE) {
locationPath.setText(R.string.storage_directory_external);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB) {
locationPath.setText(R.string.storage_directory_multiuser);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
locationPath.setText(R.string.storage_directory_manual);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
locationPath.setText(R.string.storage_directory_manual);
}
locationDesc.setText(selectedFile.getAbsolutePath() + " \u2022 " + getFreeSpace(selectedFile));
boolean readOnlyAndFileExist = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath()) &&
!OsmandSettings.isWritable(currentAppFile) && !mapsCopied;
if (readOnlyAndFileExist) {
readOnlyAndFileExist = false;
File[] lf = currentAppFile.listFiles();
if (lf != null) {
for (File f : lf) {
if (f != null) {
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
readOnlyAndFileExist = true;
break;
}
}
}
}
}
warningReadonly.setVisibility(readOnlyAndFileExist ? View.VISIBLE : View.GONE);
warningReadonly.setText(getString(R.string.android_19_location_disabled, currentAppFile.getAbsolutePath()));
copyMapsBtn.setVisibility(readOnlyAndFileExist ? View.VISIBLE : View.GONE);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_storage_type_fragment, container, false);
settings = getMyApplication().getSettings();
locationPath = (TextView) view.findViewById(R.id.location_path);
locationDesc = (TextView) view.findViewById(R.id.location_desc);
warningReadonly = (TextView) view.findViewById(R.id.android_19_location_changed);
currentAppFile = settings.getExternalStorageDirectory();
selectedFile = currentAppFile;
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
type = settings.getExternalStorageDirectoryTypeV19();
} else {
ValueHolder<Integer> vh = new ValueHolder<Integer>();
settings.getExternalStorageDirectory(vh);
if (vh.value != null && vh.value >= 0) {
type = vh.value;
} else {
type = 0;
}
}
editBtn = (ImageView) view.findViewById(R.id.edit_icon);
copyMapsBtn = view.findViewById(R.id.copy_maps);
confirmBtn = view.findViewById(R.id.confirm);
addListeners();
updateView();
return view;
return fragment.initView(inflater, container);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
protected void showSelectDialog19() {
AlertDialog.Builder editalert = new AlertDialog.Builder(getActivity());
editalert.setTitle(R.string.application_dir);
final List<String> items = new ArrayList<String>();
final List<String> paths = new ArrayList<String>();
final TIntArrayList types = new TIntArrayList();
int selected = -1;
if(type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
items.add(getString(R.string.storage_directory_manual));
paths.add(selectedFile.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED);
}
File df = settings.getDefaultInternalStorage();
if(type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT ||
OsmandSettings.isWritable(df)) {
if(type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_default));
paths.add(df.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT);
}
File[] externals = getMyApplication().getExternalFilesDirs(null);
if(externals != null) {
int i = 1;
for(File external : externals) {
if(external != null) {
if(selectedFile.getAbsolutePath().equals(external.getAbsolutePath()) ) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_external) + " " + (i++));
paths.add(external.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE);
}
}
}
File[] obbDirs = getMyApplication().getObbDirs();
if(obbDirs != null) {
int i = 1;
for(File obb : obbDirs) {
if(obb != null) {
if(selectedFile.getAbsolutePath().equals(obb.getAbsolutePath()) ) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_multiuser) + " " + (i++));
paths.add(obb.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB);
}
}
}
String pth = settings.getInternalAppPath().getAbsolutePath();
if(selectedFile.getAbsolutePath().equals(pth) ) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_internal_app));
paths.add(pth);
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE);
items.add(getString(R.string.storage_directory_manual) + getString(R.string.shared_string_ellipsis));
paths.add("");
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED);
editalert.setSingleChoiceItems(items.toArray(new String[items.size()]),
selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == items.size() - 1) {
dialog.dismiss();
showOtherDialog();
} else {
mapsCopied = false;
type = types.get(which);
selectedFile = new File(paths.get(which));
dialog.dismiss();
updateView();
}
}
});
editalert.setNegativeButton(R.string.shared_string_dismiss, null);
editalert.show();
}
public void showOtherDialog(){
AlertDialog.Builder editalert = new AlertDialog.Builder(getActivity());
editalert.setTitle(R.string.application_dir);
final EditText input = new EditText(getActivity());
input.setText(selectedFile.getAbsolutePath());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp.leftMargin = lp.rightMargin = 5;
lp.bottomMargin = lp.topMargin = 5;
input.setLayoutParams(lp);
settings.getExternalStorageDirectory().getAbsolutePath();
editalert.setView(input);
editalert.setNegativeButton(R.string.shared_string_cancel, null);
editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
selectedFile = new File(input.getText().toString());
mapsCopied = false;
updateView();
}
});
editalert.show();
}
private void addListeners() {
editBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
showOtherDialog();
} else {
showSelectDialog19();
}
}
});
copyMapsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MoveFilesToDifferentDirectory task = new MoveFilesToDifferentDirectory(getActivity(), currentAppFile,
selectedFile) {
protected Boolean doInBackground(Void[] params) {
Boolean result = super.doInBackground(params);
if (result) {
mapsCopied = true;
getMyApplication().getResourceManager().resetStoreDirectory();
} else {
AccessibleToast.makeText(getActivity(), R.string.copying_osmand_file_failed,
Toast.LENGTH_SHORT).show();
}
updateView();
return result;
}
};
task.execute();
}
});
confirmBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean wr = OsmandSettings.isWritable(selectedFile);
if(wr) {
boolean changed = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath());
getMyApplication().setExternalStorageDirectory(type, currentAppFile.getAbsolutePath());
if(changed) {
reloadData();
}
ActionBarActivity dashboardActivity = ((ActionBarActivity) getActivity());
if (dashboardActivity != null) {
dashboardActivity.getSupportFragmentManager().beginTransaction().remove(DashChooseAppDirFragment.this)
.commit();
}
} else {
AccessibleToast.makeText(getActivity(), R.string.specified_directiory_not_writeable,
Toast.LENGTH_LONG).show();
}
}
});
}
protected void reloadData() {
new ReloadData(getActivity(), getMyApplication()).execute((Void)null );
}
public static class ReloadData extends AsyncTask<Void, Void, Boolean> {
private Context ctx;
protected ProgressImplementation progress;
private OsmandApplication app;
public ReloadData(Context ctx, OsmandApplication app) {
this.ctx = ctx;
this.app = app;
}
@Override
protected void onPreExecute() {
progress = ProgressImplementation.createProgressDialog(ctx, ctx.getString(R.string.loading_data),
ctx.getString(R.string.loading_data), ProgressDialog.STYLE_HORIZONTAL);
}
@Override
protected void onPostExecute(Boolean result) {
if (progress.getDialog().isShowing()) {
progress.getDialog().dismiss();
}
}
@Override
protected Boolean doInBackground(Void... params) {
app.getResourceManager().reloadIndexes(progress, new ArrayList<String>());
return true;
}
}
public static boolean isDashNeeded(OsmandSettings settings) {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return false;
}
return !settings.isExternalStorageDirectorySpecifiedV19();
}
public static HashSet<String> getExternalMounts() {
final HashSet<String> out = new HashSet<String>();
String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
String s = "";
try {
final Process process = new ProcessBuilder().command("mount")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
s = s + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
public static class ChooseAppDirFragment {
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
private TextView locationPath;
private TextView locationDesc;
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
private View copyMapsBtn;
private ImageView editBtn;
private View confirmBtn;
private boolean mapsCopied = false;
private TextView warningReadonly;
private int type = -1;
private File selectedFile = new File("/");
private File currentAppFile;
private OsmandSettings settings;
private Activity activity;
private Fragment fragment;
private Dialog dlg;
public ChooseAppDirFragment(Activity activity, Fragment f) {
this.activity = activity;
this.fragment = f;
}
public ChooseAppDirFragment(Activity activity, Dialog dlg) {
this.activity = activity;
this.dlg = dlg;
}
private String getFreeSpace(File dir) {
if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath());
return formatGb
.format(new Object[] { (float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
}
return "";
}
public void updateView() {
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT) {
locationPath.setText(R.string.storage_directory_default);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE) {
locationPath.setText(R.string.storage_directory_external);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB) {
locationPath.setText(R.string.storage_directory_multiuser);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
locationPath.setText(R.string.storage_directory_manual);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
locationPath.setText(R.string.storage_directory_manual);
}
locationDesc.setText(selectedFile.getAbsolutePath() + " \u2022 " + getFreeSpace(selectedFile));
boolean copyFiles = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath()) && !mapsCopied;
if (copyFiles) {
copyFiles = false;
File[] lf = currentAppFile.listFiles();
if (lf != null) {
for (File f : lf) {
if (f != null) {
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
copyFiles = true;
break;
}
}
}
}
}
warningReadonly.setVisibility(copyFiles ? View.VISIBLE : View.GONE);
if (copyFiles) {
if (!OsmandSettings.isWritable(currentAppFile)) {
warningReadonly.setText(activity.getString(R.string.android_19_location_disabled,
currentAppFile.getAbsolutePath()));
} else {
warningReadonly.setText(getString(R.string.application_dir_change_warning3));
}
}
copyMapsBtn.setVisibility(copyFiles ? View.VISIBLE : View.GONE);
}
public View initView(LayoutInflater inflater, ViewGroup container) {
View view = inflater.inflate(R.layout.dash_storage_type_fragment, container, false);
settings = getMyApplication().getSettings();
locationPath = (TextView) view.findViewById(R.id.location_path);
locationDesc = (TextView) view.findViewById(R.id.location_desc);
warningReadonly = (TextView) view.findViewById(R.id.android_19_location_changed);
currentAppFile = settings.getExternalStorageDirectory();
selectedFile = currentAppFile;
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
type = settings.getExternalStorageDirectoryTypeV19();
} else {
ValueHolder<Integer> vh = new ValueHolder<Integer>();
settings.getExternalStorageDirectory(vh);
if (vh.value != null && vh.value >= 0) {
type = vh.value;
} else {
type = 0;
}
}
editBtn = (ImageView) view.findViewById(R.id.edit_icon);
copyMapsBtn = view.findViewById(R.id.copy_maps);
confirmBtn = view.findViewById(R.id.confirm);
addListeners();
updateView();
return view;
}
public String getString(int string) {
return activity.getString(string);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
protected void showSelectDialog19() {
AlertDialog.Builder editalert = new AlertDialog.Builder(activity);
editalert.setTitle(R.string.application_dir);
final List<String> items = new ArrayList<String>();
final List<String> paths = new ArrayList<String>();
final TIntArrayList types = new TIntArrayList();
int selected = -1;
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
items.add(getString(R.string.storage_directory_manual));
paths.add(selectedFile.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED);
}
File df = settings.getDefaultInternalStorage();
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT || OsmandSettings.isWritable(df)) {
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_default));
paths.add(df.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT);
}
File[] externals = getMyApplication().getExternalFilesDirs(null);
if (externals != null) {
int i = 1;
for (File external : externals) {
if (external != null) {
if (selectedFile.getAbsolutePath().equals(external.getAbsolutePath())) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_external) + " " + (i++));
paths.add(external.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE);
}
}
}
File[] obbDirs = getMyApplication().getObbDirs();
if (obbDirs != null) {
int i = 1;
for (File obb : obbDirs) {
if (obb != null) {
if (selectedFile.getAbsolutePath().equals(obb.getAbsolutePath())) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_multiuser) + " " + (i++));
paths.add(obb.getAbsolutePath());
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB);
}
}
}
String pth = settings.getInternalAppPath().getAbsolutePath();
if (selectedFile.getAbsolutePath().equals(pth)) {
selected = items.size();
}
items.add(getString(R.string.storage_directory_internal_app));
paths.add(pth);
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE);
items.add(getString(R.string.storage_directory_manual) + getString(R.string.shared_string_ellipsis));
paths.add("");
types.add(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED);
editalert.setSingleChoiceItems(items.toArray(new String[items.size()]), selected,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == items.size() - 1) {
dialog.dismiss();
showOtherDialog();
} else {
mapsCopied = false;
type = types.get(which);
selectedFile = new File(paths.get(which));
dialog.dismiss();
updateView();
}
}
});
editalert.setNegativeButton(R.string.shared_string_dismiss, null);
editalert.show();
}
public void showOtherDialog() {
AlertDialog.Builder editalert = new AlertDialog.Builder(activity);
editalert.setTitle(R.string.application_dir);
final EditText input = new EditText(activity);
input.setText(selectedFile.getAbsolutePath());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp.leftMargin = lp.rightMargin = 5;
lp.bottomMargin = lp.topMargin = 5;
input.setLayoutParams(lp);
settings.getExternalStorageDirectory().getAbsolutePath();
editalert.setView(input);
editalert.setNegativeButton(R.string.shared_string_cancel, null);
editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
selectedFile = new File(input.getText().toString());
mapsCopied = false;
updateView();
}
});
editalert.show();
}
private void addListeners() {
editBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
showOtherDialog();
} else {
showSelectDialog19();
}
}
});
copyMapsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MoveFilesToDifferentDirectory task = new MoveFilesToDifferentDirectory(activity, currentAppFile,
selectedFile) {
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
mapsCopied = true;
getMyApplication().getResourceManager().resetStoreDirectory();
} else {
AccessibleToast.makeText(activity, R.string.copying_osmand_file_failed,
Toast.LENGTH_SHORT).show();
}
updateView();
}
};
task.execute();
}
});
confirmBtn.setOnClickListener(getConfirmListener());
}
public OnClickListener getConfirmListener() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean wr = OsmandSettings.isWritable(selectedFile);
if (wr) {
boolean changed = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath());
getMyApplication().setExternalStorageDirectory(type, selectedFile.getAbsolutePath());
if (changed) {
reloadData();
}
if (fragment != null && activity instanceof FragmentActivity) {
((FragmentActivity) activity).getSupportFragmentManager().beginTransaction()
.remove(fragment).commit();
}
} else {
AccessibleToast.makeText(activity, R.string.specified_directiory_not_writeable,
Toast.LENGTH_LONG).show();
}
if(dlg != null) {
dlg.dismiss();
}
}
};
}
protected void reloadData() {
new ReloadData(activity, getMyApplication()).execute((Void) null);
}
public OsmandApplication getMyApplication() {
if (activity == null) {
return null;
}
return (OsmandApplication) activity.getApplication();
}
public static HashSet<String> getExternalMounts() {
final HashSet<String> out = new HashSet<String>();
String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
String s = "";
try {
final Process process = new ProcessBuilder().command("mount").redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
s = s + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
// parse output
final String[] lines = s.split("\n");
for (String line : lines) {
if (!line.toLowerCase(Locale.US).contains("asec")) {
if (line.matches(reg)) {
String[] parts = line.split(" ");
for (String part : parts) {
if (part.startsWith("/"))
if (!part.toLowerCase(Locale.US).contains("vold"))
out.add(part);
}
}
}
}
return out;
}
public void setDialog(Dialog dlg) {
this.dlg = dlg;
}
// parse output
final String[] lines = s.split("\n");
for (String line : lines) {
if (!line.toLowerCase(Locale.US).contains("asec")) {
if (line.matches(reg)) {
String[] parts = line.split(" ");
for (String part : parts) {
if (part.startsWith("/"))
if (!part.toLowerCase(Locale.US).contains("vold"))
out.add(part);
}
}
}
}
return out;
}
public static class MoveFilesToDifferentDirectory extends AsyncTask<Void, Void, Boolean> {
@ -476,5 +509,34 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
}
}
public static class ReloadData extends AsyncTask<Void, Void, Boolean> {
private Context ctx;
protected ProgressImplementation progress;
private OsmandApplication app;
public ReloadData(Context ctx, OsmandApplication app) {
this.ctx = ctx;
this.app = app;
}
@Override
protected void onPreExecute() {
progress = ProgressImplementation.createProgressDialog(ctx, ctx.getString(R.string.loading_data),
ctx.getString(R.string.loading_data), ProgressDialog.STYLE_HORIZONTAL);
}
@Override
protected void onPostExecute(Boolean result) {
if (progress.getDialog().isShowing()) {
progress.getDialog().dismiss();
}
}
@Override
protected Boolean doInBackground(Void... params) {
app.getResourceManager().reloadIndexes(progress, new ArrayList<String>());
return true;
}
}
}