Bug 708394: Remove unwanted LayoutInflater [r=mfinkle]

This commit is contained in:
Sriram Ramasubramanian
2011-12-07 15:12:51 -08:00
parent 3400c4cb51
commit 68532fad1d
11 changed files with 97 additions and 52 deletions

View File

@@ -79,9 +79,6 @@ public class AboutHomeContent extends LinearLayout {
public AboutHomeContent(Context context, AttributeSet attrs) { public AboutHomeContent(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.abouthome_content, this);
} }
private static final String LOGTAG = "GeckoAboutHome"; private static final String LOGTAG = "GeckoAboutHome";

View File

@@ -92,6 +92,7 @@ public class AwesomeBarTabs extends TabHost {
private static enum HistorySection { TODAY, YESTERDAY, WEEK, OLDER }; private static enum HistorySection { TODAY, YESTERDAY, WEEK, OLDER };
private Context mContext; private Context mContext;
private boolean mInflated;
private OnUrlOpenListener mUrlOpenListener; private OnUrlOpenListener mUrlOpenListener;
private View.OnTouchListener mListTouchListener; private View.OnTouchListener mListTouchListener;
private JSONArray mSearchEngines; private JSONArray mSearchEngines;
@@ -512,13 +513,21 @@ public class AwesomeBarTabs extends TabHost {
Log.d(LOGTAG, "Creating AwesomeBarTabs"); Log.d(LOGTAG, "Creating AwesomeBarTabs");
mContext = context; mContext = context;
mInflated = false;
mSearchEngines = new JSONArray(); mSearchEngines = new JSONArray();
}
// Load layout into the custom view @Override
LayoutInflater inflater = protected void onFinishInflate() {
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); super.onFinishInflate();
inflater.inflate(R.layout.awesomebar_tabs, this); // HACK: Without this, the onFinishInflate is called twice
// This issue is due to a bug when Android inflates a layout with a
// parent. Fixed in Honeycomb
if (mInflated)
return;
mInflated = true;
// This should be called before adding any tabs // This should be called before adding any tabs
// to the TabHost. // to the TabHost.

View File

@@ -62,43 +62,51 @@ import android.widget.TextSwitcher;
import android.widget.ViewSwitcher.ViewFactory; import android.widget.ViewSwitcher.ViewFactory;
public class BrowserToolbar extends LinearLayout { public class BrowserToolbar extends LinearLayout {
final private Button mAwesomeBar; private Button mAwesomeBar;
final private ImageButton mTabs; private ImageButton mTabs;
final public ImageButton mFavicon; public ImageButton mFavicon;
final public ImageButton mStop; public ImageButton mStop;
final public ImageButton mSiteSecurity; public ImageButton mSiteSecurity;
final private AnimationDrawable mProgressSpinner; private AnimationDrawable mProgressSpinner;
final private TextSwitcher mTabsCount; private TextSwitcher mTabsCount;
final private Context mContext; final private Context mContext;
final private Handler mHandler; private Handler mHandler;
final private int mColor; private boolean mInflated;
final private int mCounterColor; private int mColor;
private int mCounterColor;
final private int mDuration; private int mDuration;
final private TranslateAnimation mSlideUpIn; private TranslateAnimation mSlideUpIn;
final private TranslateAnimation mSlideUpOut; private TranslateAnimation mSlideUpOut;
final private TranslateAnimation mSlideDownIn; private TranslateAnimation mSlideDownIn;
final private TranslateAnimation mSlideDownOut; private TranslateAnimation mSlideDownOut;
private int mCount; private int mCount;
public BrowserToolbar(Context context, AttributeSet attrs) { public BrowserToolbar(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mContext = context; mContext = context;
mInflated = false;
}
@Override
protected void onFinishInflate () {
super.onFinishInflate();
// HACK: Without this, the onFinishInflate is called twice
// This issue is due to a bug when Android inflates a layout with a
// parent. Fixed in Honeycomb
if (mInflated)
return;
mInflated = true;
// Get the device's highlight color // Get the device's highlight color
ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, android.R.style.TextAppearance); ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, android.R.style.TextAppearance);
TypedArray typedArray = wrapper.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight }); TypedArray typedArray = wrapper.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
mColor = typedArray.getColor(typedArray.getIndex(0), 0); mColor = typedArray.getColor(typedArray.getIndex(0), 0);
// Load layout into the custom view
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.browser_toolbar, this);
mAwesomeBar = (Button) findViewById(R.id.awesome_bar); mAwesomeBar = (Button) findViewById(R.id.awesome_bar);
mAwesomeBar.setOnClickListener(new Button.OnClickListener() { mAwesomeBar.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
@@ -135,6 +143,7 @@ public class BrowserToolbar extends LinearLayout {
mCounterColor = 0x99ffffff; mCounterColor = 0x99ffffff;
mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count); mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count);
mTabsCount.removeAllViews();
mTabsCount.setFactory(new ViewFactory() { mTabsCount.setFactory(new ViewFactory() {
public View makeView() { public View makeView() {
TextView text = new TextView(mContext); TextView text = new TextView(mContext);
@@ -142,11 +151,11 @@ public class BrowserToolbar extends LinearLayout {
text.setTextSize(16); text.setTextSize(16);
text.setTextColor(mCounterColor); text.setTextColor(mCounterColor);
text.setTypeface(text.getTypeface(), Typeface.BOLD); text.setTypeface(text.getTypeface(), Typeface.BOLD);
return text; return (View) text;
} }
}); });
mCount = 0;
mTabsCount.setText("0"); mTabsCount.setText("0");
mCount = 0;
mFavicon = (ImageButton) findViewById(R.id.favicon); mFavicon = (ImageButton) findViewById(R.id.favicon);
mSiteSecurity = (ImageButton) findViewById(R.id.site_security); mSiteSecurity = (ImageButton) findViewById(R.id.site_security);

View File

@@ -56,11 +56,13 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
private LinearLayout mChoicesLayout; private LinearLayout mChoicesLayout;
private TextView mTextView; private TextView mTextView;
private Button mButton; private Button mButton;
private LayoutParams mLayoutParams; static private LayoutParams mLayoutParams;
public Tab mTab; public Tab mTab;
// value used to identify the notification // value used to identify the notification
private String mValue; private String mValue;
static private LayoutInflater mInflater;
private int mPersistence = 0; private int mPersistence = 0;
private long mTimeout = 0; private long mTimeout = 0;
@@ -73,15 +75,16 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
setOrientation(VERTICAL); setOrientation(VERTICAL);
setBackgroundResource(R.drawable.doorhanger_shadow_bg); setBackgroundResource(R.drawable.doorhanger_shadow_bg);
// Load layout into the custom view if (mInflater == null)
LayoutInflater inflater = mInflater = LayoutInflater.from(mContext);
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.doorhanger, this); mInflater.inflate(R.layout.doorhanger, this);
hide(); hide();
mTextView = (TextView) findViewById(R.id.doorhanger_title); mTextView = (TextView) findViewById(R.id.doorhanger_title);
mChoicesLayout = (LinearLayout) findViewById(R.id.doorhanger_choices); mChoicesLayout = (LinearLayout) findViewById(R.id.doorhanger_choices);
if (mLayoutParams == null)
mLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, mLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
1.0f); 1.0f);

