Example usage for android.view ViewStub inflate

List of usage examples for android.view ViewStub inflate

Introduction

In this page you can find the example usage for android.view ViewStub inflate.

Prototype

public View inflate() 

Source Link

Document

Inflates the layout resource identified by #getLayoutResource() and replaces this StubbedView in its parent by the inflated layout resource.

Usage

From source file:org.chromium.chrome.browser.ntp.NewTabPageView.java

/**
 * Shows the most visited placeholder ("Nothing to see here") if there are no most visited
 * items and there is no search provider logo.
 *///from w w  w.j  a  va  2  s . c om
private void updateMostVisitedPlaceholderVisibility() {
    boolean showPlaceholder = mHasReceivedMostVisitedSites && mMostVisitedLayout.getChildCount() == 0
            && !mSearchProviderHasLogo;

    mNoSearchLogoSpacer.setVisibility((mSearchProviderHasLogo || showPlaceholder) ? View.GONE : View.INVISIBLE);

    if (showPlaceholder) {
        if (mMostVisitedPlaceholder == null) {
            ViewStub mostVisitedPlaceholderStub = (ViewStub) mNewTabPageLayout
                    .findViewById(R.id.most_visited_placeholder_stub);

            mMostVisitedPlaceholder = mostVisitedPlaceholderStub.inflate();
        }
        mMostVisitedLayout.setVisibility(GONE);
        mMostVisitedPlaceholder.setVisibility(VISIBLE);
    } else if (mMostVisitedPlaceholder != null) {
        mMostVisitedLayout.setVisibility(VISIBLE);
        mMostVisitedPlaceholder.setVisibility(GONE);
    }
}

From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java

@Override
public ActionMode startActionMode(ActionMode.Callback callback) {
    if (DEBUG)//w ww. j  a  va 2  s  .  c o  m
        Log.d(TAG, "[startActionMode] callback: " + callback);

    if (mActionMode != null) {
        mActionMode.finish();
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);
    ActionMode mode = null;

    //Emulate Activity's onWindowStartingActionMode:
    initActionBar();
    if (aActionBar != null) {
        mode = aActionBar.startActionMode(wrappedCallback);
    }

    if (mode != null) {
        mActionMode = mode;
    } else {
        if (mActionModeView == null) {
            ViewStub stub = (ViewStub) mDecor.findViewById(R.id.abs__action_mode_bar_stub);
            if (stub != null) {
                mActionModeView = (ActionBarContextView) stub.inflate();
            }
        }
        if (mActionModeView != null) {
            mActionModeView.killMode();
            mode = new StandaloneActionMode(mActivity, mActionModeView, wrappedCallback, true);
            if (callback.onCreateActionMode(mode, mode.getMenu())) {
                mode.invalidate();
                mActionModeView.initForMode(mode);
                mActionModeView.setVisibility(View.VISIBLE);
                mActionMode = mode;
                mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
            } else {
                mActionMode = null;
            }
        }
    }
    if (mActionMode != null && mActivity instanceof OnActionModeStartedListener) {
        ((OnActionModeStartedListener) mActivity).onActionModeStarted(mActionMode);
    }
    return mActionMode;
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

public void init() {
    long time1 = System.currentTimeMillis();
    //Debug.startMethodTracing("file_view");
    ViewStub stub = (ViewStub) mRootView.findViewById(R.id.viewContaniner);
    stub.setLayoutResource(R.layout.file_explorer_list);
    stub.inflate();
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this, 1);
    // */ modify by droi liuhaoran for stop run
    /*/ Added by tyd wulianghuan 2013-12-12
    mCleanUpDatabaseHelper = new CleanUpDatabaseHelper(mActivity);
    mDatabase = mCleanUpDatabaseHelper.openDatabase();
    mFolderNameMap = new HashMap<String, String>();
    //*//*from  ww w.j a  v a2 s. co m*/

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication = (FileManagerApplication) mActivity.getApplication();
    // */

    // notifyFileChanged();
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*
                                                                  * folder
                                                                  * only
                                                                  */);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }
    mVolumeSwitch = (ImageButton) mRootView.findViewById(R.id.volume_navigator);
    updateVolumeSwitchState();
    mGalleryNavigationBar = (RelativeLayout) mRootView.findViewById(R.id.gallery_navigation_bar);
    mVolumeSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            int visibility = getVolumesListVisibility();
            if (visibility == View.GONE) {
                buildVolumesList();
                showVolumesList(true);
            } else if (visibility == View.VISIBLE) {
                showVolumesList(false);
            }
        }

    });
    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    initVolumeState();
    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    IntentFilter intentFilter = new IntentFilter();
    // add by xueweili for get sdcard
    intentFilter.setPriority(1000);

    /*
     * intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
     */
    if (!mReceiverTag) {
        mReceiverTag = true;
        intentFilter.addAction(GlobalConsts.BROADCAST_REFRESH);
        intentFilter.addDataScheme("file");
        mActivity.registerReceiver(mReceiver, intentFilter);
    }

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication.addSDCardChangeListener(this);
    // */

    setHasOptionsMenu(true);

    // add by mingjun for load file
    mRootView.addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6,
                int arg7, int arg8) {
            isLayout = arg1;
        }
    });
    loadDialog = new ProgressDialog(mRootView.getContext());
}

