Exemple #1
0
        protected override Response ParseNetworkResponse(NetworkResponse response)
        {
            try
            {
                var responseData = response.Data.ToString()[0];
                var header       = new Dictionary <string, string>();

                foreach (KeyValuePair <string, string> kvp in response.Headers)
                {
                    header.Add(kvp.Key, kvp.Value);
                }
                Dictionary <string, string> headerData = header;

                string jsonString = new string(responseData, HttpHeaderParser.ParseCharset(headerData).Count());
                return(Response.Success(new JSONObject(jsonString),
                                        HttpHeaderParser.ParseCacheHeaders(response)));
            }
            catch (UnsupportedEncodingException e)
            {
                return(Response.Error(new ParseError(e)));
            }
            catch (JSONException je)
            {
                return(Response.Error(new ParseError(je)));
            }
        }
 public override Response ParseNetworkResponse(NetworkResponse response)
 {
     Java.Lang.String parsed;
     try
     {
         parsed = new Java.Lang.String(response.Data, HttpHeaderParser.ParseCharset(response.Headers));
     }
     catch (Java.IO.UnsupportedEncodingException)
     {
         parsed = new Java.Lang.String(response.Data);
     }
     return(Response.Success(parsed.ToString(), HttpHeaderParser.ParseCacheHeaders(response)));
 }
        private Response DoParse(NetworkResponse response)
        {
            byte[] data = response.Data;
            BitmapFactory.Options decodeOption = new BitmapFactory.Options();
            Bitmap bitmap = null;

            if (mMaxWidth == 0 && mMaxHeight == 0)
            {
                decodeOption.InPreferredConfig = mDecodeConfig;
                bitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length, decodeOption);
            }
            else
            {
                decodeOption.InJustDecodeBounds = true;
                BitmapFactory.DecodeByteArray(data, 0, data.Length, decodeOption);
                int actualWidth  = decodeOption.OutWidth;
                int actualHeight = decodeOption.OutHeight;

                int desiredWidth  = GetResizedDimension(mMaxWidth, mMaxHeight, actualWidth, actualHeight, mScaleType);
                int desiredHeight = GetResizedDimension(mMaxHeight, mMaxWidth, actualHeight, actualWidth, mScaleType);

                decodeOption.InJustDecodeBounds = false;
                decodeOption.InSampleSize       = FindBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
                Bitmap tempBitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length, decodeOption);

                if (tempBitmap != null && (tempBitmap.Width > desiredWidth || tempBitmap.Height > desiredHeight))
                {
                    bitmap = Bitmap.CreateScaledBitmap(tempBitmap, desiredWidth, desiredHeight, true);
                    tempBitmap.Recycle();
                }
                else
                {
                    bitmap = tempBitmap;
                }
            }

            if (bitmap == null)
            {
                return(Response.Error(new ParseError(response)));
            }
            else
            {
                return(Response.Success(bitmap, HttpHeaderParser.ParseCacheHeaders(response)));
            }
        }