Set privacy chip bounds in WindowInsets for tv.
Now also listening to layout direction changes so the chip location as well as the chip bounds are updated immediately. Test: atest PrivacyIndicatorBoundsTests + manual: change languages between English and Arabic with and without the indicator present Bug: 185932128 Change-Id: Ie321982394fc63ccbd77c625cc6a51053562ea3c
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
|
||||
<ImageView
|
||||
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:minWidth="@dimen/privacy_chip_dot_bg_width"
|
||||
android:minHeight="@dimen/privacy_chip_dot_bg_height"
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<dimen name="privacy_chip_icon_margin_in_between">9dp</dimen>
|
||||
<dimen name="privacy_chip_padding_horizontal">9dp</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_min_width">30dp</dimen>
|
||||
<dimen name="privacy_chip_radius">12dp</dimen>
|
||||
|
||||
@@ -24,13 +24,17 @@ import android.animation.ObjectAnimator;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.UiThread;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -98,6 +102,10 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
|
||||
private final Context mContext;
|
||||
private final PrivacyItemController mPrivacyItemController;
|
||||
|
||||
private final IWindowManager mIWindowManager;
|
||||
private final Rect[] mBounds = new Rect[4];
|
||||
private boolean mIsRtl;
|
||||
|
||||
private ViewGroup mIndicatorView;
|
||||
private boolean mViewAndWindowAdded;
|
||||
private ObjectAnimator mAnimator;
|
||||
@@ -124,17 +132,23 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
|
||||
private int mState = STATE_NOT_SHOWN;
|
||||
|
||||
@Inject
|
||||
public TvOngoingPrivacyChip(Context context, PrivacyItemController privacyItemController) {
|
||||
public TvOngoingPrivacyChip(Context context, PrivacyItemController privacyItemController,
|
||||
IWindowManager iWindowManager) {
|
||||
super(context);
|
||||
if (DEBUG) Log.d(TAG, "Privacy chip running");
|
||||
mContext = context;
|
||||
mPrivacyItemController = privacyItemController;
|
||||
mIWindowManager = iWindowManager;
|
||||
|
||||
Resources res = mContext.getResources();
|
||||
mIconMarginStart = Math.round(
|
||||
res.getDimension(R.dimen.privacy_chip_icon_margin_in_between));
|
||||
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);
|
||||
|
||||
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
|
||||
public void start() {
|
||||
mPrivacyItemController.addCallback(this);
|
||||
@@ -181,6 +213,32 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
|
||||
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() {
|
||||
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.setListener(this);
|
||||
mChipDrawable.setRtl(isRtl);
|
||||
mChipDrawable.setRtl(mIsRtl);
|
||||
ImageView chipBackground = mIndicatorView.findViewById(R.id.chip_drawable);
|
||||
if (chipBackground != null) {
|
||||
chipBackground.setImageDrawable(mChipDrawable);
|
||||
@@ -332,17 +386,21 @@ public class TvOngoingPrivacyChip extends SystemUI implements PrivacyItemControl
|
||||
mIconsContainer.setAlpha(0f);
|
||||
updateIcons();
|
||||
|
||||
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
|
||||
windowManager.addView(mIndicatorView, getWindowLayoutParams());
|
||||
}
|
||||
|
||||
private WindowManager.LayoutParams getWindowLayoutParams() {
|
||||
final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
|
||||
WRAP_CONTENT,
|
||||
WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
||||
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.packageName = mContext.getPackageName();
|
||||
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
|
||||
windowManager.addView(mIndicatorView, layoutParams);
|
||||
return layoutParams;
|
||||
}
|
||||
|
||||
private void updateIcons() {
|
||||
|
||||
Reference in New Issue
Block a user