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.preprovisioning.anim;
17 
18 import android.content.Context;
19 import android.graphics.Color;
20 
21 /** Class finding closest match for a swiper color **/
22 public class SwiperThemeMatcher {
23     private static final String THEME_PREFIX = "Swiper";
24     private static final String STYLE_TAG = "style";
25 
26     private final Context mContext;
27     private final ColorMatcher mColorMatcher;
28 
SwiperThemeMatcher(Context context, ColorMatcher colorMatcher)29     public SwiperThemeMatcher(Context context, ColorMatcher colorMatcher) {
30         mContext = context;
31         mColorMatcher = colorMatcher;
32     }
33 
34     /**
35      * @param targetColor Target color to find the closest match to
36      */
findTheme(int targetColor)37     public int findTheme(int targetColor) {
38         int closestColor = mColorMatcher.findClosestColor(targetColor);
39         int r = Color.red(closestColor);
40         int g = Color.green(closestColor);
41         int b = Color.blue(closestColor);
42 
43         String styleName = String.format("%s%02x%02x%02x", THEME_PREFIX, r, g, b);
44         return mContext.getResources().getIdentifier(styleName, STYLE_TAG,
45                 mContext.getPackageName());
46     }
47 }