gt:             presetSizeType = instanceState.getInt(PRESET_SIZE_KEY);
context: /**
   * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
   * <p/>
   * You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
   * copy, modify, and distribute this software in source code or binary form for use
   * in connection with the web services and APIs provided by Facebook.
   * <p/>
   * As with any software that integrates with the Facebook platform, your use of
   * this software is subject to the Facebook Developer Principles and Policies
   * [http://developers.facebook.com/policy/]. This copyright notice shall be
   * included in all copies or substantial portions of the software.
   * <p/>
   * 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 THE AUTHORS OR
   * COPYRIGHT HOLDERS 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.login.widget;
  
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.os.Parcelable;
  import android.util.AttributeSet;
  import android.util.Log;
  import android.view.ViewGroup;
  import android.widget.FrameLayout;
  import android.widget.ImageView;
  
  import com.facebook.FacebookException;
  import com.facebook.LoggingBehavior;
  import com.facebook.R;
  import com.facebook.internal.ImageDownloader;
  import com.facebook.internal.ImageRequest;
  import com.facebook.internal.ImageResponse;
  import com.facebook.internal.Logger;
  import com.facebook.internal.Utility;
  
  /**
   * View that displays the profile photo of a supplied profile ID, while conforming
   * to user specified dimensions.
   */
  public class ProfilePictureView extends FrameLayout {
  
      /**
       * Tag used when logging calls are made by ProfilePictureView
       */
      public static final String TAG = ProfilePictureView.class.getSimpleName();
      /**
       * Indicates that the specific size of the View will be set via layout params.
       * ProfilePictureView will default to NORMAL X NORMAL, if the layout params set on
       * this instance do not have a fixed size.
       * Used in calls to setPresetSize() and getPresetSize().
       * Corresponds with the preset_size Xml attribute that can be set on ProfilePictureView.
       */
      public static final int CUSTOM = -1;
      /**
       * Indicates that the profile image should fit in a SMALL X SMALL space, regardless
       * of whether the cropped or un-cropped version is chosen.
       * Used in calls to setPresetSize() and getPresetSize().
       * Corresponds with the preset_size Xml attribute that can be set on ProfilePictureView.
       */
      public static final int SMALL = -2;
      /**
       * Indicates that the profile image should fit in a NORMAL X NORMAL space, regardless
       * of whether the cropped or un-cropped version is chosen.
       * Used in calls to setPresetSize() and getPresetSize().
       * Corresponds with the preset_size Xml attribute that can be set on ProfilePictureView.
       */
      public static final int NORMAL = -3;
      /**
       * Indicates that the profile image should fit in a LARGE X LARGE space, regardless
       * of whether the cropped or un-cropped version is chosen.
       * Used in calls to setPresetSize() and getPresetSize().
       * Corresponds with the preset_size Xml attribute that can be set on ProfilePictureView.
       */
      public static final int LARGE = -4;
      private static final int MIN_SIZE = 1;
      private static final boolean IS_CROPPED_DEFAULT_VALUE = true;
      private static final String SUPER_STATE_KEY = "ProfilePictureView_superState";
      private static final String PROFILE_ID_KEY = "ProfilePictureView_profileId";
      private static final String PRESET_SIZE_KEY = "ProfilePictureView_presetSize";
      private static final String IS_CROPPED_KEY = "ProfilePictureView_isCropped";
      private static final String BITMAP_KEY = "ProfilePictureView_bitmap";
      private static final String BITMAP_WIDTH_KEY = "ProfilePictureView_width";
      private static final String BITMAP_HEIGHT_KEY = "ProfilePictureView_height";
      private static final String PENDING_REFRESH_KEY = "ProfilePictureView_refresh";
      private String profileId;
      private int queryHeight = ImageRequest.UNSPECIFIED_DIMENSION;
      private int queryWidth = ImageRequest.UNSPECIFIED_DIMENSION;
      private boolean isCropped = IS_CROPPED_DEFAULT_VALUE;
      private Bitmap imageContents;
      private ImageView image;
      private int presetSizeType = CUSTOM;
      private ImageRequest lastRequest;
      private OnErrorListener onErrorListener;
      private Bitmap customizedDefaultProfilePicture = null;
      /**
       * Constructor
       *
       * @param context Context for this View
       */
      public ProfilePictureView(Context context) {
          super(context);
          initialize(context);
      }
  
      /**
       * Constructor
       *
       * @param context Context for this View
       * @param attrs   AttributeSet for this View.
       *                The attribute 'preset_size' is processed here
       */
      public ProfilePictureView(Context context, AttributeSet attrs) {
          super(context, attrs);
          initialize(context);
          parseAttributes(attrs);
      }
  
      /**
       * Constructor
       *
       * @param context  Context for this View
       * @param attrs    AttributeSet for this View.
       *                 The attribute 'preset_size' is processed here
       * @param defStyle Default style for this View
       */
      public ProfilePictureView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          initialize(context);
          parseAttributes(attrs);
      }
  
      /**
       * Gets the current preset size type
       *
       * @return The current preset size type, if set; CUSTOM if not
       */
      public final int getPresetSize() {
          return presetSizeType;
      }
  
      /**
       * Apply a preset size to this profile photo
       *
       * @param sizeType The size type to apply: SMALL, NORMAL or LARGE
       */
      public final void setPresetSize(int sizeType) {
          switch (sizeType) {
              case SMALL:
              case NORMAL:
              case LARGE:
              case CUSTOM:
                  this.presetSizeType = sizeType;
                  break;
  
              default:
                  throw new IllegalArgumentException("Must use a predefined preset size");
          }
  
          requestLayout();
      }
  
      /**
       * Indicates whether the cropped version of the profile photo has been chosen
       *
       * @return True if the cropped version is chosen, false if not.
       */
      public final boolean isCropped() {
          return isCropped;
      }
  
      /**
       * Sets the profile photo to be the cropped version, or the original version
       *
       * @param showCroppedVersion True to select the cropped version
       *                           False to select the standard version
       */
      public final void setCropped(boolean showCroppedVersion) {
          isCropped = showCroppedVersion;
          // No need to force the refresh since we will catch the change in required dimensions
          refreshImage(false);
      }
  
      /**
       * Returns the profile Id for the current profile photo
       *
       * @return The profile Id
       */
      public final String getProfileId() {
          return profileId;
      }
  
      /**
       * Sets the profile Id for this profile photo
       *
       * @param profileId The profileId
       *               NULL/Empty String will show the blank profile photo
       */
      public final void setProfileId(String profileId) {
          boolean force = false;
          if (Utility.isNullOrEmpty(this.profileId) || !this.profileId.equalsIgnoreCase(profileId)) {
              // Clear out the old profilePicture before requesting for the new one.
              setBlankProfilePicture();
              force = true;
          }
  
          this.profileId = profileId;
          refreshImage(force);
      }
  
      /**
       * Returns the current OnErrorListener for this instance of ProfilePictureView
       *
       * @return The OnErrorListener
       */
      public final OnErrorListener getOnErrorListener() {
          return onErrorListener;
      }
  
      /**
       * Sets an OnErrorListener for this instance of ProfilePictureView to call into when
       * certain errors occur.
       *
       * @param onErrorListener The Listener object to set
       */
      public final void setOnErrorListener(OnErrorListener onErrorListener) {
          this.onErrorListener = onErrorListener;
      }
  
      /**
       * The ProfilePictureView will display the provided image while the specified
       * profile is being loaded, or if the specified profile is not available.
       *
       * @param inputBitmap The bitmap to render until the actual profile is loaded.
       */
      public final void setDefaultProfilePicture(Bitmap inputBitmap) {
          customizedDefaultProfilePicture = inputBitmap;
      }
  
      /**
       * Overriding onMeasure to handle the case where WRAP_CONTENT might be
       * specified in the layout. Since we don't know the dimensions of the profile
       * photo, we need to handle this case specifically.
       * <p/>
       * The approach is to default to a NORMAL sized amount of space in the case that
       * a preset size is not specified. This logic is applied to both width and height
       */
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          ViewGroup.LayoutParams params = getLayoutParams();
          boolean customMeasure = false;
          int newHeight = MeasureSpec.getSize(heightMeasureSpec);
          int newWidth = MeasureSpec.getSize(widthMeasureSpec);
          if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY && params.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
              newHeight = getPresetSizeInPixels(true); // Default to a preset size
              heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
              customMeasure = true;
          }
  
          if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY && params.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
              newWidth = getPresetSizeInPixels(true); // Default to a preset size
              widthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
              customMeasure = true;
          }
  
          if (customMeasure) {
              // Since we are providing custom dimensions, we need to handle the measure
              // phase from here
              setMeasuredDimension(newWidth, newHeight);
              measureChildren(widthMeasureSpec, heightMeasureSpec);
          } else {
              // Rely on FrameLayout to do the right thing
              super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          }
      }
  
      /**
       * In addition to calling super.Layout(), we also attempt to get a new image that
       * is properly sized for the layout dimensions
       */
      @Override
      protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
          super.onLayout(changed, left, top, right, bottom);
  
          // See if the image needs redrawing
          refreshImage(false);
      }
  
      /**
       * Some of the current state is returned as a Bundle to allow quick restoration
       * of the ProfilePictureView object in scenarios like orientation changes.
       * @return a Parcelable containing the current state
       */
      @Override
      protected Parcelable onSaveInstanceState() {
          Parcelable superState = super.onSaveInstanceState();
          Bundle instanceState = new Bundle();
          instanceState.putParcelable(SUPER_STATE_KEY, superState);
          instanceState.putString(PROFILE_ID_KEY, profileId);
          instanceState.putInt(PRESET_SIZE_KEY, presetSizeType);
          instanceState.putBoolean(IS_CROPPED_KEY, isCropped);
          instanceState.putParcelable(BITMAP_KEY, imageContents);
          instanceState.putInt(BITMAP_WIDTH_KEY, queryWidth);
          instanceState.putInt(BITMAP_HEIGHT_KEY, queryHeight);
          instanceState.putBoolean(PENDING_REFRESH_KEY, lastRequest != null);
  
          return instanceState;
      }
  
      /**
       * If the passed in state is a Bundle, an attempt is made to restore from it.
       * @param state a Parcelable containing the current state
       */
      @Override
      protected void onRestoreInstanceState(Parcelable state) {
          if (state.getClass() != Bundle.class) {
              super.onRestoreInstanceState(state);
          } else {
              Bundle instanceState = (Bundle) state;
              super.onRestoreInstanceState(instanceState.getParcelable(SUPER_STATE_KEY));
  
              profileId = instanceState.getString(PROFILE_ID_KEY);
  