Bug 907592 - Use viewstubs for loading ViewPager. r=lucasr

This commit is contained in:
Shilpan Bhagat 2013-08-21 02:15:37 -07:00
parent db10dc6082
commit bc3f221ede
4 changed files with 56 additions and 42 deletions

View File

@ -65,6 +65,7 @@ import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@ -266,7 +267,7 @@ abstract public class BrowserApp extends GeckoApp
case KeyEvent.KEYCODE_BUTTON_Y:
// Toggle/focus the address bar on gamepad-y button.
if (mBrowserToolbar.isVisible()) {
if (isDynamicToolbarEnabled() && !mHomePager.isVisible()) {
if (isDynamicToolbarEnabled() && !isHomePagerVisible()) {
if (mLayerView != null) {
mLayerView.getLayerMarginsAnimator().hideMargins(false);
mLayerView.requestFocus();
@ -421,7 +422,11 @@ abstract public class BrowserApp extends GeckoApp
// If we get a gamepad panning MotionEvent while the focus is not on the layerview,
// put the focus on the layerview and carry on
if (mLayerView != null && !mLayerView.hasFocus() && GamepadUtils.isPanningControl(event)) {
if (mHomePager.isVisible()) {
if (mHomePager == null) {
return false;
}
if (isHomePagerVisible()) {
mLayerView.requestFocus();
} else {
mHomePager.requestFocus();
@ -431,7 +436,6 @@ abstract public class BrowserApp extends GeckoApp
}
});
mHomePager = (HomePager) findViewById(R.id.home_pager);
mHomePagerContainer = findViewById(R.id.home_pager_container);
mBrowserSearchContainer = findViewById(R.id.search_container);
@ -843,7 +847,7 @@ abstract public class BrowserApp extends GeckoApp
@Override
public void onMetricsChanged(ImmutableViewportMetrics aMetrics) {
if (mHomePager.isVisible() || mBrowserToolbar == null) {
if (isHomePagerVisible() || mBrowserToolbar == null) {
return;
}
@ -878,7 +882,7 @@ abstract public class BrowserApp extends GeckoApp
@Override
public void onPanZoomStopped() {
if (!isDynamicToolbarEnabled() || mHomePager.isVisible()) {
if (!isDynamicToolbarEnabled() || isHomePagerVisible()) {
return;
}
@ -900,7 +904,7 @@ abstract public class BrowserApp extends GeckoApp
height = mBrowserToolbar.getHeight();
}
if (!isDynamicToolbarEnabled() || mHomePager.isVisible()) {
if (!isDynamicToolbarEnabled() || isHomePagerVisible()) {
// Use aVisibleHeight here so that when the dynamic toolbar is
// enabled, the padding will animate with the toolbar becoming
// visible.
@ -1325,6 +1329,10 @@ abstract public class BrowserApp extends GeckoApp
mBrowserToolbar.cancelEdit();
}
private boolean isHomePagerVisible() {
return (mHomePager != null && mHomePager.isVisible());
}
private void openReadingList() {
Tabs.getInstance().loadUrl(ABOUT_HOME, Tabs.LOADURL_READING_LIST);
}
@ -1445,7 +1453,7 @@ abstract public class BrowserApp extends GeckoApp
}
private void showHomePagerWithAnimator(HomePager.Page page, PropertyAnimator animator) {
if (mHomePager.isVisible()) {
if (isHomePagerVisible()) {
return;
}
@ -1458,6 +1466,10 @@ abstract public class BrowserApp extends GeckoApp
mLayerView.getLayerMarginsAnimator().showMargins(true);
}
if (mHomePager == null) {
final ViewStub homePagerStub = (ViewStub) findViewById(R.id.home_pager);
mHomePager = (HomePager) homePagerStub.inflate();
}
mHomePager.show(getSupportFragmentManager(), page, animator);
}
@ -1470,7 +1482,7 @@ abstract public class BrowserApp extends GeckoApp
}
private void hideHomePagerWithAnimation(boolean animate) {
if (!mHomePager.isVisible()) {
if (!isHomePagerVisible()) {
return;
}
@ -1480,7 +1492,9 @@ abstract public class BrowserApp extends GeckoApp
}
// FIXME: do animation if animate is true
mHomePager.hide();
if (mHomePager != null) {
mHomePager.hide();
}
mBrowserToolbar.setNextFocusDownId(R.id.layer_view);

View File

@ -6,20 +6,18 @@
<!-- This file is used to include the home pager in gecko app
layout based on screen size -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<org.mozilla.gecko.home.HomePager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:visibility="gone">
<org.mozilla.gecko.home.HomePager android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:visibility="gone">
<org.mozilla.gecko.home.TabMenuStrip android:layout_width="fill_parent"
android:layout_height="32dip"
android:background="@color/background_light"
android:layout_gravity="top"
gecko:strip="@drawable/home_tab_menu_strip"/>
<org.mozilla.gecko.home.TabMenuStrip android:layout_width="fill_parent"
android:layout_height="32dip"
android:background="@color/background_light"
android:layout_gravity="top"
gecko:strip="@drawable/home_tab_menu_strip"/>
</org.mozilla.gecko.home.HomePager>
</merge>
</org.mozilla.gecko.home.HomePager>

View File

@ -31,7 +31,11 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/home_pager"/>
<ViewStub android:id="@+id/home_pager"
android:layout="@layout/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>

View File

@ -6,22 +6,20 @@
<!-- This file is used to include the home pager in gecko app
layout based on screen size -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<org.mozilla.gecko.home.HomePager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:visibility="gone">
<org.mozilla.gecko.home.HomePager android:id="@+id/home_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:visibility="gone">
<org.mozilla.gecko.home.HomePagerTabStrip android:layout_width="fill_parent"
android:layout_height="32dip"
android:layout_gravity="top"
android:gravity="bottom"
android:background="@color/background_light"
gecko:tabIndicatorColor="@color/text_color_highlight"
android:textAppearance="@style/TextAppearance.Widget.HomePagerTabStrip"/>
<org.mozilla.gecko.home.HomePagerTabStrip android:layout_width="fill_parent"
android:layout_height="32dip"
android:layout_gravity="top"
android:gravity="bottom"
android:background="@color/background_light"
gecko:tabIndicatorColor="@color/text_color_highlight"
android:textAppearance="@style/TextAppearance.Widget.HomePagerTabStrip"/>
</org.mozilla.gecko.home.HomePager>
</merge>
</org.mozilla.gecko.home.HomePager>