Example usage for android.app ActivityManager isLowRamDevice

List of usage examples for android.app ActivityManager isLowRamDevice

Introduction

In this page you can find the example usage for android.app ActivityManager isLowRamDevice.

Prototype

public boolean isLowRamDevice() 

Source Link

Document

Returns true if this is a low-RAM device.

Usage

From source file:Main.java

@TargetApi(VERSION_CODES.KITKAT)
public static boolean isLowMemory(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    return (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice())
            || activityManager.getMemoryClass() <= 64;
}

From source file:org.opensilk.music.MusicApp.java

/** Disable some features depending on device type */
@SuppressWarnings("NewApi")
@DebugLog// www  . java  2  s .  c o m
public static boolean isLowEndHardware(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
    if (VersionUtils.hasKitkat()) {
        return am.isLowRamDevice();
    } else if (VersionUtils.hasJellyBean()) {
        ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
        am.getMemoryInfo(mi);
        return mi.totalMem < (512 * 1024 * 1024);
    } else {
        return Runtime.getRuntime().availableProcessors() == 1;
    }
}

From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java

@TargetApi(VERSION_CODES.KITKAT)
public static String getMemoryClass(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    String lowMem = "";

    if (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice()) {
        lowMem = ", low-mem device";
    }/*from  www.  ja  v a  2  s.  com*/
    return activityManager.getMemoryClass() + lowMem;
}

From source file:com.google.android.apps.muzei.render.MuzeiRendererFragment.java

@Override
@TargetApi(Build.VERSION_CODES.KITKAT)/*from   w w  w.  ja  va 2  s. com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    boolean simpleDemoMode = false;
    if (mDemoMode && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Context.ACTIVITY_SERVICE);
        if (activityManager.isLowRamDevice()) {
            simpleDemoMode = true;
        }
    }

    if (simpleDemoMode) {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        int targetWidth = dm.widthPixels;
        int targetHeight = dm.heightPixels;
        if (!mDemoFocus) {
            targetHeight = MathUtil.roundMult4(
                    ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS * 10000 / MuzeiBlurRenderer.DEFAULT_BLUR);
            targetWidth = MathUtil.roundMult4((int) (dm.widthPixels * 1f / dm.heightPixels * targetHeight));
        }

        mSimpleDemoModeImageView = new ImageView(container.getContext());
        mSimpleDemoModeImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Picasso.with(getActivity()).load("file:///android_asset/starrynight.jpg")
                .resize(targetWidth, targetHeight).centerCrop().into(mSimpleDemoModeLoadedTarget);
        return mSimpleDemoModeImageView;
    } else {
        mView = new MuzeiView(getActivity());
        mView.setPreserveEGLContextOnPause(true);
        return mView;
    }
}

From source file:fr.matthiasbosc.translucentmap.MainActivity.java

public boolean isLowRamDevice() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        RamDeviceStatus = activityManager.isLowRamDevice();
    }//from  w  w  w  . jav  a  2s . com
    return RamDeviceStatus;
}

From source file:cn.edu.wyu.documentviewer.RecentLoader.java

public RecentLoader(Context context, RootsCache roots, State state) {
    super(context);
    mRoots = roots;/*from ww w  .ja v a 2s  .  c  om*/
    mState = state;

    // Keep clients around on high-RAM devices, since we'd be spinning them
    // up moments later to fetch thumbnails anyway.
    final ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    mQueryPermits = new Semaphore(
            am.isLowRamDevice() ? MAX_OUTSTANDING_RECENTS_SVELTE : MAX_OUTSTANDING_RECENTS);
}

From source file:com.ape.transfer.util.FileIconLoader.java

/**
 * Constructor.//  ww w.  j  a v a 2s.co m
 *
 * @param context content context
 */
public FileIconLoader(Context context) {
    mContext = context;
    final ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));
    final float cacheSizeAdjustment = (am.isLowRamDevice()) ? 0.5f : 1.0f;
    final int holderCacheSize = (int) (cacheSizeAdjustment * HOLDER_CACHE_SIZE);
    mImageCache = new LruCache<Object, ImageHolder>(holderCacheSize);
    mThumbnailSize = context.getResources().getDimensionPixelSize(R.dimen.icon_width_height);
}

From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java

