Bug 738049: Using LayoutInflater.Factory improves performance. [r=mfinkle]

This commit is contained in:
Sriram Ramasubramanian 2012-03-23 12:00:17 -07:00
parent 62c70a9478
commit 35a4ec6ff7
5 changed files with 66 additions and 0 deletions

View File

@ -61,6 +61,7 @@ import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
@ -109,6 +110,7 @@ public class AwesomeBar extends Activity implements GeckoEventListener {
Log.d(LOGTAG, "creating awesomebar");
mResolver = Tabs.getInstance().getContentResolver();
LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance());
setContentView(R.layout.awesomebar);

View File

@ -1623,6 +1623,8 @@ abstract public class GeckoApp
mRestoreSession = savedInstanceState.getBoolean(SAVED_STATE_SESSION);
}
LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance());
super.onCreate(savedInstanceState);
mOrientation = getResources().getConfiguration().orientation;

View File

@ -0,0 +1,59 @@
/* 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/. */
package org.mozilla.gecko;
import java.util.HashMap;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
public final class GeckoViewsFactory implements LayoutInflater.Factory {
private static final String LOGTAG = "GeckoViewsFactory";
private static final String GECKO_VIEW_IDENTIFIER = "org.mozilla.gecko.";
private static final int GECKO_VIEW_IDENTIFIER_LENGTH = GECKO_VIEW_IDENTIFIER.length();
// List of custom views used
private static final int ABOUT_HOME_SECTION = 1;
private static final int AWESOME_BAR_TABS = 2;
private static final int FORM_ASSIST_POPUP = 3;
private static final int LINK_TEXT_VIEW = 4;
private GeckoViewsFactory() { }
// Making this a singleton class.
private static final GeckoViewsFactory INSTANCE = new GeckoViewsFactory();
public static GeckoViewsFactory getInstance() {
return INSTANCE;
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
if (!TextUtils.isEmpty(name) && name.startsWith(GECKO_VIEW_IDENTIFIER)) {
String viewName = name.substring(GECKO_VIEW_IDENTIFIER_LENGTH);
if (TextUtils.isEmpty(viewName))
return null;
Log.i(LOGTAG, "Creating custom Gecko view: " + viewName);
if (TextUtils.equals(viewName, "AboutHomeSection"))
return new AboutHomeSection(context, attrs);
else if (TextUtils.equals(viewName, "AwesomeBarTabs"))
return new AwesomeBarTabs(context, attrs);
else if (TextUtils.equals(viewName, "FormAssistPopup"))
return new FormAssistPopup(context, attrs);
else if (TextUtils.equals(viewName, "LinkTextView"))
return new LinkTextView(context, attrs);
}
return null;
}
}

View File

@ -97,6 +97,7 @@ FENNEC_JAVA_FILES = \
GeckoStateListDrawable.java \
GeckoThread.java \
GlobalHistory.java \
GeckoViewsFactory.java \
LinkPreference.java \
LinkTextView.java \
NSSBridge.java \

View File

@ -53,6 +53,8 @@ public class TabsTray extends Activity implements Tabs.OnTabsChangedListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance());
setContentView(R.layout.tabs_tray);
mWaitingForClose = false;