Search in sources :

Example 1 with MyResources

use of com.dianping.loader.MyResources 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)

Example 2 with MyResources

use of com.dianping.loader.MyResources in project AndroidDynamicLoader by mmin18.

the class ImageGridFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MyResources res = MyResources.getResource(ImageGridFragment.class);
    final View v = res.inflate(getActivity(), R.layout.image_grid_fragment, container, false);
    final GridView mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(this);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                mImageFetcher.setPauseWork(true);
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math.floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                }
            }
        }
    });
    return v;
}
Also used : MyResources(com.dianping.loader.MyResources) AbsListView(android.widget.AbsListView) GridView(android.widget.GridView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) ViewTreeObserver(android.view.ViewTreeObserver)

Example 3 with MyResources

use of com.dianping.loader.MyResources in project AndroidDynamicLoader by mmin18.

the class ImageDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MyResources res = MyResources.getResource(ImageGridFragment.class);
    final View v = res.inflate(getActivity(), R.layout.image_detail_fragment, container, false);
    mImageView = (ImageView) v.findViewById(R.id.imageView);
    return v;
}
Also used : MyResources(com.dianping.loader.MyResources) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

MyResources (com.dianping.loader.MyResources)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 Bitmap (android.graphics.Bitmap)1 ViewTreeObserver (android.view.ViewTreeObserver)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageCacheParams (com.example.android.bitmapfun.util.ImageCache.ImageCacheParams)1 ImageFetcher (com.example.android.bitmapfun.util.ImageFetcher)1