/*
* Copyright 2013 Peng fei Pan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package me.xiaopan.android.examples.adapter;
import me.xiaoapn.easy.imageloader.ImageLoader;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
@SuppressWarnings("deprecation")
public class GalleryAdapter extends BaseAdapter{
private Context context;
private String[] urls;
public GalleryAdapter (Context context, String[] urls){
this.context = context;
this.urls = urls;
}
@Override
public int getCount() {
return urls.length;
}
@Override
public Object getItem(int position) {
return urls[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if(convertView == null){
viewHolder = new ViewHolder();
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT));
imageView.setScaleType(ScaleType.FIT_CENTER);
viewHolder.imageView = imageView;
convertView = imageView;
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
ImageLoader.getInstance().load(urls[position], viewHolder.imageView);
return convertView;
}
private class ViewHolder{
public ImageView imageView;
}
}