Example usage for android.view View getScrollY

List of usage examples for android.view View getScrollY

Introduction

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

Prototype

public final int getScrollY() 

Source Link

Document

Return the scrolled top position of this view.

Usage

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectLeftWithinChild = rect.left;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int width = getWidth();
    int listUnfadedLeft = getScrollX();
    int listUnfadedRight = listUnfadedLeft + width;
    final int fadingEdge = getHorizontalFadingEdgeLength();

    if (showingLeftFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectLeftWithinChild > fadingEdge)) {
            listUnfadedLeft += fadingEdge;
        }/*from  ww  w .  j  av a 2  s.c om*/
    }

    int childCount = getChildCount();
    int rightOfRightChild = getChildAt(childCount - 1).getRight();

    if (showingRightFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.right < (rightOfRightChild - fadingEdge))) {
            listUnfadedRight -= fadingEdge;
        }
    }

    int scrollXDelta = 0;

    if (rect.right > listUnfadedRight && rect.left > listUnfadedLeft) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.width() > width) {
            // just enough to get screen size chunk on
            scrollXDelta += (rect.left - listUnfadedLeft);
        } else {
            // get entire rect at bottom of screen
            scrollXDelta += (rect.right - listUnfadedRight);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToRight = rightOfRightChild - listUnfadedRight;
        scrollXDelta = Math.min(scrollXDelta, distanceToRight);
    } else if (rect.left < listUnfadedLeft && rect.right < listUnfadedRight) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.width() > width) {
            // screen size chunk
            scrollXDelta -= (listUnfadedRight - rect.right);
        } else {
            // entire rect at top
            scrollXDelta -= (listUnfadedLeft - rect.left);
        }

        // make sure we aren't scrolling any further than the top our children
        int left = getChildAt(0).getLeft();
        int deltaToLeft = left - listUnfadedLeft;
        scrollXDelta = Math.max(scrollXDelta, deltaToLeft);
    }

    final boolean scroll = scrollXDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollXDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedLeft = child.getTop();
        invalidate();
    }
    return scroll;
}

From source file:com.appunite.list.ListView.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int height = getHeight();
    int listUnfadedTop = getScrollY();
    int listUnfadedBottom = listUnfadedTop + height;
    final int fadingEdge = getVerticalFadingEdgeLength();

    if (showingTopFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if ((mSelectedPosition > 0) || (rectTopWithinChild > fadingEdge)) {
            listUnfadedTop += fadingEdge;
        }/*from  ww w . j  a  v  a  2 s  . c o m*/
    }

    int childCount = getChildCount();
    int bottomOfBottomChild = getChildAt(childCount - 1).getBottom();

    if (showingBottomFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very bottom
        if ((mSelectedPosition < mItemCount - 1) || (rect.bottom < (bottomOfBottomChild - fadingEdge))) {
            listUnfadedBottom -= fadingEdge;
        }
    }

    int scrollYDelta = 0;

    if (rect.bottom > listUnfadedBottom && rect.top > listUnfadedTop) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.height() > height) {
            // just enough to get screen size chunk on
            scrollYDelta += (rect.top - listUnfadedTop);
        } else {
            // get entire rect at bottom of screen
            scrollYDelta += (rect.bottom - listUnfadedBottom);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToBottom = bottomOfBottomChild - listUnfadedBottom;
        scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
    } else if (rect.top < listUnfadedTop && rect.bottom < listUnfadedBottom) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.height() > height) {
            // screen size chunk
            scrollYDelta -= (listUnfadedBottom - rect.bottom);
        } else {
            // entire rect at top
            scrollYDelta -= (listUnfadedTop - rect.top);
        }

        // make sure we aren't scrolling any further than the top our children
        int top = getChildAt(0).getTop();
        int deltaToTop = top - listUnfadedTop;
        scrollYDelta = Math.max(scrollYDelta, deltaToTop);
    }

    final boolean scroll = scrollYDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollYDelta);
        positionSelector(INVALID_POSITION, child);
        mSelectedTop = child.getTop();
        invalidate();
    }
    return scroll;
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * NOTE This method is borrowed from {@link ScrollView}.
 *///from www.j av a2s  . c o m
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
    // offset into coordinate space of this scroll view
    rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());

    return scrollToChildRect(rectangle, immediate);
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw/*from  ww  w . j a  va 2s  . co  m*/
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = getTextViewIcon((TextView) v);
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

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

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw//from   www  .ja va  2  s .  c om
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Set the horizontal position of the scroll bar for each view in the current selection
 * @param position the x position to which to scroll
 * @return this// w ww.  j  a  va2  s. c  o m
 */
