Search in sources :

Example 1 with LifecycleOwner

use of androidx.lifecycle.LifecycleOwner in project Signal-Android by WhisperSystems.

the class TextureViewRenderer method init.

public void init(@NonNull EglBase.Context sharedContext, @Nullable RendererCommon.RendererEvents rendererEvents, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
    ThreadUtils.checkIsOnMainThread();
    this.rendererEvents = rendererEvents;
    this.rotatedFrameWidth = 0;
    this.rotatedFrameHeight = 0;
    this.eglRenderer.init(sharedContext, this, configAttributes, drawer);
    this.lifecycle = ViewUtil.getActivityLifecycle(this);
    if (lifecycle != null) {
        lifecycle.addObserver(new DefaultLifecycleObserver() {

            @Override
            public void onDestroy(@NonNull LifecycleOwner owner) {
                release();
            }
        });
    }
}
Also used : DefaultLifecycleObserver(androidx.lifecycle.DefaultLifecycleObserver) LifecycleOwner(androidx.lifecycle.LifecycleOwner)

Example 2 with LifecycleOwner

use of androidx.lifecycle.LifecycleOwner in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DisabledSubscriptionControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    LifecycleOwner lifecycleOwner = () -> mLifecycle;
    mLifecycle = new Lifecycle(lifecycleOwner);
    doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
    mCategory = new PreferenceCategory(mContext);
    doReturn(mCategory).when(mScreen).findPreference(KEY);
    mController = new DisabledSubscriptionController(mContext, KEY);
    mController.init(mLifecycle, SUB_ID);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) LifecycleOwner(androidx.lifecycle.LifecycleOwner) Before(org.junit.Before)

Example 3 with LifecycleOwner

use of androidx.lifecycle.LifecycleOwner in project Signal-Android by signalapp.

the class TextureViewRenderer method init.

public void init(@NonNull EglBase.Context sharedContext, @Nullable RendererCommon.RendererEvents rendererEvents, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
    ThreadUtils.checkIsOnMainThread();
    this.rendererEvents = rendererEvents;
    this.rotatedFrameWidth = 0;
    this.rotatedFrameHeight = 0;
    this.eglRenderer.init(sharedContext, this, configAttributes, drawer);
    this.lifecycle = ViewUtil.getActivityLifecycle(this);
    if (lifecycle != null) {
        lifecycle.addObserver(new DefaultLifecycleObserver() {

            @Override
            public void onDestroy(@NonNull LifecycleOwner owner) {
                release();
            }
        });
    }
}
Also used : DefaultLifecycleObserver(androidx.lifecycle.DefaultLifecycleObserver) LifecycleOwner(androidx.lifecycle.LifecycleOwner)

Example 4 with LifecycleOwner

use of androidx.lifecycle.LifecycleOwner in project Signal-Android by WhisperSystems.

the class AppForegroundObserver method begin.

@MainThread
public void begin() {
    ThreadUtil.assertMainThread();
    ProcessLifecycleOwner.get().getLifecycle().addObserver(new DefaultLifecycleObserver() {

        @Override
        public void onStart(@NonNull LifecycleOwner owner) {
            onForeground();
        }

        @Override
        public void onStop(@NonNull LifecycleOwner owner) {
            onBackground();
        }
    });
}
Also used : DefaultLifecycleObserver(androidx.lifecycle.DefaultLifecycleObserver) LifecycleOwner(androidx.lifecycle.LifecycleOwner) ProcessLifecycleOwner(androidx.lifecycle.ProcessLifecycleOwner) MainThread(androidx.annotation.MainThread)

Example 5 with LifecycleOwner

use of androidx.lifecycle.LifecycleOwner in project twicalico by moko256.

the class UserInfoFragment method setShowUserInfo.

