2015년 4월 24일 금요일

Android : Android Query API (+Sample Method)

Android Query 

: Network /  Image Cache . Download  / File Download / JSON . XML / HTTP Async 모든것을 망라하는 API

# Download
https://code.google.com/p/android-query/

# 영문 메뉴얼 - 샘플 완벽
https://code.google.com/p/android-query/wiki/ImageLoading



1.  Image ReSampling Download Sample Code )

private void downloadUserProfileImage(){
AQuery aq = new AQuery(this);
Device devUser = Device.getPreference(this);
if(!TextUtils.isEmpty(devUser.getThumbUrl())){
aq.id(R.id.ivProfile).image(devUser.getThumbUrl(), true, true, 300, 0);
}
}
    

2.  Loading ProgressBar 

I have a progress bar and when my image is loaded progress bar not hide
please help me
Layout XML Code)
  <ProgressBar
             android:id="@+id/rpost_center_progress_video"
             style="@android:style/Widget.ProgressBar.Horizontal"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_centerVertical="true"
             android:layout_gravity="center_horizontal"
             android:layout_margin="10dip"
             android:visibility="gone" />



JAVA Code ) 

aq.id(holder.getmCenterImgVideo())
.progress(holder.getmCenterProgressVideo())
.image(data.getAlbumImgURL(), true, true, 0,
R.drawable.defult_image_for_video,
new BitmapAjaxCallback() {
@Override
public void callback(String url, ImageView iv,
Bitmap bm, AjaxStatus status) {
iv.setImageBitmap(bm);
holder.getmCenterProgressVideo().setVisibility(
View.GONE);

}

});


3. Android Query - file upload Sample (Multipart Request)



AQuery support multipart post such as uploading an image to a service. Simply do a regular POST and put byte array, Inputstream, or File as one of the parameters.
private void aync_multipart(){
        
        String url = "https://graph.facebook.com/me/photos";
        
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("message", "Message");
        
        //Simply put a byte[] to the params, AQuery will detect it and treat it as a multi-part post
        byte[] data = getImageData();
        params.put("source", data);
        
        //Alternatively, put a File or InputStream instead of byte[]
        //File file = getImageFile();           
        //params.put("source", file);
        
        AQuery aq = new AQuery(getApplicationContext());
        aq.auth(handle).ajax(url, params, JSONObject.class, this, "photoCb");
        
}


4. Async Image Loading + Callback Method Sample Code )


aq.ajax(loadUrl,Bitmap.class,new AjaxCallback<Bitmap>(){

@Override
public void failure(int code, String message) {
// TODO Auto-generated method stub
super.failure(code, message);
imgView.clearAnimation();
Log.e(TAG," image loading failed _____ / msg : "+message);

}


@Override
public void callback(String url, Bitmap object,
AjaxStatus status) {
// TODO Auto-generated method stub
super.callback(url, object, status);
imgView.clearAnimation();

Log.e(TAG," image loading success _____ / height : "+object.getHeight());



imgView.setImageBitmap(object);

imgView.invalidate();


}

});



* Proguard 사용할경우 
: proguard.cfg  추가코드 (* 반드시 삽입해야 컴파일이된다. )


################################################################################
# for AndroidQuery API

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

#keep all classes that might be used in XML layouts
-keep public class * extends android.view.View
-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.Fragment
#keep all public and protected methods that could be used by java reflection
-keepclassmembernames class * {
public protected <methods>;
}

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}


-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-dontwarn **CompatHoneycomb
-dontwarn org.htmlcleaner.*

-dontwarn oauth.signpost.**





* AQuery 활용 참조 url : 
http://helloworld.naver.com/helloworld/429368

댓글 없음:

댓글 쓰기