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();
|
||||
}
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
// mDrawable = null;
|
||||
if (!mQuickMode) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setProgress(0);
|
||||
mProgressBar.spin();
|
||||
// mProgressBar.setMax(100);
|
||||
}
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -127,6 +131,14 @@ 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
|
||||
*/
|
||||
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user