Add quickmode which disable progress and quickly download image

This commit is contained in:
Victor 2014-06-15 23:57:42 +03:00
parent e350a6ef58
commit be08546b49
2 changed files with 24 additions and 9 deletions

View File

@ -95,10 +95,13 @@ public class WebcamViewerFragment extends Fragment {
update();
}
};
if (autoUpdate) timer.schedule(task, 500, 100);
else {
if (autoUpdate) {
timer.schedule(task, 500, 100);
contentImage.setQuickMode(true);
} else {
timer.cancel();
timer = new Timer();
contentImage.setQuickMode(false);
}
}

View File

@ -35,6 +35,7 @@ public final class LoaderImageView extends FrameLayout {
private Drawable mDrawable;
private ProgressWheel mProgressBar;
private ImageView mImage;
private boolean mQuickMode;
/**
* This is used when creating the view in XML
@ -80,6 +81,8 @@ public final class LoaderImageView extends FrameLayout {
* get the required effects you want
*/
private void instantiate(final String imageUrl) {
mQuickMode = false;
mImage = new ImageView(getContext());
mImage.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
@ -103,11 +106,12 @@ public final class LoaderImageView extends FrameLayout {
* @param imageUrl the url of the image you wish to load
*/
public void setImageDrawable(final String imageUrl) {
mDrawable = null;
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.setProgress(0);
mProgressBar.spin();
// mProgressBar.setMax(100);
// mDrawable = null;
if (!mQuickMode) {
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.setProgress(0);
mProgressBar.spin();
}
new Thread() {
@Override
public void run() {
@ -127,7 +131,15 @@ public final class LoaderImageView extends FrameLayout {
return mImage.getDrawable();
}
/**
public boolean isQuickMode() {
return mQuickMode;
}
public void setQuickMode(boolean quickMode) {
this.mQuickMode = quickMode;
}
/**
* Callback that is received once the image has been downloaded
*/
private final Handler imageLoadedHandler = new Handler(new Callback() {
@ -164,7 +176,7 @@ public final class LoaderImageView extends FrameLayout {
conection.connect();
// this will be useful so that you can show a typical 0-100% progress bar
int lenghtOfFile = conection.getContentLength();
if (lenghtOfFile <= 0) {
if (lenghtOfFile <= 0 || mQuickMode) {
// try to load by system call
return Drawable.createFromStream((InputStream) url.getContent(), "name");
}