Makes the call details scrollable.
This change makes the call detail activity scrollable, making it easier
to see the details of multiple calls.
In order to make sure the main controls are always visible, it only
scrolls out the picture view, but always keeps the rest in view.
Bug: 5041805
Change-Id: I40b87efecfe3c921aab831e83dbff806b10b9c9f
diff --git a/src/com/android/contacts/BackScrollManager.java b/src/com/android/contacts/BackScrollManager.java
new file mode 100644
index 0000000..192b79e
--- /dev/null
+++ b/src/com/android/contacts/BackScrollManager.java
@@ -0,0 +1,89 @@
+/*
+ * 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.contacts;
+
+import android.view.View;
+import android.widget.AbsListView;
+import android.widget.ListView;
+
+/**
+ * Handles scrolling back of a list tied to a header.
+ * <p>
+ * This is used to implement a header that scrolls up with the content of a list to be partially
+ * obscured.
+ */
+public class BackScrollManager {
+ /** Defines the header to be scrolled. */
+ public interface ScrollableHeader {
+ /** Sets the offset by which to scroll. */
+ public void setOffset(int offset);
+ /** Gets the maximum offset that should be applied to the header. */
+ public int getMaximumScrollableHeaderOffset();
+ }
+
+ private final ScrollableHeader mHeader;
+ private final ListView mListView;
+
+ private final AbsListView.OnScrollListener mScrollListener =
+ new AbsListView.OnScrollListener() {
+ @Override
+ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
+ int totalItemCount) {
+ if (firstVisibleItem != 0) {
+ // The first item is not shown, the header should be pinned at the top.
+ mHeader.setOffset(mHeader.getMaximumScrollableHeaderOffset());
+ return;
+ }
+
+ View firstVisibleItemView = view.getChildAt(firstVisibleItem);
+ if (firstVisibleItemView == null) {
+ return;
+ }
+ // We scroll the header up, but at most pin it to the top of the screen.
+ int offset = Math.min(
+ (int) -view.getChildAt(firstVisibleItem).getY(),
+ mHeader.getMaximumScrollableHeaderOffset());
+ mHeader.setOffset(offset);
+ }
+
+ @Override
+ public void onScrollStateChanged(AbsListView view, int scrollState) {
+ // Nothing to do here.
+ }
+ };
+
+ /**
+ * Creates a new instance of a {@link BackScrollManager} that connected the header and the list
+ * view.
+ */
+ public static void bind(ScrollableHeader header, ListView listView) {
+ BackScrollManager backScrollManager = new BackScrollManager(header, listView);
+ backScrollManager.bind();
+ }
+
+ private BackScrollManager(ScrollableHeader header, ListView listView) {
+ mHeader = header;
+ mListView = listView;
+ }
+
+ private void bind() {
+ mListView.setOnScrollListener(mScrollListener);
+ // We disable the scroll bar because it would otherwise be incorrect because of the hidden
+ // header.
+ mListView.setVerticalScrollBarEnabled(false);
+ }
+}
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index 14b38b9..aa52d91 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -16,6 +16,7 @@
package com.android.contacts;
+import com.android.contacts.BackScrollManager.ScrollableHeader;
import com.android.contacts.calllog.CallDetailHistoryAdapter;
import com.android.contacts.calllog.CallTypeHelper;
import com.android.contacts.calllog.PhoneNumberHelper;
@@ -434,7 +435,25 @@
ListView historyList = (ListView) findViewById(R.id.history);
historyList.setAdapter(
new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater,
- mCallTypeHelper, details));
+ mCallTypeHelper, details, hasVoicemail(), canPlaceCallsTo));
+ BackScrollManager.bind(
+ new ScrollableHeader() {
+ private View controls = findViewById(R.id.controls);
+ private View photo = findViewById(R.id.contact_background_sizer);
+ private View nameHeader = findViewById(R.id.photo_text_bar);
+
+ @Override
+ public void setOffset(int offset) {
+ controls.setY(-offset);
+ }
+
+ @Override
+ public int getMaximumScrollableHeaderOffset() {
+ // We can scroll the photo out, but we should keep the header.
+ return photo.getHeight() - nameHeader.getHeight();
+ }
+ },
+ historyList);
loadContactPhotos(photoUri);
findViewById(R.id.call_detail).setVisibility(View.VISIBLE);
}
diff --git a/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java b/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java
index 3de5730..ed9c2e0 100644
--- a/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java
+++ b/src/com/android/contacts/calllog/CallDetailHistoryAdapter.java
@@ -32,42 +32,86 @@
* Adapter for a ListView containing history items from the details of a call.
*/
public class CallDetailHistoryAdapter extends BaseAdapter {
+ /** The top element is a blank header, which is hidden under the rest of the UI. */
+ private static final int VIEW_TYPE_HEADER = 0;
+ /** Each history item shows the detail of a call. */
+ private static final int VIEW_TYPE_HISTORY_ITEM = 1;
+
private final Context mContext;
private final LayoutInflater mLayoutInflater;
private final CallTypeHelper mCallTypeHelper;
private final PhoneCallDetails[] mPhoneCallDetails;
+ /** Whether the voicemail controls are shown. */
+ private final boolean mShowVoicemail;
+ /** Whether the call and SMS controls are shown. */
+ private final boolean mShowCallAndSms;
public CallDetailHistoryAdapter(Context context, LayoutInflater layoutInflater,
- CallTypeHelper callTypeHelper, PhoneCallDetails[] phoneCallDetails) {
+ CallTypeHelper callTypeHelper, PhoneCallDetails[] phoneCallDetails,
+ boolean showVoicemail, boolean showCallAndSms) {
mContext = context;
mLayoutInflater = layoutInflater;
mCallTypeHelper = callTypeHelper;
mPhoneCallDetails = phoneCallDetails;
+ mShowVoicemail = showVoicemail;
+ mShowCallAndSms = showCallAndSms;
}
@Override
public int getCount() {
- return mPhoneCallDetails.length;
+ return mPhoneCallDetails.length + 1;
}
@Override
public Object getItem(int position) {
- return mPhoneCallDetails[position];
+ if (position == 0) {
+ return null;
+ }
+ return mPhoneCallDetails[position - 1];
}
@Override
public long getItemId(int position) {
- return position;
+ if (position == 0) {
+ return -1;
+ }
+ return position - 1;
+ }
+
+ @Override
+ public int getViewTypeCount() {
+ return 2;
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (position == 0) {
+ return VIEW_TYPE_HEADER;
+ }
+ return VIEW_TYPE_HISTORY_ITEM;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
+ if (position == 0) {
+ final View header = convertView == null
+ ? mLayoutInflater.inflate(R.layout.call_detail_history_header, parent, false)
+ : convertView;
+ // Voicemail controls are only shown in the main UI if there is a voicemail.
+ View voicemailContainer = header.findViewById(R.id.header_voicemail_container);
+ voicemailContainer.setVisibility(mShowVoicemail ? View.VISIBLE : View.GONE);
+ // Call and SMS controls are only shown in the main UI if there is a known number.
+ View callAndSmsContainer = header.findViewById(R.id.header_call_and_sms_container);
+ callAndSmsContainer.setVisibility(mShowCallAndSms ? View.VISIBLE : View.GONE);
+ return header;
+ }
+
// Make sure we have a valid convertView to start with
final View result = convertView == null
? mLayoutInflater.inflate(R.layout.call_detail_history_item, parent, false)
: convertView;
- PhoneCallDetails details = mPhoneCallDetails[position];
+ PhoneCallDetails details = mPhoneCallDetails[position - 1];
CallTypeIconsView callTypeIconView =
(CallTypeIconsView) result.findViewById(R.id.call_type_icon);
TextView callTypeTextView = (TextView) result.findViewById(R.id.call_type_text);