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(); update();
} }
}; };
if (autoUpdate) timer.schedule(task, 500, 100); if (autoUpdate) {
else { timer.schedule(task, 500, 100);
contentImage.setQuickMode(true);
} else {
timer.cancel(); timer.cancel();
timer = new Timer(); timer = new Timer();
contentImage.setQuickMode(false);
} }
} }

View File

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