aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/CandidateView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/CandidateView.java')
-rw-r--r--java/src/com/android/inputmethod/latin/CandidateView.java39
1 files changed, 25 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java
index 92d26a01c..09b356d65 100644
--- a/java/src/com/android/inputmethod/latin/CandidateView.java
+++ b/java/src/com/android/inputmethod/latin/CandidateView.java
@@ -44,6 +44,8 @@ import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
+import com.android.inputmethod.compat.FrameLayoutCompatUtils;
+import com.android.inputmethod.compat.LinearLayoutCompatUtils;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.util.ArrayList;
@@ -148,7 +150,18 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
public CandidateView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, 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.candidateViewStyle) {
+ throw new IllegalArgumentException(
+ "can't accept defStyle other than R.attr.candidayeViewStyle: defStyle="
+ + defStyle);
+ }
+ setBackgroundDrawable(LinearLayoutCompatUtils.getBackgroundDrawable(
+ context, attrs, defStyle, R.style.CandidateViewStyle));
Resources res = context.getResources();
LayoutInflater inflater = LayoutInflater.from(context);
@@ -232,7 +245,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
public void setListener(Listener listener, View inputView) {
mListener = listener;
mKeyboardView = inputView.findViewById(R.id.keyboard_view);
- mCandidatesPane = (ViewGroup)inputView.findViewById(R.id.candidates_pane);
+ mCandidatesPane = FrameLayoutCompatUtils.getPlacer(
+ (ViewGroup)inputView.findViewById(R.id.candidates_pane));
mCandidatesPane.setOnClickListener(this);
mCandidatesPaneContainer = (ViewGroup)inputView.findViewById(
R.id.candidates_pane_container);
@@ -334,12 +348,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
if (x != 0) {
final View divider = mDividers.get(i - NUM_CANDIDATES_IN_STRIP);
- mCandidatesPane.addView(divider);
- placeCandidateAt(divider, x, y);
+ addCandidateAt(divider, x, y);
x += dividerWidth;
}
- mCandidatesPane.addView(tv);
- placeCandidateAt(tv, x, y);
+ addCandidateAt(tv, x, y);
x += width;
}
@@ -360,14 +372,13 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
}
- private void placeCandidateAt(View v, int x, int y) {
- ViewGroup.LayoutParams lp = v.getLayoutParams();
- if (lp instanceof ViewGroup.MarginLayoutParams) {
- ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams)lp;
- mlp.width = v.getMeasuredWidth();
- mlp.height = v.getMeasuredHeight();
- mlp.setMargins(x, y + (mCandidateStripHeight - mlp.height) / 2, 0, 0);
- }
+ private void addCandidateAt(View v, int x, int y) {
+ final int width = v.getMeasuredWidth();
+ final int height = v.getMeasuredHeight();
+ final MarginLayoutParams marginLayoutParams = FrameLayoutCompatUtils.newLayoutParam(
+ mCandidatesPane, width, height);
+ marginLayoutParams.setMargins(x, y + (mCandidateStripHeight - height) / 2, 0, 0);
+ mCandidatesPane.addView(v, marginLayoutParams);
}
private void centeringCandidates(int from, int to, int width, int paneWidth) {