Example usage for android.app ActivityManager getLargeMemoryClass

List of usage examples for android.app ActivityManager getLargeMemoryClass

Introduction

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

Prototype

public int getLargeMemoryClass() 

Source Link

Document

Return the approximate per-application memory class of the current device when an application is running with a large heap.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getLargeMemoryClass(ActivityManager am) {
    return am.getLargeMemoryClass();
}

From source file:Main.java

/**
 * @param context/*  ww  w.  j  a v a  2s.  com*/
 * @return
 */
public static int getLargeMemoryClass(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    int heapSize = manager.getLargeMemoryClass();
    return heapSize;
}

From source file:Main.java

/**
 * Gets the amount of memory available to the application.
 *
 * Queries whether the largeHeap manifest flag is set.
 *
 * @param context// w ww .  ja v  a2s  . com
 *         the application context
 * @return the amount of memory in bytes available to the application
 */
private static int getAvailableMemory(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean largeHeap = (context.getApplicationInfo().flags & 1048576) != 0;
    int memoryClass = largeHeap ? activityManager.getLargeMemoryClass() : activityManager.getMemoryClass();
    return memoryClass * 1048576;
}

From source file:com.bt.download.android.util.SystemUtils.java

public static int calculateMemoryCacheSize(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
    boolean largeHeap = (context.getApplicationInfo().flags & FLAG_LARGE_HEAP) != 0;
    int memoryClass = am.getMemoryClass();
    if (largeHeap) {
        memoryClass = am.getLargeMemoryClass();
    }/*from   w w w .j a va  2s.  c o m*/
    // Target ~15% of the available heap.
    return 1024 * 1024 * memoryClass / 7;
}

From source file:com.squareup.picasso3.Utils.java

static int calculateMemoryCacheSize(Context context) {
    ActivityManager am = ContextCompat.getSystemService(context, ActivityManager.class);
    boolean largeHeap = (context.getApplicationInfo().flags & FLAG_LARGE_HEAP) != 0;
    int memoryClass = largeHeap ? am.getLargeMemoryClass() : am.getMemoryClass();
    // Target ~15% of the available heap.
    return (int) (1024L * 1024L * memoryClass / 7);
}

From source file:org.videolan.vlc.util.BitmapCache.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private BitmapCache() {

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext()
            .getSystemService(Context.ACTIVITY_SERVICE));
    final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass();

    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 5;

    Log.d(TAG, "LRUCache size sets to " + cacheSize);

    mMemCache = new LruCache<String, Bitmap>(cacheSize) {

        @Override//from  w w w.  j a  v a 2 s.  co  m
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }

    };
}

From source file:io.github.mkjung.ivi.gui.helpers.BitmapCache.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private BitmapCache() {

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext()
            .getSystemService(Context.ACTIVITY_SERVICE));
    final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass();

    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 5;

    Log.i(TAG, "LRUCache size set to " + cacheSize);

    mMemCache = new LruCache<String, CacheableBitmap>(cacheSize) {

        @Override/*from w  w w. j  a  v a2s.  c  o  m*/
        protected int sizeOf(String key, CacheableBitmap value) {
            return value.getSize();
        }
    };
}

From source file:com.almalence.opencam.Fragment.java