From source file:org.chromium.chrome.browser.ntp.NewTabPageView.java

/**
 * Initializes the NTP. This must be called immediately after inflation, before this object is
 * used in any other way./* www .  j  av  a  2s  .co  m*/
 *
 * @param manager NewTabPageManager used to perform various actions when the user interacts
 *                with the page.
 * @param searchProviderHasLogo Whether the search provider has a logo.
 * @param scrollPosition The adapter scroll position to initialize to.
 */
public void initialize(NewTabPageManager manager, boolean searchProviderHasLogo, int scrollPosition) {
    mManager = manager;
    mUiConfig = new UiConfig(this);
    ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);

    mUseCardsUi = manager.getSuggestionsSource() != null;
    if (mUseCardsUi) {
        stub.setLayoutResource(R.layout.new_tab_page_recycler_view);
        mRecyclerView = (NewTabPageRecyclerView) stub.inflate();

        // Don't attach now, the recyclerView itself will determine when to do it.
        mNewTabPageLayout = (NewTabPageLayout) LayoutInflater.from(getContext())
                .inflate(R.layout.new_tab_page_layout, mRecyclerView, false);
        mNewTabPageLayout.setUseCardsUiEnabled(mUseCardsUi);
        mRecyclerView.setAboveTheFoldView(mNewTabPageLayout);

        // Tailor the LayoutParams for the snippets UI, as the configuration in the XML is
        // made for the ScrollView UI.
        ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        mRecyclerView.setItemAnimator(new DefaultItemAnimator() {
            @Override
            public void onAnimationFinished(ViewHolder viewHolder) {
                super.onAnimationFinished(viewHolder);
                // When removing sections, because the animations are all translations, the
                // scroll events don't fire and we can get in the situation where the toolbar
                // buttons disappear.
                updateSearchBoxOnScroll();
            }
        });
    } else {
        stub.setLayoutResource(R.layout.new_tab_page_scroll_view);
        mScrollView = (NewTabPageScrollView) stub.inflate();
        mScrollView.setBackgroundColor(NtpStyleUtils.getBackgroundColorResource(getResources(), false));
        mScrollView.enableBottomShadow(SHADOW_COLOR);
        mNewTabPageLayout = (NewTabPageLayout) findViewById(R.id.ntp_content);
    }

    mMostVisitedDesign = new MostVisitedDesign(getContext());
    mMostVisitedLayout = (MostVisitedLayout) mNewTabPageLayout.findViewById(R.id.most_visited_layout);
    mMostVisitedDesign.initMostVisitedLayout(searchProviderHasLogo);

    mSearchProviderLogoView = (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_logo);
    mSearchBoxView = (ViewGroup) mNewTabPageLayout.findViewById(R.id.search_box);
    mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo_spacer);

    initializeSearchBoxTextView();
    initializeVoiceSearchButton();
    initializeBottomToolbar();

    mNewTabPageLayout.addOnLayoutChangeListener(this);
    setSearchProviderHasLogo(searchProviderHasLogo);

    mPendingLoadTasks++;
    mManager.setMostVisitedURLsObserver(this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo));

    // Set up snippets
    if (mUseCardsUi) {
        mNewTabPageAdapter = NewTabPageAdapter.create(mManager, mNewTabPageLayout, mUiConfig);
        mRecyclerView.setAdapter(mNewTabPageAdapter);
        mRecyclerView.scrollToPosition(scrollPosition);

        if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) {
            int searchBoxHeight = NtpStyleUtils.getSearchBoxHeight(getResources());
            mRecyclerView.getLinearLayoutManager()
                    .scrollToPositionWithOffset(mNewTabPageAdapter.getFirstHeaderPosition(), searchBoxHeight);
        }

        // Set up swipe-to-dismiss
        ItemTouchHelper helper = new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks());
        helper.attachToRecyclerView(mRecyclerView);

        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            private boolean mScrolledOnce = false;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState != RecyclerView.SCROLL_STATE_DRAGGING)
                    return;
                RecordUserAction.record("MobileNTP.Snippets.Scrolled");
                if (mScrolledOnce)
                    return;
                mScrolledOnce = true;
                NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SCROLLED);
            }
        });
        initializeSearchBoxRecyclerViewScrollHandling();
    } else {
        initializeSearchBoxScrollHandling();
    }
}

