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

55 lines
1.7 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 {
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) {
removeCallbacks(delayedShow);
if (visibility == VISIBLE) {
super.setVisibility(INVISIBLE);
postDelayed(delayedShow, 500);
} else
super.setVisibility(visibility);
}
private final Runnable delayedShow = new Runnable() {
@Override
public void run() {
ContentLoadingProgressBar.super.setVisibility(VISIBLE);
}
};
}