public void from(LinearLayout layout) {
    mLayout = layout;

    mShowSiteSecurity = false;
    mShowReader = false;
    mReaderPopup = null;

    mAwesomeBar = (Button) mLayout.findViewById(R.id.awesome_bar);
    mAwesomeBar.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            GeckoApp.mAppContext.hideTabs();
            onAwesomeBarSearch();
          }
        });
    mAwesomeBar.setOnCreateContextMenuListener(
        new View.OnCreateContextMenuListener() {
          public void onCreateContextMenu(
              ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            MenuInflater inflater = GeckoApp.mAppContext.getMenuInflater();
            inflater.inflate(R.menu.titlebar_contextmenu, menu);

            String clipboard = GeckoAppShell.getClipboardText();
            if (clipboard == null || TextUtils.isEmpty(clipboard)) {
              menu.findItem(R.id.pasteandgo).setVisible(false);
              menu.findItem(R.id.paste).setVisible(false);
            }

            Tab tab = Tabs.getInstance().getSelectedTab();
            if (tab != null) {
              String url = tab.getURL();
              if (url == null) {
                menu.findItem(R.id.copyurl).setVisible(false);
                menu.findItem(R.id.share).setVisible(false);
                menu.findItem(R.id.add_to_launcher).setVisible(false);
              }
            } else {
              // if there is no tab, remove anything tab dependent
              menu.findItem(R.id.copyurl).setVisible(false);
              menu.findItem(R.id.share).setVisible(false);
              menu.findItem(R.id.add_to_launcher).setVisible(false);
            }
          }
        });

    mPadding =
        new int[] {
          mAwesomeBar.getPaddingLeft(),
          mAwesomeBar.getPaddingTop(),
          mAwesomeBar.getPaddingRight(),
          mAwesomeBar.getPaddingBottom()
        };

    mTabs = (ImageButton) mLayout.findViewById(R.id.tabs);
    mTabs.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            toggleTabs();
          }
        });
    mTabs.setImageLevel(0);

    mTabsCount = (TextSwitcher) mLayout.findViewById(R.id.tabs_count);
    mTabsCount.removeAllViews();
    mTabsCount.setFactory(this);
    mTabsCount.setText("");
    mCount = 0;

    mBack = (ImageButton) mLayout.findViewById(R.id.back);
    mBack.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            Tabs.getInstance().getSelectedTab().doBack();
          }
        });

    mForward = (ImageButton) mLayout.findViewById(R.id.forward);
    mForward.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            Tabs.getInstance().getSelectedTab().doForward();
          }
        });

    mFavicon = (ImageButton) mLayout.findViewById(R.id.favicon);
    mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
    mSiteSecurity.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            int[] lockLocation = new int[2];
            view.getLocationOnScreen(lockLocation);
            LayoutParams lockLayoutParams = (LayoutParams) view.getLayoutParams();

            // Calculate the left margin for the arrow based on the position of the lock icon.
            int leftMargin = lockLocation[0] - lockLayoutParams.rightMargin;
            SiteIdentityPopup.getInstance().show(mSiteSecurity, leftMargin);
          }
        });

    mProgressSpinner =
        (AnimationDrawable) mContext.getResources().getDrawable(R.drawable.progress_spinner);

    mStop = (ImageButton) mLayout.findViewById(R.id.stop);
    mStop.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            Tab tab = Tabs.getInstance().getSelectedTab();
            if (tab != null) tab.doStop();
          }
        });

    mReader = (ImageButton) mLayout.findViewById(R.id.reader);
    mReader.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View view) {
            if (mReaderPopup == null) mReaderPopup = new ReaderPopup(GeckoApp.mAppContext);

            mReaderPopup.show();
          }
        });

    mShadow = (ImageView) mLayout.findViewById(R.id.shadow);

    mHandler = new Handler();
    mSlideUpIn = new TranslateAnimation(0, 0, 40, 0);
    mSlideUpOut = new TranslateAnimation(0, 0, 0, -40);
    mSlideDownIn = new TranslateAnimation(0, 0, -40, 0);
    mSlideDownOut = new TranslateAnimation(0, 0, 0, 40);

    mDuration = 750;
    mSlideUpIn.setDuration(mDuration);
    mSlideUpOut.setDuration(mDuration);
    mSlideDownIn.setDuration(mDuration);
    mSlideDownOut.setDuration(mDuration);

    mMenu = (ImageButton) mLayout.findViewById(R.id.menu);
    mActionItemBar = (LinearLayout) mLayout.findViewById(R.id.menu_items);
    mHasSoftMenuButton = false;

    if (Build.VERSION.SDK_INT >= 11) mHasSoftMenuButton = true;

    if (Build.VERSION.SDK_INT >= 14) {
      if (!ViewConfiguration.get(GeckoApp.mAppContext).hasPermanentMenuKey())
        mHasSoftMenuButton = true;
      else mHasSoftMenuButton = false;
    }

    if (mHasSoftMenuButton) {
      mMenu.setVisibility(View.VISIBLE);
      mMenu.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View view) {
              GeckoApp.mAppContext.openOptionsMenu();
            }
          });
    }

    if (Build.VERSION.SDK_INT >= 11) {
      View panel = GeckoApp.mAppContext.getMenuPanel();

      // If panel is null, the app is starting up for the first time;
      //    add this to the popup only if we have a soft menu button.
      // else, browser-toolbar is initialized on rotation,
      //    and we need to re-attach action-bar items.

      if (panel == null) {
        GeckoApp.mAppContext.onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
        panel = GeckoApp.mAppContext.getMenuPanel();

        if (mHasSoftMenuButton) {
          mMenuPopup = new MenuPopup(mContext);
          mMenuPopup.setPanelView(panel);
        }
      }
    }
  }
  public BrowserToolbar(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = context;

    // Get the device's highlight color
    ContextThemeWrapper wrapper = new ContextThemeWrapper(mContext, android.R.style.TextAppearance);
    TypedArray typedArray =
        wrapper.getTheme().obtainStyledAttributes(new int[] {android.R.attr.textColorHighlight});
    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.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            onAwesomeBarSearch();
          }
        });

    Resources resources = getResources();

    int padding[] = {
      mAwesomeBar.getPaddingLeft(),
      mAwesomeBar.getPaddingTop(),
      mAwesomeBar.getPaddingRight(),
      mAwesomeBar.getPaddingBottom()
    };

    GeckoStateListDrawable states = new GeckoStateListDrawable();
    states.initializeFilter(mColor);
    states.addState(
        new int[] {android.R.attr.state_pressed},
        resources.getDrawable(R.drawable.address_bar_url_pressed));
    states.addState(new int[] {}, resources.getDrawable(R.drawable.address_bar_url_default));
    mAwesomeBar.setBackgroundDrawable(states);

    mAwesomeBar.setPadding(padding[0], padding[1], padding[2], padding[3]);

    mTabs = (ImageButton) findViewById(R.id.tabs);
    mTabs.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            if (Tabs.getInstance().getCount() > 1) showTabs();
            else addTab();
          }
        });
    mTabs.setImageLevel(1);

    mCounterColor = 0x99ffffff;

    mTabsCount = (TextSwitcher) findViewById(R.id.tabs_count);
    mTabsCount.setFactory(
        new ViewFactory() {
          public View makeView() {
            TextView text = new TextView(mContext);
            text.setGravity(Gravity.CENTER);
            text.setTextSize(16);
            text.setTextColor(mCounterColor);
            text.setTypeface(text.getTypeface(), Typeface.BOLD);
            return text;
          }
        });
    mCount = 0;
    mTabsCount.setText("0");

    mFavicon = (ImageButton) findViewById(R.id.favicon);
    mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
    mProgressSpinner = (AnimationDrawable) resources.getDrawable(R.drawable.progress_spinner);

    mStop = (ImageButton) findViewById(R.id.stop);
    mStop.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            doStop();
          }
        });

    mHandler = new Handler();
    mSlideUpIn = new TranslateAnimation(0, 0, 30, 0);
    mSlideUpOut = new TranslateAnimation(0, 0, 0, -30);
    mSlideDownIn = new TranslateAnimation(0, 0, -30, 0);
    mSlideDownOut = new TranslateAnimation(0, 0, 0, 30);

    mDuration = 750;
    mSlideUpIn.setDuration(mDuration);
    mSlideUpOut.setDuration(mDuration);
    mSlideDownIn.setDuration(mDuration);
    mSlideDownOut.setDuration(mDuration);
  }