This source file includes following definitions.
- getValue
- setValue
- setGradientColors
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;
public class ColorPickerAdvancedComponent {
private final View mGradientView;
private final SeekBar mSeekBar;
private int[] mGradientColors;
private GradientDrawable mGradientDrawable;
private final TextView mText;
ColorPickerAdvancedComponent(final View rootView,
final int textResourceId,
final int seekBarMax,
final OnSeekBarChangeListener seekBarListener) {
mGradientView = rootView.findViewById(R.id.gradient);
mText = (TextView) rootView.findViewById(R.id.text);
mText.setText(textResourceId);
mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
mSeekBar.setOnSeekBarChangeListener(seekBarListener);
mSeekBar.setMax(seekBarMax);
Context context = rootView.getContext();
int offset = context.getResources()
.getDrawable(R.drawable.color_picker_advanced_select_handle)
.getIntrinsicWidth();
mSeekBar.setThumbOffset(offset / 2);
}
public float getValue() {
return mSeekBar.getProgress();
}
public void setValue(float newValue) {
mSeekBar.setProgress((int) newValue);
}
public void setGradientColors(int[] newColors) {
mGradientColors = newColors.clone();
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);
}
}