app/src/main/java/me/zhanghai/android/douya/util/TransitionUtils.java

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/*
 * Copyright (c) 2015 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
 * All Rights Reserved.
 */

package me.zhanghai.android.douya.util;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.util.Pair;
import android.transition.Explode;
import android.transition.Transition;
import android.view.View;
import android.view.Window;

import java.util.ArrayList;

import me.zhanghai.android.douya.R;

/**
 * Facts:
 * - System window must be shared elements if fullscreen, otherwise overlap occurs.
 * - Shared element transition overlaps old and new elements for a period of time.
 * - Translucent element overlap is unacceptable.
 */
public class TransitionUtils {

    private static final String TRANSITION_NAME_APPBAR = "appbar";

    private TransitionUtils() {}

    public static boolean shouldEnableTransition() {
        // I hprof-ed the app, and found that bitmaps are kept by
        // ExitTransitionCoordinator.mSharedElementsBundle, which is in turn kept by
        // ResultReceiver$MyResultReceiver, which is kept by a FinalizerReference.
        // But this fix (
        // https://android.googlesource.com/platform/frameworks/base/+/a0a0260e48e1ee4e9b5d98b49571e8d2a6fd6c3a
        // ) should have been incorporated into android-5.0.0_r1. So I really don't know the root
        // cause now.
        // New finding at 2015-12-06: OOM even happens on Android 5.1 (CM).
        // TODO: Allow disabling transition on some pre-marshmallow devices for OOM.
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void setupTransitionBeforeDecorate(Activity activity) {

        if (!shouldEnableTransition()) {
            return;
        }

        Window window = activity.getWindow();
        window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        window.setSharedElementsUseOverlay(false);
    }
后面还有 136 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。