From c412309b7a32308b1b0a175dafc13f90254353c5 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 5 Sep 2011 16:15:28 +0900 Subject: [PATCH] Get rid of LinearLayoutCompatUtils Change-Id: If0f63eaeb4539c0e03ef20190d2f9211a176babc --- java/res/layout/suggestions_strip.xml | 15 ++--- java/res/values/dimens.xml | 2 +- .../compat/LinearLayoutCompatUtils.java | 55 ------------------- .../inputmethod/latin/SuggestionsView.java | 26 +++------ 4 files changed, 12 insertions(+), 86 deletions(-) delete mode 100644 java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java diff --git a/java/res/layout/suggestions_strip.xml b/java/res/layout/suggestions_strip.xml index 9252017b4..cbf31e6dc 100644 --- a/java/res/layout/suggestions_strip.xml +++ b/java/res/layout/suggestions_strip.xml @@ -22,16 +22,9 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" > - - - - + android:layout_height="match_parent" /> diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index c5c298df5..0ec65e3f8 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -80,7 +80,7 @@ 12dip 40dip 0.2in - 12% + 18% 40dip 0dip 44dip diff --git a/java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java b/java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java deleted file mode 100644 index 674cbe74b..000000000 --- a/java/src/com/android/inputmethod/compat/LinearLayoutCompatUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.compat; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.util.Log; - -import java.lang.reflect.Field; - -public class LinearLayoutCompatUtils { - private static final String TAG = LinearLayoutCompatUtils.class.getSimpleName(); - - private static final Class CLASS_R_STYLEABLE = CompatUtils.getClass( - "com.android.internal.R$styleable"); - private static final Field STYLEABLE_VIEW = CompatUtils.getField( - CLASS_R_STYLEABLE, "View"); - private static final Field STYLEABLE_VIEW_BACKGROUND = CompatUtils.getField( - CLASS_R_STYLEABLE, "View_background"); - private static final Object VALUE_STYLEABLE_VIEW = CompatUtils.getFieldValue( - null, null, STYLEABLE_VIEW); - private static final Integer VALUE_STYLEABLE_VIEW_BACKGROUND = - (Integer)CompatUtils.getFieldValue(null, null, STYLEABLE_VIEW_BACKGROUND); - - public static Drawable getBackgroundDrawable(Context context, AttributeSet attrs, - int defStyleAttr, int defStyleRes) { - if (!(VALUE_STYLEABLE_VIEW instanceof int[]) || VALUE_STYLEABLE_VIEW_BACKGROUND == null) { - Log.w(TAG, "Can't get View background attribute using reflection"); - return null; - } - - final int[] styleableView = (int[])VALUE_STYLEABLE_VIEW; - final TypedArray a = context.obtainStyledAttributes( - attrs, styleableView, defStyleAttr, defStyleRes); - final Drawable background = a.getDrawable(VALUE_STYLEABLE_VIEW_BACKGROUND); - a.recycle(); - return background; - } -} diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 10cd73dd3..f11ac1dcf 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -45,10 +45,10 @@ import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.PopupWindow; +import android.widget.RelativeLayout; import android.widget.TextView; import com.android.inputmethod.compat.FrameLayoutCompatUtils; -import com.android.inputmethod.compat.LinearLayoutCompatUtils; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.MoreKeysPanel; @@ -58,7 +58,8 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.util.ArrayList; import java.util.List; -public class SuggestionsView extends LinearLayout implements OnClickListener, OnLongClickListener { +public class SuggestionsView extends RelativeLayout implements OnClickListener, + OnLongClickListener { public interface Listener { public boolean addWordToDictionary(String word); public void pickSuggestionManually(int index, CharSequence word); @@ -69,7 +70,6 @@ public class SuggestionsView extends LinearLayout implements OnClickListener, On private static final boolean DBG = LatinImeLogger.sDBG; - private final ViewGroup mSuggestionsPlacer; private final ViewGroup mSuggestionsStrip; private KeyboardView mKeyboardView; @@ -451,18 +451,7 @@ public class SuggestionsView extends LinearLayout implements OnClickListener, On } public SuggestionsView(Context context, AttributeSet attrs, int defStyle) { - // Note: Up to version 10 (Gingerbread) of the API, LinearLayout doesn't have 3-argument - // constructor. - // TODO: Call 3-argument constructor, super(context, attrs, defStyle), when we abandon - // backward compatibility with the version 10 or earlier of the API. - super(context, attrs); - if (defStyle != R.attr.suggestionsViewStyle) { - throw new IllegalArgumentException( - "can't accept defStyle other than R.attr.suggestionsViewStyle: defStyle=" - + defStyle); - } - setBackgroundDrawable(LinearLayoutCompatUtils.getBackgroundDrawable( - context, attrs, defStyle, R.style.SuggestionsViewStyle)); + super(context, attrs, defStyle); final LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.suggestions_strip, this); @@ -474,7 +463,6 @@ public class SuggestionsView extends LinearLayout implements OnClickListener, On mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setBackgroundDrawable(null); - mSuggestionsPlacer = (ViewGroup)findViewById(R.id.suggestions_placer); mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip); for (int pos = 0; pos < MAX_SUGGESTIONS; pos++) { final TextView word = (TextView)inflater.inflate(R.layout.suggestion_word, null); @@ -527,7 +515,7 @@ public class SuggestionsView extends LinearLayout implements OnClickListener, On if (mSuggestions.size() == 0) return; - mParams.layout(mSuggestions, mSuggestionsStrip, mSuggestionsPlacer, getWidth()); + mParams.layout(mSuggestions, mSuggestionsStrip, this, getWidth()); } private static CharSequence getDebugInfo(SuggestedWords suggestions, int pos) { @@ -648,9 +636,9 @@ public class SuggestionsView extends LinearLayout implements OnClickListener, On public void clear() { mShowingAutoCorrectionInverted = false; - mSuggestionsPlacer.removeAllViews(); - mSuggestionsPlacer.addView(mSuggestionsStrip); mSuggestionsStrip.removeAllViews(); + removeAllViews(); + addView(mSuggestionsStrip); dismissMoreSuggestions(); }