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:
Daniel Sandler
2011-04-15 11:18:57 -04:00
parent ba61aaaaa3
commit 2943cfa606
9 changed files with 514 additions and 16 deletions

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 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.
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="2dip"
android:gravity="center_vertical">
<ImageView android:id="@+id/icon"
android:layout_width="@android:dimen/app_icon_size"
android:layout_height="@android:dimen/app_icon_size"
android:scaleType="fitCenter" />
<TextView android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingLeft="6dip" />
</LinearLayout>

View File

@@ -101,6 +101,38 @@
<item>1800000</item> <item>1800000</item>
</string-array> </string-array>
<!-- Display settings. The delay in inactivity before the dream is shown. These are shown in a list dialog. -->
<string-array name="dream_timeout_entries">
<item>Never</item>
<item>15 seconds</item>
<item>30 seconds</item>
<item>1 minute</item>
<item>2 minutes</item>
<item>5 minutes</item>
<item>10 minutes</item>
<item>30 minutes</item>
</string-array>
<!-- Do not translate. -->
<string-array name="dream_timeout_values" translatable="false">
<!-- Do not translate. -->
<item>0</item>
<!-- Do not translate. -->
<item>15000</item>
<!-- Do not translate. -->
<item>30000</item>
<!-- Do not translate. -->
<item>60000</item>
<!-- Do not translate. -->
<item>120000</item>
<!-- Do not translate. -->
<item>300000</item>
<!-- Do not translate. -->
<item>600000</item>
<!-- Do not translate. -->
<item>1800000</item>
</string-array>
<!-- Security settings. The delay after screen is turned off until device locks. <!-- Security settings. The delay after screen is turned off until device locks.
These are shown in a list dialog. --> These are shown in a list dialog. -->
<string-array name="lock_after_timeout_entries"> <string-array name="lock_after_timeout_entries">

View File

@@ -1450,6 +1450,20 @@
<string name="screen_timeout">Timeout</string> <string name="screen_timeout">Timeout</string>
<!-- Sound & display settings screen, setting option summary to change screen timeout --> <!-- Sound & display settings screen, setting option summary to change screen timeout -->
<string name="screen_timeout_summary">Screen turns off automatically after <xliff:g id="timeout_description">%1$s</xliff:g></string> <string name="screen_timeout_summary">Screen turns off automatically after <xliff:g id="timeout_description">%1$s</xliff:g></string>
<!-- Display settings screen, trigger for screen saver options -->
<string name="dream_settings_title">Android Dreams</string>
<!-- Display settings screen, summary for screen saver options -->
<string name="dream_settings_summary">Screen savers and other idle diversions</string>
<!-- Screen saver settings, setting option name to select a module -->
<string name="dream_component_title">Selected dream</string>
<!-- Screen saver settings, setting option name to change activation timeout -->
<string name="dream_timeout_title">When to activate</string>
<!-- Screen saver settings, setting option summary to change activation timeout -->
<string name="dream_timeout_summary">After <xliff:g id="timeout_description">%1$s</xliff:g> spent idle</string>
<!-- Screen saver settings, setting option summary to change activation timeout, shown when disabled -->
<string name="dream_timeout_zero_summary">Never</string>
<!-- Screen saver settings, button allowing the user to test/try the current module -->
<string name="dream_test">Try it!</string>
<!-- Sound & display settings screen, setting option name to change whether the screen adjusts automatically based on lighting conditions --> <!-- Sound & display settings screen, setting option name to change whether the screen adjusts automatically based on lighting conditions -->
<string name="automatic_brightness">Automatic brightness</string> <string name="automatic_brightness">Automatic brightness</string>
<!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size --> <!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->

View File

