From b83f5c6a421c476a0f1af6e986a88f073581afd2 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Sun, 13 Oct 2013 22:04:36 -0400 Subject: [PATCH] Limit transient nav cling to 380dp on large/land devices. Bug: 11077915 Change-Id: I141a5f3f565109ae5ac9221053e5a4db36633ca7 --- core/res/res/values-land/dimens.xml | 2 + core/res/res/values-sw600dp/dimens.xml | 2 + core/res/res/values/dimens.xml | 2 + core/res/res/values/symbols.xml | 1 + .../impl/TransientNavigationConfirmation.java | 73 +++++++++++++------ 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/core/res/res/values-land/dimens.xml b/core/res/res/values-land/dimens.xml index 8f1bd9aa75f6d..81b4c09a8ece5 100644 --- a/core/res/res/values-land/dimens.xml +++ b/core/res/res/values-land/dimens.xml @@ -61,4 +61,6 @@ Landscape's layout allows this to be smaller than for portrait. --> 400dp + + 380dp diff --git a/core/res/res/values-sw600dp/dimens.xml b/core/res/res/values-sw600dp/dimens.xml index 52c230b16b39e..6b5c5051c51f9 100644 --- a/core/res/res/values-sw600dp/dimens.xml +++ b/core/res/res/values-sw600dp/dimens.xml @@ -113,4 +113,6 @@ 12dp + + 380dp diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index e9023547fec61..f43581eb853e9 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -356,4 +356,6 @@ 2dp + + -1px diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index ea92d7d6e45d2..6c944cfbc3bc2 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -346,6 +346,7 @@ + diff --git a/policy/src/com/android/internal/policy/impl/TransientNavigationConfirmation.java b/policy/src/com/android/internal/policy/impl/TransientNavigationConfirmation.java index d3d78f7b84adb..3c7902c057ea6 100644 --- a/policy/src/com/android/internal/policy/impl/TransientNavigationConfirmation.java +++ b/policy/src/com/android/internal/policy/impl/TransientNavigationConfirmation.java @@ -16,11 +16,13 @@ package com.android.internal.policy.impl; -import android.animation.Animator; import android.animation.ArgbEvaluator; import android.animation.ValueAnimator; import android.app.ActivityManager; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.graphics.PixelFormat; import android.graphics.drawable.ColorDrawable; import android.os.Handler; @@ -166,6 +168,31 @@ public class TransientNavigationConfirmation { } } + public WindowManager.LayoutParams getClingWindowLayoutParams() { + final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.TYPE_TOAST, + 0 + | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN + | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED + , + PixelFormat.TRANSLUCENT); + lp.setTitle("TransientNavigationConfirmation"); + lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; + lp.gravity = Gravity.FILL; + return lp; + } + + public FrameLayout.LayoutParams getBubbleLayoutParams() { + return new FrameLayout.LayoutParams( + mContext.getResources().getDimensionPixelSize( + R.dimen.immersive_mode_cling_width), + ViewGroup.LayoutParams.WRAP_CONTENT, + Gravity.CENTER_HORIZONTAL | Gravity.TOP); + } + private class ClingWindowView extends FrameLayout { private static final int BGCOLOR = 0x80000000; private static final int OFFSET_DP = 48; @@ -173,6 +200,18 @@ public class TransientNavigationConfirmation { private final Runnable mConfirm; private final ColorDrawable mColor = new ColorDrawable(0); private ValueAnimator mColorAnim; + private ViewGroup mClingLayout; + + private BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) { + if (mClingLayout != null && mClingLayout.getParent() != null) { + mClingLayout.setLayoutParams(getBubbleLayoutParams()); + } + } + } + }; public ClingWindowView(Context context, Runnable confirm) { super(context); @@ -190,23 +229,20 @@ public class TransientNavigationConfirmation { float density = metrics.density; // create the confirmation cling - final ViewGroup clingLayout = (ViewGroup) + mClingLayout = (ViewGroup) View.inflate(getContext(), R.layout.transient_navigation_cling, null); - final Button ok = (Button) clingLayout.findViewById(R.id.ok); + final Button ok = (Button) mClingLayout.findViewById(R.id.ok); ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mConfirm.run(); } }); - addView(clingLayout, new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, - FrameLayout.LayoutParams.WRAP_CONTENT - )); + addView(mClingLayout, getBubbleLayoutParams()); if (ActivityManager.isHighEndGfx()) { - final View bubble = clingLayout.findViewById(R.id.text); + final View bubble = mClingLayout.findViewById(R.id.text); bubble.setAlpha(0f); bubble.setTranslationY(-OFFSET_DP*density); bubble.animate() @@ -238,6 +274,13 @@ public class TransientNavigationConfirmation { } else { mColor.setColor(BGCOLOR); } + + mContext.registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); + } + + @Override + public void onDetachedFromWindow() { + mContext.unregisterReceiver(mReceiver); } @Override @@ -259,19 +302,7 @@ public class TransientNavigationConfirmation { | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); // show the confirmation - WindowManager.LayoutParams lp = new WindowManager.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.TYPE_TOAST, - 0 - | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN - | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED - , - PixelFormat.TRANSLUCENT); - lp.setTitle("TransientNavigationConfirmation"); - lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications; - lp.gravity = Gravity.FILL; + WindowManager.LayoutParams lp = getClingWindowLayoutParams(); mWindowManager.addView(mClingWindow, lp); }