Search in sources :

Example 1 with ImageFetcher

use of com.example.android.bitmapfun.util.ImageFetcher in project AndroidDynamicLoader by mmin18.

the class ImageDetailFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mImageUrl = getActivity().getIntent().getStringExtra("imageUrl");
    // Fetch screen height and width, to use as our max size when loading images as this
    // activity runs full screen
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;
    // For this sample we'll use half of the longest width to resize our images. As the
    // image scaling ensures the image is larger than this, we should be left with a
    // resolution that is appropriate for both portrait and landscape. For best image quality
    // we shouldn't divide by 2, but this will use more memory and require a larger memory
    // cache.
    final int longest = (height > width ? height : width) / 2;
    ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(getActivity(), IMAGE_CACHE_DIR);
    // Set memory cache to 25% of app memory
    cacheParams.setMemCacheSizePercent(0.25f);
    // The ImageFetcher takes care of loading images into our ImageView children asynchronously
    mImageFetcher = new ImageFetcher(getActivity(), longest);
    mImageFetcher.addImageCache(getFragmentManager(), cacheParams);
    mImageFetcher.setImageFadeIn(false);
    if (!TextUtils.isEmpty(mImageUrl)) {
        mImageFetcher.loadImage(mImageUrl, mImageView);
    }
    // Set up activity to go full screen
    getActivity().getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);
    // Enable some additional newer visibility and ActionBar features to create a more
    // immersive photo viewing experience
    final ActionBar actionBar = getActivity().getActionBar();
    // Hide title text and set home as up
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    // Start low profile mode and hide ActionBar
    mImageView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    actionBar.hide();
    mImageView.setOnClickListener(this);
}
Also used : ImageFetcher(com.example.android.bitmapfun.util.ImageFetcher) ImageCache(com.example.android.bitmapfun.util.ImageCache) DisplayMetrics(android.util.DisplayMetrics) ActionBar(android.app.ActionBar)

Example 2 with ImageFetcher

use of com.example.android.bitmapfun.util.ImageFetcher in project AndroidDynamicLoader by mmin18.

the class ImageGridFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    MyResources res = MyResources.getResource(ImageGridFragment.class);
    mImageThumbSize = res.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    mImageThumbSpacing = res.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);
    // The empty_photo bitmap is in our package, so we use res.getResources() instead of context.getResources()
    Bitmap emptyPhoto = BitmapFactory.decodeResource(res.getResources(), R.drawable.empty_photo);
    mAdapter = new ImageAdapter(getActivity());
    ImageCacheParams cacheParams = new ImageCacheParams(getActivity(), IMAGE_CACHE_DIR);
    // Set memory cache to 25% of app memory
    cacheParams.setMemCacheSizePercent(0.25f);
    // The ImageFetcher takes care of loading images into our ImageView children asynchronously
    mImageFetcher = new ImageFetcher(getActivity(), mImageThumbSize);
    mImageFetcher.setLoadingImage(emptyPhoto);
    mImageFetcher.addImageCache(getActivity().getFragmentManager(), cacheParams);
}
Also used : Bitmap(android.graphics.Bitmap) MyResources(com.dianping.loader.MyResources) ImageFetcher(com.example.android.bitmapfun.util.ImageFetcher) ImageCacheParams(com.example.android.bitmapfun.util.ImageCache.ImageCacheParams)

Aggregations

ImageFetcher (com.example.android.bitmapfun.util.ImageFetcher)2 ActionBar (android.app.ActionBar)1 Bitmap (android.graphics.Bitmap)1 DisplayMetrics (android.util.DisplayMetrics)1 MyResources (com.dianping.loader.MyResources)1 ImageCache (com.example.android.bitmapfun.util.ImageCache)1 ImageCacheParams (com.example.android.bitmapfun.util.ImageCache.ImageCacheParams)1