View File

@@ -69,7 +69,7 @@ public class DoorHangerPopup extends PopupWindow {
setOutsideTouchable(true); setOutsideTouchable(true);
setWindowLayoutMode(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); setWindowLayoutMode(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = LayoutInflater.from(mContext);
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.doorhangerpopup, null); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.doorhangerpopup, null);
mContent = (LinearLayout) layout.findViewById(R.id.doorhanger_container); mContent = (LinearLayout) layout.findViewById(R.id.doorhanger_container);

View File

@@ -76,6 +76,11 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
private PromptInput[] mInputs; private PromptInput[] mInputs;
private AlertDialog mDialog = null; private AlertDialog mDialog = null;
private static LayoutInflater mInflater;
PromptService() {
mInflater = LayoutInflater.from(GeckoApp.mAppContext);
}
private class PromptButton { private class PromptButton {
public String label = ""; public String label = "";
@@ -189,8 +194,7 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
PromptListAdapter adapter = new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList); PromptListAdapter adapter = new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList);
if (mSelected != null && mSelected.length > 0) { if (mSelected != null && mSelected.length > 0) {
if (aMultipleSelection) { if (aMultipleSelection) {
LayoutInflater inflater = GeckoApp.mAppContext.getLayoutInflater(); adapter.listView = (ListView) mInflater.inflate(R.layout.select_dialog_list, null);
adapter.listView = (ListView) inflater.inflate(R.layout.select_dialog_list, null);
adapter.listView.setOnItemClickListener(this); adapter.listView.setOnItemClickListener(this);
builder.setInverseBackgroundForced(true); builder.setInverseBackgroundForced(true);
adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
@@ -432,8 +436,7 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
if (item.isGroup) { if (item.isGroup) {
resourceId = R.layout.list_item_header; resourceId = R.layout.list_item_header;
} }
LayoutInflater inflater = GeckoApp.mAppContext.getLayoutInflater(); View row = mInflater.inflate(resourceId, null);
View row = inflater.inflate(resourceId, null);
if (!item.isGroup){ if (!item.isGroup){
try { try {
CheckedTextView ct = (CheckedTextView)row.findViewById(android.R.id.text1); CheckedTextView ct = (CheckedTextView)row.findViewById(android.R.id.text1);

View File

@@ -37,6 +37,10 @@
<org.mozilla.gecko.AwesomeBarTabs android:id="@+id/awesomebar_tabs" <org.mozilla.gecko.AwesomeBarTabs android:id="@+id/awesomebar_tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content">
<include layout="@layout/awesomebar_tabs"/>
</org.mozilla.gecko.AwesomeBarTabs>
</LinearLayout> </LinearLayout>

View File

@@ -18,7 +18,11 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="#ffffff" android:background="#ffffff"
android:isScrollContainer="true"/> android:isScrollContainer="true">
<include layout="@layout/abouthome_content"/>
</org.mozilla.gecko.AboutHomeContent>
</RelativeLayout> </RelativeLayout>

View File

@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<org.mozilla.gecko.BrowserToolbar xmlns:android="http://schemas.android.com/apk/res/android" <org.mozilla.gecko.BrowserToolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/browser_toolbar" android:id="@+id/browser_toolbar"
style="@style/BrowserToolbar"/> style="@style/BrowserToolbar">
<include layout="@layout/browser_toolbar"/>
</org.mozilla.gecko.BrowserToolbar>

View File

@@ -36,6 +36,10 @@
<org.mozilla.gecko.AwesomeBarTabs android:id="@+id/awesomebar_tabs" <org.mozilla.gecko.AwesomeBarTabs android:id="@+id/awesomebar_tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content">
<include layout="@layout/awesomebar_tabs"/>
</org.mozilla.gecko.AwesomeBarTabs>
</LinearLayout> </LinearLayout>

View File

@@ -4,7 +4,11 @@
style="@style/Screen"> style="@style/Screen">
<org.mozilla.gecko.BrowserToolbar android:id="@+id/browser_toolbar" <org.mozilla.gecko.BrowserToolbar android:id="@+id/browser_toolbar"
style="@style/BrowserToolbar"/> style="@style/BrowserToolbar">
<include layout="@layout/browser_toolbar"/>
</org.mozilla.gecko.BrowserToolbar>
<RelativeLayout android:id="@+id/gecko_layout" <RelativeLayout android:id="@+id/gecko_layout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@@ -21,7 +25,11 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="#ffffff" android:background="#ffffff"
android:isScrollContainer="true"/> android:isScrollContainer="true">
<include layout="@layout/abouthome_content"/>
</org.mozilla.gecko.AboutHomeContent>
</RelativeLayout> </RelativeLayout>