Search in sources :

Example 1 with ImageLoader

use of com.android.volley.toolbox.ImageLoader in project MVCHelper by LuckyJayce.

the class MyVolley method init.

public static void init(Context context) {
    mRequestQueue = Volley.newRequestQueue(context);
    int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    int cacheSize = 1024 * 1024 * memClass / 8;
    mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(cacheSize));
}
Also used : ActivityManager(android.app.ActivityManager) ImageLoader(com.android.volley.toolbox.ImageLoader)

Example 2 with ImageLoader

use of com.android.volley.toolbox.ImageLoader in project FastDev4Android by jiangqqlmj.

the class VolleyTestActivity method backLinearClick.

@Click({ R.id.top_bar_linear_back, R.id.btn_string, R.id.btn_json, R.id.btn_image_request, R.id.btn_image_loader, R.id.btn_image_network, R.id.btn_string_post, R.id.btn_loader_list, R.id.btn_gson, R.id.btn_fdv_get_params, R.id.btn_fdv_post_params })
public void backLinearClick(View view) {
    switch(view.getId()) {
        case R.id.top_bar_linear_back:
            this.finish();
            break;
        case R.id.btn_string:
            //获取字符串
            Log.d(TAG, "点击获取字符串...");
            new Fdv_StringRequest(VolleyTestActivity.this).get("http://www.baidu.com", new Fdv_CallBackListener<String>() {

                @Override
                public void onSuccessResponse(String response) {
                    tv_result.setVisibility(View.VISIBLE);
                    img_result.setVisibility(View.GONE);
                    img_result_network.setVisibility(View.GONE);
                    tv_result.setText(response.toString());
                }

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });
            break;
        case R.id.btn_json:
            //获取json
            Log.d(TAG, "点击获取json...");
            new Fdv_JsonObjectRequest(VolleyTestActivity.this).get("http://interface.zttmall.com/update/mallUpdate", new Fdv_CallBackListener<JSONObject>() {

                @Override
                public void onSuccessResponse(JSONObject response) {
                    Gson gson = new Gson();
                    tv_result.setVisibility(View.VISIBLE);
                    img_result.setVisibility(View.GONE);
                    img_result_network.setVisibility(View.GONE);
                    tv_result.setText(gson.fromJson(response.toString(), UpdateBean.class).toString());
                }

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });
            break;
        case R.id.btn_image_request:
            //获取图片
            //http:\/\/interface.zttmall.com\/Images\/upload\/image\/20150325\/20150325083110_0898.jpg
            Log.d(TAG, "点击获取图片...");
            ImageRequest imageRequest = new ImageRequest("http://interface.zttmall.com/Images/upload/image/20150325/20150325083110_0898.jpg", new Response.Listener<Bitmap>() {

                @Override
                public void onResponse(Bitmap response) {
                    tv_result.setVisibility(View.GONE);
                    img_result.setVisibility(View.VISIBLE);
                    img_result.setImageBitmap(response);
                    img_result_network.setVisibility(View.GONE);
                }
            }, 0, 0, ImageView.ScaleType.FIT_XY, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });
            requestQueue.add(imageRequest);
            break;
        case R.id.btn_image_loader:
            //使用imageloader进行获取图片
            ImageLoader imageLoader = new ImageLoader(requestQueue, new Fdv_ImageCache());
            tv_result.setVisibility(View.GONE);
            img_result.setVisibility(View.VISIBLE);
            img_result_network.setVisibility(View.GONE);
            ImageLoader.ImageListener listener = ImageLoader.getImageListener(img_result, R.drawable.ic_loading, R.drawable.ic_loading);
            imageLoader.get("http://interface.zttmall.com//Images//upload//image//20150328//20150328105404_2392.jpg", listener);
            break;
        case R.id.btn_image_network:
            //采用NetworkImageView imageview控件
            ImageLoader network_imageLoader = new ImageLoader(requestQueue, new Fdv_ImageCache());
            img_result.setVisibility(View.GONE);
            tv_result.setVisibility(View.GONE);
            img_result_network.setVisibility(View.VISIBLE);
            img_result_network.setImageUrl("http://interface.zttmall.com//Images//upload//image//20150325//20150325083214_8280.jpg", network_imageLoader);
            break;
        case R.id.btn_string_post:
            //修改Volley源代码,扩展StringRequest支持post参数设置
            final Map<String, String> params = new HashMap<String, String>();
            params.put("username", "张三");
            params.put("password", "12345");
            StringRequest post_stringRequest = new StringRequest(Request.Method.POST, "http://10.18.3.123:8080/SalesWebTest/TestVolleyPost", new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    tv_result.setVisibility(View.VISIBLE);
                    img_result.setVisibility(View.GONE);
                    img_result_network.setVisibility(View.GONE);
                    tv_result.setText(response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            }) {

                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    return params;
                }
            };
            requestQueue.add(post_stringRequest);
            break;
        case R.id.btn_loader_list:
            //进行使用ImageLoader加载图片列表
            openActivity(VolleyLoaderActivity_.class);
            break;
        case R.id.btn_gson:
            //使用扩展工具 GsonRequest进行请求
            GsonRequest<UpdateBean> gsonRequest = new GsonRequest<UpdateBean>("http://interface.zttmall.com/update/mallUpdate", new Response.Listener<UpdateBean>() {

                @Override
                public void onResponse(UpdateBean response) {
                    tv_result.setVisibility(View.VISIBLE);
                    img_result.setVisibility(View.GONE);
                    img_result_network.setVisibility(View.GONE);
                    tv_result.setText(response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            }, UpdateBean.class);
            requestQueue.add(gsonRequest);
            break;
        case R.id.btn_fdv_get_params:
            //get请求  传入请求参数
            Map<String, String> params_get = new HashMap<String, String>();
            params_get.put("username", "张三");
            params_get.put("password", "12345");
            new Fdv_StringRequest(this).get("http://10.18.3.123:8080/SalesWebTest/TestVolleyPost", new Fdv_CallBackListener<String>() {

                @Override
                public void onSuccessResponse(String response) {
                    tv_result.setVisibility(View.VISIBLE);
                    img_result.setVisibility(View.GONE);
                    img_result_network.setVisibility(View.GONE);
                    tv_result.setText(response.toString());
                }

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            }, params_get);
            break;
        case R.id.btn_fdv_post_params:
            //post请求  传入请求参数
            Map<String, String> params_post = new HashMap<String, String>();
            params_post.put("username", "张三");
            params_post.put("password", "12345");
            new Fdv_StringRequest(this).post("http://10.18.3.123:8080/SalesWebTest/TestVolleyPost", new Fdv_CallBackListener<String>() {

                @Override
                public void onSuccessResponse(String response) {
                    tv_result.setVisibility(View.VISIBLE);
                    img_result.setVisibility(View.GONE);
                    img_result_network.setVisibility(View.GONE);
                    tv_result.setText(response.toString());
                }

                @Override
                public void onErrorResponse(VolleyError error) {
                }
            }, params_post);
            break;
    }
}
Also used : GsonRequest(com.android.volley.toolbox.GsonRequest) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) Bitmap(android.graphics.Bitmap) ImageRequest(com.android.volley.toolbox.ImageRequest) Fdv_ImageCache(com.chinaztt.fdv.Fdv_ImageCache) UpdateBean(com.chinaztt.fda.entity.UpdateBean) Fdv_StringRequest(com.chinaztt.fdv.Fdv_StringRequest) VolleyError(com.android.volley.VolleyError) StringRequest(com.android.volley.toolbox.StringRequest) Fdv_StringRequest(com.chinaztt.fdv.Fdv_StringRequest) Fdv_JsonObjectRequest(com.chinaztt.fdv.Fdv_JsonObjectRequest) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) ImageLoader(com.android.volley.toolbox.ImageLoader) Click(org.androidannotations.annotations.Click)

