1 /* 2 * Copyright (C) 2024 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 17 package com.android.launcher3.icons; 18 19 import android.graphics.BlendMode; 20 import android.graphics.BlendModeColorFilter; 21 import android.graphics.drawable.AdaptiveIconDrawable; 22 import android.graphics.drawable.Drawable; 23 import android.graphics.drawable.InsetDrawable; 24 25 import static android.graphics.drawable.AdaptiveIconDrawable.getExtraInsetFraction; 26 27 public class MonochromeIconFactory_Accessor { 28 // Adapted from com.android.launcher3.icons.ThemedIconDrawable getMonochromeIcon(AdaptiveIconDrawable adaptiveIcon, int foregroundColor)29 public static Drawable getMonochromeIcon(AdaptiveIconDrawable adaptiveIcon, 30 int foregroundColor) { 31 MonochromeIconFactory monoFactory = new MonochromeIconFactory(adaptiveIcon.getBounds().width()); 32 monoFactory.setColorFilter(new BlendModeColorFilter(foregroundColor, BlendMode.SRC_IN)); 33 Drawable mono = monoFactory.wrap(adaptiveIcon, adaptiveIcon.getIconMask(), 1f); 34 float inset = getExtraInsetFraction() / (1 + 2 * getExtraInsetFraction()); 35 return new InsetDrawable(mono, inset); 36 } 37 } 38