Skip to content

Commit

Permalink
Cleanup target api annotations (#2671)
Browse files Browse the repository at this point in the history
* Remove unnecessary API checks

Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored and sjudd committed Dec 5, 2017
1 parent 4e539f5 commit 6778396
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 51 deletions.
4 changes: 0 additions & 4 deletions library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bumptech.glide;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ComponentCallbacks2;
import android.content.Context;
Expand All @@ -10,7 +9,6 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
Expand Down Expand Up @@ -92,7 +90,6 @@
* {@link RequestBuilder} and maintaining an {@link Engine}, {@link BitmapPool},
* {@link com.bumptech.glide.load.engine.cache.DiskCache} and {@link MemoryCache}.
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class Glide implements ComponentCallbacks2 {
private static final String DEFAULT_DISK_CACHE_DIR = "image_manager_disk_cache";
private static final String TAG = "Glide";
Expand Down Expand Up @@ -294,7 +291,6 @@ private static GeneratedAppGlideModule getAnnotationGeneratedGlideModules() {
return result;
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
Glide(
Context context,
Engine engine,
Expand Down
3 changes: 0 additions & 3 deletions library/src/main/java/com/bumptech/glide/GlideContext.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.bumptech.glide;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
Expand All @@ -21,7 +19,6 @@
* Global context for all loads in Glide containing and exposing the various registries and classes
* required to load resources.
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class GlideContext extends ContextWrapper {
@VisibleForTesting
static final TransitionOptions<?, ?> DEFAULT_TRANSITION_OPTIONS =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.bumptech.glide.load.data;

import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.UriMatcher;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -88,7 +86,6 @@ private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver
}
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private InputStream openContactPhotoInputStream(ContentResolver contentResolver, Uri contactUri) {
return ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, contactUri,
true /*preferHighres*/);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.bumptech.glide.load.engine.bitmap_recycle;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.VisibleForTesting;
import com.bumptech.glide.util.Synthetic;
import com.bumptech.glide.util.Util;
Expand All @@ -23,7 +23,7 @@
* the performance of applications. This class works around #301 by only allowing re-use of
* {@link android.graphics.Bitmap Bitmaps} with a matching number of bytes per pixel. </p>
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(Build.VERSION_CODES.KITKAT)
public class SizeConfigStrategy implements LruPoolStrategy {
private static final int MAX_SIZE_MULTIPLE = 8;
private static final Bitmap.Config[] ARGB_8888_IN_CONFIGS =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.bumptech.glide.load.engine.bitmap_recycle;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.VisibleForTesting;
import com.bumptech.glide.util.Synthetic;
import com.bumptech.glide.util.Util;
Expand All @@ -15,7 +15,7 @@
*
* <p> Requires {@link Build.VERSION_CODES#KITKAT KitKat} or higher. </p>
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(Build.VERSION_CODES.KITKAT)
class SizeStrategy implements LruPoolStrategy {
private static final int MAX_SIZE_MULTIPLE = 8;
private final KeyPool keyPool = new KeyPool();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.engine.cache;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
Expand Down Expand Up @@ -113,6 +114,7 @@ private String toMb(int bytes) {
return Formatter.formatFileSize(context, bytes);
}

@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean isLowMemoryDevice(ActivityManager activityManager) {
// Explicitly check with an if statement, on some devices both parts of boolean expressions
// can be evaluated even if we'd normally expect a short circuit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void onObtainBounds() {
}

@Override
public void onDecodeComplete(BitmapPool bitmapPool, Bitmap downsampled) throws IOException {
public void onDecodeComplete(BitmapPool bitmapPool, Bitmap downsampled) {
// Do nothing.
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ public RequestManager get(android.app.Fragment fragment) {
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
RequestManagerFragment getRequestManagerFragment(
final android.app.FragmentManager fm, android.app.Fragment parentHint) {
RequestManagerFragment current = (RequestManagerFragment) fm.findFragmentByTag(FRAGMENT_TAG);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bumptech.glide.request.target;

import android.annotation.TargetApi;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
Expand All @@ -11,6 +10,7 @@
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import com.bumptech.glide.util.Preconditions;
import com.bumptech.glide.util.Synthetic;

Expand Down Expand Up @@ -90,7 +90,7 @@ public Callback getCallback() {
return wrapped.getCallback();
}

@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(Build.VERSION_CODES.KITKAT)
@Override
public int getAlpha() {
return wrapped.getAlpha();
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/bumptech/glide/util/LogTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public final class LogTime {
private static final double MILLIS_MULTIPLIER =
Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT ? 1d / Math.pow(10, 6) : 1d;
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? 1d / Math.pow(10, 6) : 1d;

private LogTime() {
// Utility class.
Expand All @@ -21,7 +21,7 @@ private LogTime() {
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static long getLogTime() {
if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return SystemClock.elapsedRealtimeNanos();
} else {
return SystemClock.uptimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.annotation.TargetApi;
import android.os.Build;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -21,7 +19,6 @@

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 18)
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class LruArrayPoolTest {
private static final int MAX_SIZE = 10;
private static final int MAX_PUT_SIZE = MAX_SIZE / 2;
Expand All @@ -30,7 +27,7 @@ public class LruArrayPoolTest {
private LruArrayPool pool;

@Before
public void setUp() throws Exception {
public void setUp() {
pool = new LruArrayPool(MAX_SIZE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.annotation.TargetApi;
import android.content.ComponentCallbacks2;
import android.os.Build;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.engine.Resource;
Expand All @@ -26,7 +24,6 @@
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class LruResourceCacheTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.os.Build;
import com.bumptech.glide.load.EncodeStrategy;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.engine.Resource;
Expand Down Expand Up @@ -57,7 +55,6 @@ public void testBitmapIsEncodedWithGivenQuality() throws IOException {
}

@Test
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void testEncoderObeysNonNullCompressFormat() throws IOException {
Bitmap.CompressFormat format = Bitmap.CompressFormat.WEBP;
harness.setFormat(format);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
Expand All @@ -21,7 +21,7 @@
/**
* A test activity to reproduce Issue #117: https://github.com/bumptech/glide/issues/117.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
class Issue117Activity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.os.Looper;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.bumptech.glide.RequestManager;
Expand Down Expand Up @@ -309,7 +309,7 @@ public void testCanCallGetInOnAttachToWindowInFragmentInViewPager() {
}

@Test
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void testDoesNotThrowIfAskedToGetManagerForActivityPreJellYBeanMr1() {
Util.setSdkVersionInt(Build.VERSION_CODES.JELLY_BEAN);
Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
Expand All @@ -320,7 +320,7 @@ public void testDoesNotThrowIfAskedToGetManagerForActivityPreJellYBeanMr1() {
}

@Test
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void testDoesNotThrowIfAskedToGetManagerForFragmentPreJellyBeanMr1() {
Util.setSdkVersionInt(Build.VERSION_CODES.JELLY_BEAN);
Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.bumptech.glide.samples.contacturi;

import static android.os.Build.VERSION;
import static android.os.Build.VERSION_CODES;

import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Intent;
Expand Down Expand Up @@ -45,11 +41,11 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageViewContact = (ImageView) findViewById(R.id.image_contact);
imageViewLookup = (ImageView) findViewById(R.id.image_lookup);
imageViewPhoto = (ImageView) findViewById(R.id.image_photo);
imageViewDisplayPhoto = (ImageView) findViewById(R.id.image_display_photo);
numberEntry = (EditText) findViewById(R.id.number_entry);
imageViewContact = findViewById(R.id.image_contact);
imageViewLookup = findViewById(R.id.image_lookup);
imageViewPhoto = findViewById(R.id.image_photo);
imageViewDisplayPhoto = findViewById(R.id.image_display_photo);
numberEntry = findViewById(R.id.number_entry);
// Make sure that user gives application required permissions
if (ContextCompat.checkSelfPermission(
getApplication(),
Expand Down Expand Up @@ -101,7 +97,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}

@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH)
private void showContact(long id) {
GlideRequests glideRequests = GlideApp.with(this);
RequestOptions originalSize = new RequestOptions().override(Target.SIZE_ORIGINAL);
Expand All @@ -115,9 +110,7 @@ private void showContact(long id) {
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
glideRequests.load(photoUri).apply(originalSize).into(imageViewPhoto);

if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
glideRequests.load(displayPhotoUri).apply(originalSize).into(imageViewDisplayPhoto);
}
Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
glideRequests.load(displayPhotoUri).apply(originalSize).into(imageViewDisplayPhoto);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.bumptech.glide.samples.gallery;

import android.Manifest.permission;
import android.annotation.TargetApi;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
Expand All @@ -16,6 +16,7 @@
/**
* Displays a {@link HorizontalGalleryFragment}.
*/
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
public class MainActivity extends FragmentActivity {

private static final int REQUEST_READ_STORAGE = 0;
Expand All @@ -34,7 +35,6 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void requestStoragePermission() {
ActivityCompat.requestPermissions(this,
new String[]{permission.READ_EXTERNAL_STORAGE},
Expand Down

0 comments on commit 6778396

Please sign in to comment.