Bug 727454: BrowserToolbar inflation crash in ActionBar. [r=mfinkle]

This commit is contained in:
Sriram Ramasubramanian 2012-03-20 17:23:06 -07:00
Родитель b1dd00e6aa
Коммит 0d4d143955
6 изменённых файлов: 48 добавлений и 37 удалений

Просмотреть файл

@ -64,8 +64,9 @@ import android.widget.TextView;
import android.widget.TextSwitcher;
import android.widget.ViewSwitcher.ViewFactory;
public class BrowserToolbar extends LinearLayout {
private static final String LOGTAG = "GeckoToolbar";
public class BrowserToolbar {
private static final String LOGTAG = "GeckoToolbar";
private LinearLayout mLayout;
private Button mAwesomeBar;
private ImageButton mTabs;
public ImageButton mFavicon;
@ -90,16 +91,19 @@ public class BrowserToolbar extends LinearLayout {
private int mCount;
public BrowserToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
public BrowserToolbar(Context context) {
mContext = context;
}
public void from(LinearLayout layout) {
mLayout = layout;
mTitleCanExpand = true;
// Get the device's highlight color
TypedArray typedArray;
if (Build.VERSION.SDK_INT >= 11) {
typedArray = context.obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
typedArray = mContext.obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
} else {
ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, android.R.style.TextAppearance);
typedArray = wrapper.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorHighlight });
@ -107,17 +111,14 @@ public class BrowserToolbar extends LinearLayout {
mColor = typedArray.getColor(typedArray.getIndex(0), 0);
typedArray.recycle();
}
public void init() {
mAwesomeBar = (Button) findViewById(R.id.awesome_bar);
mAwesomeBar = (Button) mLayout.findViewById(R.id.awesome_bar);
mAwesomeBar.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
onAwesomeBarSearch();
}
});
Resources resources = getResources();
Resources resources = mContext.getResources();
mPadding = new int[] { mAwesomeBar.getPaddingLeft(),
mAwesomeBar.getPaddingTop(),
@ -132,7 +133,7 @@ public class BrowserToolbar extends LinearLayout {
mAwesomeBar.setPadding(mPadding[0], mPadding[1], mPadding[2], mPadding[3]);
mTabs = (ImageButton) findViewById(R.id.tabs);
mTabs = (ImageButton) mLayout.findViewById(R.id.tabs);
mTabs.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
if (Tabs.getInstance().getCount() > 1)
@ -145,7 +146,7 @@ public class BrowserToolbar extends LinearLayout {
mCounterColor = 0xFFC7D1DB;
mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count);
mTabsCount = (TextSwitcher) mLayout.findViewById(R.id.tabs_count);
mTabsCount.removeAllViews();
mTabsCount.setFactory(new ViewFactory() {
public View makeView() {
@ -169,18 +170,18 @@ public class BrowserToolbar extends LinearLayout {
mTabsCount.setText("0");
mCount = 0;
mFavicon = (ImageButton) findViewById(R.id.favicon);
mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
mFavicon = (ImageButton) mLayout.findViewById(R.id.favicon);
mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
mProgressSpinner = (AnimationDrawable) resources.getDrawable(R.drawable.progress_spinner);
mStop = (ImageButton) findViewById(R.id.stop);
mStop = (ImageButton) mLayout.findViewById(R.id.stop);
mStop.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
doStop();
}
});
mShadow = (ImageView) findViewById(R.id.shadow);
mShadow = (ImageView) mLayout.findViewById(R.id.shadow);
mHandler = new Handler();
mSlideUpIn = new TranslateAnimation(0, 0, 40, 0);
@ -329,18 +330,26 @@ public class BrowserToolbar extends LinearLayout {
}
}
public void setVisibility(int visibility) {
mLayout.setVisibility(visibility);
}
public void requestFocusFromTouch() {
mLayout.requestFocusFromTouch();
}
public void show() {
if (Build.VERSION.SDK_INT >= 11)
GeckoActionBar.show(GeckoApp.mAppContext);
else
setVisibility(View.VISIBLE);
mLayout.setVisibility(View.VISIBLE);
}
public void hide() {
if (Build.VERSION.SDK_INT >= 11)
GeckoActionBar.hide(GeckoApp.mAppContext);
else
setVisibility(View.GONE);
mLayout.setVisibility(View.GONE);
}
public void refresh() {

Просмотреть файл

@ -1592,15 +1592,11 @@ abstract public class GeckoApp
// The ActionBar needs to be refreshed on rotation as different orientation uses different resources
public void refreshActionBar() {
if (Build.VERSION.SDK_INT >= 11) {
mBrowserToolbar = (BrowserToolbar) getLayoutInflater().inflate(R.layout.browser_toolbar, null);
mBrowserToolbar.init();
LinearLayout actionBar = (LinearLayout) getLayoutInflater().inflate(R.layout.browser_toolbar, null);
mBrowserToolbar.from(actionBar);
mBrowserToolbar.refresh();
GeckoActionBar.setBackgroundDrawable(this, getResources().getDrawable(R.drawable.gecko_actionbar_bg));
GeckoActionBar.setDisplayOptions(this, ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM |
ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE |
ActionBar.DISPLAY_USE_LOGO);
GeckoActionBar.setCustomView(this, mBrowserToolbar);
GeckoActionBar.setCustomView(this, actionBar);
}
}
@ -1633,12 +1629,16 @@ abstract public class GeckoApp
setContentView(R.layout.gecko_app);
LinearLayout actionBar;
if (Build.VERSION.SDK_INT >= 11) {
mBrowserToolbar = (BrowserToolbar) GeckoActionBar.getCustomView(this);
actionBar = (LinearLayout) GeckoActionBar.getCustomView(this);
} else {
mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
actionBar = (LinearLayout) findViewById(R.id.browser_toolbar);
}
mBrowserToolbar = new BrowserToolbar(mAppContext);
mBrowserToolbar.from(actionBar);
// setup gecko layout
mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
mMainLayout = (LinearLayout) findViewById(R.id.main_layout);
@ -1670,7 +1670,6 @@ abstract public class GeckoApp
checkAndLaunchUpdate();
}
mBrowserToolbar.init();
mBrowserToolbar.setTitle(mLastTitle);
String passedUri = null;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -29,6 +29,7 @@
</style>
<style name="Gecko.App">
<item name="android:windowBackground">@drawable/abouthome_bg_repeat</item>
<item name="android:actionBarStyle">@style/ActionBar.GeckoApp</item>
</style>

Просмотреть файл

@ -27,7 +27,9 @@
<item name="android:windowNoTitle">true</item>
</style>
<style name="Gecko.App"/>
<style name="Gecko.App">
<item name="android:windowBackground">@drawable/abouthome_bg_repeat</item>
</style>
<style name="Gecko.Light.AwesomeBar"/>