Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-23 15:47:09 +02:00
commit 91ce06e6aa
3 changed files with 22 additions and 6 deletions

View file

@ -43,6 +43,8 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.support.annotation.Nullable;
import android.text.TextUtils;
public class OsmandSettings { public class OsmandSettings {
@ -1308,6 +1310,21 @@ public class OsmandSettings {
putString(EXTERNAL_STORAGE_DIR_V19, externalStorageDir).commit(); putString(EXTERNAL_STORAGE_DIR_V19, externalStorageDir).commit();
} }
@Nullable
public static File getSecondaryStorage() {
final String value = System.getenv("SECONDARY_STORAGE");
if (!TextUtils.isEmpty(value)) {
final String[] paths = value.split(":");
for (String path : paths) {
File file = new File(path);
if (file.isDirectory() && file.canWrite()) {
return file;
}
}
}
return null;
}
public void setExternalStorageDirectory(int type, String directory) { public void setExternalStorageDirectory(int type, String directory) {
if(Build.VERSION.SDK_INT < 19) { if(Build.VERSION.SDK_INT < 19) {
setExternalStorageDirectoryPre19(directory); setExternalStorageDirectoryPre19(directory);
@ -1325,7 +1342,6 @@ public class OsmandSettings {
return settingsAPI.edit(globalPreferences).putString(EXTERNAL_STORAGE_DIR, externalStorageDir).commit(); return settingsAPI.edit(globalPreferences).putString(EXTERNAL_STORAGE_DIR, externalStorageDir).commit();
} }
public Object getGlobalPreferences() { public Object getGlobalPreferences() {
return globalPreferences; return globalPreferences;
} }

View file

@ -142,7 +142,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(null); final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(null);
final boolean externalExists = final boolean externalExists =
DataStoragePlaceDialogFragment.getExternalStorageDirectory(this) != null; DataStoragePlaceDialogFragment.getExternalStorageDirectory() != null;
if (firstTime && externalExists) { if (firstTime && externalExists) {
new DataStoragePlaceDialogFragment().show(getFragmentManager(), null); new DataStoragePlaceDialogFragment().show(getFragmentManager(), null);
} }

View file

@ -55,7 +55,7 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
internalStorage = getInternalStorageDirectory(getActivity()); internalStorage = getInternalStorageDirectory(getActivity());
externalStorage = getExternalStorageDirectory(getActivity()); externalStorage = getExternalStorageDirectory();
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container, final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
false); false);
@ -95,9 +95,8 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
return view; return view;
} }
public static File getExternalStorageDirectory(Activity activity) { public static File getExternalStorageDirectory() {
return ((OsmandApplication) activity.getApplication()).getSettings() return OsmandSettings.getSecondaryStorage();
.getExternalStorageDirectory();
} }
public static File getInternalStorageDirectory(Activity activity) { public static File getInternalStorageDirectory(Activity activity) {
@ -122,6 +121,7 @@ public class DataStoragePlaceDialogFragment extends DialogFragment {
String sz = ""; String sz = "";
if (dir.canRead()) { if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath()); StatFs fs = new StatFs(dir.getAbsolutePath());
@SuppressWarnings("deprecation")
int size = fs.getAvailableBlocks() * fs.getBlockSize(); int size = fs.getAvailableBlocks() * fs.getBlockSize();
if (size > 0) { if (size > 0) {
if (size > 1 << 20) { if (size > 1 << 20) {