Fix #10874
This commit is contained in:
parent
0ababa179c
commit
3b89528652
8 changed files with 75 additions and 22 deletions
|
@ -66,6 +66,8 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -84,6 +86,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||||
import static android.util.TypedValue.COMPLEX_UNIT_SP;
|
import static android.util.TypedValue.COMPLEX_UNIT_SP;
|
||||||
|
|
||||||
public class AndroidUtils {
|
public class AndroidUtils {
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(AndroidUtils.class);
|
||||||
|
|
||||||
public static final String STRING_PLACEHOLDER = "%s";
|
public static final String STRING_PLACEHOLDER = "%s";
|
||||||
public static final MessageFormat formatKb = new MessageFormat("{0, number,##.#}", Locale.US);
|
public static final MessageFormat formatKb = new MessageFormat("{0, number,##.#}", Locale.US);
|
||||||
|
@ -804,16 +807,24 @@ public class AndroidUtils {
|
||||||
|
|
||||||
public static long getAvailableSpace(@Nullable File dir) {
|
public static long getAvailableSpace(@Nullable File dir) {
|
||||||
if (dir != null && dir.canRead()) {
|
if (dir != null && dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
return fs.getAvailableBlocksLong() * fs.getBlockSize();
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
|
return fs.getAvailableBlocksLong() * fs.getBlockSize();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getFreeSpaceGb(File dir) {
|
public static float getFreeSpaceGb(File dir) {
|
||||||
if (dir.canRead()) {
|
if (dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
return (float) (fs.getBlockSize()) * fs.getAvailableBlocks() / (1 << 30);
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
|
return (float) (fs.getBlockSize()) * fs.getAvailableBlocks() / (1 << 30);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -23,6 +25,7 @@ import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
|
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||||
|
|
||||||
public class PicassoUtils {
|
public class PicassoUtils {
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(PicassoUtils.class);
|
||||||
|
|
||||||
private static final String PICASSO_CACHE = "picasso-cache";
|
private static final String PICASSO_CACHE = "picasso-cache";
|
||||||
private static final int MIN_DISK_CACHE_SIZE = 5 * 1024 * 1024; // 5MB
|
private static final int MIN_DISK_CACHE_SIZE = 5 * 1024 * 1024; // 5MB
|
||||||
|
@ -109,7 +112,8 @@ public class PicassoUtils {
|
||||||
long available = blockCount * blockSize;
|
long available = blockCount * blockSize;
|
||||||
// Target 2% of the total space.
|
// Target 2% of the total space.
|
||||||
size = available / 50;
|
size = available / 50;
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bound inside min/max size for disk cache.
|
// Bound inside min/max size for disk cache.
|
||||||
|
|
|
@ -384,8 +384,12 @@ public class MultimediaNotesFragment extends BaseSettingsFragment implements Cop
|
||||||
File dir = app.getAppPath("").getParentFile();
|
File dir = app.getAppPath("").getParentFile();
|
||||||
long size = 0;
|
long size = 0;
|
||||||
if (dir.canRead()) {
|
if (dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
size = ((long) fs.getBlockSize() * (long) fs.getBlockCount()) / (1 << 30);
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
|
size = ((long) fs.getBlockSize() * (long) fs.getBlockCount()) / (1 << 30);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
|
|
@ -31,6 +31,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.FileUtils;
|
import net.osmand.FileUtils;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
|
@ -39,6 +40,8 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -52,7 +55,7 @@ import java.util.Locale;
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
public class DashChooseAppDirFragment {
|
public class DashChooseAppDirFragment {
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(DashChooseAppDirFragment.class);
|
||||||
|
|
||||||
public static class ChooseAppDirFragment {
|
public static class ChooseAppDirFragment {
|
||||||
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
|
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
|
||||||
|
@ -92,8 +95,12 @@ public class DashChooseAppDirFragment {
|
||||||
|
|
||||||
private String getFreeSpace(File dir) {
|
private String getFreeSpace(File dir) {
|
||||||
if (dir.canRead()) {
|
if (dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
return AndroidUtils.formatSize(activity, (long) fs.getAvailableBlocks() * fs.getBlockSize() );
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
|
return AndroidUtils.formatSize(activity, (long) fs.getAvailableBlocks() * fs.getBlockSize());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import android.widget.ProgressBar;
|
||||||
import android.widget.Space;
|
import android.widget.Space;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.ibm.icu.impl.IllegalIcuArgumentException;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
@ -654,9 +656,13 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
String size = "";
|
String size = "";
|
||||||
int percent = 0;
|
int percent = 0;
|
||||||
if (dir.canRead()) {
|
if (dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
size = AndroidUtils.formatSize(activity, ((long) fs.getAvailableBlocks()) * fs.getBlockSize());
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
percent = 100 - (int) ((long) fs.getAvailableBlocks() * 100 / fs.getBlockCount());
|
size = AndroidUtils.formatSize(activity, ((long) fs.getAvailableBlocks()) * fs.getBlockSize());
|
||||||
|
percent = 100 - (int) ((long) fs.getAvailableBlocks() * 100 / fs.getBlockCount());
|
||||||
|
} catch (IllegalIcuArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sizeProgress.setIndeterminate(false);
|
sizeProgress.setIndeterminate(false);
|
||||||
sizeProgress.setProgress(percent);
|
sizeProgress.setProgress(percent);
|
||||||
|
|
|
@ -294,8 +294,12 @@ public class DownloadIndexesThread {
|
||||||
File dir = app.getAppPath("").getParentFile();
|
File dir = app.getAppPath("").getParentFile();
|
||||||
double asz = -1;
|
double asz = -1;
|
||||||
if (dir.canRead()) {
|
if (dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
|
asz = (((long) fs.getAvailableBlocks()) * fs.getBlockSize()) / (1 << 20);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return asz;
|
return asz;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,15 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.ibm.icu.impl.IllegalIcuArgumentException;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.FileUtils;
|
import net.osmand.FileUtils;
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OnDismissDialogFragmentListener;
|
import net.osmand.plus.OnDismissDialogFragmentListener;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
|
@ -32,9 +35,12 @@ import net.osmand.plus.dashboard.DashChooseAppDirFragment;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
import net.osmand.plus.download.DownloadIndexesThread;
|
import net.osmand.plus.download.DownloadIndexesThread;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(DataStoragePlaceDialogFragment.class);
|
||||||
|
|
||||||
public static final String TAG = "DataStoragePlaceDialogFragment";
|
public static final String TAG = "DataStoragePlaceDialogFragment";
|
||||||
private static final String STORAGE_READOLNY_KEY = "storage_readolny_key";
|
private static final String STORAGE_READOLNY_KEY = "storage_readolny_key";
|
||||||
|
@ -189,11 +195,15 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
||||||
private String getFreeSpace(File dir) {
|
private String getFreeSpace(File dir) {
|
||||||
String sz = "";
|
String sz = "";
|
||||||
if (dir != null && dir.canRead()) {
|
if (dir != null && dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
@SuppressWarnings("deprecation")
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
long size = (long) fs.getAvailableBlocks() * fs.getBlockSize();
|
@SuppressWarnings("deprecation")
|
||||||
if (size > 0) {
|
long size = (long) fs.getAvailableBlocks() * fs.getBlockSize();
|
||||||
sz = AndroidUtils.formatSize(getActivity(), size);
|
if (size > 0) {
|
||||||
|
sz = AndroidUtils.formatSize(getActivity(), size);
|
||||||
|
}
|
||||||
|
} catch (IllegalIcuArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sz;
|
return sz;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||||
import net.osmand.AndroidNetworkUtils;
|
import net.osmand.AndroidNetworkUtils;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
import net.osmand.binary.BinaryMapDataObject;
|
import net.osmand.binary.BinaryMapDataObject;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -67,6 +68,8 @@ import java.util.TimerTask;
|
||||||
|
|
||||||
public class FirstUsageWizardFragment extends BaseOsmAndFragment implements OsmAndLocationListener,
|
public class FirstUsageWizardFragment extends BaseOsmAndFragment implements OsmAndLocationListener,
|
||||||
AppInitializeListener, DownloadEvents {
|
AppInitializeListener, DownloadEvents {
|
||||||
|
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(FirstUsageWizardFragment.class);
|
||||||
|
|
||||||
public static final String TAG = "FirstUsageWizardFrag";
|
public static final String TAG = "FirstUsageWizardFrag";
|
||||||
public static final int FIRST_USAGE_LOCATION_PERMISSION = 300;
|
public static final int FIRST_USAGE_LOCATION_PERMISSION = 300;
|
||||||
public static final int FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION = 400;
|
public static final int FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION = 400;
|
||||||
|
@ -736,8 +739,12 @@ public class FirstUsageWizardFragment extends BaseOsmAndFragment implements OsmA
|
||||||
|
|
||||||
private String getFreeSpace(File dir) {
|
private String getFreeSpace(File dir) {
|
||||||
if (dir.canRead()) {
|
if (dir.canRead()) {
|
||||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
try {
|
||||||
return AndroidUtils.formatSize(getActivity(), (long) fs.getAvailableBlocks() * fs.getBlockSize() );
|
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||||
|
return AndroidUtils.formatSize(getActivity(), (long) fs.getAvailableBlocks() * fs.getBlockSize());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue