Search in sources :

Example 1 with DrawerListener

use of android.support.v4.widget.DrawerLayout.DrawerListener in project MaterialNavigationDrawer by neokree.

the class MaterialNavigationDrawer method onCreate.

@SuppressWarnings("unchecked")
@Override
protected /**
     * Do not Override this method!!! <br>
     * Use init() instead
     */
void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Resources.Theme theme = this.getTheme();
    TypedValue typedValue = new TypedValue();
    theme.resolveAttribute(R.attr.drawerType, typedValue, true);
    drawerHeaderType = typedValue.data;
    theme.resolveAttribute(R.attr.rippleBackport, typedValue, false);
    rippleSupport = typedValue.data != 0;
    theme.resolveAttribute(R.attr.uniqueToolbarColor, typedValue, false);
    uniqueToolbarColor = typedValue.data != 0;
    theme.resolveAttribute(R.attr.singleAccount, typedValue, false);
    singleAccount = typedValue.data != 0;
    theme.resolveAttribute(R.attr.multipaneSupport, typedValue, false);
    multiPaneSupport = typedValue.data != 0;
    theme.resolveAttribute(R.attr.learningPattern, typedValue, false);
    learningPattern = typedValue.data != 0;
    theme.resolveAttribute(R.attr.drawerColor, typedValue, true);
    drawerColor = typedValue.data;
    theme.resolveAttribute(R.attr.defaultSectionLoaded, typedValue, true);
    defaultSectionLoaded = typedValue.data;
    theme.resolveAttribute(R.attr.toolbarElevation, typedValue, false);
    toolbarElevation = typedValue.data != 0;
    if (drawerHeaderType == DRAWERHEADER_ACCOUNTS)
        super.setContentView(R.layout.activity_material_navigation_drawer);
    else
        super.setContentView(R.layout.activity_material_navigation_drawer_customheader);
    // init Typeface
    fontManager = new TypefaceManager(this.getAssets());
    // init toolbar & status bar
    statusBar = (ImageView) findViewById(R.id.statusBar);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    // init drawer components
    layout = (MaterialDrawerLayout) this.findViewById(R.id.drawer_layout);
    content = (RelativeLayout) this.findViewById(R.id.content);
    drawer = (RelativeLayout) this.findViewById(R.id.drawer);
    if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
        username = (TextView) this.findViewById(R.id.user_nome);
        usermail = (TextView) this.findViewById(R.id.user_email);
        userphoto = (ImageView) this.findViewById(R.id.user_photo);
        userSecondPhoto = (ImageView) this.findViewById(R.id.user_photo_2);
        userThirdPhoto = (ImageView) this.findViewById(R.id.user_photo_3);
        usercover = (ImageView) this.findViewById(R.id.user_cover);
        usercoverSwitcher = (ImageView) this.findViewById(R.id.user_cover_switcher);
        userButtonSwitcher = (ImageButton) this.findViewById(R.id.user_switcher);
        // set Roboto Fonts
        username.setTypeface(fontManager.getRobotoMedium());
        usermail.setTypeface(fontManager.getRobotoRegular());
        // get and set username and mail text colors
        theme.resolveAttribute(R.attr.accountStyle, typedValue, true);
        TypedArray attributes = theme.obtainStyledAttributes(typedValue.resourceId, R.styleable.MaterialAccount);
        try {
            username.setTextColor(attributes.getColor(R.styleable.MaterialAccount_titleColor, 0xFFF));
            usermail.setTextColor(attributes.getColor(R.styleable.MaterialAccount_subtitleColor, 0xFFF));
        } finally {
            attributes.recycle();
        }
        // set the button image
        if (!singleAccount) {
            userButtonSwitcher.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp);
            userButtonSwitcher.setOnClickListener(accountSwitcherListener);
        }
    } else
        customDrawerHeader = (LinearLayout) this.findViewById(R.id.drawer_header);
    sections = (LinearLayout) this.findViewById(R.id.sections);
    bottomSections = (LinearLayout) this.findViewById(R.id.bottom_sections);
    // init lists
    sectionList = new LinkedList<>();
    bottomSectionList = new LinkedList<>();
    accountManager = new LinkedList<>();
    accountSectionList = new LinkedList<>();
    subheaderList = new LinkedList<>();
    elementsList = new LinkedList<>();
    childFragmentStack = new LinkedList<>();
    childTitleStack = new LinkedList<>();
    // init listeners
    if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
        userphoto.setOnClickListener(currentAccountListener);
        if (singleAccount)
            usercover.setOnClickListener(currentAccountListener);
        else
            usercover.setOnClickListener(accountSwitcherListener);
        userSecondPhoto.setOnClickListener(secondAccountListener);
        userThirdPhoto.setOnClickListener(thirdAccountListener);
    }
    // set drawer backgrond color
    drawer.setBackgroundColor(drawerColor);
    //get resources and density
    resources = this.getResources();
    density = resources.getDisplayMetrics().density;
    // set the right drawer width
    DrawerLayout.LayoutParams drawerParams = (android.support.v4.widget.DrawerLayout.LayoutParams) drawer.getLayoutParams();
    drawerParams.width = Utils.getDrawerWidth(resources);
    drawer.setLayoutParams(drawerParams);
    // get primary color
    theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
    primaryColor = typedValue.data;
    theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
    primaryDarkColor = typedValue.data;
    // if device is kitkat
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        TypedArray windowTraslucentAttribute = theme.obtainStyledAttributes(new int[] { android.R.attr.windowTranslucentStatus });
        kitkatTraslucentStatusbar = windowTraslucentAttribute.getBoolean(0, false);
        if (kitkatTraslucentStatusbar) {
            Window window = this.getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            RelativeLayout.LayoutParams statusParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, resources.getDimensionPixelSize(R.dimen.traslucentStatusMargin));
            statusBar.setLayoutParams(statusParams);
            statusBar.setImageDrawable(new ColorDrawable(darkenColor(primaryColor)));
            if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
                RelativeLayout.LayoutParams photoParams = (RelativeLayout.LayoutParams) userphoto.getLayoutParams();
                photoParams.setMargins((int) (16 * density), resources.getDimensionPixelSize(R.dimen.traslucentPhotoMarginTop), 0, 0);
                userphoto.setLayoutParams(photoParams);
            }
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    // INIT TOOLBAR ELEVATION
    if (toolbarElevation) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // 4 dp elevation
            toolbar.setElevation(4 * density);
        } else {
            View elevation = LayoutInflater.from(this).inflate(R.layout.layout_toolbar_elevation, content, false);
            content.addView(elevation);
        }
    }
    // INIT ACTION BAR
    this.setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();
    // DEVELOPER CALL TO INIT
    init(savedInstanceState);
    if (sectionList.size() == 0) {
        throw new RuntimeException("You must add at least one Section to top list.");
    }
    if (deviceSupportMultiPane()) {
        // se il multipane e' attivo, si e' in landscape e si e' un tablet allora si passa in multipane mode
        layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, drawer);
        DrawerLayout.LayoutParams params = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.setMargins((int) (320 * density), 0, 0, 0);
        content.setLayoutParams(params);
        layout.setScrimColor(Color.TRANSPARENT);
        layout.openDrawer(drawer);
        layout.setMultipaneSupport(true);
    } else {
        // se non si sta lavorando in multiPane allora si inserisce il pulsante per aprire/chiudere
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        pulsante = new MaterialActionBarDrawerToggle<Fragment>(this, layout, toolbar, R.string.nothing, R.string.nothing) {

            @Override
            public void onDrawerClosed(View view) {
                // creates call to onPrepareOptionsMenu()
                invalidateOptionsMenu();
                // abilita il touch del drawer
                setDrawerTouchable(true);
                if (drawerListener != null)
                    drawerListener.onDrawerClosed(view);
                if (hasRequest()) {
                    MaterialSection section = getRequestedSection();
                    changeToolbarColor(section);
                    setFragment((Fragment) section.getTargetFragment(), section.getTitle(), (Fragment) currentSection.getTargetFragment());
                    afterFragmentSetted((Fragment) section.getTargetFragment(), section.getTitle());
                    this.removeRequest();
                }
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                // creates call to onPrepareOptionsMenu()
                invalidateOptionsMenu();
                if (drawerListener != null)
                    drawerListener.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                // if user wants the sliding arrow it compare
                if (slidingDrawerEffect)
                    super.onDrawerSlide(drawerView, slideOffset);
                else
                    super.onDrawerSlide(drawerView, 0);
                if (drawerListener != null)
                    drawerListener.onDrawerSlide(drawerView, slideOffset);
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                super.onDrawerStateChanged(newState);
                if (drawerListener != null)
                    drawerListener.onDrawerStateChanged(newState);
            }
        };
        pulsante.setToolbarNavigationClickListener(toolbarToggleListener);
        layout.setDrawerListener(pulsante);
        layout.setMultipaneSupport(false);
    }
    // si procede con gli altri elementi dopo la creazione delle viste
    ViewTreeObserver vto = drawer.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            // quando l'immagine e' stata caricata
            // change user space to 16:9
            int width = drawer.getWidth();
            int heightCover = 0;
            switch(drawerHeaderType) {
                default:
                case DRAWERHEADER_ACCOUNTS:
                case DRAWERHEADER_IMAGE:
                case DRAWERHEADER_CUSTOM:
                    // si fa il rapporto in 16 : 9
                    heightCover = (9 * width) / 16;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                        heightCover += (int) (24 * density);
                    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT && kitkatTraslucentStatusbar)
                        heightCover += (int) (25 * density);
                    break;
                case DRAWERHEADER_NO_HEADER:
                    break;
            }
            // set user space
            if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
                usercover.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, heightCover));
                usercoverSwitcher.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, heightCover));
            } else {
                customDrawerHeader.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, heightCover));
            }
            // adding status bar height for other version of android that not have traslucent status bar
            if ((Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT && !kitkatTraslucentStatusbar) || Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                heightCover += (int) (25 * density);
            }
            //  heightCover (DRAWER HEADER) + 8 (PADDING) + sections + 8 (PADDING) + 1 (DIVISOR) + bottomSections + subheaders
            int heightDrawer = (int) (((8 + 8) * density) + 1 + heightCover + sections.getHeight() + ((density * 48) * bottomSectionList.size()) + (subheaderList.size() * (35 * density)));
            // create the divisor
            View divisor = new View(MaterialNavigationDrawer.this);
            divisor.setBackgroundColor(Color.parseColor("#8f8f8f"));
            // si aggiungono le bottom sections
            if (heightDrawer >= Utils.getScreenHeight(MaterialNavigationDrawer.this)) {
                // add the divisor to the section view
                LinearLayout.LayoutParams paramDivisor = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
                paramDivisor.setMargins(0, (int) (8 * density), 0, (int) (8 * density));
                sections.addView(divisor, paramDivisor);
                for (MaterialSection section : bottomSectionList) {
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (48 * density));
                    sections.addView(section.getView(), params);
                }
            } else {
                // add the divisor to the bottom section listview
                LinearLayout.LayoutParams paramDivisor = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
                bottomSections.addView(divisor, paramDivisor);
                for (MaterialSection section : bottomSectionList) {
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (48 * density));
                    bottomSections.addView(section.getView(), params);
                }
            }
            ViewTreeObserver obs = drawer.getViewTreeObserver();
            // si rimuove il listener
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }
    });
    MaterialSection section;
    if (savedInstanceState == null) {
        // init account views
        if (accountManager.size() > 0) {
            currentAccount = accountManager.get(0);
            notifyAccountDataChanged();
        }
        // init section
        if (defaultSectionLoaded < 0 || defaultSectionLoaded >= sectionList.size()) {
            throw new RuntimeException("You are trying to open at startup a section that does not exist");
        }
        section = sectionList.get(defaultSectionLoaded);
        if (section.getTarget() != MaterialSection.TARGET_FRAGMENT)
            throw new RuntimeException("The first section added must have a fragment as target");
    } else {
        ArrayList<Integer> accountNumbers = savedInstanceState.getIntegerArrayList(STATE_ACCOUNT);
        // ripristina gli account | restore accounts
        for (int i = 0; i < accountNumbers.size(); i++) {
            MaterialAccount account = accountManager.get(i);
            account.setAccountNumber(accountNumbers.get(i));
            if (account.getAccountNumber() == MaterialAccount.FIRST_ACCOUNT) {
                currentAccount = account;
            }
        }
        notifyAccountDataChanged();
        int sectionSelected = savedInstanceState.getInt(STATE_SECTION);
        int sectionListType = savedInstanceState.getInt(STATE_LIST);
        if (sectionListType == Element.TYPE_SECTION) {
            section = sectionList.get(sectionSelected);
        } else
            section = bottomSectionList.get(sectionSelected);
        if (section.getTarget() != MaterialSection.TARGET_FRAGMENT) {
            section = sectionList.get(0);
        }
    }
    title = section.getTitle();
    currentSection = section;
    section.select();
    setFragment((Fragment) section.getTargetFragment(), section.getTitle(), null, savedInstanceState != null);
    // change the toolbar color for the first section
    changeToolbarColor(section);
    // add the first section to the child stack
    childFragmentStack.add((Fragment) section.getTargetFragment());
    childTitleStack.add(section.getTitle());
    // learning pattern
    if (learningPattern) {
        layout.openDrawer(drawer);
        disableLearningPattern();
    }
}
Also used : TypefaceManager(it.neokree.materialnavigationdrawer.util.TypefaceManager) MaterialAccount(it.neokree.materialnavigationdrawer.elements.MaterialAccount) TypedArray(android.content.res.TypedArray) MaterialSection(it.neokree.materialnavigationdrawer.elements.MaterialSection) MaterialDrawerLayout(it.neokree.materialnavigationdrawer.util.MaterialDrawerLayout) DrawerLayout(android.support.v4.widget.DrawerLayout) ViewTreeObserver(android.view.ViewTreeObserver) TypedValue(android.util.TypedValue) Window(android.view.Window) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ColorDrawable(android.graphics.drawable.ColorDrawable) RelativeLayout(android.widget.RelativeLayout) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 2 with DrawerListener

