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);
}
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;
}
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;
}
Aggregations