Example usage for android.content ComponentCallbacks2 TRIM_MEMORY_UI_HIDDEN

List of usage examples for android.content ComponentCallbacks2 TRIM_MEMORY_UI_HIDDEN

Introduction

In this page you can find the example usage for android.content ComponentCallbacks2 TRIM_MEMORY_UI_HIDDEN.

Prototype

int TRIM_MEMORY_UI_HIDDEN

To view the source code for android.content ComponentCallbacks2 TRIM_MEMORY_UI_HIDDEN.

Click Source Link

Document

Level for #onTrimMemory(int) : the process had been showing a user interface, and is no longer doing so.

Usage

From source file:Main.java

public static String getTrimLevelName(int level) {
    switch (level) {
    case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
        return "COMPLETE";
    case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
        return "MODERATE";
    case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
        return "BACKGROUND";
    case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
        return "UI_HIDDEN";
    case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
        return "RUNNING_CRITICAL";
    case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
        return "RUNNING_LOW";
    case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
        return "RUNNING_MODERATE";
    default://from   ww  w  .ja va2  s. com
        return "UNKNOWN";
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static void onTrimMemory(int level) {
    int count = 0;
    if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
        count = 10;/*w w w .  j av  a  2  s  . c  o  m*/
        if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
            count = 0;
        }
    } else
        return;

    int size = 0;
    if (count > 0) {
        for (Bitmap b : placeHolders) {
            size += b.getByteCount();
        }
    }

    int trimSize = placeHolders.size() == 0 ? 0 : ((count * size) / placeHolders.size());
    Log.v(TAG, "trim image cache from " + memCache.size() + " to " + trimSize
            + " to reduce memory usage, max size " + memCache.maxSize());
    memCache.trimToSize(trimSize);
}

From source file:github.popeen.dsub.service.DownloadService.java

@Override
public void onTrimMemory(int level) {
    ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(this);
    if (imageLoader != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        Log.i(TAG, "Memory Trim Level: " + level);
        if (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
            if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL) {
                imageLoader.onLowMemory(0.75f);
            } else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
                imageLoader.onLowMemory(0.50f);
            } else if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE) {
                imageLoader.onLowMemory(0.25f);
            }//from   w  w  w. ja  va2s  . c o m
        } else if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
            imageLoader.onLowMemory(0.25f);
        } else if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
            imageLoader.onLowMemory(0.75f);
        }
    }
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
public void onTrimMemory(int level) {
    super.onTrimMemory(level);
    if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
        // The widget preview db can result in holding onto over
        // 3MB of memory for caching which isn't necessary.
        SQLiteDatabase.releaseMemory();//from  w  w w.ja  v  a2 s  .c om

        // This clears all widget bitmaps from the widget tray
        if (mAppsCustomizeTabHost != null) {
            mAppsCustomizeTabHost.trimMemory();
        }
    }
}

From source file:com.android.launcher3.Launcher.java

@Override
public void onTrimMemory(int level) {
    super.onTrimMemory(level);
    if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
        // The widget preview db can result in holding onto over
        // 3MB of memory for caching which isn't necessary.
        SQLiteDatabase.releaseMemory();//  www . j  av a 2s .  co  m

        // This clears all widget bitmaps from the widget tray
        // TODO(hyunyoungs)
    }
    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onTrimMemory(level);
    }
}