From bafa212a4acc0e91a413701e2fe94a44cdd0fe26 Mon Sep 17 00:00:00 2001 From: "paulnavin@google.com" Date: Fri, 7 Jun 2013 12:30:28 +0000 Subject: Adding backwards compatibility to ColorPicker. Several features used in the ColorPicker are not available or deprecated in versions less than Jellybean.. These are: - SeekBar.getThumb() - GradientDrawable.setColors(int[]) - View.setBackground(Drawable) This provides alternatives for these for versions less than Jellybean. BUG=247294 Review URL: https://chromiumcodereview.appspot.com/15674008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204789 0039d316-1c4b-4281-b951-d872f2087c98 --- .../chromium/ui/ColorPickerAdvancedComponent.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'ui/android') diff --git a/ui/android/java/src/org/chromium/ui/ColorPickerAdvancedComponent.java b/ui/android/java/src/org/chromium/ui/ColorPickerAdvancedComponent.java index 259b88c..1e679d5 100644 --- a/ui/android/java/src/org/chromium/ui/ColorPickerAdvancedComponent.java +++ b/ui/android/java/src/org/chromium/ui/ColorPickerAdvancedComponent.java @@ -4,11 +4,15 @@ package org.chromium.ui; +import android.content.Context; import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.GradientDrawable.Orientation; +import android.os.Build; import android.view.View; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; +import org.chromium.base.ApiCompatibilityUtils; /** * Encapsulates a single gradient view of the HSV color display, including its label, gradient @@ -24,7 +28,7 @@ public class ColorPickerAdvancedComponent { // The set of colors to interpolate the gradient through. private int[] mGradientColors; // The Drawable that represents the gradient. - private final GradientDrawable mGradientDrawable; + private GradientDrawable mGradientDrawable; // The text label for the component. private final TextView mText; @@ -49,7 +53,11 @@ public class ColorPickerAdvancedComponent { mSeekBar.setMax(seekBarMax); // Setting the thumb offset means the seek bar thumb can move all the way to each end // of the gradient view. - mSeekBar.setThumbOffset(mSeekBar.getThumb().getIntrinsicWidth() / 2); + Context context = rootView.getContext(); + int offset = context.getResources() + .getDrawable(R.drawable.color_picker_advanced_select_handle) + .getIntrinsicWidth(); + mSeekBar.setThumbOffset(offset / 2); } /** @@ -75,7 +83,12 @@ public class ColorPickerAdvancedComponent { */ public void setGradientColors(int[] newColors) { mGradientColors = newColors.clone(); - mGradientDrawable.setColors(mGradientColors); - mGradientView.setBackground(mGradientDrawable); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + Orientation currentOrientation = Orientation.LEFT_RIGHT; + mGradientDrawable = new GradientDrawable(currentOrientation, mGradientColors); + } else { + mGradientDrawable.setColors(mGradientColors); + } + ApiCompatibilityUtils.setBackgroundForView(mGradientView, mGradientDrawable); } } -- cgit v1.1