Search in sources :

Example 21 with END

use of android.support.v7.widget.helper.ItemTouchHelper.END in project Lightning-Browser by anthonycr.

the class HorizontalItemAnimator method endAnimation.

@Override
public void endAnimation(ViewHolder item) {
    final View view = item.itemView;
    // this will trigger end callback which should set properties to their target values.
    ViewCompat.animate(view).cancel();
    // TODO if some other animations are chained to end, how do we cancel them as well?
    for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
        MoveInfo moveInfo = mPendingMoves.get(i);
        if (moveInfo.holder == item) {
            ViewCompat.setTranslationY(view, 0);
            ViewCompat.setTranslationX(view, 0);
            dispatchMoveFinished(item);
            mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(mPendingChanges, item);
    if (mPendingRemovals.remove(item)) {
        ViewCompat.setAlpha(view, 1);
        dispatchRemoveFinished(item);
    }
    if (mPendingAdditions.remove(item)) {
        ViewCompat.setAlpha(view, 1);
        dispatchAddFinished(item);
    }
    for (int i = mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            mChangesList.remove(i);
        }
    }
    for (int i = mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = mMovesList.get(i);
        for (int j = moves.size() - 1; j >= 0; j--) {
            MoveInfo moveInfo = moves.get(j);
            if (moveInfo.holder == item) {
                ViewCompat.setTranslationY(view, 0);
                ViewCompat.setTranslationX(view, 0);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    mMovesList.remove(i);
                }
                break;
            }
        }
    }
    for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = mAdditionsList.get(i);
        if (additions.remove(item)) {
            ViewCompat.setAlpha(view, 1);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                mAdditionsList.remove(i);
            }
        }
    }
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (mRemoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException("after animation is cancelled, item should not be in " + "mRemoveAnimations list");
    }
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (mAddAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException("after animation is cancelled, item should not be in " + "mAddAnimations list");
    }
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (mChangeAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException("after animation is cancelled, item should not be in " + "mChangeAnimations list");
    }
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (mMoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException("after animation is cancelled, item should not be in " + "mMoveAnimations list");
    }
    dispatchFinishedWhenDone();
}
Also used : ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 22 with END

use of android.support.v7.widget.helper.ItemTouchHelper.END in project Lightning-Browser by anthonycr.

the class HorizontalItemAnimator method animateMoveImpl.

