androidx.lifecycle.OnLifecycleEvent Java Examples

The following examples show how to use androidx.lifecycle.OnLifecycleEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdapterOperation.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterOperation(Fragment parentFragment) {
    this.parentFragment = parentFragment;
    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(context);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterOperation.this + " parent destroyed");
            AdapterOperation.this.parentFragment = null;
        }
    });
}
 
Example #2
Source File: AdapterIdentity.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterIdentity(Fragment parentFragment) {
    this.parentFragment = parentFragment;
    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(context);

    this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterIdentity.this + " parent destroyed");
            AdapterIdentity.this.parentFragment = null;
        }
    });
}
 
Example #3
Source File: AdapterRuleMatch.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterRuleMatch(Context context, LifecycleOwner owner) {
    this.context = context;
    this.owner = owner;
    this.inflater = LayoutInflater.from(context);

    this.D = new SimpleDateFormat("E");
    this.DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterRuleMatch.this + " parent destroyed");
        }
    });
}
 
Example #4
Source File: AdapterContact.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterContact(Fragment parentFragment) {
    this.parentFragment = parentFragment;

    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(context);

    this.contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS);
    this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
    this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterContact.this + " parent destroyed");
            AdapterContact.this.parentFragment = null;
        }
    });
}
 
Example #5
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
void addBillingListener(final IBillingListener listener, LifecycleOwner owner) {
    Log.i("IAB adding billing listener=" + listener);
    listeners.add(listener);

    if (billingClient != null)
        if (billingClient.isReady()) {
            listener.onConnected();
            queryPurchases();
        } else
            listener.onDisconnected();

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.i("IAB removing billing listener=" + listener);
            listeners.remove(listener);
        }
    });
}
 
Example #6
Source File: AdapterOrder.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterOrder(Fragment parentFragment) {
    this.parentFragment = parentFragment;
    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(context);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterOrder.this + " parent destroyed");
            AdapterOrder.this.parentFragment = null;
        }
    });
}
 
Example #7
Source File: AdapterLog.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterLog(Fragment parentFragment) {
    this.parentFragment = parentFragment;
    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(parentFragment.getContext());

    this.TF = Helper.getTimeInstance(context);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterLog.this + " parent destroyed");
            AdapterLog.this.parentFragment = null;
        }
    });
}
 
Example #8
Source File: AdapterAttachment.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterAttachment(Fragment parentFragment, boolean readonly) {
    this.parentFragment = parentFragment;
    this.readonly = readonly;

    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(context);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    this.debug = prefs.getBoolean("debug", false);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterAttachment.this + " parent destroyed");
            AdapterAttachment.this.parentFragment = null;
        }
    });
}
 
Example #9
Source File: AdapterAccount.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
AdapterAccount(final Fragment parentFragment, boolean settings) {
    this.parentFragment = parentFragment;
    this.settings = settings;

    this.context = parentFragment.getContext();
    this.owner = parentFragment.getViewLifecycleOwner();
    this.inflater = LayoutInflater.from(context);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
    this.colorUnread = Helper.resolveColor(context, highlight_unread ? R.attr.colorUnreadHighlight : android.R.attr.textColorPrimary);
    this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);

    this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterAccount.this + " parent destroyed");
            AdapterAccount.this.parentFragment = null;
        }
    });
}
 
Example #10
Source File: ViewModelMessages.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
void setCallback(LifecycleOwner owner, BoundaryCallbackMessages.IBoundaryCallbackMessages callback) {
    if (boundary != null) {
        boundary.setCallback(callback);

        owner.getLifecycle().addObserver(new LifecycleObserver() {
            @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
            public void onDestroyed() {
                boundary.destroy();
            }
        });
    }
}
 
Example #11
Source File: CameraView.java    From Lassi-Android with MIT License 5 votes vote down vote up
/**
 * Destroys this instance, releasing immediately
 * the camera resource.
 */
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void destroy() {
    clearCameraListeners();
    clearFrameProcessors();
    mCameraController.destroy();
    if (mCameraPreview != null) mCameraPreview.onDestroy();
}
 
Example #12
Source File: ArcusApplication.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void setupLifecycleListener() {
    ProcessLifecycleOwner
            .get()
            .getLifecycle()
            .addObserver(new LifecycleObserver() {
                @OnLifecycleEvent(Lifecycle.Event.ON_START)
                public void onForeground() {
                    NetworkConnectionMonitor.getInstance().startListening(ArcusApplication.this);

                    // Go back to 30-second timeout
                    useNormalTimeoutDelay();

                    logger.debug("Application is resumed, cancelling connection close.");
                    handler.removeCallbacks(closeCorneaRunnable);
                }

                @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
                public void onBackground() {
                    logger.debug("Application is backgrounded, posting delayed connection close.");
                    handler.postDelayed(closeCorneaRunnable, DELAY_BEFORE_CLOSE_MS);
                    NetworkConnectionMonitor.getInstance().stopListening(ArcusApplication.this);
                }
            });
}
 
