Browse Source

Fix crash that could occur pre API 16

master
Anthony Restaino 9 years ago
parent
commit
1eeddaf502
  1. 24
      app/src/main/java/acr/browser/lightning/utils/Utils.java

24
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -12,6 +12,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
@ -29,6 +30,9 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -40,8 +44,6 @@ import java.util.Date;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.DownloadHandler;
import com.anthonycr.grant.PermissionsManager;
import com.anthonycr.grant.PermissionsResultAction;
public final class Utils { public final class Utils {
@ -274,6 +276,24 @@ public final class Utils {
} }
} }
/**
* Utility method to close cursors. Cursor did not
* implement Closeable until API 16, so using this
* method for when we want to close a cursor.
*
* @param cursor the cursor to close
*/
public static void close(Cursor cursor) {
if (cursor == null) {
return;
}
try {
cursor.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/** /**
* Draws the trapezoid background for the horizontal tabs on a canvas object using * Draws the trapezoid background for the horizontal tabs on a canvas object using
* the specified color. * the specified color.

Loading…
Cancel
Save