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

58 lines
1.7 KiB
Java
Raw Normal View History

2019-05-03 16:59:27 +00:00
package eu.faircode.email;
2019-05-04 20:49:22 +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)
*/
2019-05-03 16:59:27 +00:00
import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;
public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver {
private LifecycleOwner owner;
public PopupMenuLifecycle(@NonNull Context context, LifecycleOwner owner, @NonNull View anchor) {
super(context, anchor);
this.owner = owner;
2019-09-20 06:39:31 +00:00
Log.i("Instantiate " + this);
2019-05-03 16:59:27 +00:00
}
@Override
public void show() {
2019-09-20 06:39:31 +00:00
Log.i("Show " + this);
2019-08-04 18:00:20 +00:00
try {
super.show();
} catch (Throwable ex) {
Log.e(ex);
}
2019-05-03 16:59:27 +00:00
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
2019-09-20 06:39:31 +00:00
Log.i("Destroy " + this);
2019-05-03 16:59:27 +00:00
this.dismiss();
owner = null;
}
}