android cool and warm color adjustment

The previous article introduced hsv color to RGB, adjusting brightness, saturation and hue, Last blog
There is no api for adjusting the cool and warm colors of lights on the Internet. However, after checking several articles, it is found that the cool and warm colors are actually color temperature. Generally, the bulb instructions you buy tell you how much k the color temperature is, Introduction of color temperature
Since you know that the temperature is actually the color temperature, you need to know the rgb value corresponding to each color temperature stage. If you don't know, you can click the following connection Color temperature comparison table

Let's start to adjust the color temperature of the light

First, define an array to add the representative value of color temperature you need, and then add one to the array. Here are some color values I get:

String[] colorData = new String[]{"#ffa957", "#ffad5e", "#ffb165", "#ffb46b", "#ffb872", "#ffbb78", "#ffbe7e", "#ffc184", "#ffc489", "#ffc78f",
                    "#ffc994", "#ffcc99", "#ffce9f", "#ffd1a3", "#ffd3a8", "#ffd5ad", "#ffd7b1", "#ffd9b6", "#ffdbba", "#ffddbe", "#ffdfc2", "#ffe1c6",
                    "#ffe3ca", "#ffe4ce", "#ffe6d2", "#ffe8d5", "#ffe9d9", "#ffebdc", "#ffece0", "#ffeee3", "#ffefe6", "#fff0e9", "#fff2ec", "#fff3ef", "#fff4f2",
                    "#fff5f5", "#fff6f8", "#fff8fb", "#fff9fd"};

After that, it's very easy to do. A progress bar and a percentage will go to the corresponding value,

        mSeekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
                tvSeekBar2.setText((int) ((float) progress / seekBar.getMax() * 100) + "%");
                    mColor = Color.parseColor(colorData [progress == 0 ? 0 : progress - 1]);
                    //mMaskFilterView lampshade custom view
                mMaskFilterView.setColor(mColor);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });

I really didn't find the article about color temperature conversion RGB on the Internet, so I thought of this method to meet the needs. There is no demo written. You can add Link here Add a progress bar to ColorLightActivity in the package of com.example.android.ui3.light.

Tags: Android

Posted on Mon, 06 Jan 2020 05:54:29 -0800 by rcatal02