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