1 /* 2 * Copyright (C) 2018 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.wallpaper.module; 17 18 import android.content.Context; 19 import android.content.Intent; 20 import android.net.Uri; 21 22 import androidx.fragment.app.Fragment; 23 24 import com.android.wallpaper.model.CategoryProvider; 25 import com.android.wallpaper.model.WallpaperInfo; 26 import com.android.wallpaper.monitor.PerformanceMonitor; 27 import com.android.wallpaper.picker.ImagePreviewFragment; 28 import com.android.wallpaper.picker.TopLevelPickerActivity; 29 30 /** 31 * A concrete, real implementation of the dependency provider. 32 */ 33 public class WallpapersInjector extends BaseWallpaperInjector { 34 private CategoryProvider mCategoryProvider; 35 private UserEventLogger mUserEventLogger; 36 private WallpaperRotationRefresher mWallpaperRotationRefresher; 37 private PerformanceMonitor mPerformanceMonitor; 38 39 @Override getCategoryProvider(Context context)40 public synchronized CategoryProvider getCategoryProvider(Context context) { 41 if (mCategoryProvider == null) { 42 mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext()); 43 } 44 return mCategoryProvider; 45 } 46 47 @Override getUserEventLogger(Context context)48 public synchronized UserEventLogger getUserEventLogger(Context context) { 49 if (mUserEventLogger == null) { 50 mUserEventLogger = new NoOpUserEventLogger(); 51 } 52 return mUserEventLogger; 53 } 54 55 @Override getWallpaperRotationRefresher()56 public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() { 57 if (mWallpaperRotationRefresher == null) { 58 mWallpaperRotationRefresher = new WallpaperRotationRefresher() { 59 @Override 60 public void refreshWallpaper(Context context, Listener listener) { 61 // Not implemented 62 listener.onError(); 63 } 64 }; 65 } 66 return mWallpaperRotationRefresher; 67 } 68 69 @Override getPreviewFragment( Context context, WallpaperInfo wallpaperInfo, int mode, boolean viewAsHome, boolean testingModeEnabled)70 public Fragment getPreviewFragment( 71 Context context, 72 WallpaperInfo wallpaperInfo, 73 int mode, 74 boolean viewAsHome, 75 boolean testingModeEnabled) { 76 return ImagePreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, 77 testingModeEnabled); 78 } 79 80 @Override getDeepLinkRedirectIntent(Context context, Uri uri)81 public Intent getDeepLinkRedirectIntent(Context context, Uri uri) { 82 Intent intent = new Intent(); 83 intent.setClass(context, TopLevelPickerActivity.class); 84 intent.setData(uri); 85 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 86 return intent; 87 } 88 89 @Override getPerformanceMonitor()90 public synchronized PerformanceMonitor getPerformanceMonitor() { 91 if (mPerformanceMonitor == null) { 92 mPerformanceMonitor = new PerformanceMonitor() { 93 @Override 94 public void recordFullResPreviewLoadedMemorySnapshot() { 95 // No Op 96 } 97 }; 98 } 99 return mPerformanceMonitor; 100 } 101 102 @Override getLoggingOptInStatusProvider(Context context)103 public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) { 104 return null; 105 } 106 107 @Override getDownloadableIntentAction()108 public String getDownloadableIntentAction() { 109 return null; 110 } 111 } 112