FairEmail/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java

65 lines
2.0 KiB
Java
Raw Normal View History

2018-12-27 12:31:02 +00:00
package eu.faircode.email;
2018-12-31 08:04:33 +00:00
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
2018-12-27 12:31:02 +00:00
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class ContentLoadingProgressBar extends ProgressBar {
2019-02-11 11:06:53 +00:00
private int visibility;
private static final int VISIBILITY_DELAY = 500; // milliseconds
2018-12-27 12:31:02 +00:00
public ContentLoadingProgressBar(@NonNull Context context) {
this(context, null);
}
public ContentLoadingProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs, 0);
}
@Override
public void setVisibility(int visibility) {
2019-02-11 11:06:53 +00:00
this.visibility = visibility;
2019-01-29 08:35:42 +00:00
if (false && BuildConfig.DEBUG) {
super.setVisibility(visibility);
return;
}
2018-12-27 12:31:02 +00:00
removeCallbacks(delayedShow);
if (visibility == VISIBLE) {
super.setVisibility(INVISIBLE);
2019-02-11 11:06:53 +00:00
postDelayed(delayedShow, VISIBILITY_DELAY);
2018-12-27 12:31:02 +00:00
} else
super.setVisibility(visibility);
}
private final Runnable delayedShow = new Runnable() {
@Override
public void run() {
2019-02-11 11:06:53 +00:00
if (visibility == VISIBLE)
ContentLoadingProgressBar.super.setVisibility(VISIBLE);
2018-12-27 12:31:02 +00:00
}
};
}