@TargetApi(13)
private void showCameraParameters() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle(R.string.Pref_CameraParameters_Title);
    final StringBuilder about_string = new StringBuilder();
    String version = "UNKNOWN_VERSION";
    int version_code = -1;
    try {/* w  w  w .  j a v a  2s  .  c o  m*/
        PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        version = pInfo.versionName;
        version_code = pInfo.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    about_string.append("\nApplication name: ");
    about_string.append(MainScreen.getInstance().getResources().getString(R.string.Pref_About));
    about_string.append("\nAndroid API version: ");
    about_string.append(Build.VERSION.SDK_INT);
    about_string.append("\nDevice manufacturer: ");
    about_string.append(Build.MANUFACTURER);
    about_string.append("\nDevice model: ");
    about_string.append(Build.MODEL);
    about_string.append("\nDevice code-name: ");
    about_string.append(Build.HARDWARE);
    about_string.append("\nDevice variant: ");
    about_string.append(Build.DEVICE);
    {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Activity.ACTIVITY_SERVICE);
        about_string.append("\nStandard max heap (MB): ");
        about_string.append(activityManager.getMemoryClass());
        about_string.append("\nLarge max heap (MB): ");
        about_string.append(activityManager.getLargeMemoryClass());
    }
    {
        Point display_size = new Point();
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        display.getSize(display_size);
        about_string.append("\nDisplay size: ");
        about_string.append(display_size.x);
        about_string.append("x");
        about_string.append(display_size.y);
    }

    //show camera 2 support level
    int level = CameraController.getCamera2Level();
    about_string.append("\nCamera2 API: ");
    switch (level) {
    case 0://limited
        about_string.append("limited");
        break;
    case 1://full
        about_string.append("full");
        break;
    case 2://legacy
        about_string.append("legacy");
        break;
    default:
        about_string.append("not supported");
    }

    //      about_string.append("\nSensor orientation, back camera: ");
    //      about_string.append(CameraController.getSensorOrientation(0));
    //      about_string.append("\nSensor orientation, front camera: ");
    //      about_string.append(CameraController.getSensorOrientation(1));

    if (MainScreen.getInstance().preview_sizes != null) {
        about_string.append("\nPreview resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().preview_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().preview_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().preview_sizes.get(i).getHeight());
        }
    }

    about_string.append("\nCurrent camera ID: ");
    about_string.append(MainScreen.getInstance().cameraId);

    if (MainScreen.getInstance().picture_sizes != null) {
        about_string.append("\nPhoto resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().picture_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().picture_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().picture_sizes.get(i).getHeight());
        }
    }

    if (MainScreen.getInstance().video_sizes != null) {
        about_string.append("\nVideo resolutions: ");
        for (int i = 0; i < MainScreen.getInstance().video_sizes.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().video_sizes.get(i).getWidth());
            about_string.append("x");
            about_string.append(MainScreen.getInstance().video_sizes.get(i).getHeight());
        }
    }

    about_string.append("\nVideo stabilization: ");
    about_string.append(MainScreen.getInstance().supports_video_stabilization ? "true" : "false");

    about_string.append("\nFlash modes: ");
    if (MainScreen.getInstance().flash_values != null && MainScreen.getInstance().flash_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().flash_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().flash_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nFocus modes: ");
    if (MainScreen.getInstance().focus_values != null && MainScreen.getInstance().focus_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().focus_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().focus_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nScene modes: ");
    if (MainScreen.getInstance().scene_modes_values != null
            && MainScreen.getInstance().scene_modes_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().scene_modes_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().scene_modes_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nWhite balances: ");
    if (MainScreen.getInstance().white_balances_values != null
            && MainScreen.getInstance().white_balances_values.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().white_balances_values.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().white_balances_values.get(i));
        }
    } else {
        about_string.append("None");
    }

    about_string.append("\nISOs: ");
    if (MainScreen.getInstance().isos != null && MainScreen.getInstance().isos.size() > 0) {
        for (int i = 0; i < MainScreen.getInstance().isos.size(); i++) {
            if (i > 0) {
                about_string.append(", ");
            }
            about_string.append(MainScreen.getInstance().isos.get(i));
        }
    } else {
        about_string.append("None");
    }

    String save_location = SavingService.getSaveToPath();
    about_string.append("\nSave Location: " + save_location);

    if (MainScreen.getInstance().flattenParamteters != null
            && !MainScreen.getInstance().flattenParamteters.equals("")) {
        about_string.append("\nFULL INFO:\n");
        about_string.append(MainScreen.getInstance().flattenParamteters);
    }

    alertDialog.setMessage(about_string);
    alertDialog.setPositiveButton(R.string.Pref_CameraParameters_Ok, null);
    alertDialog.setNegativeButton(R.string.Pref_CameraParameters_CopyToClipboard,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity()
                            .getSystemService(Activity.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("OpenCamera About", about_string);
                    clipboard.setPrimaryClip(clip);
                }
            });
    alertDialog.show();
}

From source file:de.schildbach.wallet.util.CrashReporter.java

public 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(Strings.emptyToNull(Build.CPU_ABI),
            Strings.emptyToNull(Build.CPU_ABI2))).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("Memory Class: " + activityManager.getMemoryClass() + "/"
            + activityManager.getLargeMemoryClass()
            + (ActivityManagerCompat.isLowRamDevice(activityManager) ? " (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: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.j av  a2  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");
}