2013-01-06 1 views
1

지금 다음 코드 조각을 사용하여 이미지를 가져오고 있는데 완벽하게 작동하고 있습니다. 그러나 universal-image-loader을 사용하여 캐시를 구현하고 싶습니다. 이미 ~ \ images와 같은 이미지의 전체 URL을 가지고있는 다른 프로젝트에서 구현했습니다. \ pic1.jpeg .on 반면에 연락처 API를 사용하는 동안 v3은 입력 스트림을 처리해야하며 완전한 url.so를 가지고 있지 않으므로 universal-image-loader을 구현하는 방법을 알지 못합니다. 기준에 대한 universal-image-loader를 사용하여 연락처 API를 사용하여 연락처 이미지를 검색 할 수 있습니까?

:

Bitmap bm=BitmapFactory.decodeResource(HomeActivity.this.getResources(), 
      R.drawable.profile_pic); 
    CONSTANTS.buffer = new byte[4096]; 

// iterate the loop upto number of contacts 
    for(int i=0;i<CONSTANTS.contactArrayList.size();i++) 
    { 


//if the contact has any profile pic then retrieve it otherwise set default profile pic from drawable folder 

    if(CONSTANTS.contactArrayList.get(i).getContactPhotoLink().getEtag()!=null) 
     { 
      try 
      { 
       GDataRequest request = CONSTANTS.mContactService.createLinkQueryRequest(CONSTANTS.contactArrayList.get(i).getContactPhotoLink()); 
        request.execute(); 
        InputStream in = request.getResponseStream(); 
        CONSTANTS.buffer = ByteStreams.toByteArray(in); 
        bm = BitmapFactory.decodeByteArray(CONSTANTS.buffer, 0, CONSTANTS.buffer.length); 
        in.close(); 
        request.end(); 
      } 
      catch (Exception e) { 
       UTILS.Log_e("loadProfilePics error", e.toString()); 
      } 

     } 
     else 
     { 
      bm = BitmapFactory.decodeResource(HomeActivity.this.getResources(), 
        R.drawable.profile_pic); 
     } 
     CONSTANTS.contactArrayList.get(i).setContactPhoto(bm); 
    } 

답변

1

예, universal-image-loader 당신이 그것을 수행 할 수 있습니다 : 여기

Contact api v3 내가 지금 사용하고있는 코드입니다. 그냥 따라이 단계 :

  1. 당신은 예를 contacts-api-v3://user_id=<user_id>
  2. 에 대한 자신의 URL 형식을 도입 할 수와 같은 URL에 InputStream 검색 할 수있는 방법 제공 :

    public class CustomImageDownloader extends URLConnectionImageDownloader { 
        @Override 
        protected InputStream getStreamFromOtherSource(URI imageUri) throws IOException { 
         if (imageUri.getScheme().equals("contacts-api-v3")) { 
          // here you can use code provided in your question 
          return retriveInputStreamForThisUser(); 
         } 
         return null; 
        } 
    } 
    
  3. 구성 ImageLoader 당신의 CustomImageDownloader을 사용하기를 :

    final ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context); 
    
    // some basic configuration should be here 
    
    builder.imageDownloader(new CustomImageDownloader()); 
    
  4. 지금 당신이이 방법을 사용할 수 있습니다

    ImageLoader.getInstance().displayImage("contacts-api-v3://user_id=123", imageView); 
    
+1

ContactPhotoLink이 같은 인 경우'''https://www.google.com/m8/feeds/contacts/ {USEREMAIL}/... ''그러면 ** https **를 ** 연락처 **로 대체하고 imageLoader : imageLoader.displayImage ("constacts : //www.google.com/m8/feeds/contacts/ ..")로 전달하는 것이 좋습니다. . ")''', CustomImageDownloader에서'''imageUri.getScheme(). equals ("contacts ")'''를 체크하고 만약 있다면 ** contact **을 ** https **로 대체하고 이것으로 InputStream을 검색하십시오. 링크. – NOSTRA

관련 문제