Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created AsyncImageSwitcher #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 66 additions & 0 deletions GreenDroid/src/greendroid/widget/AsyncImageSwitcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package greendroid.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageSwitcher;

/**
* <p>
* Combines the animations of ImageSwitcher with the asynchronous loading of
* {@link AsyncImageView}. Expects to have a <code>ViewSwitcher.ViewFactory</code>
* which returns an {@link AsyncImageView} from it's {@code makeView} function:
* </p>
* <p>
* <code>
* public View makeView() {<br/>
&nbsp;&nbsp;&nbsp;&nbsp; AsyncImageView asyncImage = new AsyncImageView(mContext);<br/>
&nbsp;&nbsp;&nbsp;&nbsp; asyncImage.setBackgroundColor(0xFF000000);<br/>
&nbsp;&nbsp;&nbsp;&nbsp; asyncImage.setScaleType(ImageView.ScaleType.CENTER_CROP);<br/>
&nbsp;&nbsp;&nbsp;&nbsp; asyncImage.setLayoutParams(new ImageSwitcher.LayoutParams(300,250));<br/>
&nbsp;&nbsp;&nbsp;&nbsp; return asyncImage;<br/>
}<br/>
* </code>
* </p>
*
*
* <p>
* When registered as as an
* <code>AdapterView.OnItemSelectedListener, the client can conveniently
* use {@link #setNextAsyncImageViewUrl(String)} to change the URL of the next {@link AsyncImageView}
* that will be displayed:
* </p>
*
* <p>
* <code>
* public void onItemSelected(AdapterView parent, View v, int position, long id) {<br/>
* &nbsp;&nbsp;&nbsp;&nbsp; mAsyncImageSwitcher.setNextAsyncImageViewUrl(imageUrls[position]);<br/>
* &nbsp;&nbsp;&nbsp;&nbsp; mAsyncImageSwitcher.showNext();<br/>
* }<br/>
* </code>
* </p>
*
*
*/
public class AsyncImageSwitcher extends ImageSwitcher {

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

}

public AsyncImageSwitcher(Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* Sets the URL of the next {@link AsyncImageView}
*
* @param url
* The url of the image to set.
*/
public void setNextAsyncImageViewUrl(String url) {
AsyncImageView image = (AsyncImageView) this.getNextView();
image.setUrl(url);
}

}