summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Charlton <evancharlton@gmail.com>2011-05-16 01:27:22 -0400
committerEvan Charlton <evancharlton@gmail.com>2011-05-16 01:30:19 -0400
commit82bb3a4395dea872eb6476423d49cdfc0a6f415f (patch)
tree176435fe94ace2cfdd618387d37fb6159de84e53
parent15682bc6e7cf2f6c5308b0ada3ff0a9ef8d8b53d (diff)
downloadandroid_packages_apps_DeskClock-82bb3a4395dea872eb6476423d49cdfc0a6f415f.tar.gz
android_packages_apps_DeskClock-82bb3a4395dea872eb6476423d49cdfc0a6f415f.tar.bz2
android_packages_apps_DeskClock-82bb3a4395dea872eb6476423d49cdfc0a6f415f.zip
Display application icon and title in alarm config
When setting an application to launch, the icon and title of the app should be displayed, rather than the intent string/URI. Change-Id: Ibf6e9e4cac547da55541e5a17b2b2bb584aeec2f
-rw-r--r--res/layout/preference_intent.xml65
-rw-r--r--res/values/attrs.xml21
-rw-r--r--res/xml/alarm_prefs.xml2
-rw-r--r--src/com/android/deskclock/IntentPreferenceScreen.java133
-rw-r--r--src/com/android/deskclock/SetAlarm.java23
5 files changed, 231 insertions, 13 deletions
diff --git a/res/layout/preference_intent.xml b/res/layout/preference_intent.xml
new file mode 100644
index 000000000..33d9b7b4d
--- /dev/null
+++ b/res/layout/preference_intent.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- Layout for a Preference in a PreferenceActivity. The
+ Preference is able to place a specific widget for its particular
+ type in the "widget_frame" layout. -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+android:id/widget_frame"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
+ android:paddingRight="?android:attr/scrollbarSize"
+ android:paddingLeft="15dp">
+
+ <RelativeLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="2dip"
+ android:layout_marginRight="6dip"
+ android:layout_marginTop="6dip"
+ android:layout_marginBottom="6dip"
+ android:layout_weight="1">
+
+ <TextView android:id="@android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal" />
+
+ <TextView android:id="@android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@android:id/title"
+ android:layout_alignLeft="@android:id/title"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:maxLines="2" />
+
+ </RelativeLayout>
+
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="6dip"
+ android:layout_marginRight="6dip"
+ android:layout_gravity="center" />
+
+</LinearLayout>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
new file mode 100644
index 000000000..88e0455d5
--- /dev/null
+++ b/res/values/attrs.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <declare-styleable name="IntentPreferenceScreen">
+ <attr name="icon" format="reference" />
+ </declare-styleable>
+</resources>
diff --git a/res/xml/alarm_prefs.xml b/res/xml/alarm_prefs.xml
index a76049d3b..22fc221bb 100644
--- a/res/xml/alarm_prefs.xml
+++ b/res/xml/alarm_prefs.xml
@@ -40,7 +40,7 @@
android:persistent="false"
android:title="@string/label"
android:dialogTitle="@string/label" />
- <Preference android:key="intent"
+ <com.android.deskclock.IntentPreferenceScreen android:key="intent"
android:persistent="false"
android:title="@string/application" />
<CheckBoxPreference android:key="no_dialog"
diff --git a/src/com/android/deskclock/IntentPreferenceScreen.java b/src/com/android/deskclock/IntentPreferenceScreen.java
new file mode 100644
index 000000000..edd9e16e2
--- /dev/null
+++ b/src/com/android/deskclock/IntentPreferenceScreen.java
@@ -0,0 +1,133 @@
+/*
+ * 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.deskclock;
+
+import java.net.URISyntaxException;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.ImageView;
+
+/**
+ * Preference used to conveniently store a reference to an Intent. Will
+ * automatically update the UI with the application's title and icon as
+ * appropriate.
+ */
+public class IntentPreferenceScreen extends Preference {
+
+ private Drawable mIcon;
+
+ private ImageView mIconView;
+
+ private Intent mIntent;
+
+ public IntentPreferenceScreen(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public IntentPreferenceScreen(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ setLayoutResource(R.layout.preference_intent);
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ R.styleable.IntentPreferenceScreen, defStyle, 0);
+ mIcon = a.getDrawable(R.styleable.IntentPreferenceScreen_icon);
+ }
+
+ /**
+ * Update the stored intent
+ *
+ * @param intent new Intent
+ */
+ public void updateIntent(Intent intent) {
+ mIntent = intent;
+
+ if (mIntent != null) {
+ setSummary(intent.toUri(Intent.URI_INTENT_SCHEME));
+ try {
+ String packageName = mIntent.getComponent().getPackageName();
+ PackageManager packageManager = getContext().getPackageManager();
+ ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0);
+ setSummary(packageManager.getApplicationLabel(info));
+ mIcon = packageManager.getApplicationIcon(packageName);
+ } catch (NameNotFoundException e) {
+ Log.e("Could not find package", e);
+ }
+ } else {
+ setSummary("");
+ mIcon = null;
+ }
+
+ updateIcon();
+ }
+
+ /**
+ * Update the stored intent based on the string representation of the
+ * intent. See {@link #getIntentString()}.
+ *
+ * @param intentUri string representation of the new Intent to use
+ */
+ public void updateIntent(String intentUri) {
+ if (intentUri == null) {
+ clearIntent();
+ }
+
+ try {
+ updateIntent(Intent.parseUri(intentUri, Intent.URI_INTENT_SCHEME));
+ } catch (URISyntaxException e) {
+ Log.i("Unable to parse intent: " + intentUri);
+ }
+ }
+
+ /**
+ * Erases the stored intent and resets the UI
+ */
+ public void clearIntent() {
+ updateIntent((Intent) null);
+ }
+
+ /**
+ * @return a string representation of the saved intent or null if no intent
+ * set
+ */
+ public String getIntentString() {
+ if (mIntent == null)
+ return null;
+
+ return mIntent.toUri(Intent.URI_INTENT_SCHEME);
+ }
+
+ private void updateIcon() {
+ if (mIconView != null) {
+ mIconView.setImageDrawable(mIcon);
+ }
+ }
+
+ @Override
+ public void onBindView(View view) {
+ super.onBindView(view);
+ mIconView = (ImageView) view.findViewById(android.R.id.icon);
+ updateIcon();
+ }
+}
diff --git a/src/com/android/deskclock/SetAlarm.java b/src/com/android/deskclock/SetAlarm.java
index db0ced7e7..8e31902e8 100644
--- a/src/com/android/deskclock/SetAlarm.java
+++ b/src/com/android/deskclock/SetAlarm.java
@@ -16,6 +16,7 @@
package com.android.deskclock;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import android.app.AlertDialog;
@@ -24,6 +25,9 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
@@ -32,15 +36,9 @@ import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.text.format.DateFormat;
-import android.view.LayoutInflater;
-import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.ListView;
import android.widget.TimePicker;
import android.widget.Toast;
@@ -60,7 +58,7 @@ public class SetAlarm extends PreferenceActivity
private CheckBoxPreference mVibratePref;
private RepeatPreference mRepeatPref;
private MenuItem mTestAlarmItem;
- private Preference mIntentPref;
+ private IntentPreferenceScreen mIntentPref;
private CheckBoxPreference mNoDialogPref;
private int mId;
@@ -121,7 +119,7 @@ public class SetAlarm extends PreferenceActivity
mRepeatPref.setOnPreferenceChangeListener(this);
mNoDialogPref = (CheckBoxPreference) findPreference("no_dialog");
mNoDialogPref.setOnPreferenceChangeListener(this);
- mIntentPref = findPreference("intent");
+ mIntentPref = (IntentPreferenceScreen) findPreference("intent");
Intent i = getIntent();
mId = i.getIntExtra(Alarms.ALARM_ID, -1);
@@ -221,7 +219,8 @@ public class SetAlarm extends PreferenceActivity
mVibratePref.setChecked(alarm.vibrate);
// Give the alert uri to the preference.
mAlarmPref.setAlert(alarm.alert);
- mIntentPref.setSummary(alarm.intent);
+ mIntentPref.updateIntent(alarm.intent);
+
updateTime();
updateNoDialog(alarm);
}
@@ -290,9 +289,9 @@ public class SetAlarm extends PreferenceActivity
String none = getString(R.string.application_none);
if (none.equals(data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME))) {
- mIntentPref.setSummary("");
+ mIntentPref.clearIntent();
} else {
- mIntentPref.setSummary(data.toUri(Intent.URI_INTENT_SCHEME));
+ mIntentPref.updateIntent(data);
}
}
@@ -347,7 +346,7 @@ public class SetAlarm extends PreferenceActivity
alarm.vibrate = mVibratePref.isChecked();
alarm.label = mLabel.getText();
alarm.alert = mAlarmPref.getAlert();
- CharSequence intent = mIntentPref.getSummary();
+ CharSequence intent = mIntentPref.getIntentString();
alarm.intent = intent == null ? "" : intent.toString();
alarm.noDialog = mNoDialogPref.isChecked();
updateNoDialog(alarm);