Skip to content

Commit

Permalink
Convert comparison app to GridView
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronen committed Jun 15, 2015
1 parent 2fdd979 commit d102cec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.view.Display;
import android.widget.ListView;
import android.widget.GridView;
import android.widget.Spinner;

import com.facebook.common.logging.FLog;
Expand All @@ -38,7 +38,7 @@ public class ScrollTest extends ActivityInstrumentationTestCase2<MainActivity> {
private static final int WAIT_BEFORE_TEST_END_MS = 5000;

private MainActivity mActivity;
private ListView mImageList;
private GridView mImageList;
private Spinner mLoaderSelect;
private Spinner mSourceSelect;

Expand All @@ -50,7 +50,7 @@ public ScrollTest() {
public void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
mImageList = (ListView) mActivity.findViewById(R.id.image_list);
mImageList = (GridView) mActivity.findViewById(R.id.image_grid);
mLoaderSelect = (Spinner) mActivity.findViewById(R.id.loader_select);
mSourceSelect = (Spinner) mActivity.findViewById(R.id.source_select);
FLog.setMinimumLoggingLevel(FLog.INFO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.GridView;
import android.widget.Spinner;
import android.widget.TextView;

Expand Down Expand Up @@ -79,7 +79,7 @@ public class MainActivity extends ActionBarActivity {
private TextView mStatsDisplay;
private Spinner mLoaderSelect;
private Spinner mSourceSelect;
private ListView mImageList;
private GridView mImageGrid;

private boolean mUseDrawee;
private boolean mAllowAnimations;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void run() {
mPerfListener = new PerfListener();

mStatsDisplay = (TextView) findViewById(R.id.stats_display);
mImageList = (ListView) findViewById(R.id.image_list);
mImageGrid = (GridView) findViewById(R.id.image_grid);
mLoaderSelect = (Spinner) findViewById(R.id.loader_select);
mLoaderSelect.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
Expand Down Expand Up @@ -236,32 +236,32 @@ private void setLoaderAdapter(int index) {
case FRESCO_OKHTTP_INDEX:
mCurrentAdapter = new FrescoAdapter(
this,
R.id.image_list,
R.id.image_grid,
mPerfListener,
index == FRESCO_INDEX ?
ImagePipelineConfigFactory.getImagePipelineConfig(this) :
ImagePipelineConfigFactory.getOkHttpImagePipelineConfig(this));
break;
case GLIDE_INDEX:
mCurrentAdapter = new GlideAdapter(this, R.id.image_list, mPerfListener);
mCurrentAdapter = new GlideAdapter(this, R.id.image_grid, mPerfListener);
break;
case PICASSO_INDEX:
mCurrentAdapter = new PicassoAdapter(this, R.id.image_list, mPerfListener);
mCurrentAdapter = new PicassoAdapter(this, R.id.image_grid, mPerfListener);
break;
case UIL_INDEX:
mCurrentAdapter = new UilAdapter(this, R.id.image_list, mPerfListener);
mCurrentAdapter = new UilAdapter(this, R.id.image_grid, mPerfListener);
break;
case VOLLEY_INDEX:
mCurrentAdapter = mUseDrawee ?
new VolleyDraweeAdapter(this, R.id.image_list, mPerfListener) :
new VolleyAdapter(this, R.id.image_list, mPerfListener);
new VolleyDraweeAdapter(this, R.id.image_grid, mPerfListener) :
new VolleyAdapter(this, R.id.image_grid, mPerfListener);
break;
default:
mCurrentAdapter = null;
return;
}

mImageList.setAdapter(mCurrentAdapter);
mImageGrid.setAdapter(mCurrentAdapter);
updateAdapter(mImageUrls);

updateStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.drawable.ProgressBarDrawable;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.samples.comparison.Drawables;
import com.facebook.samples.comparison.instrumentation.InstrumentedDraweeView;
import com.facebook.samples.comparison.instrumentation.PerfListener;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.facebook.samples.comparison.Drawables;
import com.facebook.samples.comparison.instrumentation.InstrumentedDraweeView;
import com.facebook.samples.comparison.instrumentation.PerfListener;

/** Populate the list view with images using the Fresco image pipeline. */
public class FrescoAdapter extends ImageListAdapter<InstrumentedDraweeView> {
Expand All @@ -50,8 +50,8 @@ protected InstrumentedDraweeView createView() {
GenericDraweeHierarchy gdh = new GenericDraweeHierarchyBuilder(getContext().getResources())
.setPlaceholderImage(Drawables.sPlaceholderDrawable)
.setFailureImage(Drawables.sErrorDrawable)
.setRoundingParams(RoundingParams.asCircle())
.setProgressBarImage(new ProgressBarDrawable())
.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE)
.build();
return new InstrumentedDraweeView(getContext(), gdh);
}
Expand Down
11 changes: 8 additions & 3 deletions samples/comparison/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@

</LinearLayout>

<ListView
android:id="@+id/image_list"
android:layout_width="wrap_content"
<GridView
android:id="@+id/image_grid"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:gravity="center"
/>

</LinearLayout>

0 comments on commit d102cec

Please sign in to comment.