Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Remove unnecesary ApiCompatibilityUtils calls.
Browse files Browse the repository at this point in the history
Since we only support API 16 now, we can drop all the workarounds
for pre 16 devices.

BUG=473837
[email protected]

Review URL: https://codereview.chromium.org/1078273002

Cr-Commit-Position: refs/heads/master@{#324700}
  • Loading branch information
aurimas authored and Commit bot committed Apr 10, 2015
1 parent 0e37ea0 commit 82aef33
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 166 deletions.
128 changes: 0 additions & 128 deletions base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

package org.chromium.base;

import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
Expand All @@ -20,16 +18,12 @@
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.TextView;

/**
Expand Down Expand Up @@ -241,121 +235,8 @@ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView text
}
}

/**
* @see android.view.View#postInvalidateOnAnimation()
*/
public static void postInvalidateOnAnimation(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.postInvalidateOnAnimation();
} else {
view.postInvalidate();
}
}

/**
* @see android.view.View#postOnAnimation()
*/
public static void postOnAnimation(View view, Runnable action) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.postOnAnimation(action);
} else {
view.postDelayed(action, getFrameTime());
}
}

/**
* @see android.view.View#postOnAnimationDelayed()
*/
public static void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.postOnAnimationDelayed(action, delayMillis);
} else {
view.postDelayed(action, getFrameTime() + delayMillis);
}
}

private static long getFrameTime() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return ValueAnimator.getFrameDelay();
} else {
// Any reasonable fake frame delay will have to do.
return 10;
}
}

/**
* @see android.widget.RemoteViews#setContentDescription(int, CharSequence)
*/
public static void setContentDescriptionForRemoteView(RemoteViews remoteViews, int viewId,
CharSequence contentDescription) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
remoteViews.setContentDescription(viewId, contentDescription);
} else {
// setContentDescription() is unavailable in earlier versions.
}
}

/**
* @see android.app.Activity#startActivity(Intent, Bundle)
*/
public static void startActivity(Context context, Intent intent, Bundle options) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
context.startActivity(intent, options);
} else {
context.startActivity(intent);
}
}

/**
* @see android.app.ActivityOptions#toBundle()
*/
public static Bundle toBundle(ActivityOptions options) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return options.toBundle();
} else {
return null;
}
}

// These methods have a new name, and the old name is deprecated.

/**
* @see android.view.View#setBackground(Drawable)
*/
@SuppressWarnings("deprecation")
public static void setBackgroundForView(View view, Drawable drawable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}

/**
* @see android.view.ViewTreeObserver#removeOnGlobalLayoutListener()
*/
@SuppressWarnings("deprecation")
public static void removeOnGlobalLayoutListener(
View view, ViewTreeObserver.OnGlobalLayoutListener listener) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
} else {
view.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
}
}

/**
* @see android.widget.ImageView#setImageAlpha(int)
*/
@SuppressWarnings("deprecation")
public static void setImageAlpha(ImageView iv, int alpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
iv.setImageAlpha(alpha);
} else {
iv.setAlpha(alpha);
}
}

/**
* @see android.app.PendingIntent#getCreatorPackage()
*/
Expand Down Expand Up @@ -494,13 +375,4 @@ public static Drawable getDrawable(Resources res, int id) throws NotFoundExcepti
return res.getDrawable(id);
}
}

/**
* @see android.view.View#announceForAccessibility(CharSequence text)
*/
public static void announceForAccessibility(View view, CharSequence text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.announceForAccessibility(text);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ public void disableAndWaitForVerification() {
setOverlayVisibility(View.VISIBLE);
mVerificationProgressBar.setVisibility(View.VISIBLE);
mVerificationView.setText(R.string.autofill_card_unmask_verification_in_progress);
ApiCompatibilityUtils.announceForAccessibility(
mVerificationView, mVerificationView.getText());
mVerificationView.announceForAccessibility(mVerificationView.getText());
setInputError(null);
}

Expand Down Expand Up @@ -266,7 +265,7 @@ public void run() {
});
mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox,
ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0);
ApiCompatibilityUtils.announceForAccessibility(text, text.getText());
text.announceForAccessibility(text.getText());
}

