• 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.settings.search.Indexable;
29 import com.android.settings.search.SearchIndexableRaw;
30 import com.android.settingslib.search.SearchIndexable;
31 
32 import java.util.ArrayList;
33 import java.util.List;
34 
35 @SearchIndexable
36 public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase implements Indexable {
37 
38     private static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR";
39     private static final String WALLPAPER_FOCUS = "focus_wallpaper";
40 
41     @Override
addExtras(Intent intent)42     protected void addExtras(Intent intent) {
43         intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
44     }
45 
46     @VisibleForTesting
isSuggestionComplete(Context context)47     public static boolean isSuggestionComplete(Context context) {
48         if (!isWallpaperServiceEnabled(context)) {
49             return true;
50         }
51         final WallpaperManager manager = (WallpaperManager) context.getSystemService(
52                 WALLPAPER_SERVICE);
53         return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
54     }
55 
56     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
57             new BaseSearchIndexProvider() {
58                 private static final String SUPPORT_SEARCH_INDEX_KEY = "wallpaper_type";
59 
60                 @Override
61                 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
62                         boolean enabled) {
63                     final List<SearchIndexableRaw> result = new ArrayList<>();
64                     WallpaperPreferenceController controller =
65                             new WallpaperPreferenceController(context, "dummy key");
66                     SearchIndexableRaw data = new SearchIndexableRaw(context);
67                     data.title = controller.getTitle();
68                     data.screenTitle = data.title;
69                     ComponentName component = controller.getComponentName();
70                     data.intentTargetPackage = component.getPackageName();
71                     data.intentTargetClass = component.getClassName();
72                     data.intentAction = Intent.ACTION_MAIN;
73                     data.key = SUPPORT_SEARCH_INDEX_KEY;
74                     data.keywords = controller.getKeywords();
75                     result.add(data);
76                     return result;
77                 }
78             };
79 }
80