Search in sources :

Example 1 with BookmarksFragment

use of acr.browser.lightning.fragment.BookmarksFragment in project Lightning-Browser by anthonycr.

the class BrowserActivity method initialize.

private synchronized void initialize(Bundle savedInstanceState) {
    initializeToolbarHeight(getResources().getConfiguration());
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    //TODO make sure dark theme flag gets set correctly
    mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
    mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this);
    mDisabledIconColor = mDarkTheme ? ContextCompat.getColor(this, R.color.icon_dark_theme_disabled) : ContextCompat.getColor(this, R.color.icon_light_theme_disabled);
    mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
    mSwapBookmarksAndTabs = mPreferences.getBookmarksAndTabsSwapped();
    // initialize background ColorDrawable
    int primaryColor = ThemeUtils.getPrimaryColor(this);
    mBackground.setColor(primaryColor);
    // Drawer stutters otherwise
    mDrawerLeft.setLayerType(View.LAYER_TYPE_NONE, null);
    mDrawerRight.setLayerType(View.LAYER_TYPE_NONE, null);
    mDrawerLayout.addDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }

        @Override
        public void onDrawerOpened(View drawerView) {
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            if (newState == DrawerLayout.STATE_DRAGGING) {
                mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            } else if (newState == DrawerLayout.STATE_IDLE) {
                mDrawerLeft.setLayerType(View.LAYER_TYPE_NONE, null);
                mDrawerRight.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !mShowTabsInDrawer) {
        getWindow().setStatusBarColor(Color.BLACK);
    }
    setNavigationDrawerWidth();
    mDrawerLayout.addDrawerListener(new DrawerLocker());
    mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme);
    final FragmentManager fragmentManager = getSupportFragmentManager();
    TabsFragment tabsFragment = (TabsFragment) fragmentManager.findFragmentByTag(TAG_TABS_FRAGMENT);
    BookmarksFragment bookmarksFragment = (BookmarksFragment) fragmentManager.findFragmentByTag(TAG_BOOKMARK_FRAGMENT);
    if (tabsFragment != null) {
        fragmentManager.beginTransaction().remove(tabsFragment).commit();
    }
    tabsFragment = TabsFragment.createTabsFragment(isIncognito(), mShowTabsInDrawer);
    mTabsView = tabsFragment;
    if (bookmarksFragment != null) {
        fragmentManager.beginTransaction().remove(bookmarksFragment).commit();
    }
    bookmarksFragment = BookmarksFragment.createFragment(isIncognito());
    mBookmarksView = bookmarksFragment;
    fragmentManager.executePendingTransactions();
    fragmentManager.beginTransaction().replace(getTabsFragmentViewId(), tabsFragment, TAG_TABS_FRAGMENT).replace(getBookmarksFragmentViewId(), bookmarksFragment, TAG_BOOKMARK_FRAGMENT).commit();
    if (mShowTabsInDrawer) {
        mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
    }
    Preconditions.checkNonNull(actionBar);
    // set display options of the ActionBar
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.toolbar_content);
    View customView = actionBar.getCustomView();
    LayoutParams lp = customView.getLayoutParams();
    lp.width = LayoutParams.MATCH_PARENT;
    lp.height = LayoutParams.MATCH_PARENT;
    customView.setLayoutParams(lp);
    mArrowImage = (ImageView) customView.findViewById(R.id.arrow);
    FrameLayout arrowButton = (FrameLayout) customView.findViewById(R.id.arrow_button);
    if (mShowTabsInDrawer) {
        if (mArrowImage.getWidth() <= 0) {
            mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        }
        updateTabNumber(0);
        // Post drawer locking in case the activity is being recreated
        Handlers.MAIN.post(new Runnable() {

            @Override
            public void run() {
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, getTabDrawer());
            }
        });
    } else {
        // Post drawer locking in case the activity is being recreated
        Handlers.MAIN.post(new Runnable() {

            @Override
            public void run() {
                mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, getTabDrawer());
            }
        });
        mArrowImage.setImageResource(R.drawable.ic_action_home);
        mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
    }
    // Post drawer locking in case the activity is being recreated
    Handlers.MAIN.post(new Runnable() {

        @Override
        public void run() {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, getBookmarkDrawer());
        }
    });
    arrowButton.setOnClickListener(this);
    // create the search EditText in the ToolBar
    mSearch = (SearchView) customView.findViewById(R.id.search);
    mSearchBackground = customView.findViewById(R.id.search_container);
    // initialize search background color
    mSearchBackground.getBackground().setColorFilter(getSearchBarColor(primaryColor, primaryColor), PorterDuff.Mode.SRC_IN);
    mSearch.setHintTextColor(ThemeUtils.getThemedTextHintColor(mDarkTheme));
    mSearch.setTextColor(mDarkTheme ? Color.WHITE : Color.BLACK);
    mUntitledTitle = getString(R.string.untitled);
    mBackgroundColor = ThemeUtils.getPrimaryColor(this);
    mDeleteIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_delete, mDarkTheme);
    mRefreshIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_refresh, mDarkTheme);
    mClearIcon = ThemeUtils.getThemedDrawable(this, R.drawable.ic_action_delete, mDarkTheme);
    int iconBounds = Utils.dpToPx(24);
    mDeleteIcon.setBounds(0, 0, iconBounds, iconBounds);
    mRefreshIcon.setBounds(0, 0, iconBounds, iconBounds);
    mClearIcon.setBounds(0, 0, iconBounds, iconBounds);
    mIcon = mRefreshIcon;
    SearchListenerClass search = new SearchListenerClass();
    mSearch.setCompoundDrawablePadding(Utils.dpToPx(3));
    mSearch.setCompoundDrawables(null, null, mRefreshIcon, null);
    mSearch.setOnKeyListener(search);
    mSearch.setOnFocusChangeListener(search);
    mSearch.setOnEditorActionListener(search);
    mSearch.setOnTouchListener(search);
    mSearch.setOnPreFocusListener(search);
    initializeSearchSuggestions(mSearch);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_right_shadow, GravityCompat.END);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_left_shadow, GravityCompat.START);
    if (API <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        //noinspection deprecation
        WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
    }
    @SuppressWarnings("VariableNotUsedInsideIf") Intent intent = savedInstanceState == null ? getIntent() : null;
    boolean launchedFromHistory = intent != null && (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0;
    if (isPanicTrigger(intent)) {
        setIntent(null);
        panicClean();
    } else {
        if (launchedFromHistory) {
            intent = null;
        }
        mPresenter.setupTabs(intent);
        setIntent(null);
        mProxyUtils.checkForProxy(this);
    }
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) TabsFragment(acr.browser.lightning.fragment.TabsFragment) Intent(android.content.Intent) ImageView(android.widget.ImageView) BookmarksView(acr.browser.lightning.browser.BookmarksView) BrowserView(acr.browser.lightning.browser.BrowserView) SearchView(acr.browser.lightning.view.SearchView) AutoCompleteTextView(android.widget.AutoCompleteTextView) LightningView(acr.browser.lightning.view.LightningView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) WebView(android.webkit.WebView) TextView(android.widget.TextView) VideoView(android.widget.VideoView) TabsView(acr.browser.lightning.browser.TabsView) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener) FragmentManager(android.support.v4.app.FragmentManager) BookmarksFragment(acr.browser.lightning.fragment.BookmarksFragment) FrameLayout(android.widget.FrameLayout) ActionBar(android.support.v7.app.ActionBar)

