diff --git a/res/layout/dream_picker_row.xml b/res/layout/dream_picker_row.xml new file mode 100644 index 00000000000..e5c58d00b9e --- /dev/null +++ b/res/layout/dream_picker_row.xml @@ -0,0 +1,38 @@ + + + + + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index db53501e9e6..3f2fc237e97 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -101,6 +101,38 @@ 1800000 + + + Never + 15 seconds + 30 seconds + 1 minute + 2 minutes + 5 minutes + 10 minutes + 30 minutes + + + + + + 0 + + 15000 + + 30000 + + 60000 + + 120000 + + 300000 + + 600000 + + 1800000 + + diff --git a/res/values/strings.xml b/res/values/strings.xml index f03286e8f87..c0c9e371a53 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1450,6 +1450,20 @@ Timeout Screen turns off automatically after %1$s + + Android Dreams + + Screen savers and other idle diversions + + Selected dream + + When to activate + + After %1$s spent idle + + Never + + Try it! Automatic brightness diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index 5e2d76e252d..03d9641ef0b 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -42,6 +42,13 @@ android:entries="@array/screen_timeout_entries" android:entryValues="@array/screen_timeout_values" /> + + + - + diff --git a/res/xml/dream_settings.xml b/res/xml/dream_settings.xml new file mode 100644 index 00000000000..1fbb3e92ce1 --- /dev/null +++ b/res/xml/dream_settings.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index 68d449516cc..682184eafe5 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -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); } diff --git a/src/com/android/settings/DreamComponentPreference.java b/src/com/android/settings/DreamComponentPreference.java new file mode 100644 index 00000000000..3bc0eb4994c --- /dev/null +++ b/src/com/android/settings/DreamComponentPreference.java @@ -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 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(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(); + } +} diff --git a/src/com/android/settings/DreamSettings.java b/src/com/android/settings/DreamSettings.java new file mode 100644 index 00000000000..7ddab3110de --- /dev/null +++ b/src/com/android/settings/DreamSettings.java @@ -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; + } +} diff --git a/src/com/android/settings/DreamTesterPreference.java b/src/com/android/settings/DreamTesterPreference.java new file mode 100644 index 00000000000..7ff566750cb --- /dev/null +++ b/src/com/android/settings/DreamTesterPreference.java @@ -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); + } + } +}