use of android.support.v4.widget.DrawerLayout.DrawerListener 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 3 with DrawerListener

use of android.support.v4.widget.DrawerLayout.DrawerListener in project StickyListHeaders by emilsjolander.

the class TestActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    refreshLayout.setRefreshing(false);
                }
            }, 1000);
        }
    });
    mAdapter = new TestBaseAdapter(this);
    stickyList = (StickyListHeadersListView) findViewById(R.id.list);
    stickyList.setOnItemClickListener(this);
    stickyList.setOnHeaderClickListener(this);
    stickyList.setOnStickyHeaderChangedListener(this);
    stickyList.setOnStickyHeaderOffsetChangedListener(this);
    stickyList.addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null));
    stickyList.addFooterView(getLayoutInflater().inflate(R.layout.list_footer, null));
    stickyList.setEmptyView(findViewById(R.id.empty));
    stickyList.setDrawingListUnderStickyHeader(true);
    stickyList.setAreHeadersSticky(true);
    stickyList.setAdapter(mAdapter);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description */
    R.string.drawer_close);
    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    restoreButton = (Button) findViewById(R.id.restore_button);
    restoreButton.setOnClickListener(buttonListener);
    openExpandableListButton = (Button) findViewById(R.id.open_expandable_list_button);
    openExpandableListButton.setOnClickListener(buttonListener);
    updateButton = (Button) findViewById(R.id.update_button);
    updateButton.setOnClickListener(buttonListener);
    clearButton = (Button) findViewById(R.id.clear_button);
    clearButton.setOnClickListener(buttonListener);
    stickyCheckBox = (CheckBox) findViewById(R.id.sticky_checkBox);
    stickyCheckBox.setOnCheckedChangeListener(checkBoxListener);
    fadeCheckBox = (CheckBox) findViewById(R.id.fade_checkBox);
    fadeCheckBox.setOnCheckedChangeListener(checkBoxListener);
    drawBehindCheckBox = (CheckBox) findViewById(R.id.draw_behind_checkBox);
    drawBehindCheckBox.setOnCheckedChangeListener(checkBoxListener);
    fastScrollCheckBox = (CheckBox) findViewById(R.id.fast_scroll_checkBox);
    fastScrollCheckBox.setOnCheckedChangeListener(checkBoxListener);
    stickyList.setStickyHeaderTopOffset(-20);
}
Also used : ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) Handler(android.os.Handler) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 4 with DrawerListener