Example #13
Source File: DeferredLifecycleDelegate.java    From AndroidNavigation with MIT License 5 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onStateChange() {
    if (getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
        handler.removeCallbacks(executeTask);
        tasks.clear();
        getLifecycle().removeObserver(this);
    } else {
        considerExecute();
    }
}
 
Example #14
Source File: AdapterFolder.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
AdapterFolder(Context context, LifecycleOwner owner, long account, boolean primary, boolean show_compact, boolean show_hidden, boolean show_flagged, IFolderSelectedListener listener) {
    this.account = account;
    this.primary = primary;
    this.show_compact = show_compact;
    this.show_hidden = show_hidden;
    this.show_flagged = show_flagged;
    this.listener = listener;

    this.context = context;
    this.owner = owner;
    this.inflater = LayoutInflater.from(context);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean compact = prefs.getBoolean("compact", false);
    int zoom = prefs.getInt("view_zoom", compact ? 0 : 1);
    if (zoom == 0)
        zoom = 1;

    this.subscriptions = prefs.getBoolean("subscriptions", false);
    this.subscribed_only = prefs.getBoolean("subscribed_only", false) && subscriptions;

    this.dp12 = Helper.dp2pixels(context, 12);
    this.textSize = Helper.getTextSize(context, zoom);
    this.textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
    this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);

    boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
    this.colorUnread = Helper.resolveColor(context, highlight_unread ? R.attr.colorUnreadHighlight : android.R.attr.textColorPrimary);

    setHasStableIds(true);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d(AdapterFolder.this + " parent destroyed");
            AdapterFolder.this.parentFragment = null;
        }
    });
}
 
Example #15
Source File: ActivityBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
void addKeyPressedListener(final IKeyPressedListener listener, LifecycleOwner owner) {
    Log.d("Adding back listener=" + listener);
    keyPressedListeners.add(listener);

    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d("Removing back listener=" + listener);
            keyPressedListeners.remove(listener);
        }
    });
}
 
Example #16
Source File: FragmentDialogBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setTargetFragment(@Nullable Fragment fragment, int requestCode) {
    targetFragment = fragment;
    targetRequestCode = requestCode;
    Log.i("Set target " + this + " " + fragment + " request=" + requestCode);

    fragment.getViewLifecycleOwner().getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroy() {
            Log.i("Reset target " + FragmentDialogBase.this);
            targetFragment = null;
        }
    });
}
 
Example #17
Source File: TwoStateOwner.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
TwoStateOwner(LifecycleOwner owner, String aname) {
    this(aname);

    // Destroy when parent destroyed
    owner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void onDestroyed() {
            Log.d("LifeCycle " + name + " parent destroyed");
            destroy();
        }
    });
}
 
Example #18
Source File: ObserverNoAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_STOP)
public void doOnStop() {
}
 
Example #19
Source File: MutableLiveQueue.java    From mobius with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onAny(LifecycleOwner source, Lifecycle.Event event) {
  onLifecycleChanged(event);
}
 
Example #20
Source File: PPObserverWithAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_START)
protected void doOnStart() {
}
 
Example #21
Source File: SimpleAppLifecycleTestActivity.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onEvent(LifecycleOwner provider, Lifecycle.Event event) {
    sCollectedEvents.add(new Pair<>(mType, event));
    sLatch.countDown();
}
 
Example #22
Source File: PPObserverNoAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_START)
protected void doOnStart() {
}
 
Example #23
Source File: FlapComponent.java    From Flap with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onPause() {
}
 
Example #24
Source File: InterfaceOk2.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_STOP)
void onStop2(LifecycleOwner provider);
 
Example #25
Source File: InterfaceOk2.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_STOP)
public void onStop3(LifecycleOwner provider) {
}
 
Example #26
Source File: FlapComponent.java    From Flap with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
    if (context instanceof LifecycleOwner) {
        ((LifecycleOwner) context).getLifecycle().removeObserver(this);
    }
}
 
Example #27
Source File: InvalidInheritance1.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_STOP)
void foo() {
}
 
Example #28
Source File: InvalidInheritance1.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_START)
void foo() {
}
 
Example #29
Source File: Util.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
    if (this.owner != null && this.dialog != null)
        this.dialog.dismiss();
}
 
Example #30
Source File: InvalidMethodModifier.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(ON_STOP)
private void onStop() {
}