From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java

/**
 * Configures the action buttons in the expandable actions ViewStub.  The ViewStub is not
 * inflated during initial binding, so click handlers, tags and accessibility text must be set
 * here, if necessary.// www. j  a  va2  s. co m
 *
 * @param callLogItem The call log list item view.
 */
private void inflateActionViewStub(final View callLogItem) {
    final CallLogListItemViews views = (CallLogListItemViews) callLogItem.getTag();

    ViewStub stub = (ViewStub) callLogItem.findViewById(R.id.call_log_entry_actions_stub);
    if (stub != null) {
        views.actionsView = stub.inflate();
    }

    ViewStub stub2 = (ViewStub) callLogItem.findViewById(R.id.call_log_entry_actions_stub2);
    if (stub2 != null) {
        views.actions2View = stub2.inflate();
    }

    if (views.callBackButtonView == null) {
        views.callBackButtonView = (TextView) views.actionsView.findViewById(R.id.call_back_action);
    }

    if (views.detailsButtonView == null) {
        views.detailsButtonView = (TextView) views.actionsView.findViewById(R.id.details_action);
    }

    if (views.writeBackButtonView == null) {
        views.writeBackButtonView = (TextView) views.actionsView.findViewById(R.id.write_back_action);
    }

    if (views.inviteButtonView == null) {
        views.inviteButtonView = (TextView) views.actions2View.findViewById(R.id.invite_action);
    }

    bindActionButtons(views);
}

From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java

protected void bindBadge(View view, ContactInfo info, final PhoneCallDetails details, int callType) {
    // Do not show badge in call log.
    // Offer add to contact only if we have an asserted ID aka Silent Circle SIP address
    if (!mIsCallLog) {
        final ViewStub stub = (ViewStub) view.findViewById(R.id.link_stub);
        final CallLogListItemViews views = (CallLogListItemViews) view.getTag();
        if (UriUtils.isEncodedContactUri(info.lookupUri) && !TextUtils.isEmpty(views.assertedId)) {
            if (stub != null) {
                final View inflated = stub.inflate();
                inflated.setVisibility(View.VISIBLE);
                mBadgeContainer = inflated.findViewById(R.id.badge_link_container);
                mBadgeImageView = (ImageView) inflated.findViewById(R.id.badge_image);
                mBadgeText = (TextView) inflated.findViewById(R.id.badge_text);
            }//  ww w.  j av a  2  s .  co  m

            mBadgeContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final Intent intent = ContactsUtils.getAddNumberToContactIntent(mContext, details.number,
                            views.assertedId);
                    mContext.startActivity(intent);
                }
            });
            mBadgeImageView.setImageResource(R.drawable.ic_person_add_24dp);
            mBadgeText.setText(R.string.recentCalls_addToContact);
        } else {
            // Hide badge if it was previously shown.
            if (stub == null) {
                final View container = view.findViewById(R.id.badge_container);
                if (container != null) {
                    container.setVisibility(View.GONE);
                }
            }
        }
    }
}

