diff options
author | Yorke Lee <yorkelee@google.com> | 2014-04-22 10:35:59 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2014-04-22 11:38:12 -0700 |
commit | b428689142d236505b73c09bf48244b174b3f6a1 (patch) | |
tree | a413a3eb64aad3d06fe4e98907474abdf1c4cd77 /src | |
parent | 54c6034e576fa000aae1029e5147056961043ccf (diff) | |
parent | cd1fa3922c10f1951f845386cc43dabf69e31ccc (diff) |
resolved conflicts for merge of cd1fa392 to master-nova
Change-Id: I60df511b2b8b7ae19a10fcfa36afa7b331b33389
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 158 | ||||
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteFragment.java | 120 | ||||
-rw-r--r-- | src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java | 73 |
3 files changed, 155 insertions, 196 deletions
diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 513272741..066e7537f 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -1,19 +1,34 @@ package com.android.dialer.list; -import android.app.Activity; +import android.animation.LayoutTransition; import android.app.Fragment; import android.app.FragmentManager; +import android.app.LoaderManager; +import android.content.Context; +import android.content.CursorLoader; +import android.content.Loader; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.net.Uri; import android.os.Bundle; +import android.provider.CallLog; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.ListView; -import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; +import com.android.contacts.common.GeoUtil; +import com.android.dialer.DialtactsActivity; import com.android.dialer.R; +import com.android.dialer.calllog.CallLogAdapter; import com.android.dialer.calllog.CallLogFragment; +import com.android.dialer.calllog.CallLogQuery; import com.android.dialer.calllog.CallLogQueryHandler; +import com.android.dialer.calllog.ContactInfoHelper; +import com.android.dialerbind.ObjectFactory; /** * Fragment that is used as the main screen of the Dialer. @@ -23,7 +38,23 @@ import com.android.dialer.calllog.CallLogQueryHandler; * ViewPager containing the lists up above the shortcut cards and pin it against the top of the * screen. */ -public class ListsFragment extends Fragment { +public class ListsFragment extends Fragment implements CallLogQueryHandler.Listener, + CallLogAdapter.CallFetcher { + + private static final int TAB_INDEX_SPEED_DIAL = 0; + private static final int TAB_INDEX_RECENTS = 1; + private static final int TAB_INDEX_ALL_CONTACTS = 2; + + private static final int TAB_INDEX_COUNT = 3; + + // TODO: Replace with a date limit (e.g. 2 weeks) + private static final int MAX_ENTRIES = 20; + + private static final String KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE = + "key_last_dismissed_call_shortcut_date"; + + // Used with LoaderManager + private static int MISSED_CALL_LOADER = 1; private ViewPager mViewPager; private ViewPagerAdapter mViewPagerAdapter; @@ -31,16 +62,43 @@ public class ListsFragment extends Fragment { private CallLogFragment mRecentsFragment; private AllContactsFragment mAllContactsFragment; - private static final int TAB_INDEX_SPEED_DIAL = 0; - private static final int TAB_INDEX_RECENTS = 1; - private static final int TAB_INDEX_ALL_CONTACTS = 2; - private String[] mTabTitles; - private static final int TAB_INDEX_COUNT = 3; + private PhoneFavoriteMergedAdapter mMergedAdapter; + private CallLogAdapter mCallLogAdapter; + private CallLogQueryHandler mCallLogQueryHandler; - // TODO: Replace with a date limit (e.g. 2 weeks) - private static final int MAX_ENTRIES = 20; + /** + * Call shortcuts older than this date (persisted in shared preferences) will not show up in + * at the top of the screen + */ + private long mLastCallShortcutDate = 0; + + /** + * The date of the current call shortcut that is showing on screen. + */ + private long mCurrentCallShortcutDate = 0; + + private class MissedCallLogLoaderListener implements LoaderManager.LoaderCallbacks<Cursor> { + + @Override + public Loader<Cursor> onCreateLoader(int id, Bundle args) { + final Uri uri = CallLog.Calls.CONTENT_URI; + final String[] projection = new String[] {CallLog.Calls.TYPE}; + final String selection = CallLog.Calls.TYPE + " = " + CallLog.Calls.MISSED_TYPE + + " AND " + CallLog.Calls.IS_READ + " = 0"; + return new CursorLoader(getActivity(), uri, projection, selection, null, null); + } + + @Override + public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor data) { + mCallLogAdapter.setMissedCalls(data); + } + + @Override + public void onLoaderReset(Loader<Cursor> cursorLoader) { + } + } public class ViewPagerAdapter extends FragmentPagerAdapter { public ViewPagerAdapter(FragmentManager fm) { @@ -76,6 +134,45 @@ public class ListsFragment extends Fragment { } @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), + this, 1); + final String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); + mCallLogAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this, + new ContactInfoHelper(getActivity(), currentCountryIso), false, false); + + mMergedAdapter = new PhoneFavoriteMergedAdapter(getActivity(), this, null, + mCallLogAdapter, null, null, null); + } + + @Override + public void onStart() { + super.onStart(); + getLoaderManager().initLoader(MISSED_CALL_LOADER, null, new MissedCallLogLoaderListener()); + } + + @Override + public void onResume() { + super.onResume(); + final SharedPreferences prefs = getActivity().getSharedPreferences( + DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE); + mLastCallShortcutDate = prefs.getLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, 0); + + fetchCalls(); + mCallLogAdapter.setLoading(true); + } + + @Override + public void onPause() { + // Wipe the cache to refresh the call shortcut item. This is not that expensive because + // it only contains one item. + mCallLogAdapter.invalidateCache(); + super.onPause(); + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View parentView = inflater.inflate(R.layout.lists_fragment, container, false); @@ -91,6 +188,47 @@ public class ListsFragment extends Fragment { ViewPagerTabs tabs = (ViewPagerTabs) parentView.findViewById(R.id.lists_pager_header); tabs.setViewPager(mViewPager); + + final ListView shortcutCardsListView = + (ListView) parentView.findViewById(R.id.shortcut_card_list); + shortcutCardsListView.setAdapter(mMergedAdapter); + + LayoutTransition transition = ((LinearLayout) parentView).getLayoutTransition(); + // Turns on animations for all types of layout changes so that they occur for + // height changes. + transition.enableTransitionType(LayoutTransition.CHANGING); return parentView; } + + @Override + public void onVoicemailStatusFetched(Cursor statusCursor) { + // no-op + } + + @Override + public void onCallsFetched(Cursor cursor) { + mCallLogAdapter.setLoading(false); + + // Save the date of the most recent call log item + if (cursor != null && cursor.moveToFirst()) { + mCurrentCallShortcutDate = cursor.getLong(CallLogQuery.DATE); + } + + mCallLogAdapter.changeCursor(cursor); + mMergedAdapter.notifyDataSetChanged(); + } + + @Override + public void fetchCalls() { + mCallLogQueryHandler.fetchCalls(CallLogQueryHandler.CALL_TYPE_ALL, mLastCallShortcutDate); + } + + public void dismissShortcut(View view) { + mLastCallShortcutDate = mCurrentCallShortcutDate; + final SharedPreferences prefs = view.getContext().getSharedPreferences( + DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE); + prefs.edit().putLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, mLastCallShortcutDate) + .apply(); + fetchCalls(); + } } diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java index 518aba967..05e2d44d4 100644 --- a/src/com/android/dialer/list/PhoneFavoriteFragment.java +++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java @@ -21,26 +21,20 @@ import android.animation.ObjectAnimator; import android.app.Activity; import android.app.Fragment; import android.app.LoaderManager; -import android.content.Context; import android.content.CursorLoader; import android.content.Loader; -import android.content.SharedPreferences; import android.database.Cursor; import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; -import android.preference.PreferenceManager; -import android.provider.CallLog; import android.util.Log; import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.RelativeLayout; @@ -48,17 +42,9 @@ import android.widget.RelativeLayout.LayoutParams; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactTileLoaderFactory; -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.OnPhoneNumberPickerActionListener; -import com.android.dialer.DialtactsActivity; import com.android.dialer.R; -import com.android.dialer.calllog.CallLogAdapter; -import com.android.dialer.calllog.CallLogQuery; -import com.android.dialer.calllog.CallLogQueryHandler; -import com.android.dialer.calllog.ContactInfoHelper; -import com.android.dialerbind.ObjectFactory; import java.util.ArrayList; import java.util.HashMap; @@ -72,7 +58,6 @@ import java.util.HashMap; * A contact filter header is also inserted between those adapters' results. */ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListener, - CallLogQueryHandler.Listener, CallLogAdapter.CallFetcher, PhoneFavoritesTileAdapter.OnDataSetChangedForAnimationListener { /** @@ -93,36 +78,11 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen * Used with LoaderManager. */ private static int LOADER_ID_CONTACT_TILE = 1; - private static int MISSED_CALL_LOADER = 2; - - private static final String KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE = - "key_last_dismissed_call_shortcut_date"; public interface HostInterface { public void setDragDropController(DragDropController controller); } - private class MissedCallLogLoaderListener implements LoaderManager.LoaderCallbacks<Cursor> { - - @Override - public Loader<Cursor> onCreateLoader(int id, Bundle args) { - final Uri uri = CallLog.Calls.CONTENT_URI; - final String[] projection = new String[] {CallLog.Calls.TYPE}; - final String selection = CallLog.Calls.TYPE + " = " + CallLog.Calls.MISSED_TYPE + - " AND " + CallLog.Calls.IS_READ + " = 0"; - return new CursorLoader(getActivity(), uri, projection, selection, null, null); - } - - @Override - public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor data) { - mCallLogAdapter.setMissedCalls(data); - } - - @Override - public void onLoaderReset(Loader<Cursor> cursorLoader) { - } - } - private class ContactTileLoaderListener implements LoaderManager.LoaderCallbacks<Cursor> { @Override public CursorLoader onCreateLoader(int id, Bundle args) { @@ -183,13 +143,8 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen private OnPhoneNumberPickerActionListener mPhoneNumberPickerActionListener; private OnListFragmentScrolledListener mActivityScrollListener; - private PhoneFavoriteMergedAdapter mAdapter; private PhoneFavoritesTileAdapter mContactTileAdapter; - private CallLogAdapter mCallLogAdapter; - private CallLogQueryHandler mCallLogQueryHandler; - private WifiWizardAdapter.WifiWizardModel mWifiSettings; - private View mParentView; private PhoneFavoriteListView mListView; @@ -207,17 +162,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen */ private View mEmptyView; - /** - * Call shortcuts older than this date (persisted in shared preferences) will not show up in - * at the top of the screen - */ - private long mLastCallShortcutDate = 0; - - /** - * The date of the current call shortcut that is showing on screen. - */ - private long mCurrentCallShortcutDate = 0; - private final ContactTileView.Listener mContactTileAdapterListener = new ContactTileAdapterListener(); private final LoaderManager.LoaderCallbacks<Cursor> mContactTileLoaderListener = @@ -243,26 +187,12 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen super.onCreate(savedState); mAnimationDuration = getResources().getInteger(R.integer.fade_duration); - mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), - this, 1); - final String currentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); - mCallLogAdapter = ObjectFactory.newCallLogAdapter(getActivity(), this, - new ContactInfoHelper(getActivity(), currentCountryIso), false, false); - - mWifiSettings = new WifiSettings(getActivity()); - setHasOptionsMenu(true); } @Override public void onResume() { super.onResume(); - final SharedPreferences prefs = getActivity().getSharedPreferences( - DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE); - - mLastCallShortcutDate = prefs.getLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, 0); - fetchCalls(); - mCallLogAdapter.setLoading(true); getLoaderManager().getLoader(LOADER_ID_CONTACT_TILE).forceLoad(); } @@ -291,13 +221,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen mTileInteractionTeaserView = (TileInteractionTeaserView) inflater.inflate( R.layout.tile_interactions_teaser_view, mListView, false); - mAdapter = new PhoneFavoriteMergedAdapter(getActivity(), this, mContactTileAdapter, - mCallLogAdapter, mPhoneFavoritesMenu, mTileInteractionTeaserView, - mWifiSettings); - - - mTileInteractionTeaserView.setAdapter(mAdapter); - mListView.setAdapter(mContactTileAdapter); mListView.setOnScrollListener(mScrollListener); @@ -358,7 +281,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen // This method call implicitly assures ContactTileLoaderListener's onLoadFinished() will // be called, on which we'll check if "all" contacts should be reloaded again or not. getLoaderManager().initLoader(LOADER_ID_CONTACT_TILE, null, mContactTileLoaderListener); - getLoaderManager().initLoader(MISSED_CALL_LOADER, null, new MissedCallLogLoaderListener()); } /** @@ -376,37 +298,6 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen } } - @Override - public void onVoicemailStatusFetched(Cursor statusCursor) { - // no-op - } - - @Override - public void onCallsFetched(Cursor cursor) { - mCallLogAdapter.setLoading(false); - - // Save the date of the most recent call log item - if (cursor != null && cursor.moveToFirst()) { - mCurrentCallShortcutDate = cursor.getLong(CallLogQuery.DATE); - } - - mCallLogAdapter.changeCursor(cursor); - mAdapter.notifyDataSetChanged(); - } - - @Override - public void fetchCalls() { - mCallLogQueryHandler.fetchCalls(CallLogQueryHandler.CALL_TYPE_ALL, mLastCallShortcutDate); - } - - @Override - public void onPause() { - // Wipe the cache to refresh the call shortcut item. This is not that expensive because - // it only contains one item. - mCallLogAdapter.invalidateCache(); - super.onPause(); - } - /** * Cache the current view offsets into memory. Once a relayout of views in the ListView * has happened due to a dataset change, the cached offsets are used to create animations @@ -526,15 +417,4 @@ public class PhoneFavoriteFragment extends Fragment implements OnItemClickListen public void cacheOffsetsForDatasetChange() { saveOffsets(0); } - - public void dismissShortcut(View view) { - final int height = ((View) view.getParent()).getHeight(); - saveOffsets(height); - mLastCallShortcutDate = mCurrentCallShortcutDate; - final SharedPreferences prefs = view.getContext().getSharedPreferences( - DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE); - prefs.edit().putLong(KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE, mLastCallShortcutDate) - .apply(); - fetchCalls(); - } } diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java index 7f8b5a0e6..a6af3ced8 100644 --- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java +++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java @@ -56,7 +56,7 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { private final CallLogAdapter mCallLogAdapter; private final WifiWizardAdapter mWifiWizardAdapter; private final View mPhoneFavoritesMenu; - private final PhoneFavoriteFragment mFragment; + private final ListsFragment mFragment; private final TileInteractionTeaserView mTileInteractionTeaserView; private final int mCallLogPadding; @@ -101,7 +101,7 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { }; public PhoneFavoriteMergedAdapter(Context context, - PhoneFavoriteFragment fragment, + ListsFragment fragment, PhoneFavoritesTileAdapter contactTileAdapter, CallLogAdapter callLogAdapter, View phoneFavoritesMenu, @@ -115,13 +115,8 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { mCallLogAdapter = callLogAdapter; mWifiWizardAdapter = new WifiWizardAdapter(context, wifiWizardModel); mObserver = new CustomDataSetObserver(); - mWifiWizardAdapter.registerDataSetObserver(mObserver); mCallLogAdapter.registerDataSetObserver(mObserver); - mContactTileAdapter.registerDataSetObserver(mObserver); mPhoneFavoritesMenu = phoneFavoritesMenu; - // Temporary hack to hide the favorites menu because it is not being used. - // It should be removed from this adapter entirely eventually. - mPhoneFavoritesMenu.setVisibility(View.GONE); mTileInteractionTeaserView = tileInteractionTeaserView; mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(), mCallLogQueryHandlerListener); @@ -137,20 +132,11 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { */ @Override public int getCount() { - return mWifiWizardAdapter.getCount() + mContactTileAdapter.getCount() + - mCallLogAdapter.getCount() + getTeaserViewCount() + 1; + return mCallLogAdapter.getCount(); } @Override public Object getItem(int position) { - if (mWifiWizardAdapter.getCount() > 0) { - if (position < mWifiWizardAdapter.getCount()) { - return mWifiWizardAdapter.getItem(position); - } else { - position -= mWifiWizardAdapter.getCount(); - } - } - final int callLogAdapterCount = mCallLogAdapter.getCount(); if (callLogAdapterCount > 0) { @@ -182,14 +168,6 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { public long getItemId(int position) { final int callLogAdapterCount = mCallLogAdapter.getCount(); - if (mWifiWizardAdapter.getCount() > 0) { - if (position < mWifiWizardAdapter.getCount()) { - return - callLogAdapterCount - 4; - } else { - position -= mWifiWizardAdapter.getCount(); - } - } - if (position < callLogAdapterCount) { // Call log items are not animated, so reusing their position for IDs is fine. return FAVORITES_MENU_ITEM_ID - 1 - position; @@ -218,29 +196,15 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { */ @Override public int getViewTypeCount() { - return (mWifiWizardAdapter.getViewTypeCount() + /* Enable Wifi calling */ - mContactTileAdapter.getViewTypeCount() + /* Favorite and frequent */ - mCallLogAdapter.getViewTypeCount() + /* Recent call log */ - getTeaserViewCount() + /* Teaser */ - 1); /* Favorites menu. */ + return mCallLogAdapter.getViewTypeCount(); } @Override public int getItemViewType(int position) { - if (mWifiWizardAdapter.getCount() > 0) { - if (position < mWifiWizardAdapter.getCount()) { - return mWifiWizardAdapter.getItemViewType(position); - } else { - position -= mWifiWizardAdapter.getCount(); - } - } - final int callLogAdapterCount = mCallLogAdapter.getCount(); if (position < callLogAdapterCount) { - // View type of the call log adapter is the last view type of the contact tile adapter - // + 1 - return mContactTileAdapter.getViewTypeCount(); + return 0; } else if (position == TILE_INTERACTION_TEASER_VIEW_POSITION + callLogAdapterCount && mTileInteractionTeaserView.getShouldDisplayInList()) { // View type of the teaser row is the last view type of the contact tile adapter +2 @@ -266,24 +230,9 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { */ @Override public View getView(int position, View convertView, ViewGroup parent) { - if (mWifiWizardAdapter.getCount() > 0) { - if (position < mWifiWizardAdapter.getCount()) { - SwipeableCallLogRow wrapper = new SwipeableCallLogRow(mContext); - wrapper.addView(mWifiWizardAdapter.getView(position, convertView, parent)); - wrapper.setOnItemSwipeListener(mWifiWizardAdapter.getOnItemSwipeListener()); - return wrapper; - } else { - position -= mWifiWizardAdapter.getCount(); - } - } - final int callLogAdapterCount = mCallLogAdapter.getCount(); - // Get the view for the "teaser view" which describes how to re-arrange favorites. - if (mTileInteractionTeaserView.getShouldDisplayInList() - && position == TILE_INTERACTION_TEASER_VIEW_POSITION + callLogAdapterCount) { - return mTileInteractionTeaserView; - } else if (callLogAdapterCount > 0 && position < callLogAdapterCount) { + if (callLogAdapterCount > 0 && position < callLogAdapterCount) { // Handle case where we are requesting the view for the "most recent caller". final SwipeableCallLogRow wrapper; @@ -324,19 +273,11 @@ public class PhoneFavoriteMergedAdapter extends BaseAdapter { @Override public boolean areAllItemsEnabled() { - return mCallLogAdapter.areAllItemsEnabled() && mContactTileAdapter.areAllItemsEnabled(); + return mCallLogAdapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { - if (mWifiWizardAdapter.getCount() > 0) { - if (position < mWifiWizardAdapter.getCount()) { - return mWifiWizardAdapter.isEnabled(position); - } else { - position -= mWifiWizardAdapter.getCount(); - } - } - final int callLogAdapterCount = mCallLogAdapter.getCount(); if (position < callLogAdapterCount) { return mCallLogAdapter.isEnabled(position); |