androidx.lifecycle.LifecycleObserver Java Examples
The following examples show how to use
androidx.lifecycle.LifecycleObserver.
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: AdapterLog.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #2
Source File: AdapterRule.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterRule(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(AdapterRule.this + " parent destroyed"); AdapterRule.this.parentFragment = null; } }); }
Example #3
Source File: AdapterIdentity.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #4
Source File: ActivityBilling.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: AdapterImage.java From FairEmail with GNU General Public License v3.0 | 6 votes |
AdapterImage(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(AdapterImage.this + " parent destroyed"); AdapterImage.this.parentFragment = null; } }); }
Example #6
Source File: ActivityBilling.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #7
Source File: AdapterAttachment.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #8
Source File: AdapterRuleMatch.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #9
Source File: AdapterOrder.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #10
Source File: AdapterOperation.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #11
Source File: AdapterAccount.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #12
Source File: AdapterContact.java From FairEmail with GNU General Public License v3.0 | 6 votes |
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 #13
Source File: AdapterFolder.java From FairEmail with GNU General Public License v3.0 | 5 votes |
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 #14
Source File: BasePresenter.java From MVPArms with Apache License 2.0 | 5 votes |
@Override public void onStart() { //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用 if (mRootView != null && mRootView instanceof LifecycleOwner) { ((LifecycleOwner) mRootView).getLifecycle().addObserver(this); if (mModel != null && mModel instanceof LifecycleObserver) { ((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel); } } if (useEventBus())//如果要使用 EventBus 请将此方法返回 true { EventBusManager.getInstance().register(this);//注册 EventBus } }
Example #15
Source File: LifecycleHelper.java From react-native-screens with MIT License | 5 votes |
private void registerViewWithLifecycleOwner(View view) { Fragment parent = findNearestScreenFragmentAncestor(view); if (parent != null && view instanceof LifecycleObserver) { Lifecycle lifecycle = parent.getLifecycle(); lifecycle.addObserver((LifecycleObserver) view); mViewToLifecycleMap.put(view, lifecycle); } }
Example #16
Source File: LifecycleHelper.java From react-native-screens with MIT License | 5 votes |
public <T extends View & LifecycleObserver> void register(T view) { // we need to wait until view is mounted in the hierarchy as this method is called only at the // moment of the view creation. In order to register lifecycle observer we need to find ancestor // of type Screen and this can only happen when the view is properly attached. We rely on Android's // onLayout callback being triggered when the view gets added to the hierarchy and only then we // attempt to locate lifecycle owner ancestor. view.addOnLayoutChangeListener(mRegisterOnLayoutChange); }
Example #17
Source File: ArcusApplication.java From arcusandroid with Apache License 2.0 | 5 votes |
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 #18
Source File: ActivityBase.java From FairEmail with GNU General Public License v3.0 | 5 votes |
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 #19
Source File: ViewModelMessages.java From FairEmail with GNU General Public License v3.0 | 5 votes |
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 #20
Source File: TwoStateOwner.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private void create() { // Initialize registry = new LifecycleRegistry(this); registry.addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_ANY) public void onAny() { Log.d("LifeCycle " + name + " state=" + registry.getCurrentState() + " " + registry); } }); setState(Lifecycle.State.CREATED); }
Example #21
Source File: TwoStateOwner.java From FairEmail with GNU General Public License v3.0 | 5 votes |
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 #22
Source File: FragmentDialogBase.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@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 #23
Source File: FragmentLifecycleActivity.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void observe(LifecycleOwner provider) { mObservedOwner = provider; provider.getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_ANY) public void anyEvent(@SuppressWarnings("unused") LifecycleOwner owner, Lifecycle.Event event) { mLoggedEvents.add(event); } }); }
Example #24
Source File: TestService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public TestService() { getLifecycle().addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_ANY) public void anyEvent(LifecycleOwner owner, Lifecycle.Event event) { Context context = (TestService) owner; Intent intent = new Intent(ACTION_LOG_EVENT); intent.putExtra(EXTRA_KEY_EVENT, event); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } }); }
Example #25
Source File: FlapAdapter.java From Flap with Apache License 2.0 | 4 votes |
/** * Attaches the component to lifecycle if need. * * @param component The component we are going to bind. */ private void attachLifecycleOwnerIfNeed(@NonNull final FlapComponent component) { if (lifecycleEnable && lifecycleOwner != null) { lifecycleOwner.getLifecycle().addObserver((LifecycleObserver) component); } }
Example #26
Source File: UpdatingUtil.java From BaldPhone with Apache License 2.0 | 4 votes |
public static void checkForUpdates(BaldActivity activity, boolean retAnswer) { if (!UpdatingUtil.isOnline(activity) && retAnswer) { BaldToast.from(activity) .setType(BaldToast.TYPE_ERROR) .setText(R.string.could_not_connect_to_server) .setLength(1) .show(); return; } final RequestQueue queue = Volley.newRequestQueue(activity); final Lifecycle lifecycle = activity.getLifecycle(); final LifecycleObserver observer = new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void releaseRequest() { queue.cancelAll(VOLLEY_TAG); lifecycle.removeObserver(this); } }; queue.add( new StringRequest( Request.Method.GET, MESSAGE_URL, response -> { try { final BaldUpdateObject baldUpdateObject = BaldUpdateObject.parseMessage(response); if (updatePending(baldUpdateObject)) { BDB.from(activity) .setTitle(R.string.pending_update) .setSubText(R.string.a_new_update_is_available) .addFlag(BDialog.FLAG_OK | BDialog.FLAG_CANCEL) .setPositiveButtonListener(params -> { activity.startActivity( new Intent(activity, UpdatesActivity.class) .putExtra(UpdatesActivity.EXTRA_BALD_UPDATE_OBJECT, baldUpdateObject)); return true; }) .setNegativeButtonListener(params -> { BPrefs.get(activity) .edit() .putLong(BPrefs.LAST_UPDATE_ASKED_VERSION_KEY, System.currentTimeMillis()) .apply(); return true; }) .show(); } else { if (retAnswer) BaldToast .from(activity) .setText(R.string.baldphone_is_up_to_date) .show(); } } catch (JSONException e) { if (retAnswer) { BaldToast.from(activity).setType(BaldToast.TYPE_ERROR).setText(R.string.update_message_is_corrupted).show(); BaldToast.from(activity).setType(BaldToast.TYPE_ERROR).setText(S.str(e.getMessage())).show(); } } lifecycle.removeObserver(observer); }, error -> { if (retAnswer) BaldToast.from(activity) .setLength(1) .setType(BaldToast.TYPE_ERROR) .setText(R.string.could_not_connect_to_server) .show(); lifecycle.removeObserver(observer); } ).setTag(VOLLEY_TAG)); lifecycle.addObserver(observer); }
Example #27
Source File: LifecycleHelper.java From react-native-screens with MIT License | 4 votes |
public <T extends View & LifecycleObserver> void unregister(T view) { Lifecycle lifecycle = mViewToLifecycleMap.get(view); if (lifecycle != null) { lifecycle.removeObserver(view); } }
Example #28
Source File: Flutter.java From CrazyDaily with Apache License 2.0 | 4 votes |
/** * Creates a {@link FlutterView} linked to the specified {@link Activity} and {@link Lifecycle}. * The optional initial route string will be made available to the Dart code (via * {@code window.defaultRouteName}) and may be used to determine which widget should be displayed * in the view. The default initialRoute is "/". * * @param activity an {@link Activity} * @param lifecycle a {@link Lifecycle} * @param initialRoute an initial route {@link String}, or null * @return a {@link FlutterView} */ @NonNull public static FlutterView createView(@NonNull final Activity activity, @NonNull final Lifecycle lifecycle, final String initialRoute) { FlutterMain.startInitialization(activity.getApplicationContext()); FlutterMain.ensureInitializationComplete(activity.getApplicationContext(), null); final FlutterNativeView nativeView = new FlutterNativeView(activity); final FlutterView flutterView = new FlutterView(activity, null, nativeView) { private final BasicMessageChannel<String> lifecycleMessages = new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE); @Override public void onFirstFrame() { super.onFirstFrame(); setAlpha(1.0f); } @Override public void onPostResume() { // Overriding default behavior to avoid dictating system UI via PlatformPlugin. lifecycleMessages.send("AppLifecycleState.resumed"); } }; if (initialRoute != null) { flutterView.setInitialRoute(initialRoute); } lifecycle.addObserver(new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) public void onCreate() { final FlutterRunArguments arguments = new FlutterRunArguments(); arguments.bundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext()); arguments.entrypoint = "main"; flutterView.runFromBundle(arguments); } @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onStart() { flutterView.onStart(); } @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) public void onResume() { flutterView.onPostResume(); } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) public void onPause() { flutterView.onPause(); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void onStop() { flutterView.onStop(); } @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void onDestroy() { flutterView.destroy(); } }); flutterView.setAlpha(0.0f); return flutterView; }