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 viewFullScreen, boolean testingModeEnabled)70 public Fragment getPreviewFragment( 71 Context context, 72 WallpaperInfo wallpaperInfo, 73 int mode, 74 boolean viewAsHome, 75 boolean viewFullScreen, 76 boolean testingModeEnabled) { 77 return ImagePreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, viewFullScreen, 78 testingModeEnabled); 79 } 80 81 @Override getDeepLinkRedirectIntent(Context context, Uri uri)82 public Intent getDeepLinkRedirectIntent(Context context, Uri uri) { 83 Intent intent = new Intent(); 84 intent.setClass(context, TopLevelPickerActivity.class); 85 intent.setData(uri); 86 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 87 return intent; 88 } 89 90 @Override getPerformanceMonitor()91 public synchronized PerformanceMonitor getPerformanceMonitor() { 92 if (mPerformanceMonitor == null) { 93 mPerformanceMonitor = new PerformanceMonitor() { 94 @Override 95 public void recordFullResPreviewLoadedMemorySnapshot() { 96 // No Op 97 } 98 }; 99 } 100 return mPerformanceMonitor; 101 } 102 103 @Override getLoggingOptInStatusProvider(Context context)104 public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) { 105 return null; 106 } 107 108 @Override getDownloadableIntentAction()109 public String getDownloadableIntentAction() { 110 return null; 111 } 112 } 113