public $ scrollLeft(int position) {
    for (int i = 0; i < this.views.size(); i++) {
        View view = this.views.get(i);
        view.scrollTo(position, view.getScrollY());
    }
    return this;
}

From source file:com.wb.launcher3.Page.java

@Override
protected void dispatchDraw(Canvas canvas) {
    int halfScreenSize = getViewportWidth() / 2;
    // mOverScrollX is equal to getScrollX() when we're within the normal scroll range.
    // Otherwise it is equal to the scaled overscroll position.
    int screenCenter = mOverScrollX + halfScreenSize;

    if (screenCenter != mLastScreenCenter || mForceScreenScrolled) {
        // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can
        // set it for the next frame
        mForceScreenScrolled = false;/*w ww . j  ava2 s  . co  m*/
        screenScrolled(screenCenter);
        mLastScreenCenter = screenCenter;
    }

    // Find out which screens are visible; as an optimization we only call draw on them
    final int pageCount = getChildCount();
    if (pageCount > 0) {
        //*/Modified by tyd Greg 2014-03-20,for transition effect
        boolean allowed = true;
        Workspace workspace = null;
        if (this instanceof Workspace) {
            workspace = (Workspace) this;
            allowed = !workspace.isSmall();
        }
        if (TydtechConfig.TYDTECH_DEBUG_FLAG) {
            Log.d("Greg", "allowed: " + allowed);
        }
        /*/
        if(!allowed || !TydtechConfig.TRANSITION_EFFECT_ENABLED){
        getVisiblePages(mTempVisiblePagesRange);
        }else{
        getVisiblePagesExt(mTempVisiblePagesRange);
        }
        //*/
        getVisiblePages(mTempVisiblePagesRange);
        //*/
        final int leftScreen = mTempVisiblePagesRange[0];
        final int rightScreen = mTempVisiblePagesRange[1];
        if (leftScreen != -1 && rightScreen != -1) {
            final long drawingTime = getDrawingTime();
            // Clip to the bounds
            canvas.save();
            canvas.clipRect(getScrollX(), getScrollY(), getScrollX() + getRight() - getLeft(),
                    getScrollY() + getBottom() - getTop());

            // Draw all the children, leaving the drag view for last
            for (int i = pageCount - 1; i >= 0; i--) {
                final View v = getPageAt(i);
                if (v == mDragView)
                    continue;
                if (mForceDrawAllChildrenNextFrame
                        || (leftScreen <= i && i <= rightScreen && shouldDrawChild(v))) {
                    drawChild(canvas, v, drawingTime);
                }
            }
            // Draw the drag view on top (if there is one)
            if (mDragView != null) {
                drawChild(canvas, mDragView, drawingTime);
            }

            mForceDrawAllChildrenNextFrame = false;
            canvas.restore();
        }

        //*/Added by TYD Theobald_Wu on 20130223 [begin] for cycle rolling pages
        if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED && allowed) {
            canvas.save();
            int width = 0;
            final int pageW = getViewportWidth();
            View v = null;
            int scrollOffset = (pageW - getChildWidth(0)) / 2;
            if (mOverScrollX < 0) {
                int index = pageCount - 1;
                v = getPageAt(index);
                width = getViewportOffsetX() - scrollOffset - v.getWidth();
            } else if (mOverScrollX > mMaxScrollX) {
                v = getPageAt(0);
                width = getViewportOffsetX() + pageW * pageCount + scrollOffset;
            }
            if (TydtechConfig.TYDTECH_DEBUG_FLAG) {
                Log.d("Greg", "width: " + width);
                Log.d("Greg", "mOverScrollX: " + mOverScrollX);
            }
            if (v != null) {
                canvas.translate(width, v.getY());
                canvas.concat(v.getMatrix());
                final int w = v.getWidth();
                final int h = v.getHeight();
                final int sx = v.getScrollX();
                final int sy = v.getScrollY();
                Rect rect = new Rect(sx, sy, sx + w, sy + h);
                ///* zhangwuba mark this, user verison lead to screen flash 2014-5-12
                //canvas.saveLayerAlpha(sx, sy, sx + w, sy + h, (int) (v.getAlpha() * 255),
                //  Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
                //*/
                v.draw(canvas);
            }
            canvas.restore();
        }
        //*/
    }
}