@@ -42,6 +42,13 @@
android:entries="@array/screen_timeout_entries" android:entries="@array/screen_timeout_entries"
android:entryValues="@array/screen_timeout_values" /> android:entryValues="@array/screen_timeout_values" />
<PreferenceScreen
android:title="@string/dream_settings_title"
android:summary="@string/dream_settings_summary"
android:fragment="com.android.settings.DreamSettings"
>
</PreferenceScreen>
<ListPreference <ListPreference
android:key="font_size" android:key="font_size"
android:title="@string/title_font_size" android:title="@string/title_font_size"

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/dream_settings_title"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<com.android.settings.DreamComponentPreference
android:key="dream_component"
android:title="@string/dream_component_title"
android:persistent="false"
/>
<ListPreference
android:key="dream_timeout"
android:title="@string/dream_timeout_title"
android:summary="@string/dream_timeout_summary"
android:persistent="false"
android:entries="@array/dream_timeout_entries"
android:entryValues="@array/dream_timeout_values" />
<com.android.settings.DreamTesterPreference
android:key="dream_test"
android:title="@string/dream_test"
android:persistent="false"
/>
</PreferenceScreen>

View File

@@ -18,6 +18,12 @@ package com.android.settings;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; 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.ActivityManagerNative;
import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver; import android.content.ContentResolver;
@@ -93,15 +99,32 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout)); mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));
mScreenTimeoutPreference.setOnPreferenceChangeListener(this); mScreenTimeoutPreference.setOnPreferenceChangeListener(this);
disableUnusableTimeouts(mScreenTimeoutPreference); disableUnusableTimeouts(mScreenTimeoutPreference);
updateTimeoutPreferenceDescription(resolver, currentTimeout); updateTimeoutPreferenceDescription(resolver, mScreenTimeoutPreference,
R.string.screen_timeout_summary, currentTimeout);
mFontSizePref = (ListPreference) findPreference(KEY_FONT_SIZE); mFontSizePref = (ListPreference) findPreference(KEY_FONT_SIZE);
mFontSizePref.setOnPreferenceChangeListener(this); mFontSizePref.setOnPreferenceChangeListener(this);
} }
private void updateTimeoutPreferenceDescription(ContentResolver resolver, long currentTimeout) { private void updateTimeoutPreferenceDescription(
final CharSequence[] entries = mScreenTimeoutPreference.getEntries(); ContentResolver resolver,
final CharSequence[] values = mScreenTimeoutPreference.getEntryValues(); 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; int best = 0;
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
long timeout = Long.valueOf(values[i].toString()); long timeout = Long.valueOf(values[i].toString());
@@ -109,9 +132,9 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
best = i; best = i;
} }
} }
String summary = mScreenTimeoutPreference.getContext() summary = pref.getContext().getString(summaryStrings, entries[best]);
.getString(R.string.screen_timeout_summary, entries[best]); }
mScreenTimeoutPreference.setSummary(summary); pref.setSummary(summary);
} }
private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) { private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
@@ -255,7 +278,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
Settings.System.ACCELEROMETER_ROTATION, Settings.System.ACCELEROMETER_ROTATION,
mAccelerometer.isChecked() ? 1 : 0); mAccelerometer.isChecked() ? 1 : 0);
} }
return true; return super.onPreferenceTreeClick(preferenceScreen, preference);
} }
public boolean onPreferenceChange(Preference preference, Object objValue) { public boolean onPreferenceChange(Preference preference, Object objValue) {
@@ -284,7 +307,8 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
try { try {
Settings.System.putInt(getContentResolver(), Settings.System.putInt(getContentResolver(),
SCREEN_OFF_TIMEOUT, value); SCREEN_OFF_TIMEOUT, value);
updateTimeoutPreferenceDescription(getContentResolver(), value); updateTimeoutPreferenceDescription(getContentResolver(), mScreenTimeoutPreference,
R.string.screen_timeout_summary, value);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "could not persist screen timeout setting", e); Log.e(TAG, "could not persist screen timeout setting", e);
} }

View 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();
}
}

View 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;
}
}

View 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);
}
}
}