First cut voicemail source status message ui.
The UI right now is very basic.
Also renamed Message to StatusMessage to avoid conflict with
android.os.Message used in the call fragment code.
TODO:
- make the UI look nicer.
- show more than one messages
- make db call asynchronously
Change-Id: I10c1be8a37990104b5fe428c61964e7a78b7fd46
diff --git a/res/layout/call_log_fragment.xml b/res/layout/call_log_fragment.xml
index 2a27fcd..573969b 100644
--- a/res/layout/call_log_fragment.xml
+++ b/res/layout/call_log_fragment.xml
@@ -14,21 +14,29 @@
limitations under the License.
-->
-<FrameLayout 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_height="match_parent"
+ android:orientation="vertical"
>
- <ListView android:id="@android:id/list"
+ <include layout="@layout/call_log_voicemail_status"/>
+ <FrameLayout
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scrollbarStyle="outsideOverlay"
- />
+ android:layout_height="wrap_content"
+ >
+ <ListView android:id="@android:id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:scrollbarStyle="outsideOverlay"
+ />
- <TextView android:id="@android:id/empty"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/recentCalls_empty"
- android:gravity="center"
- android:textAppearance="?android:attr/textAppearanceLarge"
- />
-</FrameLayout>
+ <TextView android:id="@android:id/empty"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="@string/recentCalls_empty"
+ android:gravity="center"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ />
+ </FrameLayout>
+</LinearLayout>
+
diff --git a/res/layout/call_log_voicemail_status.xml b/res/layout/call_log_voicemail_status.xml
new file mode 100644
index 0000000..1abe998
--- /dev/null
+++ b/res/layout/call_log_voicemail_status.xml
@@ -0,0 +1,52 @@
+<?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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/voicemail_status"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/call_log_voicemail_status_height"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentBottom="true"
+ android:background="?attr/call_log_voicemail_status_background_color"
+ android:baselineAligned="false">
+ <TextView
+ android:id="@+id/voicemail_status_message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingLeft="14dip"
+ android:paddingRight="14dip"
+ android:textColor="?attr/call_log_voicemail_status_text_color"
+ android:layout_gravity="left"
+ android:layout_weight="5"/>
+ <View android:id="@+id/divider"
+ android:layout_width="1px"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dip"
+ android:layout_marginBottom="5dip"
+ android:layout_marginLeft="11dip"
+ android:background="@drawable/divider_vertical_dark"/>
+ <TextView
+ android:id="@+id/voicemail_status_action"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:paddingLeft="14dip"
+ android:paddingRight="14dip"
+ android:textColor="?attr/call_log_voicemail_status_text_color"
+ android:gravity="right"
+ android:layout_alignParentRight="true"
+ android:clickable="true"
+ />
+</LinearLayout>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 4638b2e..43ea301 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -49,6 +49,10 @@
<item name="call_log_primary_background_color">#000000</item>
<item name="call_log_secondary_text_color">#FFFFFF</item>
<item name="call_log_secondary_background_color">#333333</item>
+ <!-- VoicemailStatus -->
+ <item name="call_log_voicemail_status_height">40dip</item>
+ <item name="call_log_voicemail_status_background_color">#FFFFE0</item>
+ <item name="call_log_voicemail_status_text_color">#000000</item>
</style>
<style name="CallDetailActivityTheme" parent="android:Theme.Holo">
@@ -161,6 +165,12 @@
<attr name="call_log_list_header_background" format="reference" />
</declare-styleable>
+ <declare-styleable name="VoicemailStatus">
+ <attr name="call_log_voicemail_status_height" format="dimension" />
+ <attr name="call_log_voicemail_status_background_color" format="color" />
+ <attr name="call_log_voicemail_status_text_color" format="color" />
+ </declare-styleable>
+
<style name="PeopleTheme" parent="android:Theme.Holo.Light.SplitActionBarWhenNarrow">
<item name="list_item_height">?android:attr/listPreferredItemHeight</item>
<item name="activated_background">@drawable/list_item_activated_background</item>
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index cd95c88..d4871ec 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -25,6 +25,7 @@
import com.android.contacts.R;
import com.android.contacts.activities.DialtactsActivity;
import com.android.contacts.activities.DialtactsActivity.ViewPagerVisibilityListener;
+import com.android.contacts.calllog.VoicemailStatusHelper.StatusMessage;
import com.android.contacts.util.ExpirableCache;
import com.android.internal.telephony.CallerInfo;
import com.google.common.annotations.VisibleForTesting;
@@ -59,8 +60,10 @@
import android.view.ViewTreeObserver;
import android.widget.ListView;
import android.widget.QuickContactBadge;
+import android.widget.TextView;
import java.util.LinkedList;
+import java.util.List;
/**
@@ -142,6 +145,11 @@
private boolean mShowOptionsMenu;
+ private VoicemailStatusHelper mVoicemailStatusHelper;
+ private View mStatusMessageView;
+ private TextView mStatusMessageText;
+ private TextView mStatusMessageAction;
+
public static final class ContactInfo {
public long personId;
public String name;
@@ -829,7 +837,12 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
- return inflater.inflate(R.layout.call_log_fragment, container, false);
+ View view = inflater.inflate(R.layout.call_log_fragment, container, false);
+ mVoicemailStatusHelper = new VoicemailStatusHelperImpl(getActivity().getContentResolver());
+ mStatusMessageView = view.findViewById(R.id.voicemail_status);
+ mStatusMessageText = (TextView) view.findViewById(R.id.voicemail_status_message);
+ mStatusMessageAction = (TextView) view.findViewById(R.id.voicemail_status_action);
+ return view;
}
@Override
@@ -855,12 +868,42 @@
startQuery();
resetNewCallsFlag();
-
+ updateVoicemailStatusMessage();
super.onResume();
mAdapter.mPreDrawListener = null; // Let it restart the thread after next draw
}
+ private void updateVoicemailStatusMessage() {
+ // TODO: make call to mVoicemailStatusHelper asynchronously.
+ List<StatusMessage> messages = mVoicemailStatusHelper.getStatusMessages();
+ if (messages.size() == 0) {
+ mStatusMessageView.setVisibility(View.GONE);
+ } else {
+ mStatusMessageView.setVisibility(View.VISIBLE);
+ // TODO: Change the code to show all messages. For now just pick the first message.
+ final StatusMessage message = messages.get(0);
+ if (message.statusMessageId != -1) {
+ mStatusMessageText.setText(message.statusMessageId);
+ }
+ if (message.actionMessageId != -1) {
+ mStatusMessageAction.setText(message.actionMessageId);
+ }
+ if (message.actionUri != null) {
+ mStatusMessageAction.setClickable(true);
+ mStatusMessageAction.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getActivity().startActivity(
+ new Intent(Intent.ACTION_VIEW, message.actionUri));
+ }
+ });
+ } else {
+ mStatusMessageAction.setClickable(false);
+ }
+ }
+ }
+
@Override
public void onPause() {
super.onPause();
diff --git a/src/com/android/contacts/calllog/VoicemailStatusHelper.java b/src/com/android/contacts/calllog/VoicemailStatusHelper.java
index d4a3965..607d31a 100644
--- a/src/com/android/contacts/calllog/VoicemailStatusHelper.java
+++ b/src/com/android/contacts/calllog/VoicemailStatusHelper.java
@@ -30,7 +30,7 @@
* this class to check if any message needs to be shown.
*/
public interface VoicemailStatusHelper {
- public class Message {
+ public class StatusMessage {
/** Package of the source on behalf of which this message has to be shown.*/
public final String sourcePackage;
/** The string resource id of the status message that should be shown. */
@@ -39,7 +39,7 @@
public final int actionMessageId;
/** URI for the corrective action, where applicable. Null if no action URI is available. */
public final Uri actionUri;
- public Message(String sourcePackage, int statusMessageId, int actionMessageId,
+ public StatusMessage(String sourcePackage, int statusMessageId, int actionMessageId,
Uri actionUri) {
this.sourcePackage = sourcePackage;
this.statusMessageId = statusMessageId;
@@ -52,5 +52,5 @@
* Returns a list of messages, in the order or priority that should be shown to the user. An
* empty list is returned if no message needs to be shown.
*/
- public List<Message> getStatusMessages();
+ public List<StatusMessage> getStatusMessages();
}
diff --git a/src/com/android/contacts/calllog/VoicemailStatusHelperImpl.java b/src/com/android/contacts/calllog/VoicemailStatusHelperImpl.java
index 9738fd7..690f102 100644
--- a/src/com/android/contacts/calllog/VoicemailStatusHelperImpl.java
+++ b/src/com/android/contacts/calllog/VoicemailStatusHelperImpl.java
@@ -133,26 +133,26 @@
mContentResolver = contentResolver;
}
- /** A wrapper on {@link Message} which additionally stores the priority of the message. */
- private static class MessageWrapper {
- private final Message mMessage;
+ /** A wrapper on {@link StatusMessage} which additionally stores the priority of the message. */
+ private static class MessageStatusWithPriority {
+ private final StatusMessage mMessage;
private final int mPriority;
- public MessageWrapper(Message message, int priority) {
+ public MessageStatusWithPriority(StatusMessage message, int priority) {
mMessage = message;
mPriority = priority;
}
}
@Override
- public List<Message> getStatusMessages() {
+ public List<StatusMessage> getStatusMessages() {
Cursor cursor = null;
try {
cursor = mContentResolver.query(Status.CONTENT_URI, PROJECTION, null, null, null);
- List<MessageWrapper> messages =
- new ArrayList<VoicemailStatusHelperImpl.MessageWrapper>();
+ List<MessageStatusWithPriority> messages =
+ new ArrayList<VoicemailStatusHelperImpl.MessageStatusWithPriority>();
while(cursor.moveToNext()) {
- MessageWrapper message = getMessageForStatusEntry(cursor);
+ MessageStatusWithPriority message = getMessageForStatusEntry(cursor);
if (message != null) {
messages.add(message);
}
@@ -164,16 +164,16 @@
}
}
- private List<Message> reorderMessages(List<MessageWrapper> messageWrappers) {
- Collections.sort(messageWrappers, new Comparator<MessageWrapper>() {
+ private List<StatusMessage> reorderMessages(List<MessageStatusWithPriority> messageWrappers) {
+ Collections.sort(messageWrappers, new Comparator<MessageStatusWithPriority>() {
@Override
- public int compare(MessageWrapper msg1, MessageWrapper msg2) {
+ public int compare(MessageStatusWithPriority msg1, MessageStatusWithPriority msg2) {
return msg1.mPriority - msg2.mPriority;
}
});
- List<Message> reorderMessages = new ArrayList<VoicemailStatusHelper.Message>();
+ List<StatusMessage> reorderMessages = new ArrayList<VoicemailStatusHelper.StatusMessage>();
// Copy the ordered message objects into the final list.
- for (MessageWrapper messageWrapper : messageWrappers) {
+ for (MessageStatusWithPriority messageWrapper : messageWrappers) {
reorderMessages.add(messageWrapper.mMessage);
}
return reorderMessages;
@@ -182,7 +182,7 @@
/**
* Returns the message for the status entry pointed to by the cursor.
*/
- private MessageWrapper getMessageForStatusEntry(Cursor cursor) {
+ private MessageStatusWithPriority getMessageForStatusEntry(Cursor cursor) {
final String sourcePackage = cursor.getString(SOURCE_PACKAGE_INDEX);
if (sourcePackage == null) {
return null;
@@ -203,8 +203,8 @@
} else if (action == Action.CONFIGURE_VOICEMAIL) {
actionUri = Uri.parse(cursor.getString(SETTINGS_URI_INDEX));
}
- return new MessageWrapper(
- new Message(sourcePackage, overallState.getMessageId(), action.getMessageId(),
+ return new MessageStatusWithPriority(
+ new StatusMessage(sourcePackage, overallState.getMessageId(), action.getMessageId(),
actionUri),
overallState.getPriority());
}
diff --git a/tests/src/com/android/contacts/calllog/VoicemailStatusHelperImplTest.java b/tests/src/com/android/contacts/calllog/VoicemailStatusHelperImplTest.java
index d577d4c..c6bff13 100644
--- a/tests/src/com/android/contacts/calllog/VoicemailStatusHelperImplTest.java
+++ b/tests/src/com/android/contacts/calllog/VoicemailStatusHelperImplTest.java
@@ -28,7 +28,7 @@
import static android.provider.VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE_OK;
import com.android.contacts.R;
-import com.android.contacts.calllog.VoicemailStatusHelper.Message;
+import com.android.contacts.calllog.VoicemailStatusHelper.StatusMessage;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -50,7 +50,8 @@
private static final Uri TEST_SETTINGS_URI = Uri.parse("http://www.visual.voicemail.setup");
private static final Uri TEST_VOICEMAIL_URI = Uri.parse("tel:901");
- private static final int ACTION_MSG_CALL_VOICEMAIL = R.string.voicemail_status_action_call_server;
+ private static final int ACTION_MSG_CALL_VOICEMAIL =
+ R.string.voicemail_status_action_call_server;
private static final int ACTION_MSG_CONFIGURE = R.string.voicemail_status_action_configure;
private static final int STATUS_MSG_VOICEMAIL_NOT_AVAILABLE =
@@ -166,7 +167,7 @@
// package2 with valuesNoNotificationNoDataChannel. Package2 should be above.
updateEntryForPackage(TEST_PACKAGE_1, valuesNoNotificationGoodDataChannel);
updateEntryForPackage(TEST_PACKAGE_2, valuesNoNotificationNoDataChannel);
- List<Message> messages = mStatusHelper.getStatusMessages();
+ List<StatusMessage> messages = mStatusHelper.getStatusMessages();
assertEquals(2, messages.size());
assertEquals(TEST_PACKAGE_1, messages.get(1).sourcePackage);
assertEquals(TEST_PACKAGE_2, messages.get(0).sourcePackage);
@@ -189,13 +190,13 @@
private void checkExpectedMessage(String sourcePackage, ContentValues values,
int expectedStatusMsg, int expectedActionMsg, Uri expectedUri) {
- List<Message> messages = mStatusHelper.getStatusMessages();
+ List<StatusMessage> messages = mStatusHelper.getStatusMessages();
assertEquals(1, messages.size());
checkMessageMatches(messages.get(0), sourcePackage, expectedStatusMsg, expectedActionMsg,
expectedUri);
}
- private void checkMessageMatches(Message message, String expectedSourcePackage,
+ private void checkMessageMatches(StatusMessage message, String expectedSourcePackage,
int expectedStatusMsg, int expectedActionMsg, Uri expectedUri) {
assertEquals(expectedSourcePackage, message.sourcePackage);
assertEquals(expectedStatusMsg, message.statusMessageId);
@@ -209,7 +210,7 @@
private void checkNoMessages(String sourcePackage, ContentValues values) {
assertEquals(1, updateEntryForPackage(sourcePackage, values));
- List<Message> messages = mStatusHelper.getStatusMessages();
+ List<StatusMessage> messages = mStatusHelper.getStatusMessages();
assertEquals(0, messages.size());
}