Add quickmode which disable progress and quickly download image
This commit is contained in:
parent
e350a6ef58
commit
be08546b49
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
mProgressBar.setVisibility(View.VISIBLE);
|
if (!mQuickMode) {
|
||||||
mProgressBar.setProgress(0);
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
mProgressBar.spin();
|
mProgressBar.setProgress(0);
|
||||||
// mProgressBar.setMax(100);
|
mProgressBar.spin();
|
||||||
|
}
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -127,7 +131,15 @@ 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
|
||||||
*/
|
*/
|
||||||
private final Handler imageLoadedHandler = new Handler(new Callback() {
|
private final Handler imageLoadedHandler = new Handler(new Callback() {
|
||||||
@ -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");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user