diff options
author | Chiao Cheng <chiaocheng@google.com> | 2013-08-21 14:51:04 -0700 |
---|---|---|
committer | Chiao Cheng <chiaocheng@google.com> | 2013-08-21 14:51:04 -0700 |
commit | 21d56f410e15520ca2c3f77408270d5dff9dbc9b (patch) | |
tree | f0ba769476187494a41545065de58cf33dc2a862 /InCallUI | |
parent | 98a02fa7d8e4f8cd10605834134ada0ac83c2873 (diff) |
Removing explicit dependency on http calls.
Bug: 10413514
Change-Id: Id4db77f4417827ce4ecc140ea09f3228154f50de
Diffstat (limited to 'InCallUI')
5 files changed, 9 insertions, 124 deletions
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java index 65a75d78a..889ff4908 100644 --- a/InCallUI/src/com/android/incallui/CallCardFragment.java +++ b/InCallUI/src/com/android/incallui/CallCardFragment.java @@ -117,7 +117,9 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr @Override public void setImage(Bitmap image) { - setDrawableToImageView(mPhoto, new BitmapDrawable(getResources(), image)); + if (image != null) { + setDrawableToImageView(mPhoto, new BitmapDrawable(getResources(), image)); + } } @Override diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 5ab2529ff..1239695c3 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -18,7 +18,6 @@ package com.android.incallui; import android.graphics.drawable.Drawable; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.text.TextUtils; import android.text.format.DateUtils; @@ -29,12 +28,9 @@ import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.service.PhoneNumberService; -import com.android.incallui.util.HttpFetcher; import com.android.services.telephony.common.AudioMode; import com.android.services.telephony.common.Call; -import java.io.IOException; - /** * Presenter for the Call Card Fragment. * <p> @@ -307,13 +303,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> @Override protected Bitmap doInBackground(Void... params) { // Fetch the image - try { - final byte[] image = HttpFetcher.getRequestAsByteArray(url); - return BitmapFactory.decodeByteArray(image, 0, image.length); - } catch (IOException e) { - Log.e(TAG, "Unable to download/decode photo.", e); - } - return null; + return mPhoneNumberService.fetchImage(url); } @Override diff --git a/InCallUI/src/com/android/incallui/Log.java b/InCallUI/src/com/android/incallui/Log.java index 029baceeb..bc57ed7d7 100644 --- a/InCallUI/src/com/android/incallui/Log.java +++ b/InCallUI/src/com/android/incallui/Log.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 The Android Open Source Project + * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/InCallUI/src/com/android/incallui/service/PhoneNumberService.java b/InCallUI/src/com/android/incallui/service/PhoneNumberService.java index 1e0cb950a..456638809 100644 --- a/InCallUI/src/com/android/incallui/service/PhoneNumberService.java +++ b/InCallUI/src/com/android/incallui/service/PhoneNumberService.java @@ -16,12 +16,16 @@ package com.android.incallui.service; +import android.graphics.Bitmap; + /** * */ public interface PhoneNumberService { public void getPhoneNumberInfo(String phoneNumber, PhoneNumberServiceListener listener); + public Bitmap fetchImage(String url); + public interface PhoneNumberServiceListener { /** diff --git a/InCallUI/src/com/android/incallui/util/HttpFetcher.java b/InCallUI/src/com/android/incallui/util/HttpFetcher.java deleted file mode 100644 index 6548a5a05..000000000 --- a/InCallUI/src/com/android/incallui/util/HttpFetcher.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.incallui.util; - -import android.os.SystemClock; - -import com.android.incallui.Log; -import com.google.common.io.Closeables; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; - -/** - * Utility for making http requests. - */ -public class HttpFetcher { - - private static final String TAG = HttpFetcher.class.getSimpleName(); - - /** - * Send a http request to the given url. - * - * @param urlString The url to request. - * @return The response body as a byte array. Or {@literal null} if status code is not 2xx. - * @throws java.io.IOException when an error occurs. - */ - public static byte[] getRequestAsByteArray(String urlString) throws IOException { - Log.d(TAG, "fetching " + urlString); - HttpURLConnection conn = null; - InputStream is = null; - boolean isError = false; - final long start = SystemClock.uptimeMillis(); - try { - final URL url = new URL(urlString); - conn = (HttpURLConnection) url.openConnection(); - Log.d(TAG, "response code: " + conn.getResponseCode()); - // All 2xx codes are successful. - if (conn.getResponseCode() / 100 == 2) { - is = conn.getInputStream(); - } else { - is = conn.getErrorStream(); - isError = true; - } - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final byte[] buffer = new byte[1024]; - int bytesRead; - - while ((bytesRead = is.read(buffer)) != -1) { - baos.write(buffer, 0, bytesRead); - } - - if (isError) { - handleBadResponse(urlString, baos.toByteArray()); - return null; - } - - final byte[] response = baos.toByteArray(); - Log.d(TAG, "received " + response.length + " bytes"); - final long end = SystemClock.uptimeMillis(); - Log.d(TAG, "fetch took " + (end - start) + " ms"); - return response; - } finally { - Closeables.closeQuietly(is); - if (conn != null) { - conn.disconnect(); - } - } - } - - /** - * Send a http request to the given url. - * - * @param urlString The url to request. - * @return The response body as a String. Or {@literal null} if status code is not 2xx. - * @throws java.io.IOException when an error occurs. - */ - public static String getRequestAsString(String urlString) throws IOException { - final byte[] byteArr = getRequestAsByteArray(urlString); - if (byteArr == null) { - // Encountered error response... just return. - return null; - } - final String response = new String(byteArr); - Log.d(TAG, "response body: "); - Log.d(TAG, response); - return response; - } - - private static void handleBadResponse(String url, byte[] response) { - Log.w(TAG, "Got bad response code from url: " + url); - Log.w(TAG, new String(response)); - } -} |