• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.customization.module;
17 
18 import static com.android.customization.picker.CustomizationPickerActivity.WALLPAPER_FLAVOR_EXTRA;
19 import static com.android.customization.picker.CustomizationPickerActivity.WALLPAPER_FOCUS;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.Uri;
24 
25 import androidx.fragment.app.Fragment;
26 import androidx.fragment.app.FragmentActivity;
27 
28 import com.android.customization.model.theme.OverlayManagerCompat;
29 import com.android.customization.model.theme.ThemeBundleProvider;
30 import com.android.customization.model.theme.ThemeManager;
31 import com.android.customization.picker.CustomizationPickerActivity;
32 import com.android.wallpaper.model.CategoryProvider;
33 import com.android.wallpaper.model.WallpaperInfo;
34 import com.android.wallpaper.module.BaseWallpaperInjector;
35 import com.android.wallpaper.module.DefaultCategoryProvider;
36 import com.android.wallpaper.module.LoggingOptInStatusProvider;
37 import com.android.wallpaper.module.WallpaperPreferences;
38 import com.android.wallpaper.module.WallpaperRotationRefresher;
39 import com.android.wallpaper.monitor.PerformanceMonitor;
40 import com.android.wallpaper.picker.PreviewFragment;
41 
42 public class DefaultCustomizationInjector extends BaseWallpaperInjector
43         implements CustomizationInjector {
44     private CategoryProvider mCategoryProvider;
45     private ThemesUserEventLogger mUserEventLogger;
46     private WallpaperRotationRefresher mWallpaperRotationRefresher;
47     private PerformanceMonitor mPerformanceMonitor;
48     private WallpaperPreferences mPrefs;
49 
50     @Override
getPreferences(Context context)51     public synchronized WallpaperPreferences getPreferences(Context context) {
52         if (mPrefs == null) {
53             mPrefs = new DefaultCustomizationPreferences(context.getApplicationContext());
54         }
55         return mPrefs;
56     }
57 
58     @Override
getCustomizationPreferences(Context context)59     public CustomizationPreferences getCustomizationPreferences(Context context) {
60         return (CustomizationPreferences) getPreferences(context);
61     }
62 
63     @Override
getCategoryProvider(Context context)64     public synchronized CategoryProvider getCategoryProvider(Context context) {
65         if (mCategoryProvider == null) {
66             mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext());
67         }
68         return mCategoryProvider;
69     }
70 
71     @Override
getUserEventLogger(Context context)72     public synchronized ThemesUserEventLogger getUserEventLogger(Context context) {
73         if (mUserEventLogger == null) {
74             mUserEventLogger = new StatsLogUserEventLogger();
75         }
76         return mUserEventLogger;
77     }
78 
79     @Override
getWallpaperRotationRefresher()80     public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() {
81         if (mWallpaperRotationRefresher == null) {
82             mWallpaperRotationRefresher = new WallpaperRotationRefresher() {
83                 @Override
84                 public void refreshWallpaper(Context context, Listener listener) {
85                     // Not implemented
86                     listener.onError();
87                 }
88             };
89         }
90         return mWallpaperRotationRefresher;
91     }
92 
93     @Override
getPreviewFragment( Context context, WallpaperInfo wallpaperInfo, int mode, boolean viewAsHome, boolean testingModeEnabled)94     public Fragment getPreviewFragment(
95             Context context,
96             WallpaperInfo wallpaperInfo,
97             int mode,
98             boolean viewAsHome,
99             boolean testingModeEnabled) {
100         return PreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, testingModeEnabled);
101     }
102 
103     @Override
getDeepLinkRedirectIntent(Context context, Uri uri)104     public Intent getDeepLinkRedirectIntent(Context context, Uri uri) {
105         Intent intent = new Intent();
106         intent.setClass(context, CustomizationPickerActivity.class);
107         intent.setData(uri);
108         intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
109         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
110         return intent;
111     }
112 
113     @Override
getPerformanceMonitor()114     public synchronized PerformanceMonitor getPerformanceMonitor() {
115         if (mPerformanceMonitor == null) {
116             mPerformanceMonitor = new PerformanceMonitor() {
117                 @Override
118                 public void recordFullResPreviewLoadedMemorySnapshot() {
119                     // No Op
120                 }
121             };
122         }
123         return mPerformanceMonitor;
124     }
125 
126     @Override
getLoggingOptInStatusProvider(Context context)127     public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) {
128         return null;
129     }
130 
131     @Override
getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger)132     public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity,
133             OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) {
134         return new ThemeManager(provider, activity, overlayManagerCompat, logger);
135     }
136 
137 }
138