From source file:cc.flydev.launcher.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw//from  w w w . j a  va 2 s  .  com
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) {
    final Rect clipRect = mTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView && pruneToDrawable) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
        destCanvas.translate(padding / 2, padding / 2);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        } else if (v instanceof BubbleTextView) {
            final BubbleTextView tv = (BubbleTextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
                    + tv.getLayout().getLineTop(0);
        } else if (v instanceof TextView) {
            final TextView tv = (TextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding()
                    + tv.getLayout().getLineTop(0);
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

/**
 * Draw the View v into the given Canvas.
 * /*from  w  w w . j av a  2 s . co m*/
 * @param v
 *            the view to draw
 * @param destCanvas
 *            the canvas to draw on
 * @param padding
 *            the horizontal and vertical padding to use when drawing
 */
private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) {
    final Rect clipRect = mTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView && pruneToDrawable) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
        destCanvas.translate(padding / 2, padding / 2);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so
            // we need to
            // hide the text completely (which can't be achieved by
            // clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        } else if (v instanceof BubbleTextView) {
            final BubbleTextView tv = (BubbleTextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
                    + tv.getLayout().getLineTop(0);
        } else if (v instanceof TextView) {
            final TextView tv = (TextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding()
                    + tv.getLayout().getLineTop(0);
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:org.telegram.ui.PassportActivity.java

@Override
public View createView(Context context) {

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        private boolean onIdentityDone(Runnable finishRunnable, ErrorRunnable errorRunnable) {
            if (!uploadingDocuments.isEmpty() || checkFieldsForError()) {
                return false;
            }/*  w  ww .  j a  v a 2  s .  c o  m*/
            if (allowNonLatinName) {
                allowNonLatinName = false;
                boolean error = false;
                for (int a = 0; a < nonLatinNames.length; a++) {
                    if (nonLatinNames[a]) {
                        inputFields[a].setErrorText(LocaleController.getString("PassportUseLatinOnly",
                                R.string.PassportUseLatinOnly));
                        if (!error) {
                            error = true;
                            String firstName = nonLatinNames[0]
                                    ? getTranslitString(
                                            inputExtraFields[FIELD_NATIVE_NAME].getText().toString())
                                    : inputFields[FIELD_NAME].getText().toString();
                            String middleName = nonLatinNames[1]
                                    ? getTranslitString(
                                            inputExtraFields[FIELD_NATIVE_MIDNAME].getText().toString())
                                    : inputFields[FIELD_MIDNAME].getText().toString();
                            String lastName = nonLatinNames[2]
                                    ? getTranslitString(
                                            inputExtraFields[FIELD_NATIVE_SURNAME].getText().toString())
                                    : inputFields[FIELD_SURNAME].getText().toString();

                            if (!TextUtils.isEmpty(firstName) && !TextUtils.isEmpty(middleName)
                                    && !TextUtils.isEmpty(lastName)) {
                                int num = a;
                                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                                builder.setMessage(LocaleController.formatString("PassportNameCheckAlert",
                                        R.string.PassportNameCheckAlert, firstName, middleName, lastName));
                                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                builder.setPositiveButton(LocaleController.getString("Done", R.string.Done),
                                        (dialogInterface, i) -> {
                                            inputFields[FIELD_NAME].setText(firstName);
                                            inputFields[FIELD_MIDNAME].setText(middleName);
                                            inputFields[FIELD_SURNAME].setText(lastName);
                                            showEditDoneProgress(true, true);
                                            onIdentityDone(finishRunnable, errorRunnable);
                                        });
                                builder.setNegativeButton(LocaleController.getString("Edit", R.string.Edit),
                                        (dialogInterface, i) -> onFieldError(inputFields[num]));
                                showDialog(builder.create());
                            } else {
                                onFieldError(inputFields[a]);
                            }
                        }
                    }
                }
                if (error) {
                    return false;
                }
            }
            if (isHasNotAnyChanges()) {
                finishFragment();
                return false;
            }
            JSONObject json = null;
            JSONObject documentsJson = null;
            try {
                if (!documentOnly) {
                    HashMap<String, String> valuesToSave = new HashMap<>(currentValues);
                    if (currentType.native_names) {
                        if (nativeInfoCell.getVisibility() == View.VISIBLE) {
                            valuesToSave.put("first_name_native",
                                    inputExtraFields[FIELD_NATIVE_NAME].getText().toString());
                            valuesToSave.put("middle_name_native",
                                    inputExtraFields[FIELD_NATIVE_MIDNAME].getText().toString());
                            valuesToSave.put("last_name_native",
                                    inputExtraFields[FIELD_NATIVE_SURNAME].getText().toString());
                        } else {
                            valuesToSave.put("first_name_native",
                                    inputFields[FIELD_NATIVE_NAME].getText().toString());
                            valuesToSave.put("middle_name_native",
                                    inputFields[FIELD_NATIVE_MIDNAME].getText().toString());
                            valuesToSave.put("last_name_native",
                                    inputFields[FIELD_NATIVE_SURNAME].getText().toString());
                        }
                    }
                    valuesToSave.put("first_name", inputFields[FIELD_NAME].getText().toString());
                    valuesToSave.put("middle_name", inputFields[FIELD_MIDNAME].getText().toString());
                    valuesToSave.put("last_name", inputFields[FIELD_SURNAME].getText().toString());
                    valuesToSave.put("birth_date", inputFields[FIELD_BIRTHDAY].getText().toString());
                    valuesToSave.put("gender", currentGender);
                    valuesToSave.put("country_code", currentCitizeship);
                    valuesToSave.put("residence_country_code", currentResidence);

                    json = new JSONObject();
                    ArrayList<String> keys = new ArrayList<>(valuesToSave.keySet());
                    Collections.sort(keys, (key1, key2) -> {
                        int val1 = getFieldCost(key1);
                        int val2 = getFieldCost(key2);
                        if (val1 < val2) {
                            return -1;
                        } else if (val1 > val2) {
                            return 1;
                        }
                        return 0;
                    });
                    for (int a = 0, size = keys.size(); a < size; a++) {
                        String key = keys.get(a);
                        json.put(key, valuesToSave.get(key));
                    }
                }

                if (currentDocumentsType != null) {
                    HashMap<String, String> valuesToSave = new HashMap<>(currentDocumentValues);
                    valuesToSave.put("document_no", inputFields[FIELD_CARDNUMBER].getText().toString());
                    if (currentExpireDate[0] != 0) {
                        valuesToSave.put("expiry_date", String.format(Locale.US, "%02d.%02d.%d",
                                currentExpireDate[2], currentExpireDate[1], currentExpireDate[0]));
                    } else {
                        valuesToSave.put("expiry_date", "");
                    }

                    documentsJson = new JSONObject();
                    ArrayList<String> keys = new ArrayList<>(valuesToSave.keySet());
                    Collections.sort(keys, (key1, key2) -> {
                        int val1 = getFieldCost(key1);
                        int val2 = getFieldCost(key2);
                        if (val1 < val2) {
                            return -1;
                        } else if (val1 > val2) {
                            return 1;
                        }
                        return 0;
                    });
                    for (int a = 0, size = keys.size(); a < size; a++) {
                        String key = keys.get(a);
                        documentsJson.put(key, valuesToSave.get(key));
                    }
                }
            } catch (Exception ignore) {

            }
            if (fieldsErrors != null) {
                fieldsErrors.clear();
            }
            if (documentsErrors != null) {
                documentsErrors.clear();
            }
            delegate.saveValue(currentType, null, json != null ? json.toString() : null, currentDocumentsType,
                    documentsJson != null ? documentsJson.toString() : null, null, selfieDocument,
                    translationDocuments, frontDocument,
                    reverseLayout != null && reverseLayout.getVisibility() == View.VISIBLE ? reverseDocument
                            : null,
                    finishRunnable, errorRunnable);
            return true;
        }

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (checkDiscard()) {
                    return;
                }
                if (currentActivityType == TYPE_REQUEST || currentActivityType == TYPE_PASSWORD) {
                    callCallback(false);
                }
                finishFragment();
            } else if (id == info_item) {
                if (getParentActivity() == null) {
                    return;
                }
                final TextView message = new TextView(getParentActivity());
                String str2 = LocaleController.getString("PassportInfo2", R.string.PassportInfo2);
                SpannableStringBuilder spanned = new SpannableStringBuilder(str2);
                int index1 = str2.indexOf('*');
                int index2 = str2.lastIndexOf('*');
                if (index1 != -1 && index2 != -1) {
                    spanned.replace(index2, index2 + 1, "");
                    spanned.replace(index1, index1 + 1, "");
                    spanned.setSpan(new URLSpanNoUnderline(
                            LocaleController.getString("PassportInfoUrl", R.string.PassportInfoUrl)) {
                        @Override
                        public void onClick(View widget) {
                            dismissCurrentDialig();
                            super.onClick(widget);
                        }
                    }, index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                message.setText(spanned);
                message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
                message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
                message.setPadding(AndroidUtilities.dp(23), 0, AndroidUtilities.dp(23), 0);
                message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
                message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));

                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setView(message);
                builder.setTitle(LocaleController.getString("PassportInfoTitle", R.string.PassportInfoTitle));
                builder.setNegativeButton(LocaleController.getString("Close", R.string.Close), null);
                showDialog(builder.create());
            } else if (id == done_button) {
                if (currentActivityType == TYPE_PASSWORD) {
                    onPasswordDone(false);
                    return;
                }
                if (currentActivityType == TYPE_PHONE_VERIFICATION) {
                    views[currentViewNum].onNextPressed();
                } else {
                    final Runnable finishRunnable = () -> finishFragment();
                    final ErrorRunnable errorRunnable = new ErrorRunnable() {
                        @Override
                        public void onError(String error, String text) {
                            if ("PHONE_VERIFICATION_NEEDED".equals(error)) {
                                startPhoneVerification(true, text, finishRunnable, this, delegate);
                            } else {
                                showEditDoneProgress(true, false);
                            }
                        }
                    };

                    if (currentActivityType == TYPE_EMAIL) {
                        String value;
                        if (useCurrentValue) {
                            value = currentEmail;
                        } else {
                            if (checkFieldsForError()) {
                                return;
                            }
                            value = inputFields[FIELD_EMAIL].getText().toString();
                        }
                        delegate.saveValue(currentType, value, null, null, null, null, null, null, null, null,
                                finishRunnable, errorRunnable);
                    } else if (currentActivityType == TYPE_PHONE) {
                        String value;
                        if (useCurrentValue) {
                            value = UserConfig.getInstance(currentAccount).getCurrentUser().phone;
                        } else {
                            if (checkFieldsForError()) {
                                return;
                            }
                            value = inputFields[FIELD_PHONECODE].getText().toString()
                                    + inputFields[FIELD_PHONE].getText().toString();
                        }
                        delegate.saveValue(currentType, value, null, null, null, null, null, null, null, null,
                                finishRunnable, errorRunnable);
                    } else if (currentActivityType == TYPE_ADDRESS) {
                        if (!uploadingDocuments.isEmpty() || checkFieldsForError()) {
                            return;
                        }
                        if (isHasNotAnyChanges()) {
                            finishFragment();
                            return;
                        }
                        JSONObject json = null;
                        try {
                            if (!documentOnly) {
                                json = new JSONObject();
                                json.put("street_line1", inputFields[FIELD_STREET1].getText().toString());
                                json.put("street_line2", inputFields[FIELD_STREET2].getText().toString());
                                json.put("post_code", inputFields[FIELD_POSTCODE].getText().toString());
                                json.put("city", inputFields[FIELD_CITY].getText().toString());
                                json.put("state", inputFields[FIELD_STATE].getText().toString());
                                json.put("country_code", currentCitizeship);
                            }
                        } catch (Exception ignore) {

                        }
                        if (fieldsErrors != null) {
                            fieldsErrors.clear();
                        }
                        if (documentsErrors != null) {
                            documentsErrors.clear();
                        }
                        delegate.saveValue(currentType, null, json != null ? json.toString() : null,
                                currentDocumentsType, null, documents, selfieDocument, translationDocuments,
                                null, null, finishRunnable, errorRunnable);
                    } else if (currentActivityType == TYPE_IDENTITY) {
                        if (!onIdentityDone(finishRunnable, errorRunnable)) {
                            return;
                        }
                    } else if (currentActivityType == TYPE_EMAIL_VERIFICATION) {
                        final TLRPC.TL_account_verifyEmail req = new TLRPC.TL_account_verifyEmail();
                        req.email = currentValues.get("email");
                        req.code = inputFields[FIELD_EMAIL].getText().toString();
                        int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req,
                                (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                                    if (error == null) {
                                        delegate.saveValue(currentType, currentValues.get("email"), null, null,
                                                null, null, null, null, null, null, finishRunnable,
                                                errorRunnable);
                                    } else {
                                        AlertsCreator.processError(currentAccount, error, PassportActivity.this,
                                                req);
                                        errorRunnable.onError(null, null);
                                    }
                                }));
                        ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
                    }
                    showEditDoneProgress(true, true);
                }
            }
        }
    });

    if (currentActivityType == TYPE_PHONE_VERIFICATION) {
        fragmentView = scrollView = new ScrollView(context) {
            @Override
            protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
                return false;
            }

            @Override
            public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
                if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                    rectangle.bottom += AndroidUtilities.dp(40);
                }
                return super.requestChildRectangleOnScreen(child, rectangle, immediate);
            }

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        };
        scrollView.setFillViewport(true);
        AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault));
    } else {
        fragmentView = new FrameLayout(context);
        FrameLayout frameLayout = (FrameLayout) fragmentView;
        fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));

        scrollView = new ScrollView(context) {
            @Override
            protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
                return false;
            }

            @Override
            public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
                rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
                rectangle.top += AndroidUtilities.dp(20);
                rectangle.bottom += AndroidUtilities.dp(50);
                return super.requestChildRectangleOnScreen(child, rectangle, immediate);
            }
        };
        scrollView.setFillViewport(true);
        AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault));
        frameLayout.addView(scrollView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
                        Gravity.LEFT | Gravity.TOP, 0, 0, 0, currentActivityType == TYPE_REQUEST ? 48 : 0));

        linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(LinearLayout.VERTICAL);
        scrollView.addView(linearLayout2, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    if (currentActivityType != TYPE_REQUEST && currentActivityType != TYPE_MANAGE) {
        ActionBarMenu menu = actionBar.createMenu();
        doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
        progressView = new ContextProgressView(context, 1);
        progressView.setAlpha(0.0f);
        progressView.setScaleX(0.1f);
        progressView.setScaleY(0.1f);
        progressView.setVisibility(View.INVISIBLE);
        doneItem.addView(progressView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

        if (currentActivityType == TYPE_IDENTITY || currentActivityType == TYPE_ADDRESS) {
            if (chatAttachAlert != null) {
                try {
                    if (chatAttachAlert.isShowing()) {
                        chatAttachAlert.dismiss();
                    }
                } catch (Exception ignore) {

                }
                chatAttachAlert.onDestroy();
                chatAttachAlert = null;
            }
        }
    }

    if (currentActivityType == TYPE_PASSWORD) {
        createPasswordInterface(context);
    } else if (currentActivityType == TYPE_REQUEST) {
        createRequestInterface(context);
    } else if (currentActivityType == TYPE_IDENTITY) {
        createIdentityInterface(context);
        fillInitialValues();
    } else if (currentActivityType == TYPE_ADDRESS) {
        createAddressInterface(context);
        fillInitialValues();
    } else if (currentActivityType == TYPE_PHONE) {
        createPhoneInterface(context);
    } else if (currentActivityType == TYPE_EMAIL) {
        createEmailInterface(context);
    } else if (currentActivityType == TYPE_EMAIL_VERIFICATION) {
        createEmailVerificationInterface(context);
    } else if (currentActivityType == TYPE_PHONE_VERIFICATION) {
        createPhoneVerificationInterface(context);
    } else if (currentActivityType == TYPE_MANAGE) {
        createManageInterface(context);
    }
    return fragmentView;
}