Use ViewCompat support library and delete ViewCompatUtils

Change-Id: I57d60cacd86e83894294c3f64402aba8c1829872
This commit is contained in:
Tadashi G. Takaoka 2014-05-24 12:21:32 +09:00
parent fdb889cb43
commit 630a24141e
4 changed files with 19 additions and 33 deletions

View file

@ -24,23 +24,13 @@ import java.lang.reflect.Method;
// Currently {@link #getPaddingEnd(View)} and {@link #setPaddingRelative(View,int,int,int,int)}
// are missing from android-support-v4 static library in KitKat SDK.
public final class ViewCompatUtils {
// Note that View.LAYOUT_DIRECTION_LTR and View.LAYOUT_DIRECTION_RTL have been introduced in
// API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1).
public static final int LAYOUT_DIRECTION_LTR = (Integer)CompatUtils.getFieldValue(null, 0x0,
CompatUtils.getField(View.class, "LAYOUT_DIRECTION_LTR"));
public static final int LAYOUT_DIRECTION_RTL = (Integer)CompatUtils.getFieldValue(null, 0x1,
CompatUtils.getField(View.class, "LAYOUT_DIRECTION_RTL"));
// Note that View.getPaddingEnd(), View.setPaddingRelative(int,int,int,int), and
// View.getLayoutDirection() have been introduced in API level 17
// (Build.VERSION_CODE.JELLY_BEAN_MR1).
// Note that View.getPaddingEnd(), View.setPaddingRelative(int,int,int,int) have been
// introduced in API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1).
private static final Method METHOD_getPaddingEnd = CompatUtils.getMethod(
View.class, "getPaddingEnd");
private static final Method METHOD_setPaddingRelative = CompatUtils.getMethod(
View.class, "setPaddingRelative",
Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE);
private static final Method METHOD_getLayoutDirection = CompatUtils.getMethod(
View.class, "getLayoutDirection");
private ViewCompatUtils() {
// This utility class is not publicly instantiable.
@ -61,11 +51,4 @@ public final class ViewCompatUtils {
}
CompatUtils.invoke(view, null, METHOD_setPaddingRelative, start, top, end, bottom);
}
public static int getLayoutDirection(final View view) {
if (METHOD_getLayoutDirection == null) {
return LAYOUT_DIRECTION_LTR;
}
return (Integer)CompatUtils.invoke(view, 0, METHOD_getLayoutDirection);
}
}

View file

@ -21,13 +21,13 @@ import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.inputmethod.compat.ViewCompatUtils;
import com.android.inputmethod.latin.R;
public final class SetupStartIndicatorView extends LinearLayout {
@ -96,13 +96,13 @@ public final class SetupStartIndicatorView extends LinearLayout {
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
final int layoutDirection = ViewCompatUtils.getLayoutDirection(this);
final int layoutDirection = ViewCompat.getLayoutDirection(this);
final int width = getWidth();
final int height = getHeight();
final float halfHeight = height / 2.0f;
final Path path = mIndicatorPath;
path.rewind();
if (layoutDirection == ViewCompatUtils.LAYOUT_DIRECTION_RTL) {
if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
// Left arrow
path.moveTo(width, 0.0f);
path.lineTo(0.0f, halfHeight);

View file

@ -20,10 +20,10 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import com.android.inputmethod.compat.ViewCompatUtils;
import com.android.inputmethod.latin.R;
public final class SetupStepIndicatorView extends View {
@ -38,12 +38,12 @@ public final class SetupStepIndicatorView extends View {
}
public void setIndicatorPosition(final int stepPos, final int totalStepNum) {
final int layoutDirection = ViewCompatUtils.getLayoutDirection(this);
final int layoutDirection = ViewCompat.getLayoutDirection(this);
// The indicator position is the center of the partition that is equally divided into
// the total step number.
final float partionWidth = 1.0f / totalStepNum;
final float pos = stepPos * partionWidth + partionWidth / 2.0f;
mXRatio = (layoutDirection == ViewCompatUtils.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
mXRatio = (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) ? 1.0f - pos : pos;
invalidate();
}

View file

@ -89,13 +89,16 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final StripVisibilityGroup mStripVisibilityGroup;
private static class StripVisibilityGroup {
private final View mSuggestionStripView;
private final View mSuggestionsStrip;
private final View mVoiceKey;
private final View mAddToDictionaryStrip;
private final View mImportantNoticeStrip;
public StripVisibilityGroup(final View suggestionsStrip, final View voiceKey,
final View addToDictionaryStrip, final View importantNoticeStrip) {
public StripVisibilityGroup(final View suggestionStripView,
final ViewGroup suggestionsStrip, final ImageButton voiceKey,
final ViewGroup addToDictionaryStrip, final View importantNoticeStrip) {
mSuggestionStripView = suggestionStripView;
mSuggestionsStrip = suggestionsStrip;
mVoiceKey = voiceKey;
mAddToDictionaryStrip = addToDictionaryStrip;
@ -103,7 +106,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
showSuggestionsStrip(false /* voiceKeyEnabled */);
}
public void setLayoutDirection(final int layoutDirection) {
public void setLayoutDirection(final boolean isRtlLanguage) {
final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
: ViewCompat.LAYOUT_DIRECTION_LTR;
ViewCompat.setLayoutDirection(mSuggestionStripView, layoutDirection);
ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection);
ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection);
@ -155,7 +161,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mVoiceKey = (ImageButton)findViewById(R.id.suggestions_strip_voice_key);
mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip);
mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mVoiceKey,
mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, mVoiceKey,
mAddToDictionaryStrip, mImportantNoticeStrip);
for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
@ -216,10 +222,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
clear();
final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
: ViewCompat.LAYOUT_DIRECTION_LTR;
setLayoutDirection(layoutDirection);
mStripVisibilityGroup.setLayoutDirection(layoutDirection);
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
mSuggestedWords = suggestedWords;
mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip(
mSuggestedWords, mSuggestionsStrip, this);