From source file:org.mozilla.gecko.BrowserApp.java

/**
* Ensure the TabsPanel view is properly inflated and returns
* true when the view has been inflated, false otherwise.
*///w ww.  ja v a2  s . c  o m
private boolean ensureTabsPanelExists() {
    if (mTabsPanel != null) {
        return false;
    }

    ViewStub tabsPanelStub = (ViewStub) findViewById(R.id.tabs_panel);
    mTabsPanel = (TabsPanel) tabsPanelStub.inflate();

    mTabsPanel.setTabsLayoutChangeListener(this);

    return true;
}

From source file:org.mozilla.gecko.BrowserApp.java

private void showFirstrunPager() {
    if (mFirstrunPane == null) {
        final ViewStub firstrunPagerStub = (ViewStub) findViewById(R.id.firstrun_pager_stub);
        mFirstrunPane = (FirstrunPane) firstrunPagerStub.inflate();
        mFirstrunPane.load(getSupportFragmentManager());
        mFirstrunPane.registerOnFinishListener(new FirstrunPane.OnFinishListener() {
            @Override//  w  w  w. jav  a  2s  .  com
            public void onFinish() {
                BrowserApp.this.mFirstrunPane = null;
            }
        });
    }

    mHomePagerContainer.setVisibility(View.VISIBLE);
}

From source file:org.mozilla.gecko.BrowserApp.java

private void showHomePagerWithAnimator(String panelId, PropertyAnimator animator) {
    if (isHomePagerVisible()) {
        // Home pager already visible, make sure it shows the correct panel.
        mHomePager.showPanel(panelId);/*from   w w w. j a  v  a2s . co  m*/
        return;
    }

    // This must be called before the dynamic toolbar is set visible because it calls
    // FormAssistPopup.onMetricsChanged, which queues a runnable that undoes the effect of hide.
    // With hide first, onMetricsChanged will return early instead.
    mFormAssistPopup.hide();
    mFindInPageBar.hide();

    // Refresh toolbar height to possibly restore the toolbar padding
    refreshToolbarHeight();

    // Show the toolbar before hiding about:home so the
    // onMetricsChanged callback still works.
    if (mDynamicToolbar.isEnabled()) {
        mDynamicToolbar.setVisible(true, VisibilityTransition.IMMEDIATE);
    }

    if (mHomePager == null) {
        final ViewStub homePagerStub = (ViewStub) findViewById(R.id.home_pager_stub);
        mHomePager = (HomePager) homePagerStub.inflate();

        mHomePager.setOnPanelChangeListener(new HomePager.OnPanelChangeListener() {
            @Override
            public void onPanelSelected(String panelId) {
                final Tab currentTab = Tabs.getInstance().getSelectedTab();
                if (currentTab != null) {
                    currentTab.setMostRecentHomePanel(panelId);
                }
            }
        });

        // Don't show the banner in guest mode.
        if (!RestrictedProfiles.isUserRestricted()) {
            final ViewStub homeBannerStub = (ViewStub) findViewById(R.id.home_banner_stub);
            final HomeBanner homeBanner = (HomeBanner) homeBannerStub.inflate();
            mHomePager.setBanner(homeBanner);

            // Remove the banner from the view hierarchy if it is dismissed.
            homeBanner.setOnDismissListener(new HomeBanner.OnDismissListener() {
                @Override
                public void onDismiss() {
                    mHomePager.setBanner(null);
                    mHomePagerContainer.removeView(homeBanner);
                }
            });
        }
    }

    mHomePagerContainer.setVisibility(View.VISIBLE);
    mHomePager.load(getSupportLoaderManager(), getSupportFragmentManager(), panelId, animator);

    // Hide the web content so it cannot be focused by screen readers.
    hideWebContentOnPropertyAnimationEnd(animator);
}