private static void appendDeviceInfo(final Appendable report, final Context context) throws IOException {
    final Resources res = context.getResources();
    final android.content.res.Configuration config = res.getConfiguration();
    final ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context
            .getSystemService(Context.DEVICE_POLICY_SERVICE);

    report.append("Device Model: " + Build.MODEL + "\n");
    report.append("Android Version: " + Build.VERSION.RELEASE + "\n");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        report.append("Android security patch level: ").append(Build.VERSION.SECURITY_PATCH).append("\n");
    report.append("ABIs: ")
            .append(Joiner.on(", ").skipNulls()
                    .join(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? supportedAbisLollipop()
                            : supportedAbisKitKat()))
            .append("\n");
    report.append("Board: " + Build.BOARD + "\n");
    report.append("Brand: " + Build.BRAND + "\n");
    report.append("Device: " + Build.DEVICE + "\n");
    report.append("Display: " + Build.DISPLAY + "\n");
    report.append("Finger Print: " + Build.FINGERPRINT + "\n");
    report.append("Host: " + Build.HOST + "\n");
    report.append("ID: " + Build.ID + "\n");
    report.append("Product: " + Build.PRODUCT + "\n");
    report.append("Tags: " + Build.TAGS + "\n");
    report.append("Time: " + Build.TIME + "\n");
    report.append("Type: " + Build.TYPE + "\n");
    report.append("User: " + Build.USER + "\n");
    report.append("Configuration: " + config + "\n");
    report.append("Screen Layout: size "
            + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) + " long "
            + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_LONG_MASK) + "\n");
    report.append("Display Metrics: " + res.getDisplayMetrics() + "\n");
    report.append(/*from w w  w  .  ja v  a  2 s  .c  o  m*/
            "Memory Class: " + activityManager.getMemoryClass() + "/" + activityManager.getLargeMemoryClass()
                    + (activityManager.isLowRamDevice() ? " (low RAM device)" : "") + "\n");
    report.append("Storage Encryption Status: " + devicePolicyManager.getStorageEncryptionStatus() + "\n");
    report.append("Bluetooth MAC: " + bluetoothMac() + "\n");
    report.append("Runtime: ").append(System.getProperty("java.vm.name")).append(" ")
            .append(System.getProperty("java.vm.version")).append("\n");
}

From source file:com.geniusgithub.contact.common.ContactPhotoManager.java

public ContactPhotoManagerImpl(Context context) {
    mContext = context;//  www  .  j a v  a  2 s.com

    final ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));

    final float cacheSizeAdjustment = (am.isLowRamDevice()) ? 0.5f : 1.0f;

    final int bitmapCacheSize = (int) (cacheSizeAdjustment * BITMAP_CACHE_SIZE);
    mBitmapCache = new LruCache<Object, Bitmap>(bitmapCacheSize) {
        @Override
        protected int sizeOf(Object key, Bitmap value) {
            return value.getByteCount();
        }

        @Override
        protected void entryRemoved(boolean evicted, Object key, Bitmap oldValue, Bitmap newValue) {
            if (DEBUG)
                dumpStats();
        }
    };
    final int holderCacheSize = (int) (cacheSizeAdjustment * HOLDER_CACHE_SIZE);
    mBitmapHolderCache = new LruCache<Object, BitmapHolder>(holderCacheSize) {
        @Override
        protected int sizeOf(Object key, BitmapHolder value) {
            return value.bytes != null ? value.bytes.length : 0;
        }

        @Override
        protected void entryRemoved(boolean evicted, Object key, BitmapHolder oldValue, BitmapHolder newValue) {
            if (DEBUG)
                dumpStats();
        }
    };
    mBitmapHolderCacheRedZoneBytes = (int) (holderCacheSize * 0.75);
    Log.i(TAG, "Cache adj: " + cacheSizeAdjustment);
    if (DEBUG) {
        Log.d(TAG, "Cache size: " + btk(mBitmapHolderCache.maxSize()) + " + " + btk(mBitmapCache.maxSize()));
    }

    mThumbnailSize = context.getResources().getDimensionPixelSize(R.dimen.contact_browser_list_item_photo_size);
}

From source file:com.android.contacts.common.ContactPhotoManager.java

public ContactPhotoManagerImpl(Context context) {
    mContext = context;// www  .  jav  a 2 s .c  o  m

    final ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));

    final float cacheSizeAdjustment = (am.isLowRamDevice()) ? 0.5f : 1.0f;

    final int bitmapCacheSize = (int) (cacheSizeAdjustment * BITMAP_CACHE_SIZE);
    mBitmapCache = new LruCache<Object, Bitmap>(bitmapCacheSize) {
        @Override
        protected int sizeOf(Object key, Bitmap value) {
            return value.getByteCount();
        }

        @Override
        protected void entryRemoved(boolean evicted, Object key, Bitmap oldValue, Bitmap newValue) {
            if (DEBUG)
                dumpStats();
        }
    };
    final int holderCacheSize = (int) (cacheSizeAdjustment * HOLDER_CACHE_SIZE);
    mBitmapHolderCache = new LruCache<Object, BitmapHolder>(holderCacheSize) {
        @Override
        protected int sizeOf(Object key, BitmapHolder value) {
            return value.bytes != null ? value.bytes.length : 0;
        }

        @Override
        protected void entryRemoved(boolean evicted, Object key, BitmapHolder oldValue, BitmapHolder newValue) {
            if (DEBUG)
                dumpStats();
        }
    };
    mBitmapHolderCacheRedZoneBytes = (int) (holderCacheSize * 0.75);
    Log.i(TAG, "Cache adj: " + cacheSizeAdjustment);
    if (DEBUG) {
        Log.d(TAG, "Cache size: " + btk(mBitmapHolderCache.maxSize()) + " + " + btk(mBitmapCache.maxSize()));
    }

    mThumbnailSize = context.getResources().getDimensionPixelSize(R.dimen.contact_browser_list_item_photo_size);

    // Get a user agent string to use for URI photo requests.
    mUserAgent = UserAgentGenerator.getUserAgent(context);
    if (mUserAgent == null) {
        mUserAgent = "";
    }
}