diff options
author | Andrew Lee <anwlee@google.com> | 2015-05-22 16:02:39 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-05-22 16:02:39 +0000 |
commit | a2e621ea90486c056a929c3ede78a6f10cd8c3fd (patch) | |
tree | feeef43d0685f60d05905376f420337c7c4710b0 | |
parent | f9821a2c9c7e6e534eacd23965632e8570acab80 (diff) | |
parent | 547a3980ca697288abcb103fd04a8fcd2d679086 (diff) |
am 547a3980: am 57b528b7: am c2ebd1cf: Merge "Some ListsFragment cleanups." into mnc-dev
* commit '547a3980ca697288abcb103fd04a8fcd2d679086':
Some ListsFragment cleanups.
-rw-r--r-- | src/com/android/dialer/DialtactsActivity.java | 40 | ||||
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 42 |
2 files changed, 30 insertions, 52 deletions
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 56d5ad171..502b8457a 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -585,7 +585,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O public void onClick(View view) { switch (view.getId()) { case R.id.floating_action_button: - if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) { + if (mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_ALL_CONTACTS) { DialerUtils.startActivityWithErrorToast( this, IntentUtil.getNewContactIntent(), @@ -1162,25 +1162,25 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - position = mListsFragment.getRtlPosition(position); - // Only scroll the button when the first tab is selected. The button should scroll from - // the middle to right position only on the transition from the first tab to the second - // tab. - // If the app is in RTL mode, we need to check against the second tab, rather than the - // first. This is because if we are scrolling between the first and second tabs, the - // viewpager will report that the starting tab position is 1 rather than 0, due to the - // reversal of the order of the tabs. - final boolean isLayoutRtl = DialerUtils.isRtl(); - final boolean shouldScrollButton = position == (isLayoutRtl - ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL); - if (shouldScrollButton && !mIsLandscape) { - mFloatingActionButtonController.onPageScrolled( - isLayoutRtl ? 1 - positionOffset : positionOffset); - } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) { + int tabIndex = mListsFragment.getCurrentTabIndex(); + + // Scroll the button from center to end when moving from the Speed Dial to Recents tab. + // In RTL, scroll when the current tab is Recents instead of Speed Dial, because the order + // of the tabs is reversed and the ViewPager returns the left tab position during scroll. + boolean isRtl = DialerUtils.isRtl(); + if (!isRtl && tabIndex == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) { + mFloatingActionButtonController.onPageScrolled(positionOffset); + } else if (isRtl && tabIndex == ListsFragment.TAB_INDEX_RECENTS && !mIsLandscape) { + mFloatingActionButtonController.onPageScrolled(1 - positionOffset); + } else if (tabIndex != ListsFragment.TAB_INDEX_SPEED_DIAL) { mFloatingActionButtonController.onPageScrolled(1); } + } - if (position == ListsFragment.TAB_INDEX_ALL_CONTACTS) { + @Override + public void onPageSelected(int position) { + int tabIndex = mListsFragment.getCurrentTabIndex(); + if (tabIndex == ListsFragment.TAB_INDEX_ALL_CONTACTS) { mFloatingActionButtonController.changeIcon( getResources().getDrawable(R.drawable.ic_person_add_24dp), getResources().getString(R.string.search_shortcut_create_new_contact)); @@ -1192,10 +1192,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } @Override - public void onPageSelected(int position) { - } - - @Override public void onPageScrollStateChanged(int state) { } @@ -1239,7 +1235,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O */ private void updateFloatingActionButtonControllerAlignment(boolean animate) { int align = (!mIsLandscape && - mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_SPEED_DIAL) ? + mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) ? FloatingActionButtonController.ALIGN_MIDDLE : FloatingActionButtonController.ALIGN_END; mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate); diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 0ac6b1ac0..a0e443c22 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -62,9 +62,6 @@ public class ListsFragment extends Fragment // Oldest recents entry to display is 2 weeks old. private static final long OLDEST_RECENTS_DATE = 1000L * 60 * 60 * 24 * 14; - private static final String KEY_LAST_DISMISSED_CALL_SHORTCUT_DATE = - "key_last_dismissed_call_shortcut_date"; - public interface HostInterface { public ActionBarController getActionBarController(); } @@ -92,18 +89,7 @@ public class ListsFragment extends Fragment /** * The position of the currently selected tab. */ - private int mTabPosition = TAB_INDEX_SPEED_DIAL; - - /** - * 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 int mTabIndex = TAB_INDEX_SPEED_DIAL; public class ViewPagerAdapter extends FragmentPagerAdapter { public ViewPagerAdapter(FragmentManager fm) { @@ -182,12 +168,9 @@ public class ListsFragment extends Fragment public void onResume() { Trace.beginSection(TAG + " 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); mActionBar = getActivity().getActionBar(); if (getUserVisibleHint()) { - sendScreenViewForPosition(mViewPager.getCurrentItem()); + sendScreenViewForCurrentPosition(); } // Fetch voicemail status to determine if we should show the voicemail tab. @@ -208,7 +191,7 @@ public class ListsFragment extends Fragment mViewPager = (ViewPager) parentView.findViewById(R.id.lists_pager); mViewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); - mViewPager.setOffscreenPageLimit(TAB_COUNT_DEFAULT - 1); + mViewPager.setOffscreenPageLimit(TAB_COUNT_WITH_VOICEMAIL - 1); mViewPager.setOnPageChangeListener(this); mViewPager.setCurrentItem(getRtlPosition(TAB_INDEX_SPEED_DIAL)); @@ -245,6 +228,8 @@ public class ListsFragment extends Fragment @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + mTabIndex = getRtlPosition(position); + final int count = mOnPageChangeListeners.size(); for (int i = 0; i < count; i++) { mOnPageChangeListeners.get(i).onPageScrolled(position, positionOffset, @@ -254,13 +239,13 @@ public class ListsFragment extends Fragment @Override public void onPageSelected(int position) { - mTabPosition = getRtlPosition(position); + mTabIndex = getRtlPosition(position); final int count = mOnPageChangeListeners.size(); for (int i = 0; i < count; i++) { mOnPageChangeListeners.get(i).onPageSelected(position); } - sendScreenViewForPosition(position); + sendScreenViewForCurrentPosition(); } @Override @@ -293,8 +278,8 @@ public class ListsFragment extends Fragment return false; } - public int getTabPosition() { - return mTabPosition; + public int getCurrentTabIndex() { + return mTabIndex; } public void showRemoveView(boolean show) { @@ -316,7 +301,7 @@ public class ListsFragment extends Fragment return mRemoveView; } - public int getRtlPosition(int position) { + private int getRtlPosition(int position) { if (DialerUtils.isRtl()) { return mViewPagerAdapter.getCount() - 1 - position; } @@ -324,15 +309,12 @@ public class ListsFragment extends Fragment } public void sendScreenViewForCurrentPosition() { - sendScreenViewForPosition(mViewPager.getCurrentItem()); - } - - private void sendScreenViewForPosition(int position) { if (!isResumed()) { return; } + String fragmentName; - switch (getRtlPosition(position)) { + switch (getCurrentTabIndex()) { case TAB_INDEX_SPEED_DIAL: fragmentName = SpeedDialFragment.class.getSimpleName(); break; |