OSDN Git Service

7ff566750cb1c02b0bc0516632bbb18dfbc2c683
[android-x86/packages-apps-Settings.git] / src / com / android / settings / DreamTesterPreference.java
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.DREAM_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.preference.Preference;
32 import android.provider.Settings;
33 import android.util.AttributeSet;
34 import android.util.Log;
35 import android.view.Gravity;
36 import android.view.LayoutInflater;
37 import android.view.View;
38 import android.view.ViewGroup;
39 import android.widget.ArrayAdapter;
40 import android.widget.ListView;
41 import android.widget.BaseAdapter;
42 import android.widget.ImageView;
43 import android.widget.ListAdapter;
44 import android.widget.TextView;
45
46 import java.util.ArrayList;
47 import java.util.List;
48
49 public class DreamTesterPreference extends Preference {
50     private static final String TAG = "DreamTesterPreference";
51     
52     private final PackageManager pm;
53     private final ContentResolver resolver;
54
55     public DreamTesterPreference(Context context, AttributeSet attrs) {
56         super(context, attrs);
57         pm = getContext().getPackageManager();
58         resolver = getContext().getContentResolver();
59     }
60
61     @Override
62     protected void onClick() {
63         String component = Settings.Secure.getString(resolver, DREAM_COMPONENT);
64         if (component != null) {
65             ComponentName cn = ComponentName.unflattenFromString(component);
66             Intent intent = new Intent(Intent.ACTION_MAIN)
67                 .setComponent(cn)
68                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
69                     | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
70                     | Intent.FLAG_ACTIVITY_SINGLE_TOP)
71                 .putExtra("android.dreams.TEST", true);
72             getContext().startActivity(intent);
73         }
74     }
75 }