Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60cbc963 authored by Robert Snoeberger's avatar Robert Snoeberger
Browse files

Dispatch onVisibilityAggregated before drawing to canvas.

This makes TextClock visible in preview image.

Bug: 123704608
Test: Checked the preview image in the picker app.
Change-Id: I2886c880326c7fd191e89a75576b2ab10a65b63a
parent 71e50791
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;

import androidx.annotation.VisibleForTesting;

@@ -241,6 +242,7 @@ public final class ClockManager {
        // Draw clock view hierarchy to canvas.
        Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        dispatchVisibilityAggregated(clockView, true);
        clockView.measure(MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
        clockView.layout(0, 0, mWidth, mHeight);
@@ -250,6 +252,24 @@ public final class ClockManager {
        return bitmap;
    }

    private void dispatchVisibilityAggregated(View view, boolean isVisible) {
        // Similar to View.dispatchVisibilityAggregated implementation.
        final boolean thisVisible = view.getVisibility() == View.VISIBLE;
        if (thisVisible || !isVisible) {
            view.onVisibilityAggregated(isVisible);
        }

        if (view instanceof ViewGroup) {
            isVisible = thisVisible && isVisible;
            ViewGroup vg = (ViewGroup) view;
            int count = vg.getChildCount();

            for (int i = 0; i < count; i++) {
                dispatchVisibilityAggregated(vg.getChildAt(i), isVisible);
            }
        }
    }

    private void notifyClockChanged(ClockPlugin plugin) {
        for (int i = 0; i < mListeners.size(); i++) {
            // It probably doesn't make sense to supply the same plugin instances to multiple