Merge "Import translations. DO NOT MERGE" into klp-dev
diff --git a/res/layout/call_log_list_item.xml b/res/layout/call_log_list_item.xml
index 46e503c..c49b4b0 100644
--- a/res/layout/call_log_list_item.xml
+++ b/res/layout/call_log_list_item.xml
@@ -17,9 +17,9 @@
<view
xmlns:android="http://schemas.android.com/apk/res/android"
class="com.android.dialer.calllog.CallLogListItemView"
- android:id="@+id/call_log_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:id="@+id/call_log_list_item"
android:orientation="vertical"
android:background="@drawable/bottom_border_background"
>
@@ -140,12 +140,4 @@
android:paddingTop="@dimen/call_log_inner_margin"
android:paddingBottom="@dimen/call_log_inner_margin" />
- <View
- android:id="@+id/call_log_divider"
- android:layout_width="match_parent"
- android:layout_height="1px"
- android:layout_marginStart="@dimen/call_log_outer_margin"
- android:layout_marginEnd="@dimen/call_log_outer_margin"
- android:background="#55ffffff"
- />
</view>
diff --git a/res/layout/phone_favorites_fragment.xml b/res/layout/phone_favorites_fragment.xml
index 3b9e589..6023fc8 100644
--- a/res/layout/phone_favorites_fragment.xml
+++ b/res/layout/phone_favorites_fragment.xml
@@ -28,7 +28,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
- <com.android.dialer.list.SwipeableListView
+ <com.android.dialer.list.PhoneFavoriteListView
android:id="@+id/contact_tile_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/res/layout/phone_loading_contacts.xml b/res/layout/phone_loading_contacts.xml
deleted file mode 100644
index afc3322..0000000
--- a/res/layout/phone_loading_contacts.xml
+++ /dev/null
@@ -1,40 +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.
--->
-
-<!-- "Loading" text with a spinner, which is used in PhoneFavorite screen -->
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:orientation="horizontal"
- android:gravity="start|center_vertical">
-
- <ProgressBar
- android:indeterminate="true"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/progress_spinner"/>
-
- <TextView
- android:id="@+id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/contact_list_loading"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_marginStart="4dip" />
-
-</LinearLayout>
diff --git a/res/layout/phone_no_favorites.xml b/res/layout/phone_no_favorites.xml
new file mode 100644
index 0000000..9fa5d47
--- /dev/null
+++ b/res/layout/phone_no_favorites.xml
@@ -0,0 +1,34 @@
+<?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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:minHeight="?android:attr/listPreferredItemHeight">
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:text="@string/listTotalAllContactsZeroStarred"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:textColor="?android:attr/textColorSecondary"
+ android:layout_marginTop="8dp"
+ android:layout_marginBottom="8dp"/>
+
+</FrameLayout>
diff --git a/res/layout/show_all_contacts_fragment.xml b/res/layout/show_all_contacts_fragment.xml
index 14fe340..ddc99e8 100644
--- a/res/layout/show_all_contacts_fragment.xml
+++ b/res/layout/show_all_contacts_fragment.xml
@@ -23,7 +23,7 @@
<!-- Shown only when an Account filter is set.
- paddingTop should be here to show "shade" effect correctly. -->
- <!-- TODO {klp} Remove the filter header. -->
+ <!-- TODO: Remove the filter header. -->
<include
android:id="@+id/account_filter_header_container"
layout="@layout/account_filter_header" />
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 52ee530..4680038 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -20,7 +20,6 @@
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
-import android.app.backup.BackupManager;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentManager.BackStackEntry;
@@ -28,20 +27,15 @@
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.CallLog.Calls;
-import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.Intents.UI;
-import android.provider.Settings;
import android.speech.RecognizerIntent;
-import android.support.v4.app.NavUtils;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.TextUtils;
@@ -51,24 +45,17 @@
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnFocusChangeListener;
-import android.view.ViewConfiguration;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView.OnScrollListener;
import android.widget.EditText;
-import android.widget.ImageView;
import android.widget.PopupMenu;
-import android.widget.SearchView;
-import android.widget.SearchView.OnCloseListener;
-import android.widget.SearchView.OnQueryTextListener;
import android.widget.Toast;
import com.android.contacts.common.CallUtil;
import com.android.contacts.common.activity.TransactionSafeActivity;
import com.android.contacts.common.dialog.ClearFrequentsDialog;
import com.android.contacts.common.interactions.ImportExportDialogFragment;
-import com.android.contacts.common.list.ContactListItemView;
import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
-import com.android.contacts.common.list.PhoneNumberPickerFragment;
import com.android.dialer.calllog.CallLogActivity;
import com.android.dialer.database.DialerDatabaseHelper;
import com.android.dialer.dialpad.DialpadFragment;
@@ -76,8 +63,8 @@
import com.android.dialer.dialpad.SmartDialPrefix;
import com.android.dialer.interactions.PhoneNumberInteraction;
import com.android.dialer.list.AllContactsActivity;
-import com.android.dialer.list.PhoneFavoriteFragment;
import com.android.dialer.list.OnListFragmentScrolledListener;
+import com.android.dialer.list.PhoneFavoriteFragment;
import com.android.dialer.list.RegularSearchFragment;
import com.android.dialer.list.SearchFragment;
import com.android.dialer.list.SmartDialSearchFragment;
@@ -381,8 +368,7 @@
}
return true;
case R.id.menu_call_settings:
- final Intent settingsIntent = DialtactsActivity.getCallSettingsIntent();
- startActivity(settingsIntent);
+ handleMenuSettings();
return true;
case R.id.menu_all_contacts:
onShowAllContacts();
@@ -391,6 +377,15 @@
return false;
}
+ protected void handleMenuSettings() {
+ openTelephonySetting(this);
+ }
+
+ public static void openTelephonySetting(Activity activity) {
+ final Intent settingsIntent = getCallSettingsIntent();
+ activity.startActivity(settingsIntent);
+ }
+
@Override
public void onClick(View view) {
switch (view.getId()) {
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index 89e8be5..c0054ba 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -90,7 +90,7 @@
/** The size of the cache of contact info. */
private static final int CONTACT_INFO_CACHE_SIZE = 100;
- private final Context mContext;
+ protected final Context mContext;
private final ContactInfoHelper mContactInfoHelper;
private final CallFetcher mCallFetcher;
private ViewTreeObserver mViewTreeObserver = null;
@@ -448,8 +448,17 @@
@Override
protected View newStandAloneView(Context context, ViewGroup parent) {
- LayoutInflater inflater =
- (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ return newChildView(context, parent);
+ }
+
+ @Override
+ protected View newGroupView(Context context, ViewGroup parent) {
+ return newChildView(context, parent);
+ }
+
+ @Override
+ protected View newChildView(Context context, ViewGroup parent) {
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.call_log_list_item, parent, false);
findAndCacheViews(view);
return view;
@@ -461,29 +470,11 @@
}
@Override
- protected View newChildView(Context context, ViewGroup parent) {
- LayoutInflater inflater =
- (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View view = inflater.inflate(R.layout.call_log_list_item, parent, false);
- findAndCacheViews(view);
- return view;
- }
-
- @Override
protected void bindChildView(View view, Context context, Cursor cursor) {
bindView(view, cursor, 1);
}
@Override
- protected View newGroupView(Context context, ViewGroup parent) {
- LayoutInflater inflater =
- (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View view = inflater.inflate(R.layout.call_log_list_item, parent, false);
- findAndCacheViews(view);
- return view;
- }
-
- @Override
protected void bindGroupView(View view, Context context, Cursor cursor, int groupSize,
boolean expanded) {
bindView(view, cursor, groupSize);
@@ -509,7 +500,6 @@
// Default case: an item in the call log.
views.primaryActionView.setVisibility(View.VISIBLE);
- views.bottomDivider.setVisibility(View.VISIBLE);
views.listHeaderTextView.setVisibility(View.GONE);
final String number = c.getString(CallLogQuery.NUMBER);
@@ -593,6 +583,7 @@
final int[] callTypes = getCallTypes(c, count);
final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION);
final PhoneCallDetails details;
+
if (TextUtils.isEmpty(name)) {
details = new PhoneCallDetails(number, numberPresentation,
formattedNumber, countryIso, geocode, callTypes, date,
@@ -623,6 +614,12 @@
mViewTreeObserver = view.getViewTreeObserver();
mViewTreeObserver.addOnPreDrawListener(this);
}
+
+ postBindView(views, info);
+ }
+
+ protected void postBindView(CallLogListItemViews views, ContactInfo info) {
+ // no-op
}
/** Checks whether the contact info from the call log matches the one from the contacts db. */
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index 9808d07..d0d34d8 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -30,13 +30,9 @@
import android.provider.CallLog.Calls;
import android.provider.ContactsContract;
import android.telephony.PhoneNumberUtils;
-import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
@@ -50,8 +46,8 @@
import com.android.dialer.voicemail.VoicemailStatusHelper;
import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage;
import com.android.dialer.voicemail.VoicemailStatusHelperImpl;
+import com.android.dialerbind.ObjectFactory;
import com.android.internal.telephony.ITelephony;
-import com.google.common.annotations.VisibleForTesting;
import java.util.List;
@@ -234,8 +230,8 @@
super.onViewCreated(view, savedInstanceState);
updateEmptyMessage(mCallTypeFilter);
String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity());
- mAdapter = new CallLogAdapter(getActivity(), this,
- new ContactInfoHelper(getActivity(), currentCountryIso), false);
+ mAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this, new ContactInfoHelper(
+ getActivity(), currentCountryIso), false, true);
setListAdapter(mAdapter);
getListView().setItemsCanFocus(true);
}
diff --git a/src/com/android/dialer/calllog/CallLogListItemViews.java b/src/com/android/dialer/calllog/CallLogListItemViews.java
index 0dd4f63..ed6218f 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViews.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViews.java
@@ -40,18 +40,15 @@
public final PhoneCallDetailsViews phoneCallDetailsViews;
/** The text of the header of a section. */
public final TextView listHeaderTextView;
- /** The divider to be shown below items. */
- public final View bottomDivider;
private CallLogListItemViews(QuickContactBadge quickContactView, View primaryActionView,
ImageView secondaryActionView, PhoneCallDetailsViews phoneCallDetailsViews,
- TextView listHeaderTextView, View bottomDivider) {
+ TextView listHeaderTextView) {
this.quickContactView = quickContactView;
this.primaryActionView = primaryActionView;
this.secondaryActionView = secondaryActionView;
this.phoneCallDetailsViews = phoneCallDetailsViews;
this.listHeaderTextView = listHeaderTextView;
- this.bottomDivider = bottomDivider;
}
public static CallLogListItemViews fromView(View view) {
@@ -60,8 +57,7 @@
view.findViewById(R.id.primary_action_view),
(ImageView) view.findViewById(R.id.secondary_action_icon),
PhoneCallDetailsViews.fromView(view),
- (TextView) view.findViewById(R.id.call_log_header),
- view.findViewById(R.id.call_log_divider));
+ (TextView) view.findViewById(R.id.call_log_header));
}
@NeededForTesting
@@ -71,7 +67,6 @@
new View(context),
new ImageView(context),
PhoneCallDetailsViews.createForTest(context),
- new TextView(context),
- new View(context));
+ new TextView(context));
}
}
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java
index 5d7aa1b..64484cb 100644
--- a/src/com/android/dialer/calllog/ContactInfoHelper.java
+++ b/src/com/android/dialer/calllog/ContactInfoHelper.java
@@ -22,18 +22,15 @@
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.DisplayNameSources;
import android.provider.ContactsContract.PhoneLookup;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
-import android.util.Log;
import com.android.contacts.common.util.Constants;
import com.android.contacts.common.util.UriUtils;
import com.android.dialer.service.CachedNumberLookupService;
-import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
-import com.android.dialerbind.ServiceFactory;
+import com.android.dialerbind.ObjectFactory;
import org.json.JSONException;
import org.json.JSONObject;
@@ -46,7 +43,7 @@
private final String mCurrentCountryIso;
private static final CachedNumberLookupService mCachedNumberLookupService =
- ServiceFactory.newCachedNumberLookupService();
+ ObjectFactory.newCachedNumberLookupService();
public ContactInfoHelper(Context context, String currentCountryIso) {
mContext = context;
diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java
index 4ffb030..270ed63 100644
--- a/src/com/android/dialer/list/PhoneFavoriteFragment.java
+++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java
@@ -19,7 +19,6 @@
import android.app.Fragment;
import android.app.LoaderManager;
import android.content.CursorLoader;
-import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.graphics.Rect;
@@ -27,7 +26,6 @@
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
-import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.View.OnClickListener;
@@ -35,7 +33,6 @@
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
-import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
@@ -44,13 +41,12 @@
import com.android.contacts.common.GeoUtil;
import com.android.contacts.common.list.ContactEntry;
import com.android.contacts.common.list.ContactTileView;
-import com.android.contacts.common.list.PhoneNumberListAdapter;
-import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
import com.android.dialer.calllog.ContactInfoHelper;
import com.android.dialer.calllog.CallLogAdapter;
import com.android.dialer.calllog.CallLogQueryHandler;
import com.android.dialer.list.PhoneFavoritesTileAdapter.ContactTileRow;
+import com.android.dialerbind.ObjectFactory;
import java.util.ArrayList;
import java.util.HashMap;
@@ -148,18 +144,17 @@
private CallLogAdapter mCallLogAdapter;
private CallLogQueryHandler mCallLogQueryHandler;
- private TextView mEmptyView;
- private SwipeableListView mListView;
+ private PhoneFavoriteListView mListView;
+
private View mShowAllContactsButton;
private final HashMap<Long, Integer> mItemIdTopMap = new HashMap<Long, Integer>();
private final HashMap<Long, Integer> mItemIdLeftMap = new HashMap<Long, Integer>();
/**
- * Layout used when contacts load is slower than expected and thus "loading" view should be
- * shown.
+ * Layout used when there are no favorites.
*/
- private View mLoadingView;
+ private View mEmptyView;
private final ContactTileView.Listener mContactTileAdapterListener =
new ContactTileAdapterListener();
@@ -175,7 +170,6 @@
// Construct two base adapters which will become part of PhoneFavoriteMergedAdapter.
// We don't construct the resultant adapter at this moment since it requires LayoutInflater
// that will be available on onCreateView().
-
mContactTileAdapter = new PhoneFavoritesTileAdapter(activity, mContactTileAdapterListener,
this,
getResources().getInteger(R.integer.contact_tile_column_count_in_favorites_new),
@@ -191,15 +185,15 @@
mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(),
this, 1);
final String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity());
- mCallLogAdapter = new CallLogAdapter(getActivity(), this,
- new ContactInfoHelper(getActivity(), currentCountryIso), true);
+ mCallLogAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this,
+ new ContactInfoHelper(getActivity(), currentCountryIso), true, false);
setHasOptionsMenu(true);
}
@Override
public void onResume() {
super.onResume();
- mCallLogQueryHandler.fetchNewCalls(CallLogQueryHandler.CALL_TYPE_ALL);
+ fetchCalls();
mCallLogAdapter.setLoading(true);
getLoaderManager().getLoader(LOADER_ID_CONTACT_TILE).forceLoad();
}
@@ -210,7 +204,7 @@
final View listLayout = inflater.inflate(
R.layout.phone_favorites_fragment, container, false);
- mListView = (SwipeableListView) listLayout.findViewById(R.id.contact_tile_list);
+ mListView = (PhoneFavoriteListView) listLayout.findViewById(R.id.contact_tile_list);
mListView.setItemsCanFocus(true);
mListView.setOnItemClickListener(this);
mListView.setVerticalScrollBarEnabled(false);
@@ -218,7 +212,8 @@
mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
mListView.setOnItemSwipeListener(mContactTileAdapter);
- mLoadingView = inflater.inflate(R.layout.phone_loading_contacts, mListView, false);
+ mEmptyView = inflater.inflate(R.layout.phone_no_favorites, mListView, false);
+
mShowAllContactsButton = inflater.inflate(R.layout.show_all_contact_button, mListView,
false);
mShowAllContactsButton.setOnClickListener(new OnClickListener() {
@@ -228,8 +223,9 @@
}
});
+ mContactTileAdapter.setEmptyView(mEmptyView);
mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), mContactTileAdapter,
- mCallLogAdapter, mLoadingView, mShowAllContactsButton);
+ mCallLogAdapter, mShowAllContactsButton);
mListView.setAdapter(mAdapter);
@@ -237,10 +233,6 @@
mListView.setFastScrollEnabled(false);
mListView.setFastScrollAlwaysVisible(false);
- mEmptyView = (TextView) listLayout.findViewById(R.id.contact_tile_list_empty);
- mEmptyView.setText(getString(R.string.listTotalAllContactsZero));
- mListView.setEmptyView(mEmptyView);
-
return listLayout;
}
@@ -301,9 +293,9 @@
mListener = listener;
}
- // TODO krelease: Implement this
@Override
public void onVoicemailStatusFetched(Cursor statusCursor) {
+ // no-op
}
@Override
@@ -313,9 +305,9 @@
mAdapter.notifyDataSetChanged();
}
- // TODO krelease: Implement this
@Override
public void fetchCalls() {
+ mCallLogQueryHandler.fetchNewCalls(CallLogQueryHandler.CALL_TYPE_ALL);
}
@Override
diff --git a/src/com/android/dialer/list/PhoneFavoriteListView.java b/src/com/android/dialer/list/PhoneFavoriteListView.java
new file mode 100644
index 0000000..b5da054
--- /dev/null
+++ b/src/com/android/dialer/list/PhoneFavoriteListView.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2012 Google Inc.
+ * Licensed to 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.dialer.list;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Handler;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnDragListener;
+import android.view.ViewConfiguration;
+import android.widget.ListView;
+
+import com.android.dialer.R;
+import com.android.dialer.list.PhoneFavoritesTileAdapter.ContactTileRow;
+import com.android.dialer.list.SwipeHelper.OnItemGestureListener;
+import com.android.dialer.list.SwipeHelper.SwipeHelperCallback;
+
+/**
+ * The ListView composed of {@link ContactTileRow}.
+ * This ListView handles both
+ * - Swiping, which is borrowed from packages/apps/UnifiedEmail (com.android.mail.ui.Swipeable)
+ * - Drag and drop
+ */
+public class PhoneFavoriteListView extends ListView implements
+ SwipeHelperCallback, OnDragListener {
+
+ public static final String LOG_TAG = PhoneFavoriteListView.class.getSimpleName();
+
+ private SwipeHelper mSwipeHelper;
+ private boolean mEnableSwipe = true;
+
+ private OnItemGestureListener mOnItemGestureListener;
+
+ private float mDensityScale;
+ private float mTouchSlop;
+
+ private int mTopScrollBound;
+ private int mBottomScrollBound;
+ private int mLastDragY;
+
+ private Handler mScrollHandler;
+ private final long SCROLL_HANDLER_DELAY_MILLIS = 5;
+ private final int DRAG_SCROLL_PX_UNIT = 10;
+
+ /**
+ * {@link #mTopScrollBound} and {@link mBottomScrollBound} will be
+ * offseted to the top / bottom by {@link #getHeight} * {@link #BOUND_GAP_RATIO} pixels.
+ */
+ private final float BOUND_GAP_RATIO = 0.2f;
+
+ private final Runnable mDragScroller = new Runnable() {
+ @Override
+ public void run() {
+ if (mLastDragY <= mTopScrollBound) {
+ smoothScrollBy(-DRAG_SCROLL_PX_UNIT, (int) SCROLL_HANDLER_DELAY_MILLIS);
+ } else if (mLastDragY >= mBottomScrollBound) {
+ smoothScrollBy(DRAG_SCROLL_PX_UNIT, (int) SCROLL_HANDLER_DELAY_MILLIS);
+ }
+ mScrollHandler.postDelayed(this, SCROLL_HANDLER_DELAY_MILLIS);
+ }
+ };
+
+ public PhoneFavoriteListView(Context context) {
+ this(context, null);
+ }
+
+ public PhoneFavoriteListView(Context context, AttributeSet attrs) {
+ this(context, attrs, -1);
+ }
+
+ public PhoneFavoriteListView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ mDensityScale = getResources().getDisplayMetrics().density;
+ mTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
+ mSwipeHelper = new SwipeHelper(context, SwipeHelper.X, this,
+ mDensityScale, mTouchSlop);
+ setItemsCanFocus(true);
+ setOnDragListener(this);
+ }
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ mDensityScale= getResources().getDisplayMetrics().density;
+ mTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
+ mSwipeHelper.setDensityScale(mDensityScale);
+ mSwipeHelper.setPagingTouchSlop(mTouchSlop);
+ }
+
+ /**
+ * Enable swipe gestures.
+ */
+ public void enableSwipe(boolean enable) {
+ mEnableSwipe = enable;
+ }
+
+ public boolean isSwipeEnabled() {
+ return mEnableSwipe && mOnItemGestureListener.isSwipeEnabled();
+ }
+
+ public void setOnItemSwipeListener(OnItemGestureListener listener) {
+ mOnItemGestureListener = listener;
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ if (isSwipeEnabled()) {
+ return mSwipeHelper.onInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev);
+ } else {
+ return super.onInterceptTouchEvent(ev);
+ }
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (mOnItemGestureListener != null) {
+ mOnItemGestureListener.onTouch();
+ }
+ if (isSwipeEnabled()) {
+ return mSwipeHelper.onTouchEvent(ev) || super.onTouchEvent(ev);
+ } else {
+ return super.onTouchEvent(ev);
+ }
+ }
+
+ @Override
+ public View getChildAtPosition(MotionEvent ev) {
+ // find the view under the pointer, accounting for GONE views
+ final int count = getChildCount();
+ final int touchY = (int) ev.getY();
+ View slidingChild;
+ for (int childIdx = 0; childIdx < count; childIdx++) {
+ slidingChild = getChildAt(childIdx);
+ if (slidingChild.getVisibility() == GONE) {
+ continue;
+ }
+ if (touchY >= slidingChild.getTop() && touchY <= slidingChild.getBottom()) {
+ if (SwipeHelper.isSwipeable(slidingChild)) {
+ // If this view is swipable in this listview, then return it. Otherwise
+ // return a null view, which will simply be ignored by the swipe helper.
+ return slidingChild;
+ } else {
+ return null;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public View getChildContentView(View view) {
+ return view.findViewById(R.id.contact_favorite_card);
+ }
+
+ @Override
+ public void onScroll() {}
+
+ @Override
+ public boolean canChildBeDismissed(View v) {
+ return SwipeHelper.isSwipeable(v);
+ }
+
+ @Override
+ public void onChildDismissed(final View v) {
+ if (v != null) {
+ if (mOnItemGestureListener != null) {
+ mOnItemGestureListener.onSwipe(v);
+ }
+ }
+ }
+
+ @Override
+ public void onDragCancelled(View v) {
+ }
+
+ @Override
+ public void onBeginDrag(View v) {
+ final View tileRow = (View) v.getParent();
+
+ // We do this so the underlying ScrollView knows that it won't get
+ // the chance to intercept events anymore
+ requestDisallowInterceptTouchEvent(true);
+ }
+
+ @Override
+ public boolean dispatchDragEvent(DragEvent event) {
+ switch (event.getAction()) {
+ case DragEvent.ACTION_DRAG_LOCATION:
+ if (mScrollHandler == null) {
+ mScrollHandler = getHandler();
+ }
+ mLastDragY = (int) event.getY();
+ mScrollHandler.postDelayed(mDragScroller, SCROLL_HANDLER_DELAY_MILLIS);
+ break;
+ case DragEvent.ACTION_DRAG_ENTERED:
+ final int boundGap = (int) (getHeight() * BOUND_GAP_RATIO);
+ mTopScrollBound = (getTop() + boundGap);
+ mBottomScrollBound = (getBottom() - boundGap);
+ break;
+ case DragEvent.ACTION_DRAG_EXITED:
+ case DragEvent.ACTION_DRAG_ENDED:
+ mScrollHandler.removeCallbacks(mDragScroller);
+ break;
+ case DragEvent.ACTION_DRAG_STARTED:
+ // Not a receiver
+ case DragEvent.ACTION_DROP:
+ // Not a receiver
+ default:
+ break;
+ }
+ return super.dispatchDragEvent(event);
+ }
+
+ @Override
+ public boolean onDrag(View v, DragEvent event) {
+ return true;
+ }
+}
diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java
index 57ae2c1..c7554e2 100644
--- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java
@@ -52,7 +52,6 @@
private static final int ALL_CONTACTS_BUTTON_ITEM_ID = -1;
private final PhoneFavoritesTileAdapter mContactTileAdapter;
private final CallLogAdapter mCallLogAdapter;
- private final View mLoadingView;
private final View mShowAllContactsButton;
private final int mCallLogPadding;
@@ -99,7 +98,6 @@
public PhoneFavoriteMergedAdapter(Context context,
PhoneFavoritesTileAdapter contactTileAdapter,
CallLogAdapter callLogAdapter,
- View loadingView,
View showAllContactsButton) {
final Resources resources = context.getResources();
mContext = context;
@@ -109,7 +107,6 @@
mObserver = new CustomDataSetObserver();
mCallLogAdapter.registerDataSetObserver(mObserver);
mContactTileAdapter.registerDataSetObserver(mObserver);
- mLoadingView = loadingView;
mShowAllContactsButton = showAllContactsButton;
mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(),
mCallLogQueryHandlerListener);
@@ -242,9 +239,6 @@
@Override
public boolean areAllItemsEnabled() {
- // If "all" section is being loaded we'll show mLoadingView, which is not enabled.
- // Otherwise check the all the other components in the ListView and return appropriate
- // result.
return mCallLogAdapter.areAllItemsEnabled() && mContactTileAdapter.areAllItemsEnabled();
}
@@ -285,7 +279,7 @@
view.setBackgroundResource(R.drawable.dialer_recent_card_bg);
final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
- FrameLayout.LayoutParams.WRAP_CONTENT,
+ FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
params.setMarginsRelative(mCallLogPadding, mCallLogPadding, mCallLogPadding,
mCallLogPadding);
diff --git a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
index 91acc6f..9662338 100644
--- a/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoritesTileAdapter.java
@@ -74,6 +74,8 @@
private Context mContext;
private Resources mResources;
+ private View mEmptyView;
+
/** Contact data stored in cache. This is used to populate the associated view. */
protected ArrayList<ContactEntry> mContactEntries = null;
/** Back up of the temporarily removed Contact during dragging. */
@@ -367,10 +369,15 @@
return mNumFrequents;
}
+ private boolean isEmptyView(int position) {
+ return position == 0 && (mContactEntries == null || mContactEntries.isEmpty());
+ }
+
@Override
public int getCount() {
if (mContactEntries == null || mContactEntries.isEmpty()) {
- return 0;
+ // empty view
+ return 1;
}
int total = mContactEntries.size();
@@ -493,7 +500,7 @@
@Override
public boolean isEnabled(int position) {
- return true;
+ return !isEmptyView(position);
}
@Override
@@ -509,8 +516,13 @@
if (DEBUG) {
Log.v(TAG, "get view for " + String.valueOf(position));
}
+
int itemViewType = getItemViewType(position);
+ if (itemViewType == ViewTypes.EMPTY) {
+ return mEmptyView;
+ }
+
ContactTileRow contactTileRowView = (ContactTileRow) convertView;
ArrayList<ContactEntry> contactList = getItem(position);
@@ -542,6 +554,7 @@
@Override
public int getItemViewType(int position) {
+ if (isEmptyView(position)) return ViewTypes.EMPTY;
if (position < getRowCount(getMaxContactsInTiles())) {
return ViewTypes.TOP;
} else {
@@ -1129,9 +1142,10 @@
}
protected static class ViewTypes {
- public static final int COUNT = 2;
+ public static final int COUNT = 3;
public static final int FREQUENT = 0;
public static final int TOP = 1;
+ public static final int EMPTY = 2;
}
@Override
@@ -1158,4 +1172,8 @@
public boolean isSwipeEnabled() {
return !mAwaitingRemove;
}
+
+ public void setEmptyView(View emptyView) {
+ mEmptyView = emptyView;
+ }
}
diff --git a/src/com/android/dialer/list/RegularSearchFragment.java b/src/com/android/dialer/list/RegularSearchFragment.java
index ccbd3d0..2a80b3e 100644
--- a/src/com/android/dialer/list/RegularSearchFragment.java
+++ b/src/com/android/dialer/list/RegularSearchFragment.java
@@ -16,7 +16,7 @@
package com.android.dialer.list;
import com.android.contacts.common.list.ContactEntryListAdapter;
-import com.android.dialerbind.ServiceFactory;
+import com.android.dialerbind.ObjectFactory;
import com.android.dialer.service.CachedNumberLookupService;
public class RegularSearchFragment extends SearchFragment {
@@ -24,7 +24,7 @@
private static final int SEARCH_DIRECTORY_RESULT_LIMIT = 5;
private static final CachedNumberLookupService mCachedNumberLookupService =
- ServiceFactory.newCachedNumberLookupService();
+ ObjectFactory.newCachedNumberLookupService();
public RegularSearchFragment() {
configureDirectorySearch();
diff --git a/src/com/android/dialer/list/SwipeableListView.java b/src/com/android/dialer/list/SwipeableListView.java
deleted file mode 100644
index 449628d..0000000
--- a/src/com/android/dialer/list/SwipeableListView.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc.
- * Licensed to 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.dialer.list;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.widget.ListView;
-
-import com.android.dialer.R;
-import com.android.dialer.list.PhoneFavoritesTileAdapter.ContactTileRow;
-import com.android.dialer.list.SwipeHelper.OnItemGestureListener;
-import com.android.dialer.list.SwipeHelper.SwipeHelperCallback;
-
-/**
- * Copy of packages/apps/UnifiedEmail - com.android.mail.ui.Swipeable with changes.
- */
-public class SwipeableListView extends ListView implements SwipeHelperCallback {
- private SwipeHelper mSwipeHelper;
- private boolean mEnableSwipe = true;
-
- public static final String LOG_TAG = SwipeableListView.class.getSimpleName();
-
- private OnItemGestureListener mOnItemGestureListener;
-
- public SwipeableListView(Context context) {
- this(context, null);
- }
-
- public SwipeableListView(Context context, AttributeSet attrs) {
- this(context, attrs, -1);
- }
-
- public SwipeableListView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- float densityScale = getResources().getDisplayMetrics().density;
- float pagingTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
- mSwipeHelper = new SwipeHelper(context, SwipeHelper.X, this, densityScale,
- pagingTouchSlop);
- setItemsCanFocus(true);
- }
-
- @Override
- protected void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- float densityScale = getResources().getDisplayMetrics().density;
- mSwipeHelper.setDensityScale(densityScale);
- float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
- mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
- }
-
- /**
- * Enable swipe gestures.
- */
- public void enableSwipe(boolean enable) {
- mEnableSwipe = enable;
- }
-
- public boolean isSwipeEnabled() {
- return mEnableSwipe && mOnItemGestureListener.isSwipeEnabled();
- }
-
- public void setOnItemSwipeListener(OnItemGestureListener listener) {
- mOnItemGestureListener = listener;
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- if (isSwipeEnabled()) {
- return mSwipeHelper.onInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev);
- } else {
- return super.onInterceptTouchEvent(ev);
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- if (mOnItemGestureListener != null) {
- mOnItemGestureListener.onTouch();
- }
- if (isSwipeEnabled()) {
- return mSwipeHelper.onTouchEvent(ev) || super.onTouchEvent(ev);
- } else {
- return super.onTouchEvent(ev);
- }
- }
-
- @Override
- public View getChildAtPosition(MotionEvent ev) {
- // find the view under the pointer, accounting for GONE views
- final int count = getChildCount();
- final int touchY = (int) ev.getY();
- View slidingChild;
- for (int childIdx = 0; childIdx < count; childIdx++) {
- slidingChild = getChildAt(childIdx);
- if (slidingChild.getVisibility() == GONE) {
- continue;
- }
- if (touchY >= slidingChild.getTop() && touchY <= slidingChild.getBottom()) {
- if (SwipeHelper.isSwipeable(slidingChild)) {
- // If this view is swipable in this listview, then return it. Otherwise
- // return a null view, which will simply be ignored by the swipe helper.
- return slidingChild;
- } else {
- return null;
- }
- }
- }
- return null;
- }
-
- @Override
- public View getChildContentView(View view) {
- return view.findViewById(R.id.contact_favorite_card);
- }
-
- @Override
- public void onScroll() {}
-
- @Override
- public boolean canChildBeDismissed(View v) {
- return SwipeHelper.isSwipeable(v);
- }
-
- @Override
- public void onChildDismissed(final View v) {
- if (v != null) {
- if (mOnItemGestureListener != null) {
- mOnItemGestureListener.onSwipe(v);
- }
- }
- }
-
- @Override
- public void onDragCancelled(View v) {
- }
-
- @Override
- public void onBeginDrag(View v) {
- final View tileRow = (View) v.getParent();
-
- // We do this so the underlying ScrollView knows that it won't get
- // the chance to intercept events anymore
- requestDisallowInterceptTouchEvent(true);
- }
-}
\ No newline at end of file
diff --git a/src/com/android/dialerbind/ObjectFactory.java b/src/com/android/dialerbind/ObjectFactory.java
new file mode 100644
index 0000000..6286c05
--- /dev/null
+++ b/src/com/android/dialerbind/ObjectFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 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.dialerbind;
+
+import static com.android.dialer.calllog.CallLogAdapter.CallFetcher;
+
+import android.content.Context;
+
+import com.android.dialer.calllog.CallLogAdapter;
+import com.android.dialer.calllog.ContactInfoHelper;
+import com.android.dialer.service.CachedNumberLookupService;
+
+/**
+ * Default static binding for various objects.
+ */
+public class ObjectFactory {
+
+ public static CachedNumberLookupService newCachedNumberLookupService() {
+ // no-op
+ return null;
+ }
+
+ public static CallLogAdapter newCallLogAdapter(Context context, CallFetcher callFetcher,
+ ContactInfoHelper contactInfoHelper, boolean useCallAsPrimaryAction,
+ boolean isCallLog) {
+ return new CallLogAdapter(context, callFetcher, contactInfoHelper, useCallAsPrimaryAction);
+ }
+}
diff --git a/src/com/android/dialerbind/ServiceFactory.java b/src/com/android/dialerbind/ServiceFactory.java
deleted file mode 100644
index e53d2e8..0000000
--- a/src/com/android/dialerbind/ServiceFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2013 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.dialerbind;
-
-import com.android.dialer.service.CachedNumberLookupService;
-
-/**
- * Default static binder for services.
- */
-public class ServiceFactory {
-
- public static CachedNumberLookupService newCachedNumberLookupService() {
- // no-op
- return null;
- }
-}
diff --git a/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java b/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
index 3e3cacd..611b3f1 100644
--- a/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
+++ b/tests/src/com/android/dialer/list/PhoneFavoritesTileAdapterTest.java
@@ -12,7 +12,7 @@
}
/**
- * TODO Krelease: Add tests
+ * TODO: Add tests
*
* Test cases (various combinations of):
* No pinned contacts
@@ -26,7 +26,7 @@
}
/**
- * TODO Krelease: Add tests
+ * TODO: Add tests
*
* This method assumes that contacts have already been reordered by
* arrangeContactsByPinnedPosition, so we can test it with a less expansive set of test data.