private void setInitialFocus() {
Expand Down Expand Up @@ -338,7 +337,7 @@ private void setInputError(String message) {
// A null message is passed in during card verification, which also makes an announcement.
// Announcing twice in a row may cancel the first announcement.
if (message != null) {
ApiCompatibilityUtils.announceForAccessibility(mErrorMessage, message);
mErrorMessage.announceForAccessibility(message);
}

// The rest of this code makes L-specific assumptions about the background being used to
Expand All @@ -364,7 +363,7 @@ private void setInputError(String message) {
private void setNoRetryError(String message) {
mNoRetryErrorMessage.setText(message);
mNoRetryErrorMessage.setVisibility(View.VISIBLE);
ApiCompatibilityUtils.announceForAccessibility(mNoRetryErrorMessage, message);
mNoRetryErrorMessage.announceForAccessibility(message);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void switchToSignedMode() {
updateProfileName();

mSpinner.setEnabled(false);
ApiCompatibilityUtils.setBackgroundForView(mSpinner, null);
mSpinner.setBackground(null);
mPositiveButton.setText(getResources().getText(R.string.fre_done));
mPositiveButton.setOnClickListener(new OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.widget.FrameLayout;

import org.chromium.base.ActivityState;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ApplicationStatus.ActivityStateListener;
import org.chromium.base.BaseChromiumApplication;
Expand Down Expand Up @@ -492,7 +491,7 @@ private void scheduleVisibilityUpdate() {
final int desiredVisibility = shouldShowAndroidControls() ? View.VISIBLE : View.INVISIBLE;
if (mControlContainer.getVisibility() == desiredVisibility) return;
mControlContainer.removeCallbacks(mUpdateVisibilityRunnable);
ApiCompatibilityUtils.postOnAnimation(mControlContainer, mUpdateVisibilityRunnable);
mControlContainer.postOnAnimation(mUpdateVisibilityRunnable);
}

private void updateVisuals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;

import java.util.ArrayList;
Expand Down Expand Up @@ -122,7 +121,7 @@ public int getAnimationType() {
*/
@Override
public void onGlobalLayout() {
ApiCompatibilityUtils.removeOnGlobalLayoutListener(mTargetWrapperView, this);
mTargetWrapperView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
continueAnimation();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public InfoBarLayout(Context context, InfoBarView infoBarView, int iconResourceI
new int [] {R.attr.selectableItemBackground});
Drawable closeButtonBackground = a.getDrawable(0);
a.recycle();
ApiCompatibilityUtils.setBackgroundForView(mCloseButton, closeButtonBackground);
mCloseButton.setBackground(closeButtonBackground);
mCloseButton.setPadding(mMargin, mMargin, mMargin, mMargin);
mCloseButton.setOnClickListener(this);
mCloseButton.setContentDescription(res.getString(R.string.infobar_close));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.google.android.gms.cast.CastMediaControlIntent;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState;
import org.chromium.third_party.android.media.MediaController;
Expand Down Expand Up @@ -181,7 +180,7 @@ protected void onResume() {
if (iv == null) return;
Bitmap posterBitmap = mMediaRouteController.getPoster();
if (posterBitmap != null) iv.setImageBitmap(posterBitmap);
ApiCompatibilityUtils.setImageAlpha(iv, POSTER_IMAGE_ALPHA);
iv.setImageAlpha(POSTER_IMAGE_ALPHA);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.view.View;
import android.widget.RemoteViews;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState;
Expand Down Expand Up @@ -577,8 +576,7 @@ private void updateNotificationInternal() {
videoInfo.currentTimeMillis, false);
contentView.setImageViewResource(R.id.playpause,
R.drawable.ic_vidcontrol_pause);
ApiCompatibilityUtils.setContentDescriptionForRemoteView(contentView,
R.id.playpause, mPauseDescription);
contentView.setContentDescription(R.id.playpause, mPauseDescription);
contentView.setOnClickPendingIntent(R.id.playpause,
getService().getPendingIntent(ListenerService.ACTION_ID_PAUSE));
break;
Expand All @@ -588,8 +586,7 @@ private void updateNotificationInternal() {
contentView.setProgressBar(R.id.progress, videoInfo.durationMillis,
videoInfo.currentTimeMillis, false);
contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_play);
ApiCompatibilityUtils.setContentDescriptionForRemoteView(contentView,
R.id.playpause, mPlayDescription);
contentView.setContentDescription(R.id.playpause, mPlayDescription);
contentView.setOnClickPendingIntent(R.id.playpause,
getService().getPendingIntent(ListenerService.ACTION_ID_PLAY));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.view.View;
import android.widget.TextView;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.widget.ChromeSwitchCompat;

Expand Down Expand Up @@ -72,7 +71,7 @@ protected void onBindView(View view) {
int right = view.getPaddingRight();
int top = view.getPaddingTop();
int bottom = view.getPaddingBottom();
ApiCompatibilityUtils.setBackgroundForView(view, DividerDrawable.create(getContext()));
view.setBackground(DividerDrawable.create(getContext()));
view.setPadding(left, top, right, bottom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.util.AttributeSet;
import android.widget.ProgressBar;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ObserverList;
import org.chromium.base.ObserverList.RewindableIterator;

Expand Down Expand Up @@ -65,8 +64,7 @@ public void run() {
// Every time, the progress bar get's at least 20% closer to mTargetProcess.
// Add 3 to guarantee progressing even if they only differ by 1.
setProgressInternal(getProgress() + (mTargetProgress - getProgress() + 3) / 4);
ApiCompatibilityUtils.postOnAnimationDelayed(
SmoothProgressBar.this, this, PROGRESS_UPDATE_DELAY_MS);
postOnAnimationDelayed(this, PROGRESS_UPDATE_DELAY_MS);
}
};

Expand Down Expand Up @@ -118,7 +116,7 @@ public void setProgress(int progress) {
if (mTargetProgress == targetProgress) return;
mTargetProgress = targetProgress;
removeCallbacks(mUpdateProgressRunnable);
ApiCompatibilityUtils.postOnAnimation(this, mUpdateProgressRunnable);
postOnAnimation(mUpdateProgressRunnable);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine;
import org.chromium.chrome.browser.EmptyTabObserver;
import org.chromium.chrome.browser.Tab;
Expand Down Expand Up @@ -53,8 +52,7 @@ public void run() {
R.drawable.btn_close);
} else {
mStopReloadButton.setImageResource(R.drawable.btn_toolbar_reload);
ApiCompatibilityUtils.postOnAnimationDelayed(ChromeShellToolbar.this,
mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS);
postOnAnimationDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS);
}
}
};
Expand Down Expand Up @@ -127,7 +125,7 @@ private void onLoadProgressChanged(int progress) {
removeCallbacks(mUpdateProgressRunnable);
mProgress = progress;
mLoading = progress != 100;
ApiCompatibilityUtils.postOnAnimation(this, mUpdateProgressRunnable);
postOnAnimation(mUpdateProgressRunnable);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.view.animation.AnimationUtils;
import android.widget.PopupWindow;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.PositionObserver;
Expand Down Expand Up @@ -244,7 +243,7 @@ public void run() {

if (mHasPendingInvalidate) return;
mHasPendingInvalidate = true;
ApiCompatibilityUtils.postOnAnimation(this, mInvalidationRunnable);
postOnAnimation(mInvalidationRunnable);
}

private void rescheduleFadeIn() {
Expand All @@ -263,8 +262,7 @@ public void run() {
}

removeCallbacks(mDeferredHandleFadeInRunnable);
ApiCompatibilityUtils.postOnAnimationDelayed(
this, mDeferredHandleFadeInRunnable, FADE_IN_DELAY_MS);
postOnAnimationDelayed(mDeferredHandleFadeInRunnable, FADE_IN_DELAY_MS);
}

private void beginFadeIn() {
Expand Down
Loading

0 comments on commit 82aef33

Please sign in to comment.