Example usage for android.view View requestLayout

List of usage examples for android.view View requestLayout

Introduction

In this page you can find the example usage for android.view View requestLayout.

Prototype

@CallSuper
public void requestLayout() 

Source Link

Document

Call this when something has changed which has invalidated the layout of this view.

Usage

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

void setupFABs() {
    fabContainer.setTag(R.id.view_tag_flags, FLAG_HIDE | FLAG_ENABLE);
    fabContainer.setTag(R.id.view_tag_animator_reveal, new Runnable() {
        @Override/*from  w  w  w  . ja va  2  s  .c  o  m*/
        public void run() {
            animateFABActions(false).start();
        }
    });
    fabContainer.setTag(R.id.view_tag_animator_hide, new Runnable() {
        @Override
        public void run() {
            animateFABActions(true).start();
        }
    });

    int navBarHeight = UIUtils.getNavBarHeight(this);
    if (navBarHeight > 0) {
        float navBarHeightPercentage = (float) navBarHeight / (float) UIUtils.getRealScreenSize().y;
        View fabAddWrapper = findById(this, R.id.fl_lwq_fab_reveal);
        PercentRelativeLayout.LayoutParams layoutParams = (PercentRelativeLayout.LayoutParams) fabAddWrapper
                .getLayoutParams();
        layoutParams.getPercentLayoutInfo().bottomMarginPercent += navBarHeightPercentage;
        fabAddWrapper.requestLayout();
    }

    fabAdd.setVisibility(View.GONE);
    fabAdd.setTag(R.id.view_tag_flags, FLAG_HIDE | FLAG_DISABLE | FLAG_NO_ROTATE);
    fabAdd.setTag(R.id.view_tag_animator_reveal, new Runnable() {
        @Override
        public void run() {
            animateFAB(fabAdd, false).start();
        }
    });
    fabAdd.setTag(R.id.view_tag_animator_hide, new Runnable() {
        @Override
        public void run() {
            animateFAB(fabAdd, true).start();
        }
    });
    fabAdd.setTag(R.id.view_tag_animator_rotate, new Runnable() {
        @Override
        public void run() {
            animateFABRotation(true).start();
        }
    });
    fabAdd.setTag(R.id.view_tag_animator_unrotate, new Runnable() {
        @Override
        public void run() {
            animateFABRotation(false).start();
        }
    });

    fabBackground.setVisibility(View.GONE);

    fabCreate.setAlpha(0f);
    fabCreate.setVisibility(View.GONE);

    fabSearch.setAlpha(0f);
    fabSearch.setVisibility(View.GONE);

    animateFAB(fabAdd, false).start();
}

From source file:de.manumaticx.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton// w  ww  .  j a va  2s.c  om
 *     The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            if (Looper.myLooper() == Looper.getMainLooper()) {
                activity.addContentView(croutonView, params);
            } else {
                final Activity mActivity = activity;
                final ViewGroup.LayoutParams mParams = params;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mActivity.addContentView(croutonView, mParams);
                    }
                });
            }
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

From source file:org.thoughtland.xlocation.ActivityShare.java

private void blueStreakOfProgress(Integer current, Integer max) {
    // Set up the progress bar
    if (mProgressWidth == 0) {
        final View vShareProgressEmpty = (View) findViewById(R.id.vShareProgressEmpty);
        mProgressWidth = vShareProgressEmpty.getMeasuredWidth();
    }/*w ww .j a  v a2 s  . c o  m*/
    // Display stuff
    if (max == 0)
        max = 1;
    int width = (int) ((float) mProgressWidth) * current / max;

    View vShareProgressFull = (View) findViewById(R.id.vShareProgressFull);
    vShareProgressFull.getLayoutParams().width = width;
    vShareProgressFull.invalidate();
    vShareProgressFull.requestLayout();
}

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

