Revive drop shadow of SuggestionWindow.

The drop shadow of the SuggestionWindow was accidentally gone by
I579c0cc5b7f0dd337bff54af77828b8af25b13d2.

The reason of drop shadow disappearance is setting TRANSPARENT
background to the popup window.

To revive drop shadow of SuggestionWindow, follows the way of floating
toolbar.
- Create PopupWindow and make it transparent. (already exists)
- Wrap contents with RelativeLayout and set layout_margin and elevation
  to drop the shadow into the transparent PopupWindow.

The changes in Editor is for keeping this margin during re-calculation
of the contents width and position.

Bug: 15347319

Change-Id: I5a9bcbe29400d6193eb0532a5e711a78a12383cd
This commit is contained in:
Seigo Nonaka
2016-01-28 17:25:18 +09:00
parent 808a91a0c6
commit 60490d1ad4
4 changed files with 91 additions and 56 deletions

View File

@@ -2872,6 +2872,7 @@ public class Editor {
protected PopupWindow mPopupWindow;
protected ViewGroup mContentView;
int mPositionX, mPositionY;
int mClippingLimitLeft, mClippingLimitRight;
protected abstract void createPopupWindow();
protected abstract void initContentView();
@@ -2939,8 +2940,9 @@ public class Editor {
// Horizontal clipping
final DisplayMetrics displayMetrics = mTextView.getResources().getDisplayMetrics();
final int width = mContentView.getMeasuredWidth();
positionX = Math.min(displayMetrics.widthPixels - width, positionX);
positionX = Math.max(0, positionX);
positionX = Math.min(
displayMetrics.widthPixels - width + mClippingLimitRight, positionX);
positionX = Math.max(-mClippingLimitLeft, positionX);
if (isShowing()) {
mPopupWindow.update(positionX, positionY, -1, -1);
@@ -3118,6 +3120,8 @@ public class Editor {
private TextView mAddToDictionaryButton;
private TextView mDeleteButton;
private SuggestionSpan mMisspelledSpan;
private int mContainerMarginWidth;
private int mContainerMarginTop;
private class CustomPopupWindow extends PopupWindow {
@Override
@@ -3155,10 +3159,20 @@ public class Editor {
protected void initContentView() {
final LayoutInflater inflater = (LayoutInflater) mTextView.getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final LinearLayout linearLayout = (LinearLayout) inflater.inflate(
final ViewGroup relativeLayout = (ViewGroup) inflater.inflate(
mTextView.mTextEditSuggestionContainerLayout, null);
final ListView suggestionListView = (ListView) linearLayout.findViewById(
final LinearLayout suggestionWindowContainer =
(LinearLayout) relativeLayout.findViewById(
com.android.internal.R.id.suggestionWindowContainer);
ViewGroup.MarginLayoutParams lp =
(ViewGroup.MarginLayoutParams) suggestionWindowContainer.getLayoutParams();
mContainerMarginWidth = lp.leftMargin + lp.rightMargin;
mContainerMarginTop = lp.topMargin;
mClippingLimitLeft = lp.leftMargin;
mClippingLimitRight = lp.rightMargin;
final ListView suggestionListView = (ListView) relativeLayout.findViewById(
com.android.internal.R.id.suggestionContainer);
mSuggestionsAdapter = new SuggestionAdapter();
@@ -3171,9 +3185,9 @@ public class Editor {
mSuggestionInfos[i] = new SuggestionInfo();
}
mContentView = linearLayout;
mContentView = relativeLayout;
mAddToDictionaryButton = (TextView) linearLayout.findViewById(
mAddToDictionaryButton = (TextView) relativeLayout.findViewById(
com.android.internal.R.id.addToDictionaryButton);
mAddToDictionaryButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@@ -3197,7 +3211,7 @@ public class Editor {
}
});
mDeleteButton = (TextView) linearLayout.findViewById(
mDeleteButton = (TextView) relativeLayout.findViewById(
com.android.internal.R.id.deleteButton);
mDeleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@@ -3306,6 +3320,8 @@ public class Editor {
mDeleteButton.measure(horizontalMeasure, verticalMeasure);
width = Math.max(width, mDeleteButton.getMeasuredWidth());
width += mContainerMarginWidth;
// Enforce the width based on actual text widths
mContentView.measure(
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
@@ -3327,7 +3343,7 @@ public class Editor {
@Override
protected int getVerticalLocalPosition(int line) {
return mTextView.getLayout().getLineBottom(line);
return mTextView.getLayout().getLineBottom(line) - mContainerMarginTop;
}
@Override

View File

@@ -14,32 +14,41 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/text_edit_suggestions_window"
android:dropDownSelector="@drawable/list_selector_background"
android:divider="@null">
<ListView
android:id="@+id/suggestionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:attr/dividerHorizontal">
<!-- Suggestions will be added here. -->
</ListView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/suggestionWindowContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<TextView
style="@android:style/Widget.Holo.SuggestionButton"
android:id="@+id/addToDictionaryButton"
android:text="@string/addToDictionary" />
<TextView
style="@android:style/Widget.Holo.SuggestionButton"
android:id="@+id/deleteButton"
android:text="@string/deleteText" />
android:elevation="2dp"
android:layout_margin="20dp"
android:background="@drawable/text_edit_suggestions_window"
android:dropDownSelector="@drawable/list_selector_background"
android:divider="@null">
<ListView
android:id="@+id/suggestionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:attr/dividerHorizontal">
<!-- Suggestions will be added here. -->
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
<TextView
style="@android:style/Widget.Holo.SuggestionButton"
android:id="@+id/addToDictionaryButton"
android:text="@string/addToDictionary" />
<TextView
style="@android:style/Widget.Holo.SuggestionButton"
android:id="@+id/deleteButton"
android:text="@string/deleteText" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@@ -16,29 +16,38 @@
<!-- Background of the popup window is the same as the one of the floating toolbar.
Use floating toolbar background style. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="?android:attr/floatingToolbarPopupBackgroundDrawable"
android:divider="?android:attr/listDivider"
android:showDividers="middle" >
<ListView
android:id="@+id/suggestionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dip"
android:paddingBottom="0dip"
android:divider="@null" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/suggestionWindowContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@android:style/Widget.Material.SuggestionButton"
android:id="@+id/addToDictionaryButton"
android:text="@string/addToDictionary" />
<TextView
style="@android:style/Widget.Material.SuggestionButton"
android:id="@+id/deleteButton"
android:text="@string/deleteText" />
android:background="?android:attr/floatingToolbarPopupBackgroundDrawable"
android:elevation="2dp"
android:layout_margin="20dp"
android:orientation="vertical"
android:divider="?android:attr/listDivider"
android:showDividers="middle">
<ListView
android:id="@+id/suggestionContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="0dp"
android:divider="@null" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@android:style/Widget.Material.SuggestionButton"
android:id="@+id/addToDictionaryButton"
android:text="@string/addToDictionary" />
<TextView
style="@android:style/Widget.Material.SuggestionButton"
android:id="@+id/deleteButton"
android:text="@string/deleteText" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@@ -2388,6 +2388,7 @@
<java-symbol type="color" name="system_bar_background_semi_transparent" />
<!-- EditText suggestion popup. -->
<java-symbol type="id" name="suggestionWindowContainer" />
<java-symbol type="id" name="suggestionContainer" />
<java-symbol type="id" name="addToDictionaryButton" />
<java-symbol type="id" name="deleteButton" />