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 static android.provider.Settings.Secure.SCREENSAVER_COMPONENT; 20 21 import android.app.AlertDialog; 22 import android.content.Context; 23 import android.content.ComponentName; 24 import android.content.ContentResolver; 25 import android.content.DialogInterface; 26 import android.content.Intent; 27 import android.content.pm.ActivityInfo; 28 import android.content.pm.PackageManager; 29 import android.content.pm.ResolveInfo; 30 import android.content.res.Resources; 31 import android.os.RemoteException; 32 import android.os.ServiceManager; 33 import android.preference.Preference; 34 import android.provider.Settings; 35 import android.service.dreams.IDreamManager; 36 import android.util.AttributeSet; 37 import android.util.Log; 38 import android.view.Gravity; 39 import android.view.LayoutInflater; 40 import android.view.View; 41 import android.view.ViewGroup; 42 import android.widget.ArrayAdapter; 43 import android.widget.ListView; 44 import android.widget.BaseAdapter; 45 import android.widget.ImageView; 46 import android.widget.ListAdapter; 47 import android.widget.TextView; 48 49 import java.util.ArrayList; 50 import java.util.List; 51 52 public class DreamTesterPreference extends Preference { 53 private static final String TAG = "DreamTesterPreference"; 54 55 private final PackageManager pm; 56 private final ContentResolver resolver; 57 DreamTesterPreference(Context context, AttributeSet attrs)58 public DreamTesterPreference(Context context, AttributeSet attrs) { 59 super(context, attrs); 60 pm = getContext().getPackageManager(); 61 resolver = getContext().getContentResolver(); 62 } 63 64 @Override onClick()65 protected void onClick() { 66 String component = Settings.Secure.getString(resolver, SCREENSAVER_COMPONENT); 67 Log.v(TAG, "component=" + component); 68 if (component != null) { 69 ComponentName cn = ComponentName.unflattenFromString(component); 70 Log.v(TAG, "cn=" + cn); 71 // Intent intent = new Intent(Intent.ACTION_MAIN) 72 // .setComponent(cn) 73 // .addFlags( 74 // Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 75 // ) 76 // .putExtra("android.dreams.TEST", true); 77 // getContext().startService(intent); 78 IDreamManager dm = IDreamManager.Stub.asInterface( 79 ServiceManager.getService("dreams")); 80 try { 81 dm.testDream(cn); 82 } catch (RemoteException ex) { 83 // too bad, so sad, oh mom, oh dad 84 } 85 } 86 } 87 } 88