private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        ViewCompat.animate(view).translationX(0);
    }
    if (deltaY != 0) {
        ViewCompat.animate(view).translationY(0);
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mMoveAnimations.add(holder);
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            if (deltaX != 0) {
                ViewCompat.setTranslationX(view, 0);
            }
            if (deltaY != 0) {
                ViewCompat.setTranslationY(view, 0);
            }
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 23 with END

use of android.support.v7.widget.helper.ItemTouchHelper.END in project xabber-android by redsolution.

the class ChatViewerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.chat_viewer_fragment, container, false);
    contactTitleView = view.findViewById(R.id.contact_title);
    abstractContact = RosterManager.getInstance().getBestContact(account, user);
    contactTitleView.findViewById(R.id.avatar).setOnClickListener(this);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar_default);
    toolbar.inflateMenu(R.menu.chat);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(getActivity());
        }
    });
    setHasOptionsMenu(true);
    sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
    sendButton.setColorFilter(ColorManager.getInstance().getAccountPainter().getGreyMain());
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    securityButton = (ImageButton) view.findViewById(R.id.button_security);
    if (abstractChat instanceof RegularChat) {
        securityButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showSecurityMenu();
            }
        });
    } else {
        securityButton.setVisibility(View.GONE);
    }
    chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user, this, this);
    recyclerView = (RecyclerView) view.findViewById(R.id.chat_messages_recycler_view);
    recyclerView.setAdapter(chatMessageAdapter);
    layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setStackFromEnd(true);
    recyclerView.setLayoutManager(layoutManager);
    // to avoid strange bug on some 4.x androids
    view.findViewById(R.id.input_layout).setBackgroundColor(ColorManager.getInstance().getChatInputBackgroundColor());
    inputView = (EditText) view.findViewById(R.id.chat_input);
    view.findViewById(R.id.button_send_message).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            sendMessage();
        }
    });
    inputView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (SettingsManager.chatsSendByEnter() && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                sendMessage();
                return true;
            }
            return false;
        }
    });
    inputView.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!skipOnTextChanges && stopTypingTimer != null) {
                stopTypingTimer.cancel();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable text) {
            setUpInputViewButtons();
            if (skipOnTextChanges) {
                return;
            }
            ChatStateManager.getInstance().onComposing(account, user, text);
            stopTypingTimer = new Timer();
            stopTypingTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    Application.getInstance().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            ChatStateManager.getInstance().onPaused(account, user);
                        }
                    });
                }
            }, STOP_TYPING_DELAY);
        }
    });
    final ImageButton emojiButton = (ImageButton) view.findViewById(R.id.button_emoticon);
    final View rootView = view.findViewById(R.id.root_view);
    // Give the topmost view of your activity layout hierarchy. This will be used to measure soft keyboard height
    final EmojiconsPopup popup = new EmojiconsPopup(rootView, getActivity());
    //Will automatically set size according to the soft keyboard size
    popup.setSizeForSoftKeyboard();
    //If the emoji popup is dismissed, change emojiButton to smiley icon
    popup.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_mood_black_24dp);
        }
    });
    //If the text keyboard closes, also dismiss the emoji popup
    popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {

        @Override
        public void onKeyboardOpen(int keyBoardHeight) {
        }

        @Override
        public void onKeyboardClose() {
            if (popup.isShowing())
                popup.dismiss();
        }
    });
    //On emoji clicked, add it to edittext
    popup.setOnEmojiconClickedListener(new EmojiconGridView.OnEmojiconClickedListener() {

        @Override
        public void onEmojiconClicked(Emojicon emojicon) {
            if (inputView == null || emojicon == null) {
                return;
            }
            int start = inputView.getSelectionStart();
            int end = inputView.getSelectionEnd();
            if (start < 0) {
                inputView.append(emojicon.getEmoji());
            } else {
                inputView.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
            }
        }
    });
    //On backspace clicked, emulate the KEYCODE_DEL key event
    popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {

        @Override
        public void onEmojiconBackspaceClicked(View v) {
            KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
            inputView.dispatchKeyEvent(event);
        }
    });
    // To toggle between text keyboard and emoji keyboard keyboard(Popup)
    emojiButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //If popup is not showing => emoji keyboard is not visible, we need to show it
            if (!popup.isShowing()) {
                //If keyboard is visible, simply show the emoji popup
                if (popup.isKeyBoardOpen()) {
                    popup.showAtBottom();
                    changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_keyboard_black_24dp);
                } else //else, open the text keyboard first and immediately after that show the emoji popup
                {
                    inputView.setFocusableInTouchMode(true);
                    inputView.requestFocus();
                    popup.showAtBottomPending();
                    final InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputMethodManager.showSoftInput(inputView, InputMethodManager.SHOW_IMPLICIT);
                    changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_keyboard_black_24dp);
                }
            } else //If popup is showing, simply dismiss it to show the undelying text keyboard
            {
                popup.dismiss();
            }
        }
    });
    attachButton = (ImageButton) view.findViewById(R.id.button_attach);
    attachButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onAttachButtonPressed();
        }
    });
    return view;
}
Also used : EmojiconGridView(github.ankushsachdeva.emojicon.EmojiconGridView) PopupWindow(android.widget.PopupWindow) ChatMessageAdapter(com.xabber.android.ui.adapter.ChatMessageAdapter) InputMethodManager(android.view.inputmethod.InputMethodManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RegularChat(com.xabber.android.data.message.RegularChat) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) TimerTask(java.util.TimerTask) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EmojiconsPopup(github.ankushsachdeva.emojicon.EmojiconsPopup) AbstractChat(com.xabber.android.data.message.AbstractChat) ImageView(android.widget.ImageView) View(android.view.View) EmojiconGridView(github.ankushsachdeva.emojicon.EmojiconGridView) RecyclerView(android.support.v7.widget.RecyclerView) Timer(java.util.Timer) Emojicon(github.ankushsachdeva.emojicon.emoji.Emojicon)

Example 24 with END

use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.

the class OnePlusNLayoutHelperEx method layoutViews.