void setupWallpaperActions() {
    int navBarHeight = UIUtils.getNavBarHeight(this);
    if (navBarHeight > 0) {
        View wallpaperActionsContainer = findById(this, R.id.group_lwq_settings_wallpaper_actions);
        float navBarHeightPercentage = (float) navBarHeight / (float) UIUtils.getRealScreenSize().y;
        final PercentFrameLayout.LayoutParams layoutParams = (PercentFrameLayout.LayoutParams) wallpaperActionsContainer
                .getLayoutParams();/* w ww. java  2s .  co m*/
        layoutParams.getPercentLayoutInfo().bottomMarginPercent += navBarHeightPercentage;
        wallpaperActionsContainer.requestLayout();
    }
    shareButton.setTag(R.id.view_tag_flags, FLAG_ENABLE | FLAG_REVEAL);
    skipButton.setTag(R.id.view_tag_flags, FLAG_ENABLE | FLAG_REVEAL | FLAG_NO_ROTATE);
    skipButton.setTag(R.id.view_tag_animator_rotate, new Runnable() {
        @Override
        public void run() {
            animateAction(skipButton);
        }
    });
    skipButton.setTag(R.id.view_tag_animator_unrotate, new Runnable() {
        @Override
        public void run() {
            endActionAnimation(skipButton);
        }
    });
    saveButton.setTag(R.id.view_tag_flags, FLAG_ENABLE | FLAG_REVEAL | FLAG_NO_ROTATE);
    saveButton.setTag(R.id.view_tag_animator_rotate, new Runnable() {
        @Override
        public void run() {
            animateAction(saveButton);
        }
    });
    saveButton.setTag(R.id.view_tag_animator_unrotate, new Runnable() {
        @Override
        public void run() {
            endActionAnimation(saveButton);
        }
    });
}

From source file:android.support.design.widget.RaeTabLayout.java

void updateTabViews(final boolean requestLayout) {
    for (int i = 0; i < mTabStrip.getChildCount(); i++) {
        View child = mTabStrip.getChildAt(i);
        child.setMinimumWidth(getTabMinWidth());
        updateTabViewLayoutParams((LinearLayout.LayoutParams) child.getLayoutParams());
        if (requestLayout) {
            child.requestLayout();
        }//w  ww. j  a  va2s  . c  om
    }
}

From source file:com.shalzz.attendance.fragment.AttendanceListFragment.java

@Override
public void onItemExpanded(final View view) {
    final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final ExpandableListAdapter.GenericViewHolder viewHolder = (ExpandableListAdapter.GenericViewHolder) view
            .getTag();//from   ww  w  .j  ava2 s  .co m
    final RelativeLayout childView = viewHolder.childView;
    childView.measure(spec, spec);
    final int startingHeight = view.getHeight();
    final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don'mTracker want to continue getting called for every draw.
            if (observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }
            // Calculate some values to help with the animation.
            final int endingHeight = view.getHeight();
            final int distance = Math.abs(endingHeight - startingHeight);
            final int baseHeight = Math.min(endingHeight, startingHeight);
            final boolean isExpanded = endingHeight > startingHeight;

            // Set the views back to the start state of the animation
            view.getLayoutParams().height = startingHeight;
            if (!isExpanded) {
                viewHolder.childView.setVisibility(View.VISIBLE);
            }

            // Set up the fade effect for the action buttons.
            if (isExpanded) {
                // Start the fade in after the expansion has partly completed, otherwise it
                // will be mostly over before the expansion completes.
                viewHolder.childView.setAlpha(0f);
                viewHolder.childView.animate().alpha(1f).setStartDelay(mFadeInStartDelay)
                        .setDuration(mFadeInDuration).start();
            } else {
                viewHolder.childView.setAlpha(1f);
                viewHolder.childView.animate().alpha(0f).setDuration(mFadeOutDuration).start();
            }
            view.requestLayout();

            // Set up the animator to animate the expansion and shadow depth.
            ValueAnimator animator = isExpanded ? ValueAnimator.ofFloat(0f, 1f) : ValueAnimator.ofFloat(1f, 0f);

            // scroll to make the view fully visible.
            mRecyclerView.smoothScrollToPosition(viewHolder.position);

            animator.addUpdateListener(animator1 -> {
                Float value = (Float) animator1.getAnimatedValue();

                // For each value from 0 to 1, animate the various parts of the layout.
                view.getLayoutParams().height = (int) (value * distance + baseHeight);
                float z = mExpandedItemTranslationZ * value;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view.setTranslationZ(z);
                }
                view.requestLayout();
            });

            // Set everything to their final values when the animation's done.
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;

                    if (!isExpanded) {
                        viewHolder.childView.setVisibility(View.GONE);
                    } else {
                        // This seems like it should be unnecessary, but without this, after
                        // navigating out of the activity and then back, the action view alpha
                        // is defaulting to the value (0) at the start of the expand animation.
                        viewHolder.childView.setAlpha(1);
                    }
                }
            });

            animator.setDuration(mExpandCollapseDuration);
            animator.start();

            // Return false so this draw does not occur to prevent the final frame from
            // being drawn for the single frame before the animations start.
            return false;
        }
    });
}

