Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daimajia committed Jul 11, 2014
1 parent 8eaaeea commit 6858e4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/**
* When you want to make your own slider view, you must extends from this class.
* BaseSliderView provides some useful methods. Such loadImage, setImage,and so on.
* BaseSliderView provides some useful methods.
* I provide two example: {@link com.daimajia.slider.library.SliderTypes.DefaultSliderView} and
* {@link com.daimajia.slider.library.SliderTypes.TextSliderView}
* if you want to show progressbar, you just need to set a progressbar id as @+id/loading_bar.
Expand Down Expand Up @@ -173,12 +173,22 @@ public BaseSliderView setOnSliderClickListener(OnSliderClickListener l){
}

/**
* when you want to extends this class, please use this method to load a image to a imageview.
* @param targetImageView
* When you want to implement your own slider view, please call this method in the end in `getView()` method
* @param v the whole view
* @param targetImageView where to place image
*/
protected void loadImage(ImageView targetImageView){
protected void bindEventAndShow(final View v, ImageView targetImageView){
final BaseSliderView me = this;

v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mOnSliderClickListener != null){
mOnSliderClickListener.onSliderClick(me);
}
}
});

mLoadListener.onStart(me);

Picasso p = Picasso.with(mContext);
Expand Down Expand Up @@ -220,8 +230,9 @@ protected void loadImage(ImageView targetImageView){
rq.into(targetImageView,new Callback() {
@Override
public void onSuccess() {
if(progressBar !=null)
progressBar.setVisibility(View.INVISIBLE);
if(v.findViewById(R.id.loading_bar) != null){
v.findViewById(R.id.loading_bar).setVisibility(View.INVISIBLE);
}
}

@Override
Expand All @@ -244,24 +255,6 @@ public ScaleType getScaleType(){
return mScaleType;
}

private View progressBar = null;
/**
* when you want to extends this class, you must call this method to bind click event to your view.
* @param v
*/
protected void bindClickEvent(View v){
final BaseSliderView me = this;
progressBar = v.findViewById(R.id.loading_bar);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mOnSliderClickListener != null){
mOnSliderClickListener.onSliderClick(me);
}
}
});
}

/**
* the extended class have to implement getView(), which is called by the adapter,
* every extended class response to render their own view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public DefaultSliderView(Context context) {
public View getView() {
View v = LayoutInflater.from(getContext()).inflate(R.layout.render_type_default,null);
ImageView target = (ImageView)v.findViewById(R.id.daimajia_slider_image);

loadImage(target);
bindClickEvent(v);

bindEventAndShow(v, target);
return v;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public View getView() {
ImageView target = (ImageView)v.findViewById(R.id.daimajia_slider_image);
TextView description = (TextView)v.findViewById(R.id.description);
description.setText(getDescription());
loadImage(target);
bindClickEvent(v);
bindEventAndShow(v, target);
return v;
}
}

0 comments on commit 6858e4b

Please sign in to comment.