• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settings.wallpaper;
18 
19 import android.app.WallpaperManager;
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.content.Intent;
23 
24 import androidx.annotation.VisibleForTesting;
25 
26 import com.android.settings.display.WallpaperPreferenceController;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settingslib.search.Indexable;
29 import com.android.settingslib.search.SearchIndexable;
30 import com.android.settingslib.search.SearchIndexableRaw;
31 
32 import com.google.android.setupcompat.util.WizardManagerHelper;
33 
34 import java.util.ArrayList;
35 import java.util.List;
36 
37 @SearchIndexable
38 public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase implements Indexable {
39 
40     private static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR";
41     private static final String WALLPAPER_FOCUS = "focus_wallpaper";
42     private static final String WALLPAPER_ONLY = "wallpaper_only";
43 
44     @Override
addExtras(Intent intent)45     protected void addExtras(Intent intent) {
46         if (WizardManagerHelper.isAnySetupWizard(intent)) {
47             intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_ONLY);
48         } else {
49             intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
50         }
51     }
52 
53     @VisibleForTesting
isSuggestionComplete(Context context)54     public static boolean isSuggestionComplete(Context context) {
55         if (!isWallpaperServiceEnabled(context)) {
56             return true;
57         }
58         final WallpaperManager manager = (WallpaperManager) context.getSystemService(
59                 WALLPAPER_SERVICE);
60         return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
61     }
62 
63     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
64             new BaseSearchIndexProvider() {
65                 private static final String SUPPORT_SEARCH_INDEX_KEY = "wallpaper_type";
66 
67                 @Override
68                 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
69                         boolean enabled) {
70                     final List<SearchIndexableRaw> result = new ArrayList<>();
71                     WallpaperPreferenceController controller =
72                             new WallpaperPreferenceController(context, "dummy key");
73                     SearchIndexableRaw data = new SearchIndexableRaw(context);
74                     data.title = controller.getTitle();
75                     data.screenTitle = data.title;
76                     ComponentName component = controller.getComponentName();
77                     data.intentTargetPackage = component.getPackageName();
78                     data.intentTargetClass = component.getClassName();
79                     data.intentAction = Intent.ACTION_MAIN;
80                     data.key = SUPPORT_SEARCH_INDEX_KEY;
81                     data.keywords = controller.getKeywords();
82                     result.add(data);
83                     return result;
84                 }
85             };
86 }
87