From source file:com.android.launcher3.CellLayout.java

/**
 * Mark a child as having been dropped./*  www  .ja  v a2s  .  c  om*/
 * At the beginning of the drag operation, the child may have been on another
 * screen, but it is re-parented before this method is called.
 *
 * @param child The child that is being dropped
 */
void onDropChild(View child) {
    if (child != null) {
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.dropped = true;
        child.requestLayout();
        markCellsAsOccupiedForView(child);
    }
}

From source file:com.android.leanlauncher.CellLayout.java

/**
 * Mark a child as having been dropped./*  ww w  .  j a v a 2  s.  c  om*/
 * At the beginning of the drag operation, the child may have been on another
 * screen, but it is re-parented before this method is called.
 *
 * @param child The child that is being dropped
 */
void onDropChild(View child) {
    if (child != null) {
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.dropped = true;
        child.requestLayout();
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final float x = ev.getX();
    final float y = ev.getY();
    if (mGestureDetector.onTouchEvent(ev)) {
        mPrevX = x;//from w  ww  . j  a  v  a2 s . c om
        mPrevY = y;
        return true;
    }

    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        if (mEditMode) {
            final View child = findIntersectChild(x, y);
            if (child != null) {
                if ((mDragNode != null) && (mDragNode.view != child)) {
                    return true;
                }
                mPrevX = x;
                mPrevY = y;

                stopAnimation(mDragNode != null ? mDragNode.view : null);

                mDragNode = new Node(child, requestPreferredRect(mTmpRect, child));
                Node.scale(mDragNode.currentRect, mScaleFactor);

                requestFreeCellRegion(child);
                requestHoveredCells(mDragNode);

                if (mDragListener != null) {
                    mDragListener.onDrag(mDragNode.view, this);
                }

                final Animation animation = new ScaleAnimation((1f - mScaleFactor) + 1f, 1f,
                        (1f - mScaleFactor) + 1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);

                animation.setDuration(DURATION);
                animation.setAnimationListener(new AbstractAnimationListener() {
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        mTmpRect.set(mDragNode.startRect);

                        child.setAnimation(null);
                        child.requestLayout();
                        invalidate(mTmpRect);
                    }
                });

                requestLayout();
                child.startAnimation(animation);

                return true;
            }

            final Cell cell = findCellUnder(x, y);
            if (cell != null) {
                mPressedCell = cell;
                invalidate();
                return true;
            }

            mEditModeSwitchOff = true;
            return true;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mPressedCell != null) {
            final Cell cell = findCellUnder(x, y);
            if (mPressedCell != cell) {
                mPressedCell = null;
                invalidate();
                return true;
            }
        } else if (mDragNode != null) {
            mDragNode.currentRect.offset((int) (x - mPrevX), (int) (y - mPrevY));
            if (mDebugMode) {
                Log.w(VIEW_LOG_TAG, "ACTION_MOVE: x=" + x + " y=" + y + " prevX=" + mPrevX + " prevY=" + mPrevY
                        + " dX=" + (x - mPrevX) + " dY=" + (y - mPrevY));
            }

            requestHoveredCells(mDragNode);
            boolean dragged = (Math.abs(x - mPrevX) < DELTA) && (Math.abs(y - mPrevY) < DELTA);
            if (dragged) {
                requestReorderRevert();
            }
            if (!mHoveredCells.isEmpty() && dragged) {
                if (!mLoongHoveredRequested) {
                    mLoongHoveredRequested = true;
                    mHandler.sendEmptyMessageDelayed(LONGHOVER_MESSAGE, LONGPRESS_TIMEOUT + TAP_TIMEOUT);
                }
            } else if (mLoongHoveredRequested) {
                mLoongHoveredRequested = false;
                mHandler.removeMessages(LONGHOVER_MESSAGE);
            }

            mPrevX = x;
            mPrevY = y;

            requestLayout();
            invalidate();
            return true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mLoongHoveredRequested = false;
        mHandler.removeMessages(LONGHOVER_MESSAGE);
        if (mPressedCell != null) {
            if (mCellClickListener != null) {
                mCellClickListener.onClick(new Point(mPressedCell.rect.left, mPressedCell.rect.top), this);
            }
            mPressedCell = null;
            invalidate();
            return true;
        } else if (mDragNode != null) {
            mDragNode.currentRect.offset((int) (x - mPrevX), (int) (y - mPrevY));

            requestHoveredCells(mDragNode);
            requestReorderRevert();
            requestDrop(mDragNode);

            mPrevX = x;
            mPrevY = y;

            mTmpRect.set(mDragNode.currentRect);
            mTmpRect.union(mDragNode.startRect);

            final View child = mDragNode.view;
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            lp.mX = mDragNode.startRect.left;
            lp.mY = mDragNode.startRect.top;

            mNodes.clear();
            mDragNode.startRect.offset(lp.leftMargin, lp.topMargin);

            final AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new TranslateAnimation(mDragNode.currentRect.left - mDragNode.startRect.left,
                    0, mDragNode.currentRect.top - mDragNode.startRect.top, 0));
            animation.addAnimation(new ScaleAnimation(mScaleFactor, 1f, mScaleFactor, 1f));

            animation.setDuration(DURATION);
            animation.setAnimationListener(new AbstractAnimationListener() {
                @Override
                public void onAnimationEnd(final Animation a) {
                    mDragNode.dispose();
                    mDragNode = null;

                    child.setAnimation(null);

                    requestLayout();
                    invalidate();
                }
            });

            if (mDragListener != null) {
                mDragListener.onDrop(mDragNode.view, this);
            }

            mDragNode.currentRect.set(mDragNode.startRect);

            child.requestLayout();
            child.startAnimation(animation);
            invalidate(mTmpRect);
            return true;
        } else if (mEditModeSwitchOff) {
            setEditMode(false);
            mEditModeSwitchOff = false;
            return true;
        }
        break;
    }

    return super.onTouchEvent(ev);
}

