From c8461d1ae26d43a09c0f835d833f3d49fbe8d2f3 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 2 Apr 2012 22:55:12 +0900 Subject: Cleanup FrameLayoutCompatUtils to ViewLayoutUtils Bug: 6129704 Change-Id: I52f2e236c7dae3ac2cba64392165f955a53d3f42 --- .../inputmethod/compat/FrameLayoutCompatUtils.java | 63 ---------------------- .../android/inputmethod/keyboard/KeyboardView.java | 5 +- .../inputmethod/keyboard/ViewLayoutUtils.java | 52 ++++++++++++++++++ .../latin/suggestions/SuggestionsView.java | 4 +- 4 files changed, 56 insertions(+), 68 deletions(-) delete mode 100644 java/src/com/android/inputmethod/compat/FrameLayoutCompatUtils.java create mode 100644 java/src/com/android/inputmethod/keyboard/ViewLayoutUtils.java (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/compat/FrameLayoutCompatUtils.java b/java/src/com/android/inputmethod/compat/FrameLayoutCompatUtils.java deleted file mode 100644 index 523bf7d0e..000000000 --- a/java/src/com/android/inputmethod/compat/FrameLayoutCompatUtils.java +++ /dev/null @@ -1,63 +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.view.View; -import android.view.ViewGroup; -import android.view.ViewGroup.MarginLayoutParams; -import android.widget.FrameLayout; -import android.widget.RelativeLayout; - -public class FrameLayoutCompatUtils { - private static final boolean NEEDS_FRAME_LAYOUT_HACK = ( - android.os.Build.VERSION.SDK_INT < 11 /* Honeycomb */); - - public static ViewGroup getPlacer(ViewGroup container) { - if (NEEDS_FRAME_LAYOUT_HACK) { - // Insert RelativeLayout to be able to setMargin because pre-Honeycomb FrameLayout - // could not handle setMargin properly. - final ViewGroup placer = new RelativeLayout(container.getContext()); - container.addView(placer); - return placer; - } else { - return container; - } - } - - public static MarginLayoutParams newLayoutParam(ViewGroup placer, int width, int height) { - if (placer instanceof FrameLayout) { - return new FrameLayout.LayoutParams(width, height); - } else if (placer instanceof RelativeLayout) { - return new RelativeLayout.LayoutParams(width, height); - } else if (placer == null) { - throw new NullPointerException("placer is null"); - } else { - throw new IllegalArgumentException("placer is neither FrameLayout nor RelativeLayout: " - + placer.getClass().getName()); - } - } - - public static void placeViewAt(View view, int x, int y, int w, int h) { - final ViewGroup.LayoutParams lp = view.getLayoutParams(); - if (lp instanceof MarginLayoutParams) { - final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp; - marginLayoutParams.width = w; - marginLayoutParams.height = h; - marginLayoutParams.setMargins(x, y, 0, 0); - } - } -} diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index c1d11a086..b51dbb906 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -37,7 +37,6 @@ import android.view.ViewGroup; import android.widget.RelativeLayout; import android.widget.TextView; -import com.android.inputmethod.compat.FrameLayoutCompatUtils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; @@ -853,7 +852,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { windowContentView.addView(mPreviewPlacer); } mPreviewPlacer.addView( - keyPreview, FrameLayoutCompatUtils.newLayoutParam(mPreviewPlacer, 0, 0)); + keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacer, 0, 0)); } private void showKey(PointerTracker tracker) { @@ -919,7 +918,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { previewText.getBackground().setState( key.mMoreKeys != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); previewText.setTextColor(params.mPreviewTextColor); - FrameLayoutCompatUtils.placeViewAt( + ViewLayoutUtils.placeViewAt( previewText, previewX, previewY, previewWidth, previewHeight); previewText.setVisibility(VISIBLE); } diff --git a/java/src/com/android/inputmethod/keyboard/ViewLayoutUtils.java b/java/src/com/android/inputmethod/keyboard/ViewLayoutUtils.java new file mode 100644 index 000000000..ee5047083 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/ViewLayoutUtils.java @@ -0,0 +1,52 @@ +/* + * 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.keyboard; + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewGroup.MarginLayoutParams; +import android.widget.FrameLayout; +import android.widget.RelativeLayout; + +public class ViewLayoutUtils { + private ViewLayoutUtils() { + // This utility class is not publicly instantiable. + } + + public static MarginLayoutParams newLayoutParam(ViewGroup placer, int width, int height) { + if (placer instanceof FrameLayout) { + return new FrameLayout.LayoutParams(width, height); + } else if (placer instanceof RelativeLayout) { + return new RelativeLayout.LayoutParams(width, height); + } else if (placer == null) { + throw new NullPointerException("placer is null"); + } else { + throw new IllegalArgumentException("placer is neither FrameLayout nor RelativeLayout: " + + placer.getClass().getName()); + } + } + + public static void placeViewAt(View view, int x, int y, int w, int h) { + final ViewGroup.LayoutParams lp = view.getLayoutParams(); + if (lp instanceof MarginLayoutParams) { + final MarginLayoutParams marginLayoutParams = (MarginLayoutParams)lp; + marginLayoutParams.width = w; + marginLayoutParams.height = h; + marginLayoutParams.setMargins(x, y, 0, 0); + } + } +} diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index ca253543e..1ad37b933 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -52,11 +52,11 @@ import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.TextView; -import com.android.inputmethod.compat.FrameLayoutCompatUtils; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.MoreKeysPanel; import com.android.inputmethod.keyboard.PointerTracker; +import com.android.inputmethod.keyboard.ViewLayoutUtils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; @@ -416,7 +416,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, ViewGroup.LayoutParams.WRAP_CONTENT); final int infoWidth = info.getMeasuredWidth(); final int y = info.getMeasuredHeight(); - FrameLayoutCompatUtils.placeViewAt( + ViewLayoutUtils.placeViewAt( info, x - infoWidth, y, infoWidth, info.getMeasuredHeight()); } } -- cgit v1.2.3-83-g751a