diff options
-rw-r--r-- | res/layout/dream_info_row.xml | 99 | ||||
-rw-r--r-- | res/values/strings.xml | 6 | ||||
-rw-r--r-- | src/com/android/settings/DreamBackend.java | 13 | ||||
-rw-r--r-- | src/com/android/settings/DreamSettings.java | 53 |
4 files changed, 92 insertions, 79 deletions
diff --git a/res/layout/dream_info_row.xml b/res/layout/dream_info_row.xml index c2a9a32..356a82a 100644 --- a/res/layout/dream_info_row.xml +++ b/res/layout/dream_info_row.xml @@ -13,19 +13,20 @@ See the License for the specific language governing permissions and limitations under the License. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:background="?android:attr/selectableItemBackground" - android:divider="?android:attr/dividerHorizontal" - android:orientation="vertical" - android:showDividers="middle" > + android:layout_height="wrap_content" > + + <!-- Dream selectable row (icon, caption, radio button) --> <RelativeLayout - android:id="@android:id/summary" + android:id="@android:id/widget_frame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentTop="true" > + android:layout_toLeftOf="@+id/divider" + android:background="?android:attr/selectableItemBackground" > + + <!-- Dream icon --> <ImageView android:id="@android:id/icon" @@ -37,18 +38,14 @@ android:layout_marginRight="6dp" android:layout_marginTop="10dp" android:contentDescription="@null" + android:maxHeight="@android:dimen/app_icon_size" + android:maxWidth="@android:dimen/app_icon_size" android:scaleType="fitCenter" /> - <RadioButton - android:id="@android:id/button1" - android:layout_width="wrap_content" - android:layout_height="match_parent" - android:layout_alignParentRight="true" - android:layout_centerVertical="true" - android:duplicateParentState="true" /> + <!-- Dream caption --> <TextView - android:id="@android:id/text1" + android:id="@android:id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" @@ -57,41 +54,43 @@ android:ellipsize="end" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceMedium" /> - </RelativeLayout> - <RelativeLayout - android:id="@android:id/widget_frame" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:visibility="gone" > + <!-- Dream radio button --> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:divider="?android:attr/dividerVertical" - android:dividerPadding="12dp" - android:showDividers="middle" > - - <Button - android:id="@android:id/button2" - style="@android:style/Widget.ActionButton" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="@string/screensaver_settings_dream_settings" - android:textAllCaps="true" - android:textSize="12dp" /> - - <Button - android:id="@android:id/button3" - style="@android:style/Widget.ActionButton" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="@string/screensaver_settings_dream_preview" - android:textAllCaps="true" - android:textSize="12dp" /> - </LinearLayout> + <RadioButton + android:id="@android:id/button1" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:duplicateParentState="true" /> </RelativeLayout> -</LinearLayout>
\ No newline at end of file + <!-- Divider --> + + <ImageView + android:id="@id/divider" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_centerVertical="true" + android:layout_toLeftOf="@android:id/button2" + android:contentDescription="@null" + android:src="@drawable/nav_divider" /> + + <!-- Settings icon --> + + <ImageView + android:id="@android:id/button2" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_alignBottom="@android:id/widget_frame" + android:layout_alignParentRight="true" + android:layout_alignTop="@android:id/widget_frame" + android:layout_centerVertical="true" + android:layout_margin="0dip" + android:background="?android:attr/selectableItemBackground" + android:contentDescription="@null" + android:padding="8dip" + android:src="@drawable/ic_bt_config" /> + +</RelativeLayout>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 6dc2f3d..2711582 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1717,10 +1717,8 @@ <string name="screensaver_settings_start_dreaming">Start dreaming now</string> <!-- Dream settings screen, action label, when to dream --> <string name="screensaver_settings_when_to_dream">When to dream</string> - <!-- Dream settings screen, button label to launch dream settings --> - <string name="screensaver_settings_dream_settings">Settings</string> - <!-- Dream settings screen, button label to preview dream --> - <string name="screensaver_settings_dream_preview">Preview</string> + <!-- Dream settings screen, button label to start dreaming --> + <string name="screensaver_settings_dream_start">Start</string> <!-- 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> <!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size --> diff --git a/src/com/android/settings/DreamBackend.java b/src/com/android/settings/DreamBackend.java index 1caabce..2f0443b 100644 --- a/src/com/android/settings/DreamBackend.java +++ b/src/com/android/settings/DreamBackend.java @@ -16,9 +16,9 @@ package com.android.settings; -import static android.provider.Settings.Secure.SCREENSAVER_ENABLED; import static android.provider.Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK; import static android.provider.Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP; +import static android.provider.Settings.Secure.SCREENSAVER_ENABLED; import android.content.ComponentName; import android.content.Context; @@ -183,6 +183,17 @@ public class DreamBackend { } } + public void startDreaming() { + logd("startDreaming()"); + if (mDreamManager == null) + return; + try { + mDreamManager.dream(); + } catch (RemoteException e) { + Log.w(TAG, "Failed to dream", e); + } + } + private static ComponentName getDreamComponentName(ResolveInfo resolveInfo) { if (resolveInfo == null || resolveInfo.serviceInfo == null) return null; diff --git a/src/com/android/settings/DreamSettings.java b/src/com/android/settings/DreamSettings.java index f7a150f..3b14fa5 100644 --- a/src/com/android/settings/DreamSettings.java +++ b/src/com/android/settings/DreamSettings.java @@ -27,7 +27,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.preference.PreferenceActivity; -import android.preference.PreferenceFragment; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -41,7 +40,6 @@ import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageView; @@ -66,7 +64,7 @@ public class DreamSettings extends SettingsPreferenceFragment { private DreamBackend mBackend; private DreamInfoAdapter mAdapter; private Switch mSwitch; - private MenuItem mWhenToDream; + private MenuItem[] mMenuItemsWhenEnabled; private boolean mRefreshing; @Override @@ -133,19 +131,33 @@ public class DreamSettings extends SettingsPreferenceFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { logd("onCreateOptionsMenu()"); - super.onCreateOptionsMenu(menu, inflater); boolean isEnabled = mBackend.isEnabled(); - mWhenToDream = createMenuItem(menu, - R.string.screensaver_settings_when_to_dream, + // create "start" action + MenuItem start = createMenuItem(menu, R.string.screensaver_settings_dream_start, MenuItem.SHOW_AS_ACTION_ALWAYS, + isEnabled, new Runnable(){ + @Override + public void run() { + mBackend.startDreaming(); + }}); + + // create "when to dream" overflow menu item + MenuItem whenToDream = createMenuItem(menu, + R.string.screensaver_settings_when_to_dream, + MenuItem.SHOW_AS_ACTION_NEVER, isEnabled, new Runnable() { @Override public void run() { showDialog(DIALOG_WHEN_TO_DREAM); }}); + + // create "help" overflow menu item (make sure it appears last) + super.onCreateOptionsMenu(menu, inflater); + + mMenuItemsWhenEnabled = new MenuItem[] { start, whenToDream }; } private MenuItem createMenuItem(Menu menu, @@ -242,8 +254,9 @@ public class DreamSettings extends SettingsPreferenceFragment { List<DreamInfo> dreamInfos = mBackend.getDreamInfos(); mAdapter.addAll(dreamInfos); } - if (mWhenToDream != null) - mWhenToDream.setEnabled(dreamsEnabled); + if (mMenuItemsWhenEnabled != null) + for (MenuItem menuItem : mMenuItemsWhenEnabled) + menuItem.setEnabled(dreamsEnabled); mRefreshing = false; } @@ -252,7 +265,6 @@ public class DreamSettings extends SettingsPreferenceFragment { Log.d(TAG, args == null || args.length == 0 ? msg : String.format(msg, args)); } - private class DreamInfoAdapter extends ArrayAdapter<DreamInfo> { private final LayoutInflater mInflater; @@ -272,7 +284,7 @@ public class DreamSettings extends SettingsPreferenceFragment { ((ImageView) row.findViewById(android.R.id.icon)).setImageDrawable(dreamInfo.icon); // bind caption - ((TextView) row.findViewById(android.R.id.text1)).setText(dreamInfo.caption); + ((TextView) row.findViewById(android.R.id.title)).setText(dreamInfo.caption); // bind radio button RadioButton radioButton = (RadioButton) row.findViewById(android.R.id.button1); @@ -284,24 +296,17 @@ public class DreamSettings extends SettingsPreferenceFragment { return false; }}); - // bind button container - View widgetFrame = row.findViewById(android.R.id.widget_frame); - widgetFrame.setVisibility(dreamInfo.isActive ? View.VISIBLE : View.GONE); + // bind settings button + divider + boolean showSettings = dreamInfo.settingsComponentName != null; + View settingsDivider = row.findViewById(R.id.divider); + settingsDivider.setVisibility(showSettings ? View.VISIBLE : View.INVISIBLE); - // bind settings button - Button settingsButton = (Button) row.findViewById(android.R.id.button2); - settingsButton.setVisibility(dreamInfo.settingsComponentName != null ? View.VISIBLE : View.GONE); + ImageView settingsButton = (ImageView) row.findViewById(android.R.id.button2); + settingsButton.setVisibility(showSettings ? View.VISIBLE : View.INVISIBLE); settingsButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { - mBackend.launchSettings((DreamInfo)row.getTag()); - }}); - - // bind preview button - ((Button) row.findViewById(android.R.id.button3)).setOnClickListener(new OnClickListener(){ - @Override - public void onClick(View v) { - mBackend.preview((DreamInfo)row.getTag()); + mBackend.launchSettings((DreamInfo) row.getTag()); }}); return row; |