More traditional list item style for dreams settings.
Other improvements: - remove "Start dreaming now", promote "When to dream" to action bar - added logging - hide dream settings button if n/a - new flat style for settings/preview + dividers - refresh dreams list when packages are installed/uninstalled - added placeholder for help url Bug:7010260 Change-Id: Ia443b4f76678eaf1a52b907d50aefb0d8f7e4748
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 180 B |
Binary file not shown.
Before Width: | Height: | Size: 176 B |
Binary file not shown.
Before Width: | Height: | Size: 171 B |
Binary file not shown.
Before Width: | Height: | Size: 165 B |
Binary file not shown.
Before Width: | Height: | Size: 207 B |
Binary file not shown.
Before Width: | Height: | Size: 200 B |
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2012 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.
|
|
||||||
-->
|
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item android:drawable="@drawable/dream_info_bg_pressed" android:state_pressed="true"/>
|
|
||||||
<item android:drawable="@drawable/dream_info_bg_unpressed" android:state_pressed="false"/>
|
|
||||||
|
|
||||||
</selector>
|
|
@@ -16,19 +16,26 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/dream_info_bg"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:orientation="vertical" >
|
android:divider="?android:attr/dividerHorizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:showDividers="middle" >
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
android:id="@android:id/summary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" >
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true" >
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@android:id/icon"
|
android:id="@android:id/icon"
|
||||||
android:layout_width="@android:dimen/app_icon_size"
|
android:layout_width="@android:dimen/app_icon_size"
|
||||||
android:layout_height="@android:dimen/app_icon_size"
|
android:layout_height="@android:dimen/app_icon_size"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_margin="8dp"
|
android:layout_marginBottom="10dp"
|
||||||
|
android:layout_marginLeft="0dp"
|
||||||
|
android:layout_marginRight="6dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
android:contentDescription="@null"
|
android:contentDescription="@null"
|
||||||
android:scaleType="fitCenter" />
|
android:scaleType="fitCenter" />
|
||||||
|
|
||||||
@@ -38,7 +45,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_margin="8dp"
|
|
||||||
android:duplicateParentState="true" />
|
android:duplicateParentState="true" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -49,33 +55,42 @@
|
|||||||
android:layout_toLeftOf="@android:id/button1"
|
android:layout_toLeftOf="@android:id/button1"
|
||||||
android:layout_toRightOf="@android:id/icon"
|
android:layout_toRightOf="@android:id/icon"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:fontFamily="sans-serif-light"
|
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@android:id/widget_frame"
|
android:id="@android:id/widget_frame"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" >
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" >
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" >
|
android:layout_height="wrap_content"
|
||||||
|
android:divider="?android:attr/dividerVertical"
|
||||||
|
android:dividerPadding="12dp"
|
||||||
|
android:showDividers="middle" >
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@android:id/button2"
|
android:id="@android:id/button2"
|
||||||
|
style="@android:style/Widget.ActionButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/screensaver_settings_dream_settings" />
|
android:text="@string/screensaver_settings_dream_settings"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textSize="12dp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@android:id/button3"
|
android:id="@android:id/button3"
|
||||||
|
style="@android:style/Widget.ActionButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/screensaver_settings_dream_preview" />
|
android:text="@string/screensaver_settings_dream_preview"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textSize="12dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
@@ -4167,6 +4167,8 @@
|
|||||||
<string name="help_url_backup_reset" translatable="false"></string>
|
<string name="help_url_backup_reset" translatable="false"></string>
|
||||||
<!-- Help URL, Tethering [DO NOT TRANSLATE] -->
|
<!-- Help URL, Tethering [DO NOT TRANSLATE] -->
|
||||||
<string name="help_url_tether" translatable="false"></string>
|
<string name="help_url_tether" translatable="false"></string>
|
||||||
|
<!-- Help URL, Dreams [DO NOT TRANSLATE] -->
|
||||||
|
<string name="help_url_dreams" translatable="false"></string>
|
||||||
|
|
||||||
<!-- User account title [CHAR LIMIT=30] -->
|
<!-- User account title [CHAR LIMIT=30] -->
|
||||||
<string name="user_account_title">Account for content</string>
|
<string name="user_account_title">Account for content</string>
|
||||||
|
@@ -31,6 +31,7 @@ import android.os.ServiceManager;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.dreams.Dream;
|
import android.service.dreams.Dream;
|
||||||
import android.service.dreams.IDreamManager;
|
import android.service.dreams.IDreamManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -38,6 +39,7 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DreamBackend {
|
public class DreamBackend {
|
||||||
|
private static final String TAG = DreamSettings.class.getSimpleName() + ".Backend";
|
||||||
|
|
||||||
public static class DreamInfo {
|
public static class DreamInfo {
|
||||||
CharSequence caption;
|
CharSequence caption;
|
||||||
@@ -45,6 +47,18 @@ public class DreamBackend {
|
|||||||
boolean isActive;
|
boolean isActive;
|
||||||
public ComponentName componentName;
|
public ComponentName componentName;
|
||||||
public ComponentName settingsComponentName;
|
public ComponentName settingsComponentName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder(DreamInfo.class.getSimpleName());
|
||||||
|
sb.append('[').append(caption);
|
||||||
|
if (isActive)
|
||||||
|
sb.append(",active");
|
||||||
|
sb.append(',').append(componentName);
|
||||||
|
if (settingsComponentName != null)
|
||||||
|
sb.append("settings=").append(settingsComponentName);
|
||||||
|
return sb.append(']').toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -58,6 +72,7 @@ public class DreamBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<DreamInfo> getDreamInfos() {
|
public List<DreamInfo> getDreamInfos() {
|
||||||
|
logd("getDreamInfos()");
|
||||||
ComponentName activeDream = getActiveDream();
|
ComponentName activeDream = getActiveDream();
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
Intent dreamIntent = new Intent(Intent.ACTION_MAIN)
|
Intent dreamIntent = new Intent(Intent.ACTION_MAIN)
|
||||||
@@ -86,6 +101,7 @@ public class DreamBackend {
|
|||||||
try {
|
try {
|
||||||
return mDreamManager.getDefaultDreamComponent();
|
return mDreamManager.getDefaultDreamComponent();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Failed to get default dream", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,6 +111,7 @@ public class DreamBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabled(boolean value) {
|
public void setEnabled(boolean value) {
|
||||||
|
logd("setEnabled(%s)", value);
|
||||||
setBoolean(SCREENSAVER_ENABLED, value);
|
setBoolean(SCREENSAVER_ENABLED, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +120,7 @@ public class DreamBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setActivatedOnDock(boolean value) {
|
public void setActivatedOnDock(boolean value) {
|
||||||
|
logd("setActivatedOnDock(%s)", value);
|
||||||
setBoolean(SCREENSAVER_ACTIVATE_ON_DOCK, value);
|
setBoolean(SCREENSAVER_ACTIVATE_ON_DOCK, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +129,7 @@ public class DreamBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setActivatedOnSleep(boolean value) {
|
public void setActivatedOnSleep(boolean value) {
|
||||||
|
logd("setActivatedOnSleep(%s)", value);
|
||||||
setBoolean(SCREENSAVER_ACTIVATE_ON_SLEEP, value);
|
setBoolean(SCREENSAVER_ACTIVATE_ON_SLEEP, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,23 +141,15 @@ public class DreamBackend {
|
|||||||
Settings.Secure.putInt(mContext.getContentResolver(), key, value ? 1 : 0);
|
Settings.Secure.putInt(mContext.getContentResolver(), key, value ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDreamingNow() {
|
|
||||||
if (mDreamManager == null)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
mDreamManager.dream();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActiveDream(ComponentName dream) {
|
public void setActiveDream(ComponentName dream) {
|
||||||
|
logd("setActiveDream(%s)", dream);
|
||||||
if (mDreamManager == null)
|
if (mDreamManager == null)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
ComponentName[] dreams = { dream };
|
ComponentName[] dreams = { dream };
|
||||||
mDreamManager.setDreamComponents(dream == null ? null : dreams);
|
mDreamManager.setDreamComponents(dream == null ? null : dreams);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// noop
|
Log.w(TAG, "Failed to set active dream to " + dream, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,39 +160,49 @@ public class DreamBackend {
|
|||||||
ComponentName[] dreams = mDreamManager.getDreamComponents();
|
ComponentName[] dreams = mDreamManager.getDreamComponents();
|
||||||
return dreams != null && dreams.length > 0 ? dreams[0] : null;
|
return dreams != null && dreams.length > 0 ? dreams[0] : null;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Failed to get active dream", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void launchSettings(DreamInfo dreamInfo) {
|
public void launchSettings(DreamInfo dreamInfo) {
|
||||||
|
logd("launchSettings(%s)", dreamInfo);
|
||||||
if (dreamInfo == null || dreamInfo.settingsComponentName == null)
|
if (dreamInfo == null || dreamInfo.settingsComponentName == null)
|
||||||
return;
|
return;
|
||||||
mContext.startActivity(new Intent().setComponent(dreamInfo.settingsComponentName));
|
mContext.startActivity(new Intent().setComponent(dreamInfo.settingsComponentName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preview(DreamInfo dreamInfo) {
|
public void preview(DreamInfo dreamInfo) {
|
||||||
|
logd("preview(%s)", dreamInfo);
|
||||||
if (mDreamManager == null || dreamInfo == null || dreamInfo.componentName == null)
|
if (mDreamManager == null || dreamInfo == null || dreamInfo.componentName == null)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
mDreamManager.testDream(dreamInfo.componentName);
|
mDreamManager.testDream(dreamInfo.componentName);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// noop
|
Log.w(TAG, "Failed to preview " + dreamInfo, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComponentName getDreamComponentName(ResolveInfo ri) {
|
private static ComponentName getDreamComponentName(ResolveInfo resolveInfo) {
|
||||||
if (ri == null || ri.serviceInfo == null)
|
if (resolveInfo == null || resolveInfo.serviceInfo == null)
|
||||||
return null;
|
return null;
|
||||||
return new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name);
|
return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComponentName getSettingsComponentName(ResolveInfo ri) {
|
private static ComponentName getSettingsComponentName(ResolveInfo resolveInfo) {
|
||||||
if (ri == null || ri.serviceInfo == null || ri.serviceInfo.metaData == null)
|
if (resolveInfo == null
|
||||||
|
|| resolveInfo.serviceInfo == null
|
||||||
|
|| resolveInfo.serviceInfo.metaData == null)
|
||||||
return null;
|
return null;
|
||||||
String cn = ri.serviceInfo.metaData.getString(Dream.METADATA_NAME_CONFIG_ACTIVITY);
|
String cn = resolveInfo.serviceInfo.metaData.getString(Dream.METADATA_NAME_CONFIG_ACTIVITY);
|
||||||
return cn == null ? null : ComponentName.unflattenFromString(cn);
|
return cn == null ? null : ComponentName.unflattenFromString(cn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void logd(String msg, Object... args) {
|
||||||
|
if (DreamSettings.DEBUG)
|
||||||
|
Log.d(TAG, args == null || args.length == 0 ? msg : String.format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
private static class DreamInfoComparator implements Comparator<DreamInfo> {
|
private static class DreamInfoComparator implements Comparator<DreamInfo> {
|
||||||
private final ComponentName mDefaultDream;
|
private final ComponentName mDefaultDream;
|
||||||
|
|
||||||
|
@@ -20,11 +20,15 @@ import android.app.ActionBar;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Color;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -51,24 +55,35 @@ import com.android.settings.DreamBackend.DreamInfo;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DreamSettings extends SettingsPreferenceFragment {
|
public class DreamSettings extends SettingsPreferenceFragment {
|
||||||
|
private static final String TAG = DreamSettings.class.getSimpleName();
|
||||||
|
static final boolean DEBUG = false;
|
||||||
private static final int DIALOG_WHEN_TO_DREAM = 1;
|
private static final int DIALOG_WHEN_TO_DREAM = 1;
|
||||||
private static final int DIVIDER_HEIGHT = 15;
|
private static final String PACKAGE_SCHEME = "package";
|
||||||
|
|
||||||
|
private final PackageReceiver mPackageReceiver = new PackageReceiver();
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private DreamBackend mBackend;
|
private DreamBackend mBackend;
|
||||||
private DreamInfoAdapter mAdapter;
|
private DreamInfoAdapter mAdapter;
|
||||||
private Switch mSwitch;
|
private Switch mSwitch;
|
||||||
private MenuItem[] mDependentMenuItems;
|
private MenuItem mWhenToDream;
|
||||||
private boolean mRefreshing;
|
private boolean mRefreshing;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
return R.string.help_url_dreams;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
|
logd("onAttach(%s)", activity.getClass().getSimpleName());
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
mContext = activity;
|
mContext = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
|
logd("onCreate(%s)", icicle);
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
|
||||||
@@ -102,6 +117,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
logd("onActivityCreated(%s)", savedInstanceState);
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
ListView listView = getListView();
|
ListView listView = getListView();
|
||||||
@@ -112,48 +128,24 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
mAdapter = new DreamInfoAdapter(mContext);
|
mAdapter = new DreamInfoAdapter(mContext);
|
||||||
listView.setAdapter(mAdapter);
|
listView.setAdapter(mAdapter);
|
||||||
listView.setDivider(null);
|
|
||||||
listView.setDividerHeight(DIVIDER_HEIGHT);
|
|
||||||
listView.setBackgroundColor(Color.BLACK);
|
|
||||||
listView.setPadding(0, DIVIDER_HEIGHT, 0, DIVIDER_HEIGHT);
|
|
||||||
listView.setHeaderDividersEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
logd("onCreateOptionsMenu()");
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
|
||||||
boolean isEnabled = mBackend.isEnabled();
|
boolean isEnabled = mBackend.isEnabled();
|
||||||
|
|
||||||
MenuItem whenToDream = createMenuItem(menu,
|
mWhenToDream = createMenuItem(menu,
|
||||||
R.string.screensaver_settings_when_to_dream,
|
R.string.screensaver_settings_when_to_dream,
|
||||||
MenuItem.SHOW_AS_ACTION_NEVER,
|
MenuItem.SHOW_AS_ACTION_ALWAYS,
|
||||||
isEnabled,
|
isEnabled,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
showDialog(DIALOG_WHEN_TO_DREAM);
|
showDialog(DIALOG_WHEN_TO_DREAM);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
createMenuItem(menu,
|
|
||||||
R.string.help_label,
|
|
||||||
MenuItem.SHOW_AS_ACTION_NEVER,
|
|
||||||
true,
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// TODO show help url
|
|
||||||
}});
|
|
||||||
|
|
||||||
MenuItem startDreaming = createMenuItem(menu,
|
|
||||||
R.string.screensaver_settings_start_dreaming,
|
|
||||||
MenuItem.SHOW_AS_ACTION_ALWAYS,
|
|
||||||
isEnabled,
|
|
||||||
new Runnable(){
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mBackend.startDreamingNow();
|
|
||||||
}});
|
|
||||||
|
|
||||||
mDependentMenuItems = new MenuItem[] { whenToDream, startDreaming };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MenuItem createMenuItem(Menu menu,
|
private MenuItem createMenuItem(Menu menu,
|
||||||
@@ -173,6 +165,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(int dialogId) {
|
public Dialog onCreateDialog(int dialogId) {
|
||||||
|
logd("onCreateDialog(%s)", dialogId);
|
||||||
if (dialogId == DIALOG_WHEN_TO_DREAM)
|
if (dialogId == DIALOG_WHEN_TO_DREAM)
|
||||||
return createWhenToDreamDialog();
|
return createWhenToDreamDialog();
|
||||||
return super.onCreateDialog(dialogId);
|
return super.onCreateDialog(dialogId);
|
||||||
@@ -201,10 +194,27 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
logd("onPause()");
|
||||||
|
super.onPause();
|
||||||
|
mContext.unregisterReceiver(mPackageReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
logd("onResume()");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
refreshFromBackend();
|
refreshFromBackend();
|
||||||
|
|
||||||
|
// listen for package changes
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||||
|
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
||||||
|
filter.addDataScheme(PACKAGE_SCHEME);
|
||||||
|
mContext.registerReceiver(mPackageReceiver , filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSummaryResource(Context context) {
|
public static int getSummaryResource(Context context) {
|
||||||
@@ -221,6 +231,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshFromBackend() {
|
private void refreshFromBackend() {
|
||||||
|
logd("refreshFromBackend()");
|
||||||
mRefreshing = true;
|
mRefreshing = true;
|
||||||
boolean dreamsEnabled = mBackend.isEnabled();
|
boolean dreamsEnabled = mBackend.isEnabled();
|
||||||
if (mSwitch.isChecked() != dreamsEnabled)
|
if (mSwitch.isChecked() != dreamsEnabled)
|
||||||
@@ -231,12 +242,17 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
List<DreamInfo> dreamInfos = mBackend.getDreamInfos();
|
List<DreamInfo> dreamInfos = mBackend.getDreamInfos();
|
||||||
mAdapter.addAll(dreamInfos);
|
mAdapter.addAll(dreamInfos);
|
||||||
}
|
}
|
||||||
if (mDependentMenuItems != null)
|
if (mWhenToDream != null)
|
||||||
for (MenuItem item : mDependentMenuItems)
|
mWhenToDream.setEnabled(dreamsEnabled);
|
||||||
item.setEnabled(dreamsEnabled);
|
|
||||||
mRefreshing = false;
|
mRefreshing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void logd(String msg, Object... args) {
|
||||||
|
if (DEBUG)
|
||||||
|
Log.d(TAG, args == null || args.length == 0 ? msg : String.format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private class DreamInfoAdapter extends ArrayAdapter<DreamInfo> {
|
private class DreamInfoAdapter extends ArrayAdapter<DreamInfo> {
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
@@ -248,6 +264,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
DreamInfo dreamInfo = getItem(position);
|
DreamInfo dreamInfo = getItem(position);
|
||||||
|
logd("getView(%s)", dreamInfo.caption);
|
||||||
final View row = convertView != null ? convertView : createDreamInfoRow(parent);
|
final View row = convertView != null ? convertView : createDreamInfoRow(parent);
|
||||||
row.setTag(dreamInfo);
|
row.setTag(dreamInfo);
|
||||||
|
|
||||||
@@ -258,8 +275,9 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
((TextView) row.findViewById(android.R.id.text1)).setText(dreamInfo.caption);
|
((TextView) row.findViewById(android.R.id.text1)).setText(dreamInfo.caption);
|
||||||
|
|
||||||
// bind radio button
|
// bind radio button
|
||||||
((RadioButton) row.findViewById(android.R.id.button1)).setChecked(dreamInfo.isActive);
|
RadioButton radioButton = (RadioButton) row.findViewById(android.R.id.button1);
|
||||||
((RadioButton) row.findViewById(android.R.id.button1)).setOnTouchListener(new OnTouchListener() {
|
radioButton.setChecked(dreamInfo.isActive);
|
||||||
|
radioButton.setOnTouchListener(new OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
row.onTouchEvent(event);
|
row.onTouchEvent(event);
|
||||||
@@ -267,11 +285,13 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
// bind button container
|
// bind button container
|
||||||
row.findViewById(android.R.id.widget_frame).setVisibility(dreamInfo.isActive ? View.VISIBLE : View.GONE);
|
View widgetFrame = row.findViewById(android.R.id.widget_frame);
|
||||||
|
widgetFrame.setVisibility(dreamInfo.isActive ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
// bind settings button
|
// bind settings button
|
||||||
((Button) row.findViewById(android.R.id.button2)).setEnabled(dreamInfo.settingsComponentName != null);
|
Button settingsButton = (Button) row.findViewById(android.R.id.button2);
|
||||||
((Button) row.findViewById(android.R.id.button2)).setOnClickListener(new OnClickListener(){
|
settingsButton.setVisibility(dreamInfo.settingsComponentName != null ? View.VISIBLE : View.GONE);
|
||||||
|
settingsButton.setOnClickListener(new OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mBackend.launchSettings((DreamInfo)row.getTag());
|
mBackend.launchSettings((DreamInfo)row.getTag());
|
||||||
@@ -298,7 +318,17 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DreamInfo getCurrentSelection() {
|
||||||
|
for (int i = 0; i < getCount(); i++) {
|
||||||
|
DreamInfo dreamInfo = getItem(i);
|
||||||
|
if (dreamInfo.isActive)
|
||||||
|
return dreamInfo;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private void activate(DreamInfo dreamInfo) {
|
private void activate(DreamInfo dreamInfo) {
|
||||||
|
if (dreamInfo.equals(getCurrentSelection()))
|
||||||
|
return;
|
||||||
for (int i = 0; i < getCount(); i++) {
|
for (int i = 0; i < getCount(); i++) {
|
||||||
getItem(i).isActive = false;
|
getItem(i).isActive = false;
|
||||||
}
|
}
|
||||||
@@ -307,4 +337,12 @@ public class DreamSettings extends SettingsPreferenceFragment {
|
|||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class PackageReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
logd("PackageReceiver.onReceive");
|
||||||
|
refreshFromBackend();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user