use of android.support.v4.widget.DrawerLayout.DrawerListener in project AndroidChangeSkin by hongyangAndroid.

the class MainActivity method initEvents.

private void initEvents() {
    mListView = (ListView) findViewById(R.id.id_listview);
    mListView.setAdapter(mAdapter = new ArrayAdapter<String>(this, -1, mDatas) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.item, parent, false);
            }
            SkinManager.getInstance().injectSkin(convertView);
            TextView tv = (TextView) convertView.findViewById(R.id.id_tv_title);
            tv.setText(getItem(position));
            return convertView;
        }
    });
    mDrawerLayout.setDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerStateChanged(int newState) {
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            View mContent = mDrawerLayout.getChildAt(0);
            View mMenu = drawerView;
            float scale = 1 - slideOffset;
            float rightScale = 0.8f + scale * 0.2f;
            if (drawerView.getTag().equals("LEFT")) {
                float leftScale = 1 - 0.3f * scale;
                ViewHelper.setScaleX(mMenu, leftScale);
                ViewHelper.setScaleY(mMenu, leftScale);
                ViewHelper.setAlpha(mMenu, 0.6f + 0.4f * (1 - scale));
                ViewHelper.setTranslationX(mContent, mMenu.getMeasuredWidth() * (1 - scale));
                ViewHelper.setPivotX(mContent, 0);
                ViewHelper.setPivotY(mContent, mContent.getMeasuredHeight() / 2);
                mContent.invalidate();
                ViewHelper.setScaleX(mContent, rightScale);
                ViewHelper.setScaleY(mContent, rightScale);
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ArrayAdapter(android.widget.ArrayAdapter) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener)

Example 5 with DrawerListener

use of android.support.v4.widget.DrawerLayout.DrawerListener in project Cangol-uiframe by Cangol.

the class DrawerMenuNavigationFragmentActivityDelegate method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    mDrawerMenuLayout = (DrawerMenuLayout) LayoutInflater.from(mActivity).inflate(R.layout.navigation_drawer_main, null);
    mDrawerMenuLayout.setDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerClosed(View view) {
            Log.d("onDrawerClosed");
            if (mActivity.getCustomFragmentManager().size() <= 1) {
                mDrawerMenuLayout.setDrawerLockMode(Gravity.LEFT, DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
                mActivity.getCustomActionBar().displayHomeIndicator();
            } else {
                mDrawerMenuLayout.setDrawerLockMode(Gravity.LEFT, DrawerLayout.LOCK_MODE_UNLOCKED);
                mActivity.getCustomActionBar().displayUpIndicator();
            }
            // 通知menu onClose
            mActivity.notifyMenuOnClose();
        }

        @Override
        public void onDrawerOpened(View view) {
            Log.d("onDrawerOpened");
            // 通知menu onOpen
            mActivity.notifyMenuOnOpen();
            mActivity.getCustomActionBar().displayUpIndicator();
        }

        @Override
        public void onDrawerSlide(View view, float slideOffset) {
            mActivity.getCustomActionBar().displayIndicator(slideOffset);
        }

        @Override
        public void onDrawerStateChanged(int arg0) {
        }
    });
}
Also used : View(android.view.View) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener)

Aggregations

View (android.view.View)6 DrawerListener (android.support.v4.widget.DrawerLayout.DrawerListener)5 TextView (android.widget.TextView)4 ImageView (android.widget.ImageView)3 BookmarksView (acr.browser.lightning.browser.BookmarksView)2 BrowserView (acr.browser.lightning.browser.BrowserView)2 TabsView (acr.browser.lightning.browser.TabsView)2 LightningView (acr.browser.lightning.view.LightningView)2 SearchView (acr.browser.lightning.view.SearchView)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 WebView (android.webkit.WebView)2 AdapterView (android.widget.AdapterView)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 VideoView (android.widget.VideoView)2 BindView (butterknife.BindView)2 BookmarksFragment (acr.browser.lightning.fragment.BookmarksFragment)1 TabsFragment (acr.browser.lightning.fragment.TabsFragment)1 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1