am 630a2414: Use ViewCompat support library and delete ViewCompatUtils

* commit '630a24141eeb80063648bc1bc4678439117321d2':
  Use ViewCompat support library and delete ViewCompatUtils
main
Tadashi G. Takaoka 2014-05-24 12:10:16 +00:00 committed by Android Git Automerger
commit 08acd8c06a
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)} // Currently {@link #getPaddingEnd(View)} and {@link #setPaddingRelative(View,int,int,int,int)}
// are missing from android-support-v4 static library in KitKat SDK. // are missing from android-support-v4 static library in KitKat SDK.
public final class ViewCompatUtils { public final class ViewCompatUtils {
// Note that View.LAYOUT_DIRECTION_LTR and View.LAYOUT_DIRECTION_RTL have been introduced in // Note that View.getPaddingEnd(), View.setPaddingRelative(int,int,int,int) have been
// API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1). // 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).
private static final Method METHOD_getPaddingEnd = CompatUtils.getMethod( private static final Method METHOD_getPaddingEnd = CompatUtils.getMethod(
View.class, "getPaddingEnd"); View.class, "getPaddingEnd");
private static final Method METHOD_setPaddingRelative = CompatUtils.getMethod( private static final Method METHOD_setPaddingRelative = CompatUtils.getMethod(
View.class, "setPaddingRelative", View.class, "setPaddingRelative",
Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE);
private static final Method METHOD_getLayoutDirection = CompatUtils.getMethod(
View.class, "getLayoutDirection");
private ViewCompatUtils() { private ViewCompatUtils() {
// This utility class is not publicly instantiable. // 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); 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.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.android.inputmethod.compat.ViewCompatUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
public final class SetupStartIndicatorView extends LinearLayout { public final class SetupStartIndicatorView extends LinearLayout {
@ -96,13 +96,13 @@ public final class SetupStartIndicatorView extends LinearLayout {
@Override @Override
protected void onDraw(final Canvas canvas) { protected void onDraw(final Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
final int layoutDirection = ViewCompatUtils.getLayoutDirection(this); final int layoutDirection = ViewCompat.getLayoutDirection(this);
final int width = getWidth(); final int width = getWidth();
final int height = getHeight(); final int height = getHeight();
final float halfHeight = height / 2.0f; final float halfHeight = height / 2.0f;
final Path path = mIndicatorPath; final Path path = mIndicatorPath;
path.rewind(); path.rewind();
if (layoutDirection == ViewCompatUtils.LAYOUT_DIRECTION_RTL) { if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
// Left arrow // Left arrow
path.moveTo(width, 0.0f); path.moveTo(width, 0.0f);
path.lineTo(0.0f, halfHeight); path.lineTo(0.0f, halfHeight);

View File

@ -20,10 +20,10 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import com.android.inputmethod.compat.ViewCompatUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
public final class SetupStepIndicatorView extends View { 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) { 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 indicator position is the center of the partition that is equally divided into
// the total step number. // the total step number.
final float partionWidth = 1.0f / totalStepNum; final float partionWidth = 1.0f / totalStepNum;
final float pos = stepPos * partionWidth + partionWidth / 2.0f; 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(); invalidate();
} }

View File

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