From source file:org.de.jmg.learn.MainActivity.java

private void _SetShowAsAction(final MenuItem m) {

    final View tb = this.findViewById(R.id.action_bar);
    int SizeOther = 0;
    int width;/*  w  w w.  j  av a 2s  .co m*/
    ActionMenu = null;
    if (tb != null) {
        width = tb.getWidth();
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        double height = metrics.heightPixels;
        int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop();
        double scale = (height - viewTop) / (double) 950;

        if (scale < .5f) {
            isSmallDevice = true;
        }
        double ActionBarHeight = tb.getHeight();
        if (isSmallDevice && ActionBarHeight / height > .15f) {
            try {
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) tb.getLayoutParams();
                layoutParams.height = (int) (height * .15f);

                tb.setMinimumHeight((int) (height * .15f));
                tb.setLayoutParams(layoutParams);
                tb.requestLayout();
            } catch (Exception ex) {
                Log.e("SetToolbarHeight", ex.getMessage(), ex);
            }
        }
        if (width > 0) {
            ViewGroup g = (ViewGroup) tb;
            for (int i = 0; i < g.getChildCount(); i++) {
                View v = g.getChildAt(i);
                if ((v instanceof android.support.v7.widget.ActionMenuView)) {
                    SizeOther += v.getWidth();
                    ActionMenu = (android.support.v7.widget.ActionMenuView) v;
                }
            }
            if (SizeOther < width * .7)
                _blnReverse = true;
            if ((_blnReverse || SizeOther > width * .7) && ActionMenu != null) {
                if (_blnReverse) {
                    //if (!_hasBeenDownsized || _hasBeenDownsized)
                    //{
                    MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu();
                    int Actions = mm.getActionItems().size();
                    try {
                        MenuItem mmm = ActionMenu.getMenu().getItem(Actions + _invisibleCount);
                        if (mmm.isVisible()) {
                            MenuItemCompat.setShowAsAction(mmm, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
                        } else {
                            _invisibleCount += 1;
                            _SetShowAsAction(mmm);
                        }
                    } catch (IndexOutOfBoundsException ex) {
                        return;
                    }
                    //}

                } else {
                    MenuItemCompat.setShowAsAction(m, MenuItemCompat.SHOW_AS_ACTION_NEVER);
                    _hasBeenDownsized = true;
                }
                ActionMenu.getViewTreeObserver()
                        .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                            @Override
                            public void onGlobalLayout() {
                                if (ActionMenu != null) {
                                    lib.removeLayoutListener(ActionMenu.getViewTreeObserver(), this);
                                    int SizeNew = ActionMenu.getWidth();
                                    Log.v("Test", "" + SizeNew);
                                    MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu();
                                    int count = mm.getActionItems().size();
                                    if (count >= 1 && !(_blnReverse && SizeNew > tb.getWidth() * .7)) {
                                        MenuItem m = mm.getActionItems().get(count - 1);
                                        _SetShowAsAction(m);
                                    }

                                }

                            }
                        });

            }
        }
    }

}