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.app.Activity;
     20 import android.content.ComponentName;
     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 
     28 import java.util.List;
     29 
     30 public class WallpaperTypeSettings extends SettingsPreferenceFragment {
     31     @Override
     32     public void onCreate(Bundle savedInstanceState) {
     33         super.onCreate(savedInstanceState);
     34 
     35         addPreferencesFromResource(R.xml.wallpaper_settings);
     36         populateWallpaperTypes();
     37     }
     38 
     39     private void populateWallpaperTypes() {
     40         // Search for activities that satisfy the ACTION_SET_WALLPAPER action
     41         Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
     42         final PackageManager pm = getPackageManager();
     43         List<ResolveInfo> rList = pm.queryIntentActivities(intent,
     44                 PackageManager.MATCH_DEFAULT_ONLY);
     45 
     46         final PreferenceScreen parent = getPreferenceScreen();
     47         parent.setOrderingAsAdded(false);
     48         // Add Preference items for each of the matching activities
     49         for (ResolveInfo info : rList) {
     50             Preference pref = new Preference(getActivity());
     51             Intent prefIntent = new Intent(intent);
     52             prefIntent.setComponent(new ComponentName(
     53                     info.activityInfo.packageName, info.activityInfo.name));
     54             pref.setIntent(prefIntent);
     55             CharSequence label = info.loadLabel(pm);
     56             if (label == null) label = info.activityInfo.packageName;
     57             pref.setTitle(label);
     58             parent.addPreference(pref);
     59         }
     60     }
     61 }
     62