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

Commit 18a1243a authored by Jacqueline Bronger's avatar Jacqueline Bronger Committed by Android (Google) Code Review
Browse files

Merge "Set privacy chip bounds in WindowInsets for tv."

parents d8a0e22e 9b360639
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -26,7 +26,7 @@


    <ImageView
    <ImageView
        android:id="@+id/chip_drawable"
        android:id="@+id/chip_drawable"
        android:layout_width="51dp"
        android:layout_width="@dimen/privacy_chip_max_width"
        android:layout_height="@dimen/privacy_chip_height"
        android:layout_height="@dimen/privacy_chip_height"
        android:minWidth="@dimen/privacy_chip_dot_bg_width"
        android:minWidth="@dimen/privacy_chip_dot_bg_width"
        android:minHeight="@dimen/privacy_chip_dot_bg_height"
        android:minHeight="@dimen/privacy_chip_dot_bg_height"
+1 −0
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@
    <dimen name="privacy_chip_icon_margin_in_between">9dp</dimen>
    <dimen name="privacy_chip_icon_margin_in_between">9dp</dimen>
    <dimen name="privacy_chip_padding_horizontal">9dp</dimen>
    <dimen name="privacy_chip_padding_horizontal">9dp</dimen>
    <dimen name="privacy_chip_icon_size">12dp</dimen>
    <dimen name="privacy_chip_icon_size">12dp</dimen>
    <dimen name="privacy_chip_max_width">51dp</dimen>
    <dimen name="privacy_chip_height">24dp</dimen>
    <dimen name="privacy_chip_height">24dp</dimen>
    <dimen name="privacy_chip_min_width">30dp</dimen>
    <dimen name="privacy_chip_min_width">30dp</dimen>
    <dimen name="privacy_chip_radius">12dp</dimen>
    <dimen name="privacy_chip_radius">12dp</dimen>
+67 −9
Original line number Original line Diff line number Diff line
@@ -24,13 +24,17 @@ import android.animation.ObjectAnimator;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.UiThread;
import android.annotation.UiThread;
import android.content.Context;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;
import android.view.Gravity;
import android.view.Gravity;
import android.view.IWindowManager;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
@@ -98,6 +102,10 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
    private final Context mContext;
    private final Context mContext;
    private final PrivacyItemController mPrivacyItemController;
    private final PrivacyItemController mPrivacyItemController;


    private final IWindowManager mIWindowManager;
    private final Rect[] mBounds = new Rect[4];
    private boolean mIsRtl;

    private ViewGroup mIndicatorView;
    private ViewGroup mIndicatorView;
    private boolean mViewAndWindowAdded;
    private boolean mViewAndWindowAdded;
    private ObjectAnimator mAnimator;
    private ObjectAnimator mAnimator;
