Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: ui/android/java/src/org/chromium/ui/ColorPickerAdvancedComponent.java

Issue 2398543003: Move Android view based ColorPicker from ui/ to components/ (Closed)
Patch Set: add owners Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.ui;
6
7 import android.content.Context;
8 import android.graphics.drawable.GradientDrawable;
9 import android.view.View;
10 import android.widget.SeekBar;
11 import android.widget.SeekBar.OnSeekBarChangeListener;
12 import android.widget.TextView;
13
14 import org.chromium.base.ApiCompatibilityUtils;
15
16 /**
17 * Encapsulates a single gradient view of the HSV color display, including its l abel, gradient
18 * view and seek bar.
19 *
20 * Mirrors a "color_picker_advanced_component" layout.
21 */
22 public class ColorPickerAdvancedComponent {
23 // The view that displays the gradient.
24 private final View mGradientView;
25 // The seek bar that allows the user to change the value of this component.
26 private final SeekBar mSeekBar;
27 // The set of colors to interpolate the gradient through.
28 private int[] mGradientColors;
29 // The Drawable that represents the gradient.
30 private GradientDrawable mGradientDrawable;
31 // The text label for the component.
32 private final TextView mText;
33
34 /**
35 * Initializes the views.
36 *
37 * @param rootView View that contains all the content, such as the label, gr adient view, etc.
38 * @param textResourceId The resource ID of the text to show on the label.
39 * @param seekBarMax The range of the seek bar.
40 * @param seekBarListener The listener for when the seek bar value changes.
41 */
42 ColorPickerAdvancedComponent(final View rootView,
43 final int textResourceId,
44 final int seekBarMax,
45 final OnSeekBarChangeListener seekBarListener) {
46 mGradientView = rootView.findViewById(R.id.gradient);
47 mText = (TextView) rootView.findViewById(R.id.text);
48 mText.setText(textResourceId);
49 mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LE FT_RIGHT, null);
50 mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
51 mSeekBar.setOnSeekBarChangeListener(seekBarListener);
52 mSeekBar.setMax(seekBarMax);
53 // Setting the thumb offset means the seek bar thumb can move all the wa y to each end
54 // of the gradient view.
55 Context context = rootView.getContext();
56 int offset = ApiCompatibilityUtils.getDrawable(context.getResources(),
57 R.drawable.color_picker_advanced_select_handle).getIntrinsicWidt h();
58 mSeekBar.setThumbOffset(offset / 2);
59 }
60
61 /**
62 * @return The value represented by this component, maintained by the seek b ar progress.
63 */
64 public float getValue() {
65 return mSeekBar.getProgress();
66 }
67
68 /**
69 * Sets the value of the component (by setting the seek bar value).
70 *
71 * @param newValue The value to give the component.
72 */
73 public void setValue(float newValue) {
74 mSeekBar.setProgress((int) newValue);
75 }
76
77 /**
78 * Sets the colors for the gradient view to interpolate through.
79 *
80 * @param newColors The set of colors representing the interpolation points for the gradient.
81 */
82 public void setGradientColors(int[] newColors) {
83 mGradientColors = newColors.clone();
84 mGradientDrawable.setColors(mGradientColors);
85 mGradientView.setBackground(mGradientDrawable);
86 }
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698