2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.gallery3d.filtershow.colorpicker;
19 import android.app.Dialog;
20 import android.content.Context;
21 import android.graphics.Color;
22 import android.graphics.drawable.GradientDrawable;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.Button;
27 import com.android.gallery3d.R;
29 import java.util.ArrayList;
31 public class ColorGridDialog extends Dialog {
32 RGBListener mCallback;
33 private static final String LOGTAG = "ColorGridDialog";
35 public ColorGridDialog(Context context, final RGBListener cl) {
38 setTitle(R.string.color_pick_title);
39 setContentView(R.layout.filtershow_color_gird);
40 Button sel = (Button) findViewById(R.id.filtershow_cp_custom);
41 ArrayList<Button> b = getButtons((ViewGroup) getWindow().getDecorView());
43 float[] hsv = new float[3];
45 for (Button button : b) {
46 if (!button.equals(sel)){
47 hsv[0] = (k % 5) * 360 / 5;
48 hsv[1] = (k / 5) / 3.0f;
49 hsv[2] = (k < 5) ? (k / 4f) : 1;
50 final int c = (Color.HSVToColor(hsv) & 0x00FFFFFF) | 0xAA000000;
51 GradientDrawable sd = ((GradientDrawable) button.getBackground());
52 button.setOnClickListener(new View.OnClickListener() {
54 public void onClick(View v) {
55 mCallback.setColor(c);
64 sel.setOnClickListener(new View.OnClickListener() {
66 public void onClick(View v) {
68 ColorGridDialog.this.dismiss();
73 private ArrayList<Button> getButtons(ViewGroup vg) {
74 ArrayList<Button> list = new ArrayList<Button>();
75 for (int i = 0; i < vg.getChildCount(); i++) {
76 View v = vg.getChildAt(i);
77 if (v instanceof Button) {
79 } else if (v instanceof ViewGroup) {
80 list.addAll(getButtons((ViewGroup) v));
86 public void showColorPicker() {
87 ColorListener cl = new ColorListener() {
89 public void setColor(float[] hsvo) {
90 int c = Color.HSVToColor(hsvo) & 0xFFFFFF;
91 int alpha = (int) (hsvo[3] * 255);
93 mCallback.setColor(c);
96 ColorPickerDialog cpd = new ColorPickerDialog(this.getContext(), cl);