Dream (screensaver) settings.
Depends on change Ied691856 for Settings.Secure.DREAM_TIMEOUT and Settings.Secure.DREAM_COMPONENT. Change-Id: Ib6f74b74036e12637efb891b97e459a4e33444e7
This commit is contained in:
@@ -18,6 +18,12 @@ package com.android.settings;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ContentResolver;
|
||||
@@ -93,25 +99,42 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));
|
||||
mScreenTimeoutPreference.setOnPreferenceChangeListener(this);
|
||||
disableUnusableTimeouts(mScreenTimeoutPreference);
|
||||
updateTimeoutPreferenceDescription(resolver, currentTimeout);
|
||||
|
||||
updateTimeoutPreferenceDescription(resolver, mScreenTimeoutPreference,
|
||||
R.string.screen_timeout_summary, currentTimeout);
|
||||
|
||||
mFontSizePref = (ListPreference) findPreference(KEY_FONT_SIZE);
|
||||
mFontSizePref.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
private void updateTimeoutPreferenceDescription(ContentResolver resolver, long currentTimeout) {
|
||||
final CharSequence[] entries = mScreenTimeoutPreference.getEntries();
|
||||
final CharSequence[] values = mScreenTimeoutPreference.getEntryValues();
|
||||
int best = 0;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
long timeout = Long.valueOf(values[i].toString());
|
||||
if (currentTimeout >= timeout) {
|
||||
best = i;
|
||||
private void updateTimeoutPreferenceDescription(
|
||||
ContentResolver resolver,
|
||||
ListPreference pref,
|
||||
int summaryStrings,
|
||||
long currentTimeout) {
|
||||
updateTimeoutPreferenceDescription(resolver, pref, summaryStrings, 0, currentTimeout);
|
||||
}
|
||||
private void updateTimeoutPreferenceDescription(
|
||||
ContentResolver resolver,
|
||||
ListPreference pref,
|
||||
int summaryStrings,
|
||||
int zeroString,
|
||||
long currentTimeout) {
|
||||
String summary;
|
||||
if (currentTimeout == 0) {
|
||||
summary = pref.getContext().getString(zeroString);
|
||||
} else {
|
||||
final CharSequence[] entries = pref.getEntries();
|
||||
final CharSequence[] values = pref.getEntryValues();
|
||||
int best = 0;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
long timeout = Long.valueOf(values[i].toString());
|
||||
if (currentTimeout >= timeout) {
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
summary = pref.getContext().getString(summaryStrings, entries[best]);
|
||||
}
|
||||
String summary = mScreenTimeoutPreference.getContext()
|
||||
.getString(R.string.screen_timeout_summary, entries[best]);
|
||||
mScreenTimeoutPreference.setSummary(summary);
|
||||
pref.setSummary(summary);
|
||||
}
|
||||
|
||||
private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
|
||||
@@ -255,7 +278,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
mAccelerometer.isChecked() ? 1 : 0);
|
||||
}
|
||||
return true;
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
@@ -284,7 +307,8 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
try {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
SCREEN_OFF_TIMEOUT, value);
|
||||
updateTimeoutPreferenceDescription(getContentResolver(), value);
|
||||
updateTimeoutPreferenceDescription(getContentResolver(), mScreenTimeoutPreference,
|
||||
R.string.screen_timeout_summary, value);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "could not persist screen timeout setting", e);
|
||||
}
|
||||
|
139
src/com/android/settings/DreamComponentPreference.java
Normal file
139
src/com/android/settings/DreamComponentPreference.java
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static android.provider.Settings.Secure.DREAM_COMPONENT;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.Preference;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DreamComponentPreference extends Preference {
|
||||
private static final String TAG = "DreamComponentPreference";
|
||||
|
||||
private final PackageManager pm;
|
||||
private final ContentResolver resolver;
|
||||
|
||||
public DreamComponentPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
pm = getContext().getPackageManager();
|
||||
resolver = getContext().getContentResolver();
|
||||
|
||||
refreshFromSettings();
|
||||
}
|
||||
|
||||
private void refreshFromSettings() {
|
||||
String component = Settings.Secure.getString(resolver, DREAM_COMPONENT);
|
||||
if (component != null) {
|
||||
ComponentName cn = ComponentName.unflattenFromString(component);
|
||||
try {
|
||||
setSummary(pm.getActivityInfo(cn, 0).loadLabel(pm));
|
||||
} catch (PackageManager.NameNotFoundException ex) {
|
||||
setSummary("(unknown)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DreamListAdapter extends BaseAdapter implements ListAdapter {
|
||||
private ArrayList<ResolveInfo> results;
|
||||
private final LayoutInflater inflater;
|
||||
|
||||
public DreamListAdapter(Context context) {
|
||||
Intent choosy = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory("android.intent.category.DREAM");
|
||||
|
||||
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
results = new ArrayList<ResolveInfo>(pm.queryIntentActivities(choosy, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return results.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return results.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId (int position) {
|
||||
return (long) position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View row = (convertView != null)
|
||||
? convertView
|
||||
: inflater.inflate(R.layout.dream_picker_row, parent, false);
|
||||
ResolveInfo ri = results.get(position);
|
||||
((TextView)row.findViewById(R.id.title)).setText(ri.loadLabel(pm));
|
||||
((ImageView)row.findViewById(R.id.icon)).setImageDrawable(ri.loadIcon(pm));
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
final DreamListAdapter list = new DreamListAdapter(getContext());
|
||||
AlertDialog alert = new AlertDialog.Builder(getContext())
|
||||
.setAdapter(
|
||||
list,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ResolveInfo ri = (ResolveInfo)list.getItem(which);
|
||||
ActivityInfo act = ri.activityInfo;
|
||||
ComponentName cn = new ComponentName(
|
||||
act.applicationInfo.packageName,
|
||||
act.name);
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN).setComponent(cn);
|
||||
|
||||
setSummary(ri.loadLabel(pm));
|
||||
//getContext().startActivity(intent);
|
||||
|
||||
Settings.Secure.putString(resolver, DREAM_COMPONENT, cn.flattenToString());
|
||||
}
|
||||
})
|
||||
.create();
|
||||
alert.show();
|
||||
}
|
||||
}
|
128
src/com/android/settings/DreamSettings.java
Normal file
128
src/com/android/settings/DreamSettings.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static android.provider.Settings.Secure.DREAM_TIMEOUT;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.IWindowManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DreamSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "DreamSettings";
|
||||
|
||||
private static final String KEY_DREAM_TIMEOUT = "dream_timeout";
|
||||
|
||||
private ListPreference mScreenTimeoutPreference;
|
||||
private ListPreference mDreamTimeoutPreference;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
addPreferencesFromResource(R.xml.dream_settings);
|
||||
|
||||
mDreamTimeoutPreference = (ListPreference) findPreference(KEY_DREAM_TIMEOUT);
|
||||
final long currentSaverTimeout = Settings.Secure.getLong(resolver, DREAM_TIMEOUT,
|
||||
0);
|
||||
mDreamTimeoutPreference.setValue(String.valueOf(currentSaverTimeout));
|
||||
mDreamTimeoutPreference.setOnPreferenceChangeListener(this);
|
||||
updateTimeoutPreferenceDescription(resolver, mDreamTimeoutPreference,
|
||||
R.string.dream_timeout_summary,
|
||||
R.string.dream_timeout_zero_summary,
|
||||
currentSaverTimeout);
|
||||
}
|
||||
|
||||
private void updateTimeoutPreferenceDescription(
|
||||
ContentResolver resolver,
|
||||
ListPreference pref,
|
||||
int summaryStrings,
|
||||
long currentTimeout) {
|
||||
updateTimeoutPreferenceDescription(resolver, pref, summaryStrings, 0, currentTimeout);
|
||||
}
|
||||
private void updateTimeoutPreferenceDescription(
|
||||
ContentResolver resolver,
|
||||
ListPreference pref,
|
||||
int summaryStrings,
|
||||
int zeroString,
|
||||
long currentTimeout) {
|
||||
String summary;
|
||||
if (currentTimeout == 0) {
|
||||
summary = pref.getContext().getString(zeroString);
|
||||
} else {
|
||||
final CharSequence[] entries = pref.getEntries();
|
||||
final CharSequence[] values = pref.getEntryValues();
|
||||
int best = 0;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
long timeout = Long.valueOf(values[i].toString());
|
||||
if (currentTimeout >= timeout) {
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
summary = pref.getContext().getString(summaryStrings, entries[best]);
|
||||
}
|
||||
pref.setSummary(summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||
final String key = preference.getKey();
|
||||
if (KEY_DREAM_TIMEOUT.equals(key)) {
|
||||
int value = Integer.parseInt((String) objValue);
|
||||
try {
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
DREAM_TIMEOUT, value);
|
||||
updateTimeoutPreferenceDescription(getContentResolver(),
|
||||
mDreamTimeoutPreference,
|
||||
R.string.dream_timeout_summary,
|
||||
R.string.dream_timeout_zero_summary,
|
||||
value);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "could not persist dream timeout setting", e);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
75
src/com/android/settings/DreamTesterPreference.java
Normal file
75
src/com/android/settings/DreamTesterPreference.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static android.provider.Settings.Secure.DREAM_COMPONENT;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.Preference;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DreamTesterPreference extends Preference {
|
||||
private static final String TAG = "DreamTesterPreference";
|
||||
|
||||
private final PackageManager pm;
|
||||
private final ContentResolver resolver;
|
||||
|
||||
public DreamTesterPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
pm = getContext().getPackageManager();
|
||||
resolver = getContext().getContentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
String component = Settings.Secure.getString(resolver, DREAM_COMPONENT);
|
||||
if (component != null) {
|
||||
ComponentName cn = ComponentName.unflattenFromString(component);
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN)
|
||||
.setComponent(cn)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
.putExtra("android.dreams.TEST", true);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user