@TargetApi(Build.VERSION_CODES.KITKAT) @Synthetic 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. //noinspection SimplifiableIfStatement if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return activityManager.isLowRamDevice(); } else { return true; } }
@Override public void applyOptions(Context context, GlideBuilder builder) { final RequestOptions defaultOptions = new RequestOptions(); // Prefer higher quality images unless we're on a low RAM device ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); defaultOptions.format(activityManager.isLowRamDevice() ? PREFER_RGB_565 : PREFER_ARGB_8888); // Disable hardware bitmaps as they don't play nicely with Palette defaultOptions.disallowHardwareConfig(); builder.setDefaultRequestOptions(defaultOptions); }
@Test @Config(minSdk = KITKAT) public void setIsLowRamDevice() { final ActivityManager activityManager = getActivityManager(); shadowOf(activityManager).setIsLowRamDevice(true); assertThat(activityManager.isLowRamDevice()).isTrue(); }
@TargetApi(Build.VERSION_CODES.KITKAT) private static boolean isLowMemoryDevice(ActivityManager activityManager) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return activityManager.isLowRamDevice(); } else { return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB; } }
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. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return activityManager.isLowRamDevice(); } else { return false; } }
public static boolean isLowRamDevice(ActivityManager am) { return am.isLowRamDevice(); } }
@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"; } return activityManager.getMemoryClass() + lowMem; }
@TargetApi(Build.VERSION_CODES.KITKAT) public static boolean isLowRamDevice(Context context) { if(Utils.hasKitKat()){ final ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); return am.isLowRamDevice(); } return !hasMoreHeap(); }
Context.ACTIVITY_SERVICE)); final float cacheSizeAdjustment = (am.isLowRamDevice()) ? 0.5f : 1.0f;
@Override public void applyOptions(Context context, GlideBuilder builder) { boolean runsMinSDK = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context .ACTIVITY_SERVICE); boolean lowRAMDevice; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { lowRAMDevice = activityManager.isLowRamDevice(); } else { ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memInfo); lowRAMDevice = memInfo.lowMemory; } builder.setDecodeFormat(runsMinSDK ? lowRAMDevice ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888 : DecodeFormat.PREFER_RGB_565); }
@TargetApi(23) @Override protected boolean fitSystemWindows(Rect insets) { boolean rawInsetsChanged = !mInsets.equals(insets); mDrawSideInsetBar = (insets.right > 0 || insets.left > 0) && (!Utilities.ATLEAST_MARSHMALLOW || getContext().getSystemService(ActivityManager.class).isLowRamDevice()); mRightInsetBarWidth = insets.right; mLeftInsetBarWidth = insets.left; setInsets(mDrawSideInsetBar ? new Rect(0, insets.top, 0, insets.bottom) : insets); if (mAlignedView != null && mDrawSideInsetBar) { // Apply margins on aligned view to handle left/right insets. MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams(); if (lp.leftMargin != insets.left || lp.rightMargin != insets.right) { lp.leftMargin = insets.left; lp.rightMargin = insets.right; mAlignedView.setLayoutParams(lp); } } if (rawInsetsChanged) { // Update the grid again Launcher launcher = Launcher.getLauncher(getContext()); launcher.onInsetsChanged(insets); } return true; // I'll take it from here }
@TargetApi(23) @Override protected boolean fitSystemWindows(Rect insets) { boolean rawInsetsChanged = !mInsets.equals(insets); mDrawSideInsetBar = (insets.right > 0 || insets.left > 0) && (!AndroidVersion.isAtLeastMarshmallow || getContext().getSystemService(ActivityManager.class).isLowRamDevice()); mRightInsetBarWidth = insets.right; mLeftInsetBarWidth = insets.left; setInsets(mDrawSideInsetBar ? new Rect(0, insets.top, 0, insets.bottom) : insets); if (mAlignedView != null && mDrawSideInsetBar) { // Apply margins on aligned view to handle left/right insets. MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams(); if (lp.leftMargin != insets.left || lp.rightMargin != insets.right) { lp.leftMargin = insets.left; lp.rightMargin = insets.right; mAlignedView.setLayoutParams(lp); } } if (rawInsetsChanged) { // Update the grid again Launcher launcher = Launcher.getLauncher(getContext()); launcher.onInsetsChanged(insets); } return true; // I'll take it from here }
@TargetApi(23) @Override protected boolean fitSystemWindows(Rect insets) { boolean rawInsetsChanged = !mInsets.equals(insets); mDrawSideInsetBar = (insets.right > 0 || insets.left > 0) && (!Utilities.ATLEAST_MARSHMALLOW || getContext().getSystemService(ActivityManager.class).isLowRamDevice()); mRightInsetBarWidth = insets.right; mLeftInsetBarWidth = insets.left; setInsets(mDrawSideInsetBar ? new Rect(0, insets.top, 0, insets.bottom) : insets); if (mAlignedView != null && mDrawSideInsetBar) { // Apply margins on aligned view to handle left/right insets. MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams(); if (lp.leftMargin != insets.left || lp.rightMargin != insets.right) { lp.leftMargin = insets.left; lp.rightMargin = insets.right; mAlignedView.setLayoutParams(lp); } } if (rawInsetsChanged) { // Update the grid again Launcher launcher = Launcher.getLauncher(getContext()); launcher.onInsetsChanged(insets); } return true; // I'll take it from here }