@@ -124,17 +132,23 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
    private int mState = STATE_NOT_SHOWN;
    private int mState = STATE_NOT_SHOWN;


    @Inject
    @Inject
    public TvOngoingPrivacyChip(Context context, PrivacyItemController privacyItemController) {
    public TvOngoingPrivacyChip(Context context, PrivacyItemController privacyItemController,
            IWindowManager iWindowManager) {
        super(context);
        super(context);
        if (DEBUG) Log.d(TAG, "Privacy chip running");
        if (DEBUG) Log.d(TAG, "Privacy chip running");
        mContext = context;
        mContext = context;
        mPrivacyItemController = privacyItemController;
        mPrivacyItemController = privacyItemController;
        mIWindowManager = iWindowManager;


        Resources res = mContext.getResources();
        Resources res = mContext.getResources();
        mIconMarginStart = Math.round(
        mIconMarginStart = Math.round(
                res.getDimension(R.dimen.privacy_chip_icon_margin_in_between));
                res.getDimension(R.dimen.privacy_chip_icon_margin_in_between));
        mIconSize = res.getDimensionPixelSize(R.dimen.privacy_chip_icon_size);
        mIconSize = res.getDimensionPixelSize(R.dimen.privacy_chip_icon_size);


        mIsRtl = mContext.getResources().getConfiguration().getLayoutDirection()
                == View.LAYOUT_DIRECTION_RTL;
        updateStaticPrivacyIndicatorBounds();

        mAnimationDurationMs = res.getInteger(R.integer.privacy_chip_animation_millis);
        mAnimationDurationMs = res.getInteger(R.integer.privacy_chip_animation_millis);


        mMicCameraIndicatorFlagEnabled = privacyItemController.getMicCameraAvailable();
        mMicCameraIndicatorFlagEnabled = privacyItemController.getMicCameraAvailable();
@@ -146,6 +160,24 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
        }
        }
    }
    }


    @Override
    public void onConfigurationChanged(Configuration config) {
        boolean updatedRtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        if (mIsRtl == updatedRtl) {
            return;
        }
        mIsRtl = updatedRtl;

        updateStaticPrivacyIndicatorBounds();

        // Update privacy chip location.
        if (mState == STATE_NOT_SHOWN || mIndicatorView == null) {
            return;
        }
        fadeOutIndicator();
        createAndShowIndicator();
    }

    @Override
    @Override
    public void start() {
    public void start() {
        mPrivacyItemController.addCallback(this);
        mPrivacyItemController.addCallback(this);
@@ -181,6 +213,32 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
        updateChip();
        updateChip();
    }
    }


    private void updateStaticPrivacyIndicatorBounds() {
        Resources res = mContext.getResources();
        int mMaxExpandedWidth = res.getDimensionPixelSize(R.dimen.privacy_chip_max_width);
        int mMaxExpandedHeight = res.getDimensionPixelSize(R.dimen.privacy_chip_height);
        int mChipMarginTotal = 2 * res.getDimensionPixelSize(R.dimen.privacy_chip_margin);

        final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
        Rect screenBounds = windowManager.getCurrentWindowMetrics().getBounds();
        mBounds[0] = new Rect(
                mIsRtl ? screenBounds.left
                        : screenBounds.right - mChipMarginTotal - mMaxExpandedWidth,
                screenBounds.top,
                mIsRtl ? screenBounds.left + mChipMarginTotal + mMaxExpandedWidth
                        : screenBounds.right,
                screenBounds.top + mChipMarginTotal + mMaxExpandedHeight
        );

        if (DEBUG) Log.v(TAG, "privacy indicator bounds: " + mBounds[0].toShortString());

        try {
            mIWindowManager.updateStaticPrivacyIndicatorBounds(mContext.getDisplayId(), mBounds);
        } catch (RemoteException e) {
            Log.w(TAG, "could not update privacy indicator bounds");
        }
    }

    private void updateChip() {
    private void updateChip() {
        if (DEBUG) Log.d(TAG, mPrivacyItems.size() + " privacy items");
        if (DEBUG) Log.d(TAG, mPrivacyItems.size() + " privacy items");


@@ -316,13 +374,9 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
                            }
                            }
                        });
                        });


        final boolean isRtl = mContext.getResources().getConfiguration().getLayoutDirection()
                == View.LAYOUT_DIRECTION_RTL;
        if (DEBUG) Log.d(TAG, "is RTL: " + isRtl);

        mChipDrawable = new PrivacyChipDrawable(mContext);
        mChipDrawable = new PrivacyChipDrawable(mContext);
        mChipDrawable.setListener(this);
        mChipDrawable.setListener(this);
        mChipDrawable.setRtl(isRtl);
        mChipDrawable.setRtl(mIsRtl);
        ImageView chipBackground = mIndicatorView.findViewById(R.id.chip_drawable);
        ImageView chipBackground = mIndicatorView.findViewById(R.id.chip_drawable);
        if (chipBackground != null) {
        if (chipBackground != null) {
            chipBackground.setImageDrawable(mChipDrawable);
            chipBackground.setImageDrawable(mChipDrawable);
@@ -332,17 +386,21 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
        mIconsContainer.setAlpha(0f);
        mIconsContainer.setAlpha(0f);
        updateIcons();
        updateIcons();


        final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
        windowManager.addView(mIndicatorView, getWindowLayoutParams());
    }

    private WindowManager.LayoutParams getWindowLayoutParams() {
        final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
        final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                WRAP_CONTENT,
                WRAP_CONTENT,
                WRAP_CONTENT,
                WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
                PixelFormat.TRANSLUCENT);
        layoutParams.gravity = Gravity.TOP | (isRtl ? Gravity.LEFT : Gravity.RIGHT);
        layoutParams.gravity = Gravity.TOP | (mIsRtl ? Gravity.LEFT : Gravity.RIGHT);
        layoutParams.setTitle(LAYOUT_PARAMS_TITLE);
        layoutParams.setTitle(LAYOUT_PARAMS_TITLE);
        layoutParams.packageName = mContext.getPackageName();
        layoutParams.packageName = mContext.getPackageName();
        final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
        return layoutParams;
        windowManager.addView(mIndicatorView, layoutParams);
    }
    }


    private void updateIcons() {
    private void updateIcons() {