List of usage examples for android.app ActivityManager getMemoryClass
public int getMemoryClass()
From source file:com.android.ex.photo.PhotoViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActivityManager mgr = (ActivityManager) getApplicationContext() .getSystemService(Activity.ACTIVITY_SERVICE); sMemoryClass = mgr.getMemoryClass(); Intent mIntent = getIntent();// w ww. java2s. com int currentItem = -1; if (savedInstanceState != null) { currentItem = savedInstanceState.getInt(STATE_ITEM_KEY, -1); mFullScreen = savedInstanceState.getBoolean(STATE_FULLSCREEN_KEY, false); } // uri of the photos to view; optional if (mIntent.hasExtra(Intents.EXTRA_PHOTOS_URI)) { mPhotosUri = mIntent.getStringExtra(Intents.EXTRA_PHOTOS_URI); } // projection for the query; optional // I.f not set, the default projection is used. // This projection must include the columns from the default projection. if (mIntent.hasExtra(Intents.EXTRA_PROJECTION)) { mProjection = mIntent.getStringArrayExtra(Intents.EXTRA_PROJECTION); } else { mProjection = null; } // Set the current item from the intent if wasn't in the saved instance if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) { currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1); } mPhotoIndex = currentItem; setContentView(R.layout.photo_activity_view); // Create the adapter and add the view pager mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null); mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager); mViewPager.setAdapter(mAdapter); mViewPager.setOnPageChangeListener(this); mViewPager.setOnInterceptTouchListener(this); // Kick off the loader getLoaderManager().initLoader(LOADER_PHOTO_LIST, null, this); final ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); mActionBarHideDelayTime = getResources().getInteger(R.integer.action_bar_delay_time_in_millis); actionBar.addOnMenuVisibilityListener(this); actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); }
From source file:org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkManager.java
/** * Creates an instance of {@link EnhancedBookmarkManager}. It also initializes resources, * bookmark models and jni bridges.//www.j a va 2s.co m * @param activity The activity context to use. */ public EnhancedBookmarkManager(Activity activity) { mActivity = activity; mEnhancedBookmarksModel = new EnhancedBookmarksModel(); mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.eb_main, null); mDrawer = (DrawerLayout) mMainView.findViewById(R.id.eb_drawer_layout); mDrawerListView = (EnhancedBookmarkDrawerListView) mMainView.findViewById(R.id.eb_drawer_list); mContentView = (EnhancedBookmarkContentView) mMainView.findViewById(R.id.eb_content_view); mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.eb_view_switcher); mUndoController = new EnhancedBookmarkUndoController(activity, mEnhancedBookmarksModel, ((SnackbarManageable) activity).getSnackbarManager()); mSearchView = (EnhancedBookmarkSearchView) getView().findViewById(R.id.eb_search_view); mEnhancedBookmarksModel.addObserver(mBookmarkModelObserver); initializeIfBookmarkModelLoaded(); // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup // code, but that might be executed much later. Especially on L, showing loading // progress bar blocks that so it won't be loaded. http://crbug.com/429383 PartnerBookmarksShim.kickOffReading(activity); mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile()); ActivityManager activityManager = ((ActivityManager) ApplicationStatus.getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE)); int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024, FAVICON_MAX_CACHE_SIZE_BYTES); mLargeIconBridge.createCache(maxSize); }
From source file:org.totschnig.myexpenses.MyApplication.java
public int getMemoryClass() { ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); return am.getMemoryClass(); }
From source file:com.andrew.apollo.cache.ImageCache.java
/** * Sets up the Lru cache/*www.ja v a2s . c o m*/ * * @param context The {@link Context} to use */ @SuppressLint("NewApi") public void initLruCache(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final int lruCacheSize = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass() * 1024 * 1024); mLruCache = new MemoryCache(lruCacheSize); // Release some memory as needed if (ApolloUtils.hasICS()) { context.registerComponentCallbacks(new ComponentCallbacks2() { /** * {@inheritDoc} */ @Override public void onTrimMemory(final int level) { if (level >= TRIM_MEMORY_MODERATE) { evictAll(); } else if (level >= TRIM_MEMORY_BACKGROUND) { mLruCache.trimToSize(mLruCache.size() / 2); } } /** * {@inheritDoc} */ @Override public void onLowMemory() { // Nothing to do } /** * {@inheritDoc} */ @Override public void onConfigurationChanged(final Configuration newConfig) { // Nothing to do } }); } }
From source file:com.boko.vimusic.cache.ImageCache.java
/** * Sets up the Lru cache// w w w. j a v a2 s .c o m * * @param context * The {@link Context} to use */ @SuppressLint("NewApi") public void initLruCache(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final int lruCacheSize = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass() * 1024 * 1024); mLruCache = new MemoryCache(lruCacheSize); // Release some memory as needed context.registerComponentCallbacks(new ComponentCallbacks2() { /** * {@inheritDoc} */ @Override public void onTrimMemory(final int level) { if (level >= TRIM_MEMORY_MODERATE) { evictAll(); } else if (level >= TRIM_MEMORY_BACKGROUND) { mLruCache.trimToSize(mLruCache.size() / 2); } } /** * {@inheritDoc} */ @Override public void onLowMemory() { // Nothing to do } /** * {@inheritDoc} */ @Override public void onConfigurationChanged(final Configuration newConfig) { // Nothing to do } }); }
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 {//from w w w . j a v a 2 s . c om 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:com.utils.image.cache.ImageCache.java
/** * Sets up the Lru cache/*from w w w .ja v a 2s. co m*/ * * @param context The {@link Context} to use */ @SuppressLint("NewApi") public void initLruCache(final Context context) { final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final int lruCacheSize = Math.round(MEM_CACHE_DIVIDER * activityManager.getMemoryClass() * 1024 * 1024); KeelLog.d("lruCacheSize:" + lruCacheSize); mLruCache = new MemoryCache(lruCacheSize / 2); // Release some memory as needed if (ApolloUtils.hasICS()) { context.registerComponentCallbacks(new ComponentCallbacks2() { /** * {@inheritDoc} */ @Override public void onTrimMemory(final int level) { if (level >= TRIM_MEMORY_MODERATE) { evictAll(); } else if (level >= TRIM_MEMORY_BACKGROUND) { mLruCache.trimToSize(mLruCache.size() / 2); } } /** * {@inheritDoc} */ @Override public void onLowMemory() { // Nothing to do } /** * {@inheritDoc} */ @Override public void onConfigurationChanged(final Configuration newConfig) { // Nothing to do } }); } }
From source file:info.guardianproject.pixelknot.PixelKnotActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dump = new File(DUMP); if (!dump.exists()) dump.mkdir();//from w w w .ja va 2s .c o m d = R.drawable.progress_off_selected; d_ = R.drawable.progress_on; setContentView(R.layout.pixel_knot_activity); ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); scale = Image.getScale(am.getMemoryClass()); if (Build.VERSION.SDK_INT <= 10) getSupportActionBar().hide(); else ((RelativeLayout) findViewById(R.id.pk_header)).setVisibility(View.GONE); imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); options_holder = (LinearLayout) findViewById(R.id.options_holder); action_display = (LinearLayout) findViewById(R.id.action_display); action_display_ = (LinearLayout) findViewById(R.id.action_display_); progress_holder = (LinearLayout) findViewById(R.id.progress_holder); List<Fragment> fragments = new Vector<Fragment>(); if (getIntent().getData() == null) { Fragment cover_image_fragment = Fragment.instantiate(this, CoverImageFragment.class.getName()); Fragment set_message_fragment = Fragment.instantiate(this, SetMessageFragment.class.getName()); Fragment share_fragment = Fragment.instantiate(this, ShareFragment.class.getName()); fragments.add(0, cover_image_fragment); fragments.add(1, set_message_fragment); fragments.add(2, share_fragment); } else { Fragment stego_image_fragment = Fragment.instantiate(this, StegoImageFragment.class.getName()); Bundle args = new Bundle(); args.putString(Keys.COVER_IMAGE_NAME, IO.pullPathFromUri(this, getIntent().getData())); stego_image_fragment.setArguments(args); Fragment decrypt_image_fragment = Fragment.instantiate(this, DecryptImageFragment.class.getName()); fragments.add(0, stego_image_fragment); fragments.add(1, decrypt_image_fragment); } pk_pager = new PKPager(getSupportFragmentManager(), fragments); view_pager = (ViewPager) findViewById(R.id.fragment_holder); view_pager.setAdapter(pk_pager); view_pager.setOnPageChangeListener(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.setMargins(5, 0, 5, 0); for (int p = 0; p < fragments.size(); p++) { ImageView progress_view = new ImageView(this); progress_view.setLayoutParams(lp); progress_view.setBackgroundResource(p == 0 ? d_ : d); progress_holder.addView(progress_view); } last_diff = 0; activity_root = findViewById(R.id.activity_root); activity_root.getViewTreeObserver().addOnGlobalLayoutListener(this); last_locale = PreferenceManager.getDefaultSharedPreferences(this).getString(Settings.LANGUAGE, "0"); }
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:com.digipom.manteresting.android.service.cache.CacheService.java
private int tryGetLargeMemoryClass(ActivityManager am) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { try {/* ww w. j av a 2s . c om*/ final Method getLargeMemoryClass = ActivityManager.class.getMethod("getLargeMemoryClass", (Class[]) null); final Integer largeMemoryClass = (Integer) getLargeMemoryClass.invoke(am, (Object[]) null); return largeMemoryClass; } catch (Exception e) { if (LoggerConfig.canLog(Log.ERROR)) { Log.e(TAG, "Reflection call failed.", e); } return am.getMemoryClass(); } } else { return am.getMemoryClass(); } }