Example 3 with ImageLoader

use of com.android.volley.toolbox.ImageLoader in project WordPress-Android by wordpress-mobile.

the class LegacyEditorFragment method loadWPImageSpanThumbnail.

private void loadWPImageSpanThumbnail(MediaFile mediaFile, String imageURL, ImageLoader imageLoader) {
    if (mediaFile == null || imageURL == null) {
        return;
    }
    final String mediaId = mediaFile.getMediaId();
    if (mediaId == null) {
        return;
    }
    final int maxThumbWidth = ImageUtils.getMaximumThumbnailWidthForEditor(getActivity());
    imageLoader.get(imageURL, new ImageLoader.ImageListener() {

        @Override
        public void onErrorResponse(VolleyError arg0) {
        }

        @Override
        public void onResponse(ImageLoader.ImageContainer container, boolean arg1) {
            Bitmap downloadedBitmap = container.getBitmap();
            if (downloadedBitmap == null) {
                // no bitmap downloaded from the server.
                return;
            }
            if (downloadedBitmap.getWidth() < MIN_THUMBNAIL_WIDTH) {
                // Picture is too small. Show the placeholder in this case.
                return;
            }
            Bitmap resizedBitmap;
            // resize the downloaded bitmap
            resizedBitmap = ImageUtils.getScaledBitmapAtLongestSide(downloadedBitmap, maxThumbWidth);
            if (resizedBitmap == null) {
                return;
            }
            final EditText editText = mContentEditText;
            Editable s = editText.getText();
            if (s == null) {
                return;
            }
            WPImageSpan[] spans = s.getSpans(0, s.length(), WPImageSpan.class);
            if (spans.length != 0 && getActivity() != null) {
                for (WPImageSpan is : spans) {
                    MediaFile mediaFile = is.getMediaFile();
                    if (mediaFile == null) {
                        continue;
                    }
                    if (mediaId.equals(mediaFile.getMediaId()) && !is.isNetworkImageLoaded()) {
                        // replace the existing span with a new one with the correct image, re-add
                        // it to the same position.
                        int spanStart = is.getStartPosition();
                        int spanEnd = is.getEndPosition();
                        WPEditImageSpan imageSpan = new WPEditImageSpan(getActivity(), resizedBitmap, is.getImageSource());
                        imageSpan.setMediaFile(is.getMediaFile());
                        imageSpan.setNetworkImageLoaded(true);
                        imageSpan.setPosition(spanStart, spanEnd);
                        s.removeSpan(is);
                        s.setSpan(imageSpan, spanStart, spanEnd + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        break;
                    }
                }
            }
        }
    }, 0, 0);
}
Also used : VolleyError(com.android.volley.VolleyError) WPEditText(org.wordpress.android.util.widgets.WPEditText) EditText(android.widget.EditText) MediaFile(org.wordpress.android.util.helpers.MediaFile) WPEditImageSpan(org.wordpress.android.editor.legacy.WPEditImageSpan) WPImageSpan(org.wordpress.android.util.helpers.WPImageSpan) Bitmap(android.graphics.Bitmap) Editable(android.text.Editable) ImageLoader(com.android.volley.toolbox.ImageLoader)

Example 4 with ImageLoader

use of com.android.volley.toolbox.ImageLoader in project Presentation by feelinglucky.

the class Huaban method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mInstance = Huaban.this;
    mGson = new Gson();
    mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(getApplicationContext()));
    mDatabaseHelper = new DatabaseHelper(getApplicationContext());
    mPresentationsManager = new PstManager(getApplicationContext());
}
Also used : BitmapLruCache(com.gracecode.android.presentation.cache.BitmapLruCache) DatabaseHelper(com.gracecode.android.presentation.helper.DatabaseHelper) PstManager(com.gracecode.android.presentation.util.PstManager) Gson(com.google.gson.Gson) ImageLoader(com.android.volley.toolbox.ImageLoader)

Example 5 with ImageLoader

use of com.android.volley.toolbox.ImageLoader in project FastDev4Android by jiangqqlmj.

the class VolleyLoaderActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestQueue = Volley.newRequestQueue(this);
    imageLoader = new ImageLoader(requestQueue, new Fdv_ImageCache());
}
Also used : ImageLoader(com.android.volley.toolbox.ImageLoader) Fdv_ImageCache(com.chinaztt.fdv.Fdv_ImageCache)

Aggregations

ImageLoader (com.android.volley.toolbox.ImageLoader)5 Bitmap (android.graphics.Bitmap)2 VolleyError (com.android.volley.VolleyError)2 Fdv_ImageCache (com.chinaztt.fdv.Fdv_ImageCache)2 Gson (com.google.gson.Gson)2 ActivityManager (android.app.ActivityManager)1 Editable (android.text.Editable)1 EditText (android.widget.EditText)1 Response (com.android.volley.Response)1 GsonRequest (com.android.volley.toolbox.GsonRequest)1 ImageRequest (com.android.volley.toolbox.ImageRequest)1 StringRequest (com.android.volley.toolbox.StringRequest)1 UpdateBean (com.chinaztt.fda.entity.UpdateBean)1 Fdv_JsonObjectRequest (com.chinaztt.fdv.Fdv_JsonObjectRequest)1 Fdv_StringRequest (com.chinaztt.fdv.Fdv_StringRequest)1 BitmapLruCache (com.gracecode.android.presentation.cache.BitmapLruCache)1 DatabaseHelper (com.gracecode.android.presentation.helper.DatabaseHelper)1 PstManager (com.gracecode.android.presentation.util.PstManager)1 HashMap (java.util.HashMap)1 Click (org.androidannotations.annotations.Click)1