Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 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 | |
Chihhang Chuang | eecf85e | 2021-06-14 13:48:57 +0800 | [diff] [blame^] | 18 | import static com.android.wallpaper.picker.CustomizationPickerActivity.WALLPAPER_FLAVOR_EXTRA; |
| 19 | import static com.android.wallpaper.picker.CustomizationPickerActivity.WALLPAPER_FOCUS; |
Chuck Liao | 4a777fb | 2020-08-15 04:15:46 +0800 | [diff] [blame] | 20 | |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Chuck Liao | 4a777fb | 2020-08-15 04:15:46 +0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.net.Uri; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 24 | |
| 25 | import androidx.fragment.app.Fragment; |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 26 | import androidx.fragment.app.FragmentActivity; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 27 | |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 28 | import com.android.customization.model.theme.OverlayManagerCompat; |
| 29 | import com.android.customization.model.theme.ThemeBundleProvider; |
| 30 | import com.android.customization.model.theme.ThemeManager; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 31 | import com.android.wallpaper.model.CategoryProvider; |
| 32 | import com.android.wallpaper.model.WallpaperInfo; |
| 33 | import com.android.wallpaper.module.BaseWallpaperInjector; |
| 34 | import com.android.wallpaper.module.DefaultCategoryProvider; |
Chihhang Chuang | 1473ab0 | 2021-06-10 10:49:38 +0800 | [diff] [blame] | 35 | import com.android.wallpaper.module.HubSections; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 36 | import com.android.wallpaper.module.LoggingOptInStatusProvider; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 37 | import com.android.wallpaper.module.WallpaperPreferences; |
| 38 | import com.android.wallpaper.module.WallpaperRotationRefresher; |
| 39 | import com.android.wallpaper.monitor.PerformanceMonitor; |
Chihhang Chuang | eecf85e | 2021-06-14 13:48:57 +0800 | [diff] [blame^] | 40 | import com.android.wallpaper.picker.CustomizationPickerActivity; |
Santiago Etchebehere | 57778a2 | 2019-11-08 14:09:56 -0800 | [diff] [blame] | 41 | import com.android.wallpaper.picker.PreviewFragment; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 42 | |
| 43 | public class DefaultCustomizationInjector extends BaseWallpaperInjector |
| 44 | implements CustomizationInjector { |
| 45 | private CategoryProvider mCategoryProvider; |
Santiago Etchebehere | f64c5d0 | 2019-04-09 11:53:35 -0300 | [diff] [blame] | 46 | private ThemesUserEventLogger mUserEventLogger; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 47 | private WallpaperRotationRefresher mWallpaperRotationRefresher; |
| 48 | private PerformanceMonitor mPerformanceMonitor; |
| 49 | private WallpaperPreferences mPrefs; |
Chihhang Chuang | 1473ab0 | 2021-06-10 10:49:38 +0800 | [diff] [blame] | 50 | private HubSections mHubSections; |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 51 | |
| 52 | @Override |
| 53 | public synchronized WallpaperPreferences getPreferences(Context context) { |
| 54 | if (mPrefs == null) { |
| 55 | mPrefs = new DefaultCustomizationPreferences(context.getApplicationContext()); |
| 56 | } |
| 57 | return mPrefs; |
| 58 | } |
| 59 | |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 60 | @Override |
| 61 | public CustomizationPreferences getCustomizationPreferences(Context context) { |
| 62 | return (CustomizationPreferences) getPreferences(context); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public synchronized CategoryProvider getCategoryProvider(Context context) { |
| 67 | if (mCategoryProvider == null) { |
| 68 | mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext()); |
| 69 | } |
| 70 | return mCategoryProvider; |
| 71 | } |
| 72 | |
| 73 | @Override |
Santiago Etchebehere | f64c5d0 | 2019-04-09 11:53:35 -0300 | [diff] [blame] | 74 | public synchronized ThemesUserEventLogger getUserEventLogger(Context context) { |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 75 | if (mUserEventLogger == null) { |
Santiago Etchebehere | f64c5d0 | 2019-04-09 11:53:35 -0300 | [diff] [blame] | 76 | mUserEventLogger = new StatsLogUserEventLogger(); |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 77 | } |
| 78 | return mUserEventLogger; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() { |
| 83 | if (mWallpaperRotationRefresher == null) { |
| 84 | mWallpaperRotationRefresher = new WallpaperRotationRefresher() { |
| 85 | @Override |
| 86 | public void refreshWallpaper(Context context, Listener listener) { |
| 87 | // Not implemented |
| 88 | listener.onError(); |
| 89 | } |
| 90 | }; |
| 91 | } |
| 92 | return mWallpaperRotationRefresher; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Fragment getPreviewFragment( |
Clément Julliard | fe83976 | 2019-05-02 07:13:56 -0700 | [diff] [blame] | 97 | Context context, |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 98 | WallpaperInfo wallpaperInfo, |
| 99 | int mode, |
Ching-Sung Li | 3e5a805 | 2020-06-06 12:10:46 +0800 | [diff] [blame] | 100 | boolean viewAsHome, |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 101 | boolean testingModeEnabled) { |
chihhangchuang | 172211a | 2020-07-02 21:01:47 +0800 | [diff] [blame] | 102 | return PreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, testingModeEnabled); |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
Chuck Liao | 4a777fb | 2020-08-15 04:15:46 +0800 | [diff] [blame] | 106 | public Intent getDeepLinkRedirectIntent(Context context, Uri uri) { |
| 107 | Intent intent = new Intent(); |
| 108 | intent.setClass(context, CustomizationPickerActivity.class); |
| 109 | intent.setData(uri); |
| 110 | intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS); |
| 111 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 112 | return intent; |
| 113 | } |
| 114 | |
| 115 | @Override |
Chuck Liao | dfff1de | 2020-12-22 23:18:47 +0800 | [diff] [blame] | 116 | public String getDownloadableIntentAction() { |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | @Override |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 121 | public synchronized PerformanceMonitor getPerformanceMonitor() { |
| 122 | if (mPerformanceMonitor == null) { |
| 123 | mPerformanceMonitor = new PerformanceMonitor() { |
| 124 | @Override |
| 125 | public void recordFullResPreviewLoadedMemorySnapshot() { |
| 126 | // No Op |
| 127 | } |
| 128 | }; |
| 129 | } |
| 130 | return mPerformanceMonitor; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) { |
| 135 | return null; |
| 136 | } |
| 137 | |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 138 | @Override |
| 139 | public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity, |
Santiago Etchebehere | 1754f33 | 2020-04-09 19:17:19 -0700 | [diff] [blame] | 140 | OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) { |
| 141 | return new ThemeManager(provider, activity, overlayManagerCompat, logger); |
Santiago Etchebehere | 43b2518 | 2019-05-24 11:37:15 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Chihhang Chuang | 1473ab0 | 2021-06-10 10:49:38 +0800 | [diff] [blame] | 144 | @Override |
| 145 | public HubSections getHubSections() { |
| 146 | if (mHubSections == null) { |
| 147 | mHubSections = new DefaultCustomizationSections(); |
| 148 | } |
| 149 | return mHubSections; |
| 150 | } |
Santiago Etchebehere | ab63985 | 2019-02-26 10:42:44 -0800 | [diff] [blame] | 151 | } |