Bug 1016613 - Replace RemoteTabsPanel view with ViewStub in tabs_panel.xml and created new layout file to inflate the ViewStub when user clicks on 3rd button in TabsPanel. r=mcomella

This was done in order to save on resources and not create the RemoteTabsPanel until needed
This commit is contained in:
Ethan Pransky 2014-08-13 10:39:32 -07:00
parent bf8e054248
commit 3cba06f3f1
4 changed files with 53 additions and 15 deletions

View File

@ -46,11 +46,10 @@
android:layout_height="match_parent"
android:visibility="gone"/>
<org.mozilla.gecko.tabs.RemoteTabsPanel
android:id="@+id/remote_tabs"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<ViewStub android:id="@+id/remote_tabs_panel_stub"
android:layout="@layout/remote_tabs_panel_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</view>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<org.mozilla.gecko.tabspanel.RemoteTabsPanel xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/remote_tabs_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

View File

@ -45,11 +45,10 @@
android:layout_height="match_parent"
android:visibility="gone"/>
<org.mozilla.gecko.tabs.RemoteTabsPanel
android:id="@+id/remote_tabs"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<ViewStub android:id="@+id/remote_tabs_panel_stub"
android:layout="@layout/remote_tabs_panel_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</view>

View File

@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
@ -113,7 +114,7 @@ public class TabsPanel extends LinearLayout
public void onResume() {
if (mPanel == mPanelRemote) {
// Refresh the remote panel.
mPanelRemote.show();
getRemotePanelView().show();
}
}
@ -127,7 +128,23 @@ public class TabsPanel extends LinearLayout
};
}
/**
* Initializes views in tabs_panel layout
*
* @throws IllegalStateException
* mCurrentPanel must have a non-null value
*/
private void initialize() {
if (mCurrentPanel == null) {
throw new IllegalStateException(
"mCurrentPanel cannot be null in order for RemotePanelView to be initialized");
}
if (mCurrentPanel == Panel.REMOTE_TABS) {
// Initializes mPanelRemote
getRemotePanelView();
}
mHeader = (RelativeLayout) findViewById(R.id.tabs_panel_header);
mTabsContainer = (TabsListContainer) findViewById(R.id.tabs_container);
@ -137,9 +154,6 @@ public class TabsPanel extends LinearLayout
mPanelPrivate = (PanelView) findViewById(R.id.private_tabs_panel);
mPanelPrivate.setTabsPanel(this);
mPanelRemote = (PanelView) findViewById(R.id.remote_tabs);
mPanelRemote.setTabsPanel(this);
mFooter = (RelativeLayout) findViewById(R.id.tabs_panel_footer);
mAddTab = (ImageButton) findViewById(R.id.add_tab);
@ -416,7 +430,7 @@ public class TabsPanel extends LinearLayout
mPanel = mPanelPrivate;
break;
case REMOTE_TABS:
mPanel = mPanelRemote;
mPanel = getRemotePanelView();
break;
default:
@ -472,6 +486,9 @@ public class TabsPanel extends LinearLayout
public void refresh() {
removeAllViews();
// The View that mPanelRemote points to is invalidated because the layout is invalidated.
// mPanelRemote must be null in order to properly initialize RemotePanelView.
mPanelRemote = null;
LayoutInflater.from(mContext).inflate(R.layout.tabs_panel, this);
initialize();
@ -570,4 +587,18 @@ public class TabsPanel extends LinearLayout
public void setIconDrawable(Panel panel, int resource) {
mTabWidget.setIconDrawable(panel.ordinal(), resource);
}
/**
* Initializes mPanelRemote if necessary and provides getter because you
* should probably not access mPanelRemote directly
*
* @return PanelView
*/
private PanelView getRemotePanelView() {
if (mPanelRemote == null) {
mPanelRemote = (PanelView) ((ViewStub) findViewById(R.id.remote_tabs_panel_stub)).inflate();
mPanelRemote.setTabsPanel(TabsPanel.this);
}
return mPanelRemote;
}
}