1 /* 2 * Copyright (C) 2009 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.widget; 18 19 import android.app.WallpaperColors; 20 import android.appwidget.AppWidgetHostView; 21 import android.content.Context; 22 import android.graphics.Rect; 23 import android.util.SparseIntArray; 24 import android.view.View; 25 26 import androidx.annotation.Nullable; 27 28 import com.android.launcher3.R; 29 import com.android.launcher3.util.ResourceBasedOverride; 30 31 /** Extracts the colors we need from the wallpaper at given locations. */ 32 public class LocalColorExtractor implements ResourceBasedOverride { 33 34 /** Listener for color changes on a screen location. */ 35 public interface Listener { 36 /** 37 * Method called when the colors on a registered location has changed. 38 * 39 * {@code extractedColors} maps the color resources {@code android.R.colors.system_*} to 40 * their value, in a format that can be passed directly to 41 * {@link AppWidgetHostView#setColorResources(SparseIntArray)}. 42 */ onColorsChanged(SparseIntArray extractedColors)43 void onColorsChanged(SparseIntArray extractedColors); 44 } 45 46 /** 47 * Creates a new instance of LocalColorExtractor 48 */ newInstance(Context context)49 public static LocalColorExtractor newInstance(Context context) { 50 return Overrides.getObject(LocalColorExtractor.class, context.getApplicationContext(), 51 R.string.local_colors_extraction_class); 52 } 53 54 /** Sets the object that will receive the color changes. */ setListener(@ullable Listener listener)55 public void setListener(@Nullable Listener listener) { 56 // no-op 57 } 58 59 /** 60 * Sets the location used for color extraction 61 * @param pos position to use for color extraction 62 * @param child view whose coordinate space is used for {@code pos} 63 * @param screenId the workspace screenId 64 */ setWorkspaceLocation(Rect pos, View child, int screenId)65 public void setWorkspaceLocation(Rect pos, View child, int screenId) { } 66 67 /** 68 * Updates the base context to contain the colors override 69 */ applyColorsOverride(Context base, WallpaperColors colors)70 public void applyColorsOverride(Context base, WallpaperColors colors) { } 71 72 /** 73 * Generates color resource overrides from {@link WallpaperColors}. 74 */ 75 @Nullable generateColorsOverride(WallpaperColors colors)76 public SparseIntArray generateColorsOverride(WallpaperColors colors) { 77 return null; 78 } 79 80 } 81