@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
    // reach the end of this layout
    final int originCurPos = layoutState.getCurrentPosition();
    if (isOutOfRange(originCurPos)) {
        return;
    }
    if (mChildrenViews == null || mChildrenViews.length != getItemCount()) {
        mChildrenViews = new View[getItemCount()];
    }
    int count = getAllChildren(mChildrenViews, recycler, layoutState, result, helper);
    if (count != getItemCount()) {
        Log.w(TAG, "The real number of children is not match with range of LayoutHelper");
    }
    final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
    final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
    final int parentWidth = helper.getContentWidth();
    final int parentHeight = helper.getContentHeight();
    final int parentHPadding = helper.getPaddingLeft() + helper.getPaddingRight() + getHorizontalMargin() + getHorizontalPadding();
    final int parentVPadding = helper.getPaddingTop() + helper.getPaddingBottom() + getVerticalMargin() + getVerticalPadding();
    int mainConsumed = 0;
    if (count == 5) {
        final View child1 = mChildrenViews[0];
        final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
        final View child2 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[1];
        final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
        final View child3 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[2];
        final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
        final View child4 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[3];
        final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
        final View child5 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[4];
        final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
        final float weight1 = getViewMainWeight(lp1, 0);
        final float weight2 = getViewMainWeight(lp1, 1);
        final float weight3 = getViewMainWeight(lp1, 2);
        final float weight4 = getViewMainWeight(lp1, 3);
        final float weight5 = getViewMainWeight(lp1, 4);
        if (layoutInVertical) {
            lp2.topMargin = lp1.topMargin;
            lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
            lp3.leftMargin = lp2.leftMargin;
            lp4.rightMargin = lp2.rightMargin;
            lp5.rightMargin = lp3.rightMargin;
            if (!Float.isNaN(mAspectRatio)) {
                lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
            }
            int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin - lp3.leftMargin - lp3.rightMargin;
            int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
            int width2 = Float.isNaN(weight2) ? (availableSpace - width1) / 2 : (int) (availableSpace * weight2 / 100 + 0.5f);
            int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5f);
            int width4 = Float.isNaN(weight4) ? width2 : (int) (availableSpace * weight4 / 100 + 0.5f);
            int width5 = Float.isNaN(weight5) ? width2 : (int) (availableSpace * weight5 / 100 + 0.5f);
            helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
            int height1 = child1.getMeasuredHeight();
            int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 2.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
            int height3 = (height1 - lp2.bottomMargin - lp3.topMargin) - height2;
            helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
            mainConsumed = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, height2 + lp2.topMargin + lp2.bottomMargin + Math.max(height3 + lp3.topMargin + lp3.bottomMargin, height3 + lp4.topMargin + lp4.bottomMargin)) + getVerticalMargin() + getVerticalPadding();
            calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
            int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
            layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
            int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
            layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
            int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child3);
            layoutChild(child3, right2, mAreaRect.top, right3, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), helper);
            int right4 = right1 + orientationHelper.getDecoratedMeasurementInOther(child4);
            layoutChild(child4, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right4, mAreaRect.bottom, helper);
            layoutChild(child5, right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child5), right4 + orientationHelper.getDecoratedMeasurementInOther(child5), mAreaRect.bottom, helper);
        } else {
        // TODO: horizontal support
        }
        handleStateOnResult(result, child1, child2, child3, child4, child5);
    } else if (count == 6) {
        // added at 2017/3/7 can extract method
        final View child1 = mChildrenViews[0];
        final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
        final View child2 = helper.getReverseLayout() ? mChildrenViews[5] : mChildrenViews[1];
        final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
        final View child3 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[2];
        final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
        final View child4 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[3];
        final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
        final View child5 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[4];
        final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
        final View child6 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[5];
        final VirtualLayoutManager.LayoutParams lp6 = new VirtualLayoutManager.LayoutParams(child6.getLayoutParams());
        final float weight1 = getViewMainWeight(lp1, 0);
        final float weight2 = getViewMainWeight(lp1, 1);
        final float weight3 = getViewMainWeight(lp1, 2);
        final float weight4 = getViewMainWeight(lp1, 3);
        final float weight5 = getViewMainWeight(lp1, 4);
        final float weight6 = getViewMainWeight(lp1, 5);
        if (layoutInVertical) {
            lp2.topMargin = lp1.topMargin;
            lp3.bottomMargin = lp4.bottomMargin = lp1.bottomMargin;
            lp3.leftMargin = lp2.leftMargin;
            lp4.rightMargin = lp2.rightMargin;
            lp5.rightMargin = lp2.rightMargin;
            if (!Float.isNaN(mAspectRatio)) {
                lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
            }
            int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin;
            int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 2.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
            int width2 = Float.isNaN(weight2) ? availableSpace - width1 : (int) (availableSpace * weight2 / 100 + 0.5f);
            int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5);
            int bottomavailableSpace = parentWidth - parentHPadding - lp4.leftMargin - lp4.rightMargin - lp5.leftMargin - lp5.rightMargin - lp6.leftMargin - lp6.rightMargin;
            int width4 = Float.isNaN(weight4) ? (int) (bottomavailableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight4 / 100 + 0.5f);
            int width5 = Float.isNaN(weight5) ? width4 : (int) (availableSpace * weight5 / 100 + 0.5f);
            int width6 = Float.isNaN(weight6) ? width4 : (int) (availableSpace * weight6 / 100 + 0.5f);
            helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
            int height1 = child1.getMeasuredHeight();
            int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 2.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
            int height3 = (height1 - lp2.bottomMargin - lp3.topMargin) - height2;
            helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child6, MeasureSpec.makeMeasureSpec(width6 + lp6.leftMargin + lp6.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height3 + lp6.topMargin + lp6.bottomMargin, MeasureSpec.EXACTLY));
            int maxTopHeight = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, (height2 + lp2.topMargin + lp2.bottomMargin) * 2);
            int maxBottomHeight = Math.max(height3 + lp4.topMargin + lp4.bottomMargin, Math.max(height3 + lp5.topMargin + lp5.bottomMargin, height3 + lp6.topMargin + lp6.bottomMargin));
            mainConsumed = maxTopHeight + maxBottomHeight + getVerticalMargin() + getVerticalPadding();
            calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
            int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
            layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), helper);
            int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
            layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
            int right3 = right1 + orientationHelper.getDecoratedMeasurementInOther(child3);
            layoutChild(child3, right1, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), right3, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), helper);
            int right4 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child4);
            layoutChild(child4, mAreaRect.left, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child4), right4, mAreaRect.bottom, helper);
            int right5 = right4 + orientationHelper.getDecoratedMeasurementInOther(child5);
            layoutChild(child5, right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child5), right5, mAreaRect.bottom, helper);
            int right6 = right5 + orientationHelper.getDecoratedMeasurementInOther(child6);
            layoutChild(child6, right5, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), right6, mAreaRect.bottom, helper);
        } else {
        // TODO: horizontal support
        }
        handleStateOnResult(result, child1, child2, child3, child4, child5, child6);
    } else if (count == 7) {
        final View child1 = mChildrenViews[0];
        final VirtualLayoutManager.LayoutParams lp1 = new VirtualLayoutManager.LayoutParams(child1.getLayoutParams());
        final View child2 = helper.getReverseLayout() ? mChildrenViews[6] : mChildrenViews[1];
        final VirtualLayoutManager.LayoutParams lp2 = new VirtualLayoutManager.LayoutParams(child2.getLayoutParams());
        final View child3 = helper.getReverseLayout() ? mChildrenViews[5] : mChildrenViews[2];
        final VirtualLayoutManager.LayoutParams lp3 = new VirtualLayoutManager.LayoutParams(child3.getLayoutParams());
        final View child4 = helper.getReverseLayout() ? mChildrenViews[4] : mChildrenViews[3];
        final VirtualLayoutManager.LayoutParams lp4 = new VirtualLayoutManager.LayoutParams(child4.getLayoutParams());
        final View child5 = helper.getReverseLayout() ? mChildrenViews[3] : mChildrenViews[4];
        final VirtualLayoutManager.LayoutParams lp5 = new VirtualLayoutManager.LayoutParams(child5.getLayoutParams());
        final View child6 = helper.getReverseLayout() ? mChildrenViews[2] : mChildrenViews[5];
        final VirtualLayoutManager.LayoutParams lp6 = new VirtualLayoutManager.LayoutParams(child6.getLayoutParams());
        final View child7 = helper.getReverseLayout() ? mChildrenViews[1] : mChildrenViews[6];
        final VirtualLayoutManager.LayoutParams lp7 = new VirtualLayoutManager.LayoutParams(child7.getLayoutParams());
        final float weight1 = getViewMainWeight(lp1, 0);
        final float weight2 = getViewMainWeight(lp1, 1);
        final float weight3 = getViewMainWeight(lp1, 2);
        final float weight4 = getViewMainWeight(lp1, 3);
        final float weight5 = getViewMainWeight(lp1, 4);
        final float weight6 = getViewMainWeight(lp1, 5);
        final float weight7 = getViewMainWeight(lp1, 6);
        if (layoutInVertical) {
            if (!Float.isNaN(mAspectRatio)) {
                lp1.height = (int) ((parentWidth - parentHPadding) / mAspectRatio);
            }
            int availableSpace = parentWidth - parentHPadding - lp1.leftMargin - lp1.rightMargin - lp2.leftMargin - lp2.rightMargin - lp3.leftMargin - lp3.rightMargin;
            int width1 = Float.isNaN(weight1) ? (int) (availableSpace / 3.0f + 0.5f) : (int) (availableSpace * weight1 / 100 + 0.5f);
            int width2 = Float.isNaN(weight2) ? (availableSpace - width1) / 2 : (int) (availableSpace * weight2 / 100 + 0.5f);
            int width3 = Float.isNaN(weight3) ? width2 : (int) (availableSpace * weight3 / 100 + 0.5);
            int width4 = Float.isNaN(weight4) ? width2 : (int) (availableSpace * weight4 / 100 + 0.5f);
            int width5 = Float.isNaN(weight5) ? width2 : (int) (availableSpace * weight5 / 100 + 0.5f);
            int width6 = Float.isNaN(weight6) ? width2 : (int) (availableSpace * weight6 / 100 + 0.5f);
            int width7 = Float.isNaN(weight6) ? width2 : (int) (availableSpace * weight7 / 100 + 0.5f);
            helper.measureChild(child1, MeasureSpec.makeMeasureSpec(width1 + lp1.leftMargin + lp1.rightMargin, MeasureSpec.EXACTLY), helper.getChildMeasureSpec(helper.getContentHeight(), lp1.height, true));
            int height1 = child1.getMeasuredHeight();
            int height2 = Float.isNaN(mRowWeight) ? (int) ((height1 - lp2.bottomMargin - lp3.topMargin) / 3.0f + 0.5f) : (int) ((height1 - lp2.bottomMargin - lp3.topMargin) * mRowWeight / 100 + 0.5f);
            helper.measureChild(child2, MeasureSpec.makeMeasureSpec(width2 + lp2.leftMargin + lp2.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp2.topMargin + lp2.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child3, MeasureSpec.makeMeasureSpec(width3 + lp3.leftMargin + lp3.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp3.topMargin + lp3.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child4, MeasureSpec.makeMeasureSpec(width4 + lp4.leftMargin + lp4.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp4.topMargin + lp4.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child5, MeasureSpec.makeMeasureSpec(width5 + lp5.leftMargin + lp5.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp5.topMargin + lp5.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child6, MeasureSpec.makeMeasureSpec(width6 + lp6.leftMargin + lp6.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp6.topMargin + lp6.bottomMargin, MeasureSpec.EXACTLY));
            helper.measureChild(child7, MeasureSpec.makeMeasureSpec(width7 + lp7.leftMargin + lp7.rightMargin, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height2 + lp7.topMargin + lp7.bottomMargin, MeasureSpec.EXACTLY));
            int maxRightHeight = Math.max(height2 + lp2.topMargin + lp2.bottomMargin, height2 + lp3.topMargin + lp3.bottomMargin) + Math.max(height2 + lp4.topMargin + lp4.bottomMargin, height2 + lp5.topMargin + lp5.bottomMargin) + Math.max(height2 + lp6.topMargin + lp6.bottomMargin, height2 + lp7.topMargin + lp7.bottomMargin);
            int maxHeight = Math.max(height1 + lp1.topMargin + lp1.bottomMargin, maxRightHeight);
            mainConsumed = maxHeight + getVerticalMargin() + getVerticalPadding();
            calculateRect(mainConsumed - getVerticalMargin() - getVerticalPadding(), mAreaRect, layoutState, helper);
            int right1 = mAreaRect.left + orientationHelper.getDecoratedMeasurementInOther(child1);
            layoutChild(child1, mAreaRect.left, mAreaRect.top, right1, mAreaRect.bottom, helper);
            int right2 = right1 + orientationHelper.getDecoratedMeasurementInOther(child2);
            layoutChild(child2, right1, mAreaRect.top, right2, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), helper);
            int right3 = right2 + orientationHelper.getDecoratedMeasurementInOther(child3);
            layoutChild(child3, right2, mAreaRect.top, right3, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child3), helper);
            int right4 = right1 + orientationHelper.getDecoratedMeasurementInOther(child4);
            layoutChild(child4, right1, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), right4, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), helper);
            int right5 = right4 + orientationHelper.getDecoratedMeasurementInOther(child5);
            layoutChild(child5, right4, mAreaRect.top + orientationHelper.getDecoratedMeasurement(child2), right5, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child7), helper);
            int right6 = right1 + orientationHelper.getDecoratedMeasurementInOther(child6);
            layoutChild(child6, right1, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child6), right6, mAreaRect.bottom, helper);
            layoutChild(child7, right6, mAreaRect.bottom - orientationHelper.getDecoratedMeasurement(child7), right6 + orientationHelper.getDecoratedMeasurementInOther(child7), mAreaRect.bottom, helper);
        } else {
        // TODO: horizontal support
        }
        handleStateOnResult(result, child1, child2, child3, child4, child5, child6);
    }
    result.mConsumed = mainConsumed;
    Arrays.fill(mChildrenViews, null);
}
Also used : OrientationHelper(android.support.v7.widget.OrientationHelper) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 25 with END

