Search in sources :

Example 56 with ViewTreeObserver

use of android.view.ViewTreeObserver in project android_frameworks_base by ParanoidAndroid.

the class RecentsHorizontalScrollView method update.

private void update() {
    for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
        View v = mLinearLayout.getChildAt(i);
        addToRecycledViews(v);
        mAdapter.recycleView(v);
    }
    LayoutTransition transitioner = getLayoutTransition();
    setLayoutTransition(null);
    mLinearLayout.removeAllViews();
    Iterator<View> recycledViews = mRecycledViews.iterator();
    for (int i = 0; i < mAdapter.getCount(); i++) {
        View old = null;
        if (recycledViews.hasNext()) {
            old = recycledViews.next();
            recycledViews.remove();
            old.setVisibility(VISIBLE);
        }
        final View view = mAdapter.getView(i, old, mLinearLayout);
        if (mPerformanceHelper != null) {
            mPerformanceHelper.addViewCallback(view);
        }
        OnTouchListener noOpListener = new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        };
        view.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                mCallback.dismiss();
            }
        });
        // We don't want a click sound when we dimiss recents
        view.setSoundEffectsEnabled(false);
        OnClickListener launchAppListener = new OnClickListener() {

            public void onClick(View v) {
                mCallback.handleOnClick(view);
            }
        };
        RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) view.getTag();
        final View thumbnailView = holder.thumbnailView;
        OnLongClickListener longClickListener = new OnLongClickListener() {

            public boolean onLongClick(View v) {
                final View anchorView = view.findViewById(R.id.app_description);
                mCallback.handleLongPress(view, anchorView, thumbnailView);
                return true;
            }
        };
        thumbnailView.setClickable(true);
        thumbnailView.setOnClickListener(launchAppListener);
        thumbnailView.setOnLongClickListener(longClickListener);
        // We don't want to dismiss recents if a user clicks on the app title
        // (we also don't want to launch the app either, though, because the
        // app title is a small target and doesn't have great click feedback)
        final View appTitle = view.findViewById(R.id.app_label);
        appTitle.setContentDescription(" ");
        appTitle.setOnTouchListener(noOpListener);
        mLinearLayout.addView(view);
    }
    setLayoutTransition(transitioner);
    // Scroll to end after initial layout.
    final OnGlobalLayoutListener updateScroll = new OnGlobalLayoutListener() {

        public void onGlobalLayout() {
            mLastScrollPosition = scrollPositionOfMostRecent();
            scrollTo(mLastScrollPosition, 0);
            final ViewTreeObserver observer = getViewTreeObserver();
            if (observer.isAlive()) {
                observer.removeOnGlobalLayoutListener(this);
            }
        }
    };
    getViewTreeObserver().addOnGlobalLayoutListener(updateScroll);
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) LayoutTransition(android.animation.LayoutTransition) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) MotionEvent(android.view.MotionEvent) ViewTreeObserver(android.view.ViewTreeObserver)

Example 57 with ViewTreeObserver

use of android.view.ViewTreeObserver in project UltimateAndroid by cymcsg.

the class DynamicListView method handleCellSwitch.

/**
     * This method determines whether the hover cell has been shifted far enough
     * to invoke a cell swap. If so, then the respective cell swap candidate is
     * determined and the data set is changed. Upon posting a notification of the
     * data set change, a layout is invoked to place the cells in the right place.
     * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
     * offset the cell being swapped to where it previously was and then animate it to
     * its new position.
     */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;
    View belowView = getViewForId(mBelowItemId);
    View mobileView = getViewForId(mMobileItemId);
    View aboveView = getViewForId(mAboveItemId);
    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());
    if (isBelow || isAbove) {
        final long switchItemId = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView);
        if (switchView == null) {
            updateNeighborViewsForId(mMobileItemId);
            return;
        }
        if (getPositionForView(switchView) < getHeaderViewsCount()) {
            return;
        }
        swapElements(originalItem, getPositionForView(switchView));
        BaseAdapter adapter;
        if (getAdapter() instanceof HeaderViewListAdapter) {
            adapter = (BaseAdapter) ((HeaderViewListAdapter) getAdapter()).getWrappedAdapter();
        } else {
            adapter = (BaseAdapter) getAdapter();
        }
        adapter.notifyDataSetChanged();
        mDownY = mLastEventY;
        mDownX = mLastEventX;
        final int switchViewStartTop = switchView.getTop();
        mobileView.setVisibility(View.VISIBLE);
        switchView.setVisibility(View.INVISIBLE);
        updateNeighborViewsForId(mMobileItemId);
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);
                View switchView = getViewForId(switchItemId);
                mTotalOffset += deltaY;
                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;
                ViewHelper.setTranslationY(switchView, delta);
                ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, "translationY", 0);
                animator.setDuration(MOVE_DURATION);
                animator.start();
                return true;
            }
        });
    }
}
Also used : ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) BaseAdapter(android.widget.BaseAdapter) ViewTreeObserver(android.view.ViewTreeObserver)

