1 /* 2 * Copyright (C) 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 17 package com.android.launcher3.compat; 18 19 import android.content.Context; 20 import android.support.annotation.Nullable; 21 22 import com.android.launcher3.Utilities; 23 24 public abstract class WallpaperManagerCompat { 25 26 private static final Object sInstanceLock = new Object(); 27 private static WallpaperManagerCompat sInstance; 28 getInstance(Context context)29 public static WallpaperManagerCompat getInstance(Context context) { 30 synchronized (sInstanceLock) { 31 if (sInstance == null) { 32 context = context.getApplicationContext(); 33 34 if (Utilities.ATLEAST_OREO) { 35 try { 36 sInstance = new WallpaperManagerCompatVOMR1(context); 37 } catch (Throwable e) { 38 // The wallpaper APIs do not yet exist 39 } 40 } 41 if (sInstance == null) { 42 sInstance = new WallpaperManagerCompatVL(context); 43 } 44 } 45 return sInstance; 46 } 47 } 48 49 getWallpaperColors(int which)50 public abstract @Nullable WallpaperColorsCompat getWallpaperColors(int which); 51 addOnColorsChangedListener(OnColorsChangedListenerCompat listener)52 public abstract void addOnColorsChangedListener(OnColorsChangedListenerCompat listener); 53 54 /** 55 * Interface definition for a callback to be invoked when colors change on a wallpaper. 56 */ 57 public interface OnColorsChangedListenerCompat { 58 onColorsChanged(WallpaperColorsCompat colors, int which)59 void onColorsChanged(WallpaperColorsCompat colors, int which); 60 } 61 } 62