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.graphics.RectF; 24 import android.util.SparseIntArray; 25 import android.view.View; 26 27 import androidx.annotation.Nullable; 28 29 import com.android.launcher3.Launcher; 30 import com.android.launcher3.R; 31 import com.android.launcher3.util.ResourceBasedOverride; 32 33 import java.util.List; 34 35 /** Extracts the colors we need from the wallpaper at given locations. */ 36 public class LocalColorExtractor implements ResourceBasedOverride { 37 38 /** Listener for color changes on a screen location. */ 39 public interface Listener { 40 /** 41 * Method called when the colors on a registered location has changed. 42 * 43 * {@code extractedColors} maps the color resources {@code android.R.colors.system_*} to 44 * their value, in a format that can be passed directly to 45 * {@link AppWidgetHostView#setColorResources(SparseIntArray)}. 46 */ onColorsChanged(RectF rect, SparseIntArray extractedColors)47 void onColorsChanged(RectF rect, SparseIntArray extractedColors); 48 } 49 50 /** 51 * Creates a new instance of LocalColorExtractor 52 */ newInstance(Context context)53 public static LocalColorExtractor newInstance(Context context) { 54 return Overrides.getObject(LocalColorExtractor.class, context.getApplicationContext(), 55 R.string.local_colors_extraction_class); 56 } 57 58 /** Sets the object that will receive the color changes. */ setListener(@ullable Listener listener)59 public void setListener(@Nullable Listener listener) { 60 // no-op 61 } 62 63 /** Adds a list of locations to track with this listener. */ addLocation(List<RectF> locations)64 public void addLocation(List<RectF> locations) { 65 // no-op 66 } 67 68 /** Stops tracking any locations. */ removeLocations()69 public void removeLocations() { 70 // no-op 71 } 72 73 /** 74 * Updates the base context to contain the colors override 75 */ applyColorsOverride(Context base, WallpaperColors colors)76 public void applyColorsOverride(Context base, WallpaperColors colors) { } 77 78 /** 79 * Generates color resource overrides from {@link WallpaperColors}. 80 */ 81 @Nullable generateColorsOverride(WallpaperColors colors)82 public SparseIntArray generateColorsOverride(WallpaperColors colors) { 83 return null; 84 } 85 86 /** 87 * Takes a view and returns its rect that can be used by the wallpaper local color extractor. 88 * 89 * @param launcher Launcher class class. 90 * @param pageId The page the workspace item is on. 91 * @param v The view. 92 * @param colorExtractionRectOut The location rect, but converted to a format expected by the 93 * wallpaper local color extractor. 94 */ getExtractedRectForView(Launcher launcher, int pageId, View v, RectF colorExtractionRectOut)95 public void getExtractedRectForView(Launcher launcher, int pageId, View v, 96 RectF colorExtractionRectOut) { 97 // no-op 98 } 99 100 /** 101 * Takes a rect in drag layer coordinates and returns the rect that can be used by the wallpaper 102 * local color extractor. 103 * 104 * @param launcher Launcher class. 105 * @param pageId The page the workspace item is on. 106 * @param rectInDragLayer The relevant bounds of the view in drag layer coordinates. 107 * @param colorExtractionRectOut The location rect, but converted to a format expected by the 108 * wallpaper local color extractor. 109 */ getExtractedRectForViewRect(Launcher launcher, int pageId, Rect rectInDragLayer, RectF colorExtractionRectOut)110 public void getExtractedRectForViewRect(Launcher launcher, int pageId, Rect rectInDragLayer, 111 RectF colorExtractionRectOut) { 112 // no-op 113 } 114 } 115