use of android.support.v7.widget.helper.ItemTouchHelper.END in project android by owncloud.

the class LocalFolderPickerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreate() start");
    super.onCreate(savedInstanceState);
    // set current folder
    String startPath = (savedInstanceState != null) ? savedInstanceState.getString(LocalFolderPickerActivity.EXTRA_PATH) : getIntent().getStringExtra(EXTRA_PATH);
    if (startPath != null) {
        mCurrentFolder = new File(startPath);
    }
    if (mCurrentFolder == null || !mCurrentFolder.exists()) {
        // default
        mCurrentFolder = Environment.getExternalStorageDirectory();
    } else if (!mCurrentFolder.isDirectory()) {
        mCurrentFolder = mCurrentFolder.getParentFile();
    }
    // inflate and set the layout view
    // beware - inflated in other activities too
    setContentView(R.layout.files_folder_picker);
    if (savedInstanceState == null) {
        createFragments();
    }
    // set input controllers
    mCancelBtn = (Button) findViewById(R.id.folder_picker_btn_cancel);
    mCancelBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });
    mChooseBtn = (Button) findViewById(R.id.folder_picker_btn_choose);
    mChooseBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // return the path of the current folder
            Intent data = new Intent();
            data.putExtra(EXTRA_PATH, mCurrentFolder.getAbsolutePath());
            setResult(RESULT_OK, data);
            finish();
        }
    });
    // init toolbar
    setupToolbar();
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(true);
    }
    updateActionBar();
    Log_OC.d(TAG, "onCreate() end");
}
Also used : Intent(android.content.Intent) File(java.io.File) View(android.view.View) ActionBar(android.support.v7.app.ActionBar)

Aggregations

View (android.view.View)129 RecyclerView (android.support.v7.widget.RecyclerView)113 TextView (android.widget.TextView)35 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)25 ImageView (android.widget.ImageView)20 ArrayList (java.util.ArrayList)19 SuppressLint (android.annotation.SuppressLint)15 Intent (android.content.Intent)15 ViewGroup (android.view.ViewGroup)13 DialogInterface (android.content.DialogInterface)12 PreferenceScreen (android.support.v7.preference.PreferenceScreen)11 Toolbar (android.support.v7.widget.Toolbar)11 AdapterView (android.widget.AdapterView)11 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)10 List (java.util.List)10 AlertDialog (android.support.v7.app.AlertDialog)9 Context (android.content.Context)8 ActionBar (android.support.v7.app.ActionBar)8 ListView (android.widget.ListView)8 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)8