Implement smoother swipe animation for Phone UI
Phone UI conditionally shows split ActionBar on the bottom,
which makes swipe animation less smooth. This change makes it
smoother by reducing layout re-calculation.
- stop changing menu state on onPageSelected but do so on
onPageScrollStateChange.
- use android:windowActionBarOverlay to suppress recalculation
during menu show-up
- add marginTop to every fragment for Phone so that fragments
won't overlap with ActionBar
- add paddingBottom for CallLog and Favorites so that those
fragments won't overlap with split ActionBar
FUTURE TODO:
We need custom assets for android:actionBarStyle
- android:background
- android:backgroundStacked
- android:backgroundSplit
Bug: 5022052
Change-Id: I3bd48cf9d8aaa398806531823fca63de328b807a
diff --git a/res/layout/call_log_fragment.xml b/res/layout/call_log_fragment.xml
index 2d0b9b5..ff7dd4b 100644
--- a/res/layout/call_log_fragment.xml
+++ b/res/layout/call_log_fragment.xml
@@ -18,7 +18,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
->
+ android:paddingBottom="?android:attr/actionBarSize">
+
<FrameLayout
android:id="@+id/voicemail_status"
android:layout_width="match_parent"
diff --git a/res/layout/contact_tile_list.xml b/res/layout/contact_tile_list.xml
index c72386e..2047b13 100644
--- a/res/layout/contact_tile_list.xml
+++ b/res/layout/contact_tile_list.xml
@@ -17,7 +17,8 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:paddingBottom="?attr/favorites_padding_bottom">
<ListView
android:id="@+id/contact_tile_list"
diff --git a/res/layout/dialtacts_activity.xml b/res/layout/dialtacts_activity.xml
index 14fb137..6484d87 100644
--- a/res/layout/dialtacts_activity.xml
+++ b/res/layout/dialtacts_activity.xml
@@ -16,7 +16,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:layout_marginTop="?android:attr/actionBarSize">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
diff --git a/res/values/styles.xml b/res/values/styles.xml
index f32ae4c..e98175d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -14,7 +14,9 @@
limitations under the License.
-->
<resources>
- <style name="DialtactsTheme" parent="android:Theme.Holo.SplitActionBarWhenNarrow">
+ <style name="DialtactsTheme"
+ parent="android:Theme.Holo.SolidActionBar.SplitActionBarWhenNarrow">
+ <item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/black</item>
<item name="activated_background">@drawable/list_item_activated_background</item>
@@ -51,6 +53,8 @@
<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>
+ <!-- Favorites -->
+ <item name="favorites_padding_bottom">?android:attr/actionBarSize</item>
</style>
<style name="CallDetailActivityTheme" parent="android:Theme.Holo.SplitActionBarWhenNarrow">
@@ -161,6 +165,10 @@
<attr name="call_log_voicemail_status_text_color" format="color" />
</declare-styleable>
+ <declare-styleable name="Favorites">
+ <attr name="favorites_padding_bottom" format="dimension" />
+ </declare-styleable>
+
<style name="PeopleTheme" parent="@android:style/Theme.Holo.Light.SolidActionBar.Inverse.SplitActionBarWhenNarrow">
<item name="android:actionBarStyle">@style/ContactsActionBarStyle</item>
<item name="list_item_height">?android:attr/listPreferredItemHeight</item>
@@ -188,6 +196,8 @@
<item name="list_item_header_underline_height">1px</item>
<item name="list_item_header_underline_color">@color/people_app_theme_color</item>
<item name="contact_filter_popup_width">320dip</item>
+ <!-- Favorites -->
+ <item name="favorites_padding_bottom">0dip</item>
</style>
<style name="ContactsActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
diff --git a/src/com/android/contacts/activities/DialtactsActivity.java b/src/com/android/contacts/activities/DialtactsActivity.java
index 7e41a5c..022a724 100644
--- a/src/com/android/contacts/activities/DialtactsActivity.java
+++ b/src/com/android/contacts/activities/DialtactsActivity.java
@@ -122,7 +122,12 @@
}
private class PageChangeListener implements OnPageChangeListener {
- private int mPreviousPosition = -1; // Invalid at first
+ private int mCurrentPosition = -1;
+ /**
+ * Used during page migration, to remember the next position {@link #onPageSelected(int)}
+ * specified.
+ */
+ private int mNextPosition = -1;
@Override
public void onPageScrolled(
@@ -132,34 +137,38 @@
@Override
public void onPageSelected(int position) {
final ActionBar actionBar = getActionBar();
- if (mPreviousPosition == position) {
+ if (mCurrentPosition == position) {
Log.w(TAG, "Previous position and next position became same (" + position + ")");
}
- if (mPreviousPosition >= 0) {
- sendFragmentVisibilityChange(mPreviousPosition, false);
- }
- sendFragmentVisibilityChange(position, true);
-
actionBar.selectTab(actionBar.getTabAt(position));
-
- // Activity#onPrepareOptionsMenu() may not be called when Fragment has it's own
- // options menu. We force this Activity to call it to hide/show bottom bar. Also
- // we don't want to do so when it is unnecessary (buttons may flicker).
- if (mPreviousPosition == TAB_INDEX_DIALER || position == TAB_INDEX_DIALER) {
- // Force this Activity to prepare Menu again.
- invalidateOptionsMenu();
- }
-
- mPreviousPosition = position;
+ mNextPosition = position;
}
public void setCurrentPosition(int position) {
- mPreviousPosition = position;
+ mCurrentPosition = position;
}
@Override
public void onPageScrollStateChanged(int state) {
+ switch (state) {
+ case ViewPager.SCROLL_STATE_IDLE: {
+ if (mCurrentPosition >= 0) {
+ sendFragmentVisibilityChange(mCurrentPosition, false);
+ }
+ if (mNextPosition >= 0) {
+ sendFragmentVisibilityChange(mNextPosition, true);
+ }
+ invalidateOptionsMenu();
+
+ mCurrentPosition = mNextPosition;
+ break;
+ }
+ case ViewPager.SCROLL_STATE_DRAGGING:
+ case ViewPager.SCROLL_STATE_SETTLING:
+ default:
+ break;
+ }
}
}
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 8f7cfa8..abc9adf 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -989,19 +989,16 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
- inflater.inflate(R.menu.call_log_options, menu);
+ if (mShowOptionsMenu) {
+ inflater.inflate(R.menu.call_log_options, menu);
+ }
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
- menu.findItem(R.id.delete_all).setVisible(mShowOptionsMenu);
- menu.findItem(R.id.show_voicemails_only).setVisible(mShowOptionsMenu);
- final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings_call_log);
if (mShowOptionsMenu) {
- callSettingsMenuItem.setVisible(true);
- callSettingsMenuItem.setIntent(DialtactsActivity.getCallSettingsIntent());
- } else {
- callSettingsMenuItem.setVisible(false);
+ menu.findItem(R.id.menu_call_settings_call_log)
+ .setIntent(DialtactsActivity.getCallSettingsIntent());
}
}
diff --git a/src/com/android/contacts/dialpad/DialpadFragment.java b/src/com/android/contacts/dialpad/DialpadFragment.java
index 6acbc85..add6b80 100644
--- a/src/com/android/contacts/dialpad/DialpadFragment.java
+++ b/src/com/android/contacts/dialpad/DialpadFragment.java
@@ -538,10 +538,8 @@
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
-
- // If the hardware doesn't have a hardware menu key, we'll show soft menu button on the
- // right side of digits EditText.
- if (ViewConfiguration.get(getActivity()).hasPermanentMenuKey()) {
+ if (mShowOptionsMenu && ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
+ mDialpadChooser != null && mDigits != null) {
inflater.inflate(R.menu.dialpad_options, menu);
}
}
@@ -549,16 +547,9 @@
@Override
public void onPrepareOptionsMenu(Menu menu) {
// Hardware menu key should be available and Views should already be ready.
- if (ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
+ if (mShowOptionsMenu && ViewConfiguration.get(getActivity()).hasPermanentMenuKey() &&
mDialpadChooser != null && mDigits != null) {
- if (mShowOptionsMenu) {
- setupMenuItems(menu);
- } else {
- menu.findItem(R.id.menu_call_settings_dialpad).setVisible(false);
- menu.findItem(R.id.menu_add_contacts).setVisible(false);
- menu.findItem(R.id.menu_2s_pause).setVisible(false);
- menu.findItem(R.id.menu_add_wait).setVisible(false);
- }
+ setupMenuItems(menu);
}
}