Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2011 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;
     18 
     19 import android.content.ComponentName;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.content.pm.PackageManager;
     23 import android.content.pm.ResolveInfo;
     24 import android.os.Bundle;
     25 import android.preference.Preference;
     26 import android.preference.PreferenceScreen;
     27 import com.android.internal.logging.MetricsLogger;
     28 import com.android.settings.search.BaseSearchIndexProvider;
     29 import com.android.settings.search.Indexable;
     30 import com.android.settings.search.SearchIndexableRaw;
     31 
     32 import java.util.ArrayList;
     33 import java.util.List;
     34 
     35 public class WallpaperTypeSettings extends SettingsPreferenceFragment implements Indexable {
     36 
     37     @Override
     38     protected int getMetricsCategory() {
     39         return MetricsLogger.WALLPAPER_TYPE;
     40     }
     41 
     42     @Override
     43     protected int getHelpResource() {
     44         return R.string.help_uri_wallpaper;
     45     }
     46 
     47     @Override
     48     public void onCreate(Bundle savedInstanceState) {
     49         super.onCreate(savedInstanceState);
     50 
     51         addPreferencesFromResource(R.xml.wallpaper_settings);
     52         populateWallpaperTypes();
     53     }
     54 
     55     private void populateWallpaperTypes() {
     56         // Search for activities that satisfy the ACTION_SET_WALLPAPER action
     57         final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
     58         final PackageManager pm = getPackageManager();
     59         final List<ResolveInfo> rList = pm.queryIntentActivities(intent,
     60                 PackageManager.MATCH_DEFAULT_ONLY);
     61 
     62         final PreferenceScreen parent = getPreferenceScreen();
     63         parent.setOrderingAsAdded(false);
     64         // Add Preference items for each of the matching activities
     65         for (ResolveInfo info : rList) {
     66             Preference pref = new Preference(getActivity());
     67             Intent prefIntent = new Intent(intent);
     68             prefIntent.setComponent(new ComponentName(
     69                     info.activityInfo.packageName, info.activityInfo.name));
     70             pref.setIntent(prefIntent);
     71             CharSequence label = info.loadLabel(pm);
     72             if (label == null) label = info.activityInfo.packageName;
     73             pref.setTitle(label);
     74             parent.addPreference(pref);
     75         }
     76     }
     77 
     78     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     79         new BaseSearchIndexProvider() {
     80             @Override
     81             public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
     82                 final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
     83 
     84                 final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
     85                 final PackageManager pm = context.getPackageManager();
     86                 final List<ResolveInfo> rList = pm.queryIntentActivities(intent,
     87                         PackageManager.MATCH_DEFAULT_ONLY);
     88 
     89                 // Add indexable data for each of the matching activities
     90                 for (ResolveInfo info : rList) {
     91                     CharSequence label = info.loadLabel(pm);
     92                     if (label == null) label = info.activityInfo.packageName;
     93 
     94                     SearchIndexableRaw data = new SearchIndexableRaw(context);
     95                     data.title = label.toString();
     96                     data.screenTitle = context.getResources().getString(
     97                             R.string.wallpaper_settings_fragment_title);
     98                     data.intentAction = Intent.ACTION_SET_WALLPAPER;
     99                     data.intentTargetPackage = info.activityInfo.packageName;
    100                     data.intentTargetClass = info.activityInfo.name;
    101                     result.add(data);
    102                 }
    103 
    104                 return result;
    105             }
    106         };
    107 }
    108