Skip to content

Commit 82657e9

Browse files
falhassenglide-copybara-robot
authored andcommitted
No public description
PiperOrigin-RevId: 852944433
1 parent d591539 commit 82657e9

3 files changed

Lines changed: 2 additions & 122 deletions

File tree

library/src/main/java/com/bumptech/glide/Glide.java

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.bumptech.glide;
22

33
import android.app.Activity;
4-
import android.app.Application;
54
import android.content.ComponentCallbacks2;
65
import android.content.Context;
76
import android.content.res.Configuration;
87
import android.graphics.Bitmap;
9-
import android.os.Bundle;
108
import android.os.MessageQueue.IdleHandler;
119
import android.util.Log;
1210
import android.view.View;
@@ -35,7 +33,6 @@
3533
import com.bumptech.glide.request.RequestOptions;
3634
import com.bumptech.glide.request.target.ImageViewTargetFactory;
3735
import com.bumptech.glide.request.target.Target;
38-
import com.bumptech.glide.util.GlideSuppliers;
3936
import com.bumptech.glide.util.GlideSuppliers.GlideSupplier;
4037
import com.bumptech.glide.util.Preconditions;
4138
import com.bumptech.glide.util.Util;
@@ -84,13 +81,6 @@ public class Glide implements ComponentCallbacks2 {
8481
@Nullable
8582
private BitmapPreFiller bitmapPreFiller;
8683

87-
private boolean inBackground = false;
88-
private MemoryCategory memoryCategoryInBackground = null;
89-
private MemoryCategory memoryCategoryInForeground = MemoryCategory.NORMAL;
90-
91-
private final GlideSupplier<SetMemoryCategoryOnLifecycleCallbacks> setMemoryCategoryCallbacks =
92-
GlideSuppliers.memorize(SetMemoryCategoryOnLifecycleCallbacks::new);
93-
9484
/**
9585
* Returns a directory with a default name in the private cache directory of the application to
9686
* use to store retrieved media and thumbnails.
@@ -215,9 +205,7 @@ public static void enableHardwareBitmaps() {
215205
public static void tearDown() {
216206
synchronized (Glide.class) {
217207
if (glide != null) {
218-
Application application = (Application) glide.getContext().getApplicationContext();
219-
application.unregisterComponentCallbacks(glide);
220-
glide.unregisterActivityLifecycleCallbacks();
208+
glide.getContext().getApplicationContext().unregisterComponentCallbacks(glide);
221209
glide.engine.shutdown();
222210
}
223211
glide = null;
@@ -236,7 +224,7 @@ private static void initializeGlide(
236224
@NonNull Context context,
237225
@NonNull GlideBuilder builder,
238226
@Nullable GeneratedAppGlideModule annotationGeneratedModule) {
239-
Application applicationContext = (Application) context.getApplicationContext();
227+
Context applicationContext = context.getApplicationContext();
240228
List<GlideModule> manifestModules = Collections.emptyList();
241229
if (annotationGeneratedModule == null || annotationGeneratedModule.isManifestParsingEnabled()) {
242230
manifestModules = new ManifestParser(applicationContext).parse();
@@ -277,7 +265,6 @@ private static void initializeGlide(
277265
}
278266
Glide glide = builder.build(applicationContext, manifestModules, annotationGeneratedModule);
279267
applicationContext.registerComponentCallbacks(glide);
280-
glide.registerActivityLifecycleCallbacks();
281268
Glide.glide = glide;
282269
}
283270

@@ -345,12 +332,6 @@ private static void throwIncorrectGlideModule(Exception e) {
345332
this.connectivityMonitorFactory = connectivityMonitorFactory;
346333
this.defaultRequestOptionsFactory = defaultRequestOptionsFactory;
347334

348-
GlideBuilder.MemoryCategoryInBackground memoryCategoryInBackground =
349-
experiments.get(GlideBuilder.MemoryCategoryInBackground.class);
350-
if (memoryCategoryInBackground != null) {
351-
this.memoryCategoryInBackground = memoryCategoryInBackground.value();
352-
}
353-
354335
// This has a circular relationship with Glide and GlideContext in that it depends on both,
355336
// but it's created by Glide's constructor. In practice this shouldn't matter because the
356337
// supplier holding the registry should never be initialized before this constructor finishes.
@@ -373,20 +354,6 @@ private static void throwIncorrectGlideModule(Exception e) {
373354
logLevel);
374355
}
375356

376-
private void registerActivityLifecycleCallbacks() {
377-
if (memoryCategoryInBackground != null) {
378-
Application context = (Application) getContext().getApplicationContext();
379-
context.registerActivityLifecycleCallbacks(setMemoryCategoryCallbacks.get());
380-
}
381-
}
382-
383-
private void unregisterActivityLifecycleCallbacks() {
384-
if (memoryCategoryInBackground != null) {
385-
Application context = (Application) getContext().getApplicationContext();
386-
context.unregisterActivityLifecycleCallbacks(setMemoryCategoryCallbacks.get());
387-
}
388-
}
389-
390357
/**
391358
* Returns the {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool} used to
392359
* temporarily store {@link android.graphics.Bitmap}s so they can be reused to avoid garbage
@@ -708,30 +675,9 @@ void unregisterRequestManager(RequestManager requestManager) {
708675
}
709676
}
710677

711-
private void setMemoryCategoryWhenInBackground() {
712-
if (memoryCategoryInBackground == null || inBackground) {
713-
return;
714-
}
715-
inBackground = true;
716-
memoryCategoryInForeground = setMemoryCategory(memoryCategoryInBackground);
717-
}
718-
719-
private void setMemoryCategoryWhenInForeground() {
720-
if (memoryCategoryInBackground == null || !inBackground) {
721-
return;
722-
}
723-
inBackground = false;
724-
setMemoryCategory(memoryCategoryInForeground);
725-
}
726-
727678
@Override
728679
public void onTrimMemory(int level) {
729680
trimMemory(level);
730-
// when level is TRIM_MEMORY_UI_HIDDEN or higher, it indicates that the app is
731-
// in the background, limit the memory usage by memoryCategoryInBackground.
732-
if (level >= TRIM_MEMORY_UI_HIDDEN) {
733-
setMemoryCategoryWhenInBackground();
734-
}
735681
}
736682

737683
@Override
@@ -751,44 +697,4 @@ public interface RequestOptionsFactory {
751697
@NonNull
752698
RequestOptions build();
753699
}
754-
755-
private final class SetMemoryCategoryOnLifecycleCallbacks
756-
implements Application.ActivityLifecycleCallbacks {
757-
@Override
758-
public void onActivityStarted(Activity activity) {
759-
// Do nothing.
760-
}
761-
762-
@Override
763-
public void onActivityResumed(Activity activity) {
764-
// Any activity resumed indicates that the app is no longer in the background,
765-
// and we should restore the memory usage to normal.
766-
setMemoryCategoryWhenInForeground();
767-
}
768-
769-
@Override
770-
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
771-
// Do nothing.
772-
}
773-
774-
@Override
775-
public void onActivityDestroyed(Activity activity) {
776-
// Do nothing.
777-
}
778-
779-
@Override
780-
public void onActivityStopped(Activity activity) {
781-
// Do nothing.
782-
}
783-
784-
@Override
785-
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
786-
// Do nothing.
787-
}
788-
789-
@Override
790-
public void onActivityPaused(Activity activity) {
791-
// Do nothing.
792-
}
793-
}
794700
}

library/src/main/java/com/bumptech/glide/GlideBuilder.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,6 @@ public GlideBuilder setUseMediaStoreOpenFileApisIfPossible(boolean isEnabled) {
512512
return this;
513513
}
514514

515-
/**
516-
* Set to {@code true} to make Glide use {@link MemoryCategory} to set the memory category when
517-
* the app is in the background.
518-
*
519-
* <p>This is an experimental API that may be removed in the future.
520-
*/
521-
public GlideBuilder setMemoryCategoryInBackground(MemoryCategory memoryCategory) {
522-
glideExperimentsBuilder.add(new MemoryCategoryInBackground(memoryCategory));
523-
return this;
524-
}
525-
526515
/**
527516
* @deprecated This method does nothing. It will be hard coded and removed in a future release
528517
* without further warning.
@@ -664,17 +653,4 @@ public static final class OverrideGlideThreadPriority implements Experiment {}
664653

665654
/** See {@link #setUseMediaStoreOpenFileApisIfPossible(boolean)}. */
666655
public static final class UseMediaStoreOpenFileApisIfPossible implements Experiment {}
667-
668-
/** See {@link #setMemoryCategoryInBackground(MemoryCategory)} */
669-
public static final class MemoryCategoryInBackground implements Experiment {
670-
private final MemoryCategory memoryCategory;
671-
672-
MemoryCategoryInBackground(MemoryCategory memoryCategory) {
673-
this.memoryCategory = memoryCategory;
674-
}
675-
676-
public MemoryCategory value() {
677-
return memoryCategory;
678-
}
679-
}
680656
}

library/src/main/java/com/bumptech/glide/MemoryCategory.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
/** An enum for dynamically modifying the amount of memory Glide is able to use. */
44
public enum MemoryCategory {
5-
/** Tells Glide's memory cache and bitmap pool to use no memory. */
6-
ZERO(0f),
75
/**
86
* Tells Glide's memory cache and bitmap pool to use at most half of their initial maximum size.
97
*/

0 commit comments

Comments
 (0)