/*
 * This file provided by Facebook is for non-commercial testing and evaluation
 * purposes only.  Facebook reserves all rights not expressly granted.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.facebook.fresco.samples.showcase.drawee;

import android.graphics.PointF;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Spinner;

import com.facebook.drawee.drawable.ScalingUtils.ScaleType;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.fresco.samples.showcase.BaseShowcaseFragment;
import com.facebook.fresco.samples.showcase.R;
import com.facebook.fresco.samples.showcase.common.SimpleScaleTypeAdapter;

/**
 * Simple drawee fragment that illustrates different scale types
 */
public class DraweeScaleTypeFragment extends BaseShowcaseFragment {

  private static final Uri URI_1 =
      Uri.parse("http://frescolib.org/static/sample-images/animal_a_m.jpg");
  private static final Uri URI_2 =
      Uri.parse("http://frescolib.org/static/sample-images/animal_d_m.jpg");

  private SimpleDraweeView mDraweeTop1;
  private SimpleDraweeView mDraweeTop2;
  private SimpleDraweeView mDraweeMain;
  private Spinner mSpinner;

  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater,
      @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_drawee_scale_type, container, false);

    mDraweeTop1 = (SimpleDraweeView) view.findViewById(R.id.drawee_view_top_1);
    mDraweeTop2 = (SimpleDraweeView) view.findViewById(R.id.drawee_view_top_2);
    mDraweeMain = (SimpleDraweeView) view.findViewById(R.id.drawee_view);
    mSpinner = (Spinner) view.findViewById(R.id.spinner);

    mDraweeTop1.setImageURI(URI_1);
    mDraweeTop1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        changeMainDraweeUri(URI_1);
      }
    });

    mDraweeTop2.setImageURI(URI_2);
    mDraweeTop2.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        changeMainDraweeUri(URI_2);
      }
    });

    changeMainDraweeUri(URI_1);

    final SimpleScaleTypeAdapter adapter = SimpleScaleTypeAdapter.createForAllScaleTypes();
    mSpinner.setAdapter(adapter);
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        final SimpleScaleTypeAdapter.Entry spinnerEntry =
            (SimpleScaleTypeAdapter.Entry) adapter.getItem(position);
        changeMainDraweeScaleType(spinnerEntry.scaleType, spinnerEntry.focusPoint);
      }

      @Override
      public void onNothingSelected(AdapterView<?> parent) {
      }
    });
    mSpinner.setSelection(0);

    return view;
  }

  private void changeMainDraweeUri(Uri uri) {
    mDraweeMain.setImageURI(uri);
  }

  private void changeMainDraweeScaleType(ScaleType scaleType, @Nullable PointF focusPoint) {
    final GenericDraweeHierarchy hierarchy = mDraweeMain.getHierarchy();
    hierarchy.setActualImageScaleType(scaleType);
    hierarchy.setActualImageFocusPoint(focusPoint != null ? focusPoint : new PointF(0.5f, 0.5f));
  }

  @Override
  public int getTitleId() {
    return R.string.drawee_scale_type_title;
  }
}

@@ -1304,16 +1304,83 @@
 Adapter;
+%0Aimport com.facebook.fresco.samples.showcase.misc.ImageUriProvider;
 %0A%0A/**%0A *
@@ -1519,233 +1519,8 @@
  %7B%0A%0A
-  private static final Uri URI_1 =%0A      Uri.parse(%22http://frescolib.org/static/sample-images/animal_a_m.jpg%22);%0A  private static final Uri URI_2 =%0A      Uri.parse(%22http://frescolib.org/static/sample-images/animal_d_m.jpg%22);%0A%0A
   pr
@@ -1921,24 +1921,398 @@
 r, false);%0A%0A
+    final ImageUriProvider imageUriProvider = ImageUriProvider.getInstance(getContext());%0A    final Uri uri1 = imageUriProvider.createSampleUri(%0A        ImageUriProvider.ImageSize.M,%0A        ImageUriProvider.Orientation.LANDSCAPE);%0A    final Uri uri2 = imageUriProvider.createSampleUri(%0A        ImageUriProvider.ImageSize.M,%0A        ImageUriProvider.Orientation.PORTRAIT);%0A%0A
     mDraweeT
@@ -2620,20 +2620,19 @@
 mageURI(
-URI_
+uri
 1);%0A    
@@ -2767,28 +2767,27 @@
 inDraweeUri(
-URI_
+uri
 1);%0A      %7D%0A
@@ -2823,20 +2823,19 @@
 mageURI(
-URI_
+uri
 2);%0A    
@@ -2974,20 +2974,19 @@
 aweeUri(
-URI_
+uri
 2);%0A    
@@ -3026,12 +3026,11 @@
 Uri(
-URI_
+uri
 1);%0A

Update DraweeScaleTypeFragment