1 /*
2  * Copyright 2017, The Android Open Source Project
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.android.managedprovisioning.tools.anim;
17 
18 import android.graphics.Color;
19 
20 import com.android.managedprovisioning.preprovisioning.anim.ColorMatcher;
21 
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.OutputStreamWriter;
25 import java.util.HashSet;
26 import java.util.Set;
27 
28 /** Generates swiper themes (styles_swiper.xml) to allow for color customization. */
29 public class SwiperThemeGenerator {
30     /**
31      * @param args Specify output file path as the first argument
32      */
main(String[] args)33     public static void main(String[] args) throws IOException, InterruptedException {
34         String outFilePath = args[0];
35         ColorMatcher colorMatcher = new ColorMatcher();
36 
37         Set<Integer> seen = new HashSet<>();
38         try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outFilePath))) {
39 
40             for (int r = 0; r <= 0xff; r++) {
41                 for (int g = 0; g <= 0xff; g++) {
42                     for (int b = 0; b <= 0xff; b++) {
43                         int color = Color.argb(0xff, r, g, b);
44                         int candidate = colorMatcher.findClosestColor(color);
45                         if (seen.add(candidate)) {
46                             String colorHex = String.format("%02x%02x%02x", Color.red(candidate),
47                                     Color.green(candidate), Color.blue(candidate));
48                             out.append("<style name=\"Swiper")
49                                     .append(colorHex)
50                                     .append("\" parent=\"Provisioning2Theme\">")
51                                     .append("<item name=\"swiper_color\">#")
52                                     .append(colorHex)
53                                     .append("</item></style>\n");
54                         }
55                     }
56                 }
57             }
58         }
59     }
60 }