2020-03-24 10:18:18 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
|
2021-01-01 07:56:36 +00:00
|
|
|
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
2020-03-24 10:18:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
|
|
|
|
|
|
public class ViewTextDelayed extends AppCompatTextView {
|
2020-08-29 16:40:29 +00:00
|
|
|
private int visibility = VISIBLE;
|
2021-03-13 07:15:33 +00:00
|
|
|
private boolean delaying = false;
|
2020-03-24 10:18:18 +00:00
|
|
|
|
2021-03-13 07:15:33 +00:00
|
|
|
private static final int VISIBILITY_DELAY = 1500; // milliseconds
|
2020-03-24 10:18:18 +00:00
|
|
|
|
|
|
|
public ViewTextDelayed(@NonNull Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ViewTextDelayed(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ViewTextDelayed(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
|
|
|
this.visibility = visibility;
|
|
|
|
|
2021-03-13 07:15:33 +00:00
|
|
|
if (visibility == VISIBLE) {
|
|
|
|
if (delaying)
|
|
|
|
return;
|
|
|
|
delaying = true;
|
|
|
|
super.setVisibility(INVISIBLE);
|
2020-08-29 16:40:29 +00:00
|
|
|
ApplicationEx.getMainHandler().postDelayed(delayedShow, VISIBILITY_DELAY);
|
2021-03-13 07:15:33 +00:00
|
|
|
} else {
|
|
|
|
ApplicationEx.getMainHandler().removeCallbacks(delayedShow);
|
|
|
|
delaying = false;
|
2020-03-24 10:18:18 +00:00
|
|
|
super.setVisibility(visibility);
|
2021-03-13 07:15:33 +00:00
|
|
|
}
|
2020-03-24 10:18:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 22:08:03 +00:00
|
|
|
@Override
|
|
|
|
public int getVisibility() {
|
|
|
|
return this.visibility;
|
|
|
|
}
|
|
|
|
|
2020-03-24 10:18:18 +00:00
|
|
|
private final Runnable delayedShow = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2021-03-13 07:15:33 +00:00
|
|
|
delaying = false;
|
2020-03-24 10:18:18 +00:00
|
|
|
if (visibility == VISIBLE)
|
|
|
|
ViewTextDelayed.super.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|