Example 2 with BookmarksFragment

use of acr.browser.lightning.fragment.BookmarksFragment in project Lightning-Browser by anthonycr.

the class BrowserActivity method initializePreferences.

private void initializePreferences() {
    final LightningView currentView = mTabsManager.getCurrentTab();
    mFullScreen = mPreferences.getFullScreenEnabled();
    boolean colorMode = mPreferences.getColorModeEnabled();
    colorMode &= !mDarkTheme;
    if (!isIncognito() && !colorMode && !mDarkTheme && mWebpageBitmap != null) {
        changeToolbarBackground(mWebpageBitmap, null);
    } else if (!isIncognito() && currentView != null && !mDarkTheme) {
        changeToolbarBackground(currentView.getFavicon(), null);
    } else if (!isIncognito() && !mDarkTheme && mWebpageBitmap != null) {
        changeToolbarBackground(mWebpageBitmap, null);
    }
    FragmentManager manager = getSupportFragmentManager();
    Fragment tabsFragment = manager.findFragmentByTag(TAG_TABS_FRAGMENT);
    if (tabsFragment instanceof TabsFragment) {
        ((TabsFragment) tabsFragment).reinitializePreferences();
    }
    Fragment bookmarksFragment = manager.findFragmentByTag(TAG_BOOKMARK_FRAGMENT);
    if (bookmarksFragment instanceof BookmarksFragment) {
        ((BookmarksFragment) bookmarksFragment).reinitializePreferences();
    }
    // TODO layout transition causing memory leak
    //        mBrowserFrame.setLayoutTransition(new LayoutTransition());
    setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
    switch(mPreferences.getSearchChoice()) {
        case 0:
            mSearchText = mPreferences.getSearchUrl();
            if (!mSearchText.startsWith(Constants.HTTP) && !mSearchText.startsWith(Constants.HTTPS)) {
                mSearchText = Constants.GOOGLE_SEARCH;
            }
            break;
        case 1:
            mSearchText = Constants.GOOGLE_SEARCH;
            break;
        case 2:
            mSearchText = Constants.ASK_SEARCH;
            break;
        case 3:
            mSearchText = Constants.BING_SEARCH;
            break;
        case 4:
            mSearchText = Constants.YAHOO_SEARCH;
            break;
        case 5:
            mSearchText = Constants.STARTPAGE_SEARCH;
            break;
        case 6:
            mSearchText = Constants.STARTPAGE_MOBILE_SEARCH;
            break;
        case 7:
            mSearchText = Constants.DUCK_SEARCH;
            break;
        case 8:
            mSearchText = Constants.DUCK_LITE_SEARCH;
            break;
        case 9:
            mSearchText = Constants.BAIDU_SEARCH;
            break;
        case 10:
            mSearchText = Constants.YANDEX_SEARCH;
            break;
    }
    updateCookiePreference().subscribeOn(Schedulers.worker()).subscribe();
    mProxyUtils.updateProxySettings(this);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) BookmarksFragment(acr.browser.lightning.fragment.BookmarksFragment) TabsFragment(acr.browser.lightning.fragment.TabsFragment) LightningView(acr.browser.lightning.view.LightningView) Fragment(android.support.v4.app.Fragment) BookmarksFragment(acr.browser.lightning.fragment.BookmarksFragment) TabsFragment(acr.browser.lightning.fragment.TabsFragment)

Aggregations

BookmarksFragment (acr.browser.lightning.fragment.BookmarksFragment)2 TabsFragment (acr.browser.lightning.fragment.TabsFragment)2 LightningView (acr.browser.lightning.view.LightningView)2 FragmentManager (android.support.v4.app.FragmentManager)2 BookmarksView (acr.browser.lightning.browser.BookmarksView)1 BrowserView (acr.browser.lightning.browser.BrowserView)1 TabsView (acr.browser.lightning.browser.TabsView)1 SearchView (acr.browser.lightning.view.SearchView)1 Intent (android.content.Intent)1 Fragment (android.support.v4.app.Fragment)1 DrawerListener (android.support.v4.widget.DrawerLayout.DrawerListener)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 WebView (android.webkit.WebView)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1