Skip to content

Commit

Permalink
hopefully this will fix some crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Calsign committed May 17, 2020
1 parent d0121af commit 4597902
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
36 changes: 20 additions & 16 deletions APDE/src/main/java/com/calsignlabs/apde/APDE.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,23 +811,27 @@ public static enum StorageDriveType {
final static double BYTE_PER_GB = 1_073_741_824.0d; // 1024^3

public static String getAvailableSpace(File drive) {
StatFs stat = new StatFs(drive.getAbsolutePath());

DecimalFormat df = new DecimalFormat("#.00");
df.setRoundingMode(RoundingMode.HALF_UP);

long available;
long total;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
available = stat.getAvailableBytes();
total = stat.getTotalBytes();
} else {
available = stat.getAvailableBlocks() * stat.getBlockSize();
total = stat.getBlockCount() * stat.getBlockSize();
try {
StatFs stat = new StatFs(drive.getAbsolutePath());

DecimalFormat df = new DecimalFormat("#.00");
df.setRoundingMode(RoundingMode.HALF_UP);

long available;
long total;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
available = stat.getAvailableBytes();
total = stat.getTotalBytes();
} else {
available = stat.getAvailableBlocks() * stat.getBlockSize();
total = stat.getBlockCount() * stat.getBlockSize();
}

return df.format(available / BYTE_PER_GB) + " GB free of " + df.format(total / BYTE_PER_GB) + " GB";
} catch (IllegalArgumentException e) {
return "Failed to stat FS";
}

return df.format(available / BYTE_PER_GB) + " GB free of " + df.format(total / BYTE_PER_GB) + " GB";
}

/**
Expand Down
10 changes: 6 additions & 4 deletions APDE/src/main/java/com/calsignlabs/apde/EditorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,11 @@ public void onGlobalLayout() {
consoleWasHidden = false;
}

// Remove any unnecessary focus from the code area
getSelectedCodeArea().clearFocus();
getSelectedCodeArea().matchingBracket = -1;
if (getSelectedCodeArea() != null) {
// Remove any unnecessary focus from the code area
getSelectedCodeArea().clearFocus();
getSelectedCodeArea().matchingBracket = -1;
}

// Update the character insert tray
toggleCharInsertsProblemOverviewButton(true, true);
Expand Down Expand Up @@ -1322,7 +1324,7 @@ public void onResume() {

Intent intent = getIntent();

if ((intent.getAction().equals(Intent.ACTION_VIEW) || intent.getAction().equals(Intent.ACTION_EDIT))) {
if (intent.getAction() != null && (intent.getAction().equals(Intent.ACTION_VIEW) || intent.getAction().equals(Intent.ACTION_EDIT)) && intent.getData() != null) {
String scheme = intent.getData().getScheme();
String filePath = intent.getData().getPath();

Expand Down

0 comments on commit 4597902

Please sign in to comment.