From source file:org.mozilla.gecko.BrowserApp.java

@Override
public void onCreate(Bundle savedInstanceState) {
    final Intent intent = getIntent();

    // Note that we're calling GeckoProfile.get *before GeckoApp.onCreate*.
    // This means we're reliant on the logic in GeckoProfile to correctly
    // look up our launch intent (via BrowserApp's Activity-ness) and pull
    // out the arguments. Be careful if you change that!
    final GeckoProfile p = GeckoProfile.get(this);

    if (p != null && !p.inGuestMode()) {
        // This is *only* valid because we never want to use the guest mode
        // profile concurrently with a normal profile -- no syncing to it,
        // no dual-profile usage, nothing. BrowserApp startup with a conventional
        // GeckoProfile will cause the guest profile to be deleted.
        GeckoProfile.maybeCleanupGuestProfile(this);
    }/*from   www  .  ja v a2  s  . c o  m*/

    // This has to be prepared prior to calling GeckoApp.onCreate, because
    // widget code and BrowserToolbar need it, and they're created by the
    // layout, which GeckoApp takes care of.
    ((GeckoApplication) getApplication()).prepareLightweightTheme();
    super.onCreate(savedInstanceState);

    final Context appContext = ((GeckoApplication) getApplication()).getContext();
    SharedPreferences prefs = GeckoSharedPrefs.forProfile(appContext);
    // TODO: Prevent if in Guest Mode?
    if (AppConstants.MOZ_ANDROID_GCM_PUSH) {
        this.gcmBridge = new GCM(AppConstants.MOZ_ANDROID_GCM_SENDERID);
        try {
            this.gcmBridge.onCreate(appContext, getActivity(), savedInstanceState);
            // A thread has been spawned to put the push endpoint into the preferences.
        } catch (IOException x) {
            // could not instantiate the GCM bridge, so fail.
            Logger.info(LOGTAG, "Google Play not present or available. GCM bridge unavailable.");
            this.gcmBridge = null;
        } catch (BridgeException x) {
            // Some other error caused the bridge to fail.
            Logger.error(LOGTAG, "Could not create the GCM bridge.", x);
            this.gcmBridge = null;
        }
        /* At this point, we have a GCM endpoint registered with the Push Service, but we
        need the user to log in so that we can associate the URL and user within the Device
        Manager. See
         */
    }

    mBrowserChrome = (ViewGroup) findViewById(R.id.browser_chrome);
    mActionBarFlipper = (ViewFlipper) findViewById(R.id.browser_actionbar);
    mActionBar = (ActionModeCompatView) findViewById(R.id.actionbar);

    mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
    mProgressView = (ToolbarProgressView) findViewById(R.id.progress);
    mBrowserToolbar.setProgressBar(mProgressView);

    // Initialize Tab History Controller.
    tabHistoryController = new TabHistoryController(new OnShowTabHistory() {
        @Override
        public void onShowHistory(final List<TabHistoryPage> historyPageList, final int toIndex) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    final TabHistoryFragment fragment = TabHistoryFragment.newInstance(historyPageList,
                            toIndex);
                    final FragmentManager fragmentManager = getSupportFragmentManager();
                    GeckoAppShell.vibrateOnHapticFeedbackEnabled(
                            getResources().getIntArray(R.array.long_press_vibrate_msec));
                    fragment.show(R.id.tab_history_panel, fragmentManager.beginTransaction(),
                            TAB_HISTORY_FRAGMENT_TAG);
                }
            });
        }
    });
    mBrowserToolbar.setTabHistoryController(tabHistoryController);

    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action)) {
        // Show the target URL immediately in the toolbar.
        mBrowserToolbar.setTitle(intent.getDataString());

        showTabQueuePromptIfApplicable(intent);
    } else if (GuestSession.NOTIFICATION_INTENT.equals(action)) {
        GuestSession.handleIntent(this, intent);
    } else if (TabQueueHelper.LOAD_URLS_ACTION.equals(action)) {
        Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.NOTIFICATION,
                "tabqueue");
    }

    if (HardwareUtils.isTablet()) {
        mTabStrip = (Refreshable) (((ViewStub) findViewById(R.id.new_tablet_tab_strip)).inflate());
    }

    ((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideOnTouchListener());
    ((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
        @Override
        public boolean onInterceptMotionEvent(View view, MotionEvent event) {
            // If we get a gamepad panning MotionEvent while the focus is not on the layerview,
            // put the focus on the layerview and carry on
            if (mLayerView != null && !mLayerView.hasFocus() && GamepadUtils.isPanningControl(event)) {
                if (mHomePager == null) {
                    return false;
                }

                if (isHomePagerVisible()) {
                    mLayerView.requestFocus();
                } else {
                    mHomePager.requestFocus();
                }
            }
            return false;
        }
    });

    mHomePagerContainer = (ViewGroup) findViewById(R.id.home_pager_container);

    mBrowserSearchContainer = findViewById(R.id.search_container);
    mBrowserSearch = (BrowserSearch) getSupportFragmentManager().findFragmentByTag(BROWSER_SEARCH_TAG);
    if (mBrowserSearch == null) {
        mBrowserSearch = BrowserSearch.newInstance();
        mBrowserSearch.setUserVisibleHint(false);
    }

    setBrowserToolbarListeners();

    mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
    mMediaCastingBar = (MediaCastingBar) findViewById(R.id.media_casting);

    EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this, "Menu:Open",
            "Menu:Update", "LightweightTheme:Update", "Search:Keyword", "Prompt:ShowTop", "Accounts:Exist");

    EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this, "Accounts:Create",
            "Accounts:CreateFirefoxAccountFromJSON", "CharEncoding:Data", "CharEncoding:State",
            "Favicon:CacheLoad", "Feedback:LastUrl", "Feedback:MaybeLater", "Feedback:OpenPlayStore",
            "Menu:Add", "Menu:Remove", "Reader:Share", "Sanitize:ClearHistory", "Sanitize:ClearSyncedTabs",
            "Settings:Show", "Telemetry:Gather", "Updater:Launch");

    Distribution distribution = Distribution.init(this);

    // Init suggested sites engine in BrowserDB.
    final SuggestedSites suggestedSites = new SuggestedSites(appContext, distribution);
    final BrowserDB db = getProfile().getDB();
    db.setSuggestedSites(suggestedSites);

    JavaAddonManager.getInstance().init(appContext);
    mSharedPreferencesHelper = new SharedPreferencesHelper(appContext);
    mOrderedBroadcastHelper = new OrderedBroadcastHelper(appContext);
    mBrowserHealthReporter = new BrowserHealthReporter();
    mReadingListHelper = new ReadingListHelper(appContext, getProfile(), this);

    if (AppConstants.MOZ_ANDROID_BEAM) {
        NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
        if (nfc != null) {
            nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
                @Override
                public NdefMessage createNdefMessage(NfcEvent event) {
                    Tab tab = Tabs.getInstance().getSelectedTab();
                    if (tab == null || tab.isPrivate()) {
                        return null;
                    }
                    return new NdefMessage(new NdefRecord[] { NdefRecord.createUri(tab.getURL()) });
                }
            }, this);
        }
    }

    if (savedInstanceState != null) {
        mDynamicToolbar.onRestoreInstanceState(savedInstanceState);
        mHomePagerContainer.setPadding(0, savedInstanceState.getInt(STATE_ABOUT_HOME_TOP_PADDING), 0, 0);
    }

    mDynamicToolbar.setEnabledChangedListener(new DynamicToolbar.OnEnabledChangedListener() {
        @Override
        public void onEnabledChanged(boolean enabled) {
            setDynamicToolbarEnabled(enabled);
        }
    });

    mDragHelper = new DragHelper();
    mRootLayout.setDraggableCallback(mDragHelper);

    // Set the maximum bits-per-pixel the favicon system cares about.
    IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth());

    if (ZOOMED_VIEW_ENABLED) {
        ViewStub stub = (ViewStub) findViewById(R.id.zoomed_view_stub);
        mZoomedView = (ZoomedView) stub.inflate();
    }
}