Open adrissacf opened 9 years ago
Edited the BaseSliderView class in the library project to the following, and then you can just use a bitmap like
DefaultSliderView defaultSliderView = new DefaultSliderView(getBaseContext()); defaultSliderView.image(bmp); sliderShow.addSlider(defaultSliderView);
Updated BaseSliderView class:
package com.daimajia.slider.library.SliderTypes;
import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.widget.ImageView;
import com.daimajia.slider.library.R; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import com.squareup.picasso.RequestCreator;
import java.io.File;
/**
if you want to show progressbar, you just need to set a progressbar id as @+id/loading_bar. */ public abstract class BaseSliderView {
protected Context mContext;
private Bundle mBundle;
/**
/**
private String mUrl; private File mFile; private int mRes; private Bitmap mBitmap;
protected OnSliderClickListener mOnSliderClickListener;
private boolean mErrorDisappear;
private ImageLoadListener mLoadListener;
private String mDescription;
/**
public enum ScaleType{ CenterCrop, CenterInside, Fit, FitCenterCrop }
protected BaseSliderView(Context context) { mContext = context; this.mBundle = new Bundle(); }
/**
/**
/**
/**
/**
/**
public BaseSliderView image(int res){ if(mUrl != null || mFile != null || mBitmap != null){ throw new IllegalStateException("Call multi image function," + "you only have permission to call it once"); } mRes = res; return this; }
public BaseSliderView image(Bitmap bitmap){ if(mUrl != null || mFile != null || mBitmap != null){ throw new IllegalStateException("Call multi image function," + "you only have permission to call it once"); } mBitmap = bitmap; return this; }
public String getUrl(){ return mUrl; }
public boolean isErrorDisappear(){ return mErrorDisappear; }
public int getEmpty(){ return mEmptyPlaceHolderRes; }
public int getError(){ return mErrorPlaceHolderRes; }
public String getDescription(){ return mDescription; }
public Context getContext(){ return mContext; }
/**
/**
getView()
methodv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(mOnSliderClickListener != null){ mOnSliderClickListener.onSliderClick(me); } } });
mLoadListener.onStart(me);
Picasso p = Picasso.with(mContext); RequestCreator rq = null; if(mUrl!=null){ rq = p.load(mUrl); }else if(mFile != null){ rq = p.load(mFile); }else if(mBitmap != null){ targetImageView.setImageBitmap(mBitmap); if(v.findViewById(R.id.loading_bar) != null){ v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE); } }else if(mRes != 0){ rq = p.load(mRes); }else{ return; }
if(rq == null){ return; }
if(getEmpty() != 0){ rq.placeholder(getEmpty()); }
if(getError() != 0){ rq.error(getError()); }
switch (mScaleType){ case Fit: rq.fit(); break; case CenterCrop: rq.fit().centerCrop(); break; case CenterInside: rq.fit().centerInside(); break; }
rq.into(targetImageView,new Callback() { @Override public void onSuccess() { if(v.findViewById(R.id.loading_bar) != null){ v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE); } }
@Override
public void onError() {
if(mLoadListener != null){
mLoadListener.onEnd(false,me);
}
}
}); }
public BaseSliderView setScaleType(ScaleType type){ mScaleType = type; return this; }
public ScaleType getScaleType(){ return mScaleType; }
/**
/**
public interface OnSliderClickListener { public void onSliderClick(BaseSliderView slider); }
/**
public interface ImageLoadListener{ public void onStart(BaseSliderView target); public void onEnd(boolean result,BaseSliderView target); }
}
same question for me can you use it?
Can you fork this repository and make the improvement please?
Solution above worked!
I've had this:
"Cannot resolve method 'bundle(android.io.Bundle)"
Just need to add bundle method:
public BaseSliderView bundle(Bundle bundle){ mBundle = bundle; return this; }
This is a useful solution. Thank you.
Is it possible to use a bitmap as the source, since i download my images from a database and get them as a byte array which i decode to a bitmap.