Android Open Source - AndroidImageManager Sample Image Manager Activity






From Project

Back to project page AndroidImageManager.

License

The source code is released under:

Apache License

If you think the Android project AndroidImageManager 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.marczych.androidimagemanager.sample;
/* w  ww.j a v a 2  s  . c  o m*/
import java.util.ArrayList;

import com.marczych.androidimagemanager.ImageManager;

import android.app.Activity;
import android.app.ListActivity;

import android.content.Context;

import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SampleImageManagerActivity extends ListActivity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setListAdapter(new SampleListAdapter(this,
       ((SampleApplication)getApplication()).getImageManager()));
   }

   private class SampleListAdapter extends BaseAdapter {
      private static final String BASE_IMAGE_URL = 
       "http://goodmorningkitten.com/media/kittypix/1/kitten15";

      protected Activity mActivity;
      protected ImageManager mImageManager;
      protected ArrayList<String> mImageUrls;

      public SampleListAdapter(Activity activity, ImageManager imageManager) {
         mImageManager = imageManager;
         mActivity = activity;
         initImageUrls();
      }

      public int getCount() {
         return mImageUrls.size();
      }

      public Object getItem(int position) {
         return mImageUrls.get(position);
      }

      public long getItemId(int position) {
         return position;
      }

      public View getView(int position, View convertView, ViewGroup parent) {
         ListImage listImage = (ListImage)convertView;

         if (listImage == null) {
            listImage = new ListImage(mActivity);
         }

         mImageManager.displayImage(mImageUrls.get(position), mActivity,
          listImage.mImageView);
         listImage.mText.setText(mImageUrls.get(position));

         return listImage;
      }

      private void initImageUrls() {
         String url;
         mImageUrls = new ArrayList<String>();

         for (int i = 10; i < 25; i ++) {
            if (i == 15) {
               url = "jkdfj;kwjekf"; // Oops.
            } else {
               url = BASE_IMAGE_URL + i + ".jpg";
            }

            mImageUrls.add(url);
         }
      }
   }

   public class ListImage extends LinearLayout {
      public ImageView mImageView;
      public TextView mText;

      public ListImage(Context context) {
         super(context);

         LayoutInflater inflater = (LayoutInflater)context.
          getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         inflater.inflate(R.layout.list_image, this, true);

         mImageView = (ImageView)findViewById(R.id.list_image);
         mText = (TextView)findViewById(R.id.list_text);
      }
   }
}




Java Source Code List

com.marczych.androidimagemanager.ImageManager.java
com.marczych.androidimagemanager.sample.SampleApplication.java
com.marczych.androidimagemanager.sample.SampleImageManagerActivity.java