private void setShowUserInfo(User user) {
    if (user.getId() == client.getAccessToken().getUserId()) {
        userIsYouOrFollowedYou.setVisibility(View.VISIBLE);
        userIsYouOrFollowedYou.setText(R.string.you);
    }
    MediaUrlConverter mediaUrlConverter = client.getMediaUrlConverter();
    String headerUrl = mediaUrlConverter.convertProfileBannerLargeUrl(user);
    if (headerUrl != null) {
        glideRequests.load(headerUrl).transition(DrawableTransitionOptions.withCrossFade()).into(header);
        header.setOnClickListener(v -> startActivity(ShowMediasActivity.Companion.getIntent(v.getContext(), new Media[] { new Media(null, headerUrl, null, Media.MediaType.PICTURE.getValue()) }, CLIENT_TYPE_NOTHING, 0)));
    }
    glideRequests.load(mediaUrlConverter.convertProfileIconUriBySize(user, DpToPxKt.dpToPx(this, 68))).circleCrop().transition(DrawableTransitionOptions.withCrossFade()).into(icon);
    icon.setOnClickListener(v -> startActivity(ShowMediasActivity.Companion.getIntent(v.getContext(), new Media[] { new Media(null, mediaUrlConverter.convertProfileIconOriginalUrl(user), null, Media.MediaType.PICTURE.getValue()) }, CLIENT_TYPE_NOTHING, 0)));
    CharSequence userName = TwitterStringUtils.plusUserMarks(user.getName(), userNameText, user.isProtected(), user.isVerified());
    CharSequence userBio = TwitterStringUtils.getLinkedSequence(client.getAccessToken(), user.getDescription(), user.getDescriptionLinks());
    userNameText.setText(userName);
    userBioText.setText(userBio);
    Emoji[] userNameEmojis = user.getEmojis();
    if (userNameEmojis != null) {
        EmojiToTextViewSetter nameSetter = new EmojiToTextViewSetter(glideRequests, userNameText, userName, userNameEmojis);
        EmojiToTextViewSetter bioSetter = new EmojiToTextViewSetter(glideRequests, userBioText, userBio, userNameEmojis);
        getLifecycle().addObserver(new LifecycleEventObserver() {

            @Override
            public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
                if (event == Lifecycle.Event.ON_DESTROY) {
                    nameSetter.dispose();
                    bioSetter.dispose();
                    getLifecycle().removeObserver(this);
                }
            }
        });
    }
    userIdText.setText(TwitterStringUtils.plusAtMark(user.getScreenName()));
    if (!TextUtils.isEmpty(user.getLocation())) {
        userLocation.setText(getString(R.string.location_is, user.getLocation()));
    } else {
        userLocation.setVisibility(View.GONE);
    }
    final String url = user.getUrl();
    if (!TextUtils.isEmpty(url)) {
        String text = getString(R.string.url_is, url);
        SpannableString spannableString = new SpannableString(text);
        int start = text.indexOf(url);
        spannableString.setSpan(new ClickableNoLineSpan() {

            @Override
            public void onClick(@NonNull View widget) {
                AppCustomTabsKt.launchChromeCustomTabs(widget.getContext(), url, false);
            }
        }, start, start + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        userUrl.setText(spannableString);
        userUrl.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        userUrl.setVisibility(View.GONE);
    }
    userCreatedAt.setText(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL).format(user.getCreatedAt()));
    userCounts.setText(getString(R.string.user_counts_is, user.getStatusesCount(), user.getFriendsCount(), user.getFollowersCount()));
}
Also used : EmojiToTextViewSetter(com.github.moko256.twitlatte.view.EmojiToTextViewSetter) Lifecycle(androidx.lifecycle.Lifecycle) Media(com.github.moko256.latte.client.base.entity.Media) MediaUrlConverter(com.github.moko256.latte.client.base.MediaUrlConverter) ClickableNoLineSpan(com.github.moko256.twitlatte.text.style.ClickableNoLineSpan) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) UserHeaderImageView(com.github.moko256.twitlatte.widget.UserHeaderImageView) SpannableString(android.text.SpannableString) LifecycleEventObserver(androidx.lifecycle.LifecycleEventObserver) Emoji(com.github.moko256.latte.client.base.entity.Emoji) LifecycleOwner(androidx.lifecycle.LifecycleOwner)

Aggregations

LifecycleOwner (androidx.lifecycle.LifecycleOwner)6 DefaultLifecycleObserver (androidx.lifecycle.DefaultLifecycleObserver)4 MainThread (androidx.annotation.MainThread)2 ProcessLifecycleOwner (androidx.lifecycle.ProcessLifecycleOwner)2 SpannableString (android.text.SpannableString)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Lifecycle (androidx.lifecycle.Lifecycle)1 LifecycleEventObserver (androidx.lifecycle.LifecycleEventObserver)1 PreferenceCategory (androidx.preference.PreferenceCategory)1 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)1 MediaUrlConverter (com.github.moko256.latte.client.base.MediaUrlConverter)1 Emoji (com.github.moko256.latte.client.base.entity.Emoji)1 Media (com.github.moko256.latte.client.base.entity.Media)1 ClickableNoLineSpan (com.github.moko256.twitlatte.text.style.ClickableNoLineSpan)1 EmojiToTextViewSetter (com.github.moko256.twitlatte.view.EmojiToTextViewSetter)1 UserHeaderImageView (com.github.moko256.twitlatte.widget.UserHeaderImageView)1 Before (org.junit.Before)1