Example 58 with ViewTreeObserver

use of android.view.ViewTreeObserver in project UltimateAndroid by cymcsg.

the class TextRoundCornerProgressBar method setup.

@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
    int color;
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
    autoTextChange = typedArray.getBoolean(R.styleable.RoundCornerProgress_rcp_autoTextChange, false);
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
    radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
    textViewValue = (TextView) findViewById(R.id.round_corner_progress_text);
    textSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressSize, textSize);
    textViewValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    textViewValue.setTextColor(typedArray.getColor(R.styleable.RoundCornerProgress_rcp_textProgressColor, textColor));
    text = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgress);
    text = (text == null) ? "" : text;
    textViewValue.setText(text);
    textPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressPadding, textPadding);
    textViewValue.setPadding(textPadding, 0, textPadding, 0);
    textUnit = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgressUnit);
    textUnit = (textUnit == null) ? "" : textUnit;
    textWidth = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressWidth, textWidth);
    layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
    padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
    layoutBackground.setPadding(padding, padding, padding, padding);
    if (!isBackgroundColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
        setBackgroundColor(color);
    }
    ViewTreeObserver observer = layoutBackground.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            int height = 0;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                backgroundWidth = layoutBackground.getMeasuredWidth() - textWidth;
                height = layoutBackground.getMeasuredHeight();
            } else {
                backgroundWidth = layoutBackground.getWidth() - textWidth;
                height = layoutBackground.getHeight();
            }
            backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
            ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) layoutBackground.getLayoutParams();
            params.width = backgroundWidth;
            params.height = backgroundHeight;
            layoutBackground.setLayoutParams(params);
            setProgress(progress);
        }
    });
    layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
    if (!isProgressColorSetBeforeDraw) {
        color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
        setProgressColor(color);
    }
    if (!isMaxProgressSetBeforeDraw) {
        max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
    }
    if (!isProgressSetBeforeDraw) {
        progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
    }
    typedArray.recycle();
}
Also used : ViewGroup(android.view.ViewGroup) TypedArray(android.content.res.TypedArray) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) DisplayMetrics(android.util.DisplayMetrics) ViewTreeObserver(android.view.ViewTreeObserver) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 59 with ViewTreeObserver

use of android.view.ViewTreeObserver 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 60 with ViewTreeObserver

use of android.view.ViewTreeObserver in project GalleryFinal by pengjianbo.

the class PhotoViewAttacher method cleanup.

/**
     * Clean-up the resources attached to this object. This needs to be called when the ImageView is
     * no longer used. A good example is from {@link View#onDetachedFromWindow()} or
     * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
     * {@link cn.finalteam.galleryfinal.widget.zoonview.PhotoView}.
     */
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        // cleanup already done
        return;
    }
    final ImageView imageView = mImageView.get();
    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }
        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);
        // make sure a pending fling runnable won't be run
        cancelFling();
    }
    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }
    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;
    // Finally, clear ImageView
    mImageView = null;
}
Also used : ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

ViewTreeObserver (android.view.ViewTreeObserver)222 View (android.view.View)56 OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)25 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)15 ViewGroup (android.view.ViewGroup)14 SuppressLint (android.annotation.SuppressLint)13 AdapterView (android.widget.AdapterView)12 TypedArray (android.content.res.TypedArray)7 Test (org.junit.Test)7 RectF (android.graphics.RectF)6 DisplayMetrics (android.util.DisplayMetrics)6 ViewParent (android.view.ViewParent)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 Resources (android.content.res.Resources)5 ValueAnimator (android.animation.ValueAnimator)4 TargetApi (android.annotation.TargetApi)4 Activity (android.app.Activity)4 Paint (android.graphics.Paint)4