Android Open Source - webimageloader Progress Activity






From Project

Back to project page webimageloader.

License

The source code is released under:

Apache License

If you think the Android project webimageloader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.webimageloader.sample.progress;
//  ww w.  jav a2s  .co m
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.*;

import com.google.gson.JsonParser;
import com.webimageloader.ImageLoader;
import com.webimageloader.Request;
import com.webimageloader.ext.ImageHelper;
import com.webimageloader.ext.ImageLoaderApplication;
import com.webimageloader.sample.R;

import java.io.*;
import java.net.URL;

public class ProgressActivity extends Activity {
    private static final String TAG = "ProgressActivity";

    private static final String INSTAGRAM_URL = "https://api.instagram.com/v1/media/popular?client_id=f005c552182d434e8532e11c8af82f6e";

    private ImageLoader imageLoader;
    private ImageHelper imageHelper;

    private ImageView imageView;
    private ProgressBar progressBar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_progress);

        ImageLoader.Logger.logAll();

        imageLoader = ImageLoaderApplication.getLoader(this);

        imageHelper = new ImageHelper(this, imageLoader);
        imageHelper.setFadeIn(true);

        imageView = (ImageView) findViewById(R.id.image);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showImage();
            }
        });

        progressBar = (ProgressBar) findViewById(R.id.progress);
        progressBar.setMax(100);

        showImage();
    }

    private void showImage() {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected void onPreExecute() {
                imageView.setVisibility(View.INVISIBLE);
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setIndeterminate(true);
            }

            @Override
            protected String doInBackground(Void... params) {
                try {
                    Reader reader = new InputStreamReader(new URL(INSTAGRAM_URL).openStream(), "utf-8");
                    return new JsonParser().parse(reader).getAsJsonObject()
                            .getAsJsonArray("data")
                            .get(0).getAsJsonObject()
                            .getAsJsonObject("images")
                            .getAsJsonObject("standard_resolution")
                            .get("url").getAsString();
                } catch (IOException e) {
                    Log.e(TAG, "Failed to fetch images", e);

                    return null;
                }
            }

            @Override
            protected void onPostExecute(String url) {
                if (url == null) {
                    Toast.makeText(ProgressActivity.this, "Failed to fetch image url", Toast.LENGTH_SHORT).show();
                } else {
                    progressBar.setIndeterminate(false);
                    imageHelper.load(imageView, progressBar, new Request(url));
                }
            }
        }.execute();
    }
}




Java Source Code List

com.webimageloader.ConnectionFactory.java
com.webimageloader.ConnectionHandler.java
com.webimageloader.Constants.java
com.webimageloader.ImageLoaderImpl.java
com.webimageloader.ImageLoader.java
com.webimageloader.Request.java
com.webimageloader.content.ContentURLConnection.java
com.webimageloader.content.ContentURLStreamHandler.java
com.webimageloader.ext.ImageHelper.java
com.webimageloader.ext.ImageLoaderApplication.java
com.webimageloader.loader.BackgroundLoader.java
com.webimageloader.loader.DiskLoader.java
com.webimageloader.loader.LoaderManager.java
com.webimageloader.loader.LoaderRequest.java
com.webimageloader.loader.LoaderWork.java
com.webimageloader.loader.Loader.java
com.webimageloader.loader.MemoryCache.java
com.webimageloader.loader.MemoryLoader.java
com.webimageloader.loader.Metadata.java
com.webimageloader.loader.NetworkLoader.java
com.webimageloader.loader.PendingRequests.java
com.webimageloader.loader.SimpleBackgroundLoader.java
com.webimageloader.loader.TransformingLoader.java
com.webimageloader.sample.AsyncLoader.java
com.webimageloader.sample.ExampleApplication.java
com.webimageloader.sample.FastImageView.java
com.webimageloader.sample.MainActivity.java
com.webimageloader.sample.numbers.NumberDetailsActivity.java
com.webimageloader.sample.numbers.NumbersActivity.java
com.webimageloader.sample.patterns.PatternDetailsActivity.java
com.webimageloader.sample.patterns.PatternsActivity.java
com.webimageloader.sample.patterns.PatternsListFragment.java
com.webimageloader.sample.progress.ProgressActivity.java
com.webimageloader.transformation.ScaleTransformation.java
com.webimageloader.transformation.SimpleTransformation.java
com.webimageloader.transformation.Transformation.java
com.webimageloader.util.AbstractImageLoader.java
com.webimageloader.util.Android.java
com.webimageloader.util.BitmapUtils.java
com.webimageloader.util.FlushedInputStream.java
com.webimageloader.util.Hasher.java
com.webimageloader.util.HeaderParser.java
com.webimageloader.util.IOUtil.java
com.webimageloader.util.InputSupplier.java
com.webimageloader.util.ListenerFuture.java
com.webimageloader.util.LruCache.java
com.webimageloader.util.PriorityThreadFactory.java
com.webimageloader.util.WaitFuture.java