Example usage for android.view Gravity LEFT

List of usage examples for android.view Gravity LEFT

Introduction

In this page you can find the example usage for android.view Gravity LEFT.

Prototype

int LEFT

To view the source code for android.view Gravity LEFT.

Click Source Link

Document

Push object to the left of its container, not changing its size.

Usage

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    mDragger.processTouchEvent(ev);/*from w w w .ja  va2s  . c om*/
    final int absGravity = getDrawerViewAbsoluteGravity(findDrawerView());
    final int edge;
    if (absGravity == Gravity.LEFT) {
        edge = ViewDragHelper.EDGE_LEFT;
    } else {
        edge = ViewDragHelper.EDGE_RIGHT;
    }

    // don't allow views behind the drawer to be touched
    boolean drawerPartiallyOpen = onScreen() > 0;
    return mDragger.isEdgeTouched(edge) || mDragger.getCapturedView() != null || drawerPartiallyOpen;
}

From source file:com.ferg.awfulapp.widget.AwfulViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view.  We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    // Children are just made to fill our space.
    int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*/*from  w  w  w .j a  v  a  2s  .  c  o m*/
    * Make sure all children have been properly measured. Decor views first.
    * Right now we cheat and make this less complicated by assuming decor
    * views won't intersect. We will pin to edges based on gravity.
    */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                //Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav);
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            //                   if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child
            //                           + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec);
            }
        }
    }
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

@NonNull
@Override//from   ww w.java  2 s  .  co  m
protected Parcelable onSaveInstanceState() {
    Bundle saved = new Bundle();
    saved.putParcelable(KEY_SUPER, super.onSaveInstanceState());

    if (isDrawerOpen(Gravity.LEFT)) {
        saved.putInt(KEY_OPENED_DRAWER, Gravity.LEFT);
    } else if (isDrawerOpen(Gravity.RIGHT)) {
        saved.putInt(KEY_OPENED_DRAWER, Gravity.RIGHT);
    }
    saved.putInt(KEY_LEFT_LOCK_MODER, mLeftLockMode);
    saved.putInt(KEY_RIGHT_LOCK_MODER, mRightLockMode);
    return saved;
}

From source file:beichen.douban.ui.view.LazyViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view. We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    // Children are just made to fill our space.
    int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*//  w  w w  .  j a  va2 s  .  c om
     * Make sure all children have been properly measured. Decor views
     * first. Right now we cheat and make this less complicated by assuming
     * decor views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav);
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec);
            }
        }
    }
}

From source file:com.cybrosys.scientific.EventListener.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override/*  www  .j a  v a2 s  .  com*/
public void onClick(View vwView) {
    vibrate();
    ctx = PalmCalcActivity.ctx;
    int id = vwView.getId();
    ScientificActivity.txtvShift.setText("");
    switch (id) {

    case R.id.buttonDel:
        mHandler.onDelete();
        break;
    case R.id.button3:
        if (inShift == 0)
            mHandler.insert("3");
        else {
            mHandler.insert(",");
            inShift = 0;
        }
        break;
    case R.id.buttonDot:
        if (inShift == 0)
            mHandler.insert(".");
        else {
            showD();
            inShift = 0;
        }
        break;
    case R.id.buttonAC:
        mHandler.onClear();
        break;

    case R.id.ButtonEqual:
        String strDisplayEq = mHandler.getDisplayText();
        if (!strDisplayEq.equalsIgnoreCase(""))
            mHandler.onEnter();
        break;

    case R.id.ButtonAns:
        if (inShift == 0)
            mHandler.onShow();
        else {
            showHistory();
            inShift = 0;
        }
        break;
    case R.id.buttonDeg:
        mHandler.onDegChange();
        break;
    case R.id.buttonAlt:

        if (inShift == 0) {
            String[] strMode = new String[] { "Floatpt", "FIX", "SCI" };
            int inSizeM = 3;

            LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            vwLayout = inflater.inflate(R.layout.pop_history,
                    (ViewGroup) ((Activity) ctx).findViewById(R.id.popup_element));
            TextView txtvHeaderPop = (TextView) vwLayout.findViewById(R.id.txtvHeaderPop);
            txtvHeaderPop.setText("MODE");
            popmW1 = new PopupWindow(vwLayout, PalmCalcActivity.inDispwidth, PalmCalcActivity.inDispheight,
                    true);
            popmW1.setBackgroundDrawable(new BitmapDrawable());
            popmW1.setOutsideTouchable(true);
            popmW1.showAtLocation(vwLayout, Gravity.CENTER, 0, 0);
            tblltTable = (TableLayout) vwLayout.findViewById(R.id.tablelay);
            ImageButton btnCancel = (ImageButton) vwLayout.findViewById(R.id.butcancelmain);
            btnCancel.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    popmW1.dismiss();

                }
            });
            txtvHistory = new TextView[inSizeM];
            btnHistory = new Button[inSizeM];
            tblrRowL = new TableRow[inSizeM];
            TableRow.LayoutParams buttonParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                    TableRow.LayoutParams.WRAP_CONTENT, 1f);
            TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                    TableRow.LayoutParams.WRAP_CONTENT, .1f);
            int inJ = 0;
            for (int inI = 0; inI < inSizeM; inI++) {
                btnHistory[inJ] = new Button(ctx);
                txtvHistory[inJ] = new TextView(ctx);
                txtvHistory[inJ].setText("" + (inJ + 1));
                txtvHistory[inJ].setLayoutParams(textParams);
                btnHistory[inJ].setText(strMode[inI]);
                txtvHistory[inJ].setGravity(Gravity.CENTER);
                txtvHistory[inJ]
                        .setTextColor(ScientificActivity.ctx.getResources().getColor(R.color.HistColor));
                btnHistory[inJ].setTextColor(Color.WHITE);
                btnHistory[inJ].setGravity(Gravity.LEFT);
                btnHistory[inJ].setLayoutParams(buttonParams);
                btnHistory[inJ].setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.button_effect));
                tblrRowL[inJ] = new TableRow(ctx);
                tblrRowL[inJ].addView(txtvHistory[inJ]);
                tblrRowL[inJ].addView(btnHistory[inJ]);
                tblltTable.addView(tblrRowL[inJ]);
                final int inK = inJ;
                btnHistory[inK].setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // etxt.setText(btns[inK].getText().toString());
                        ScientificActivity.txtvFSE.setText(btnHistory[inK].getText().toString());
                        popmW1.dismiss();
                    }
                });

                inJ++;

            }

        } else {
            setFSE();
            inShift = 0;
        }
        mHandler.onFSEChange();
        break;
    case R.id.buttonShift:
        if (inShift == 0) {
            inShift = 1;
            mHandler.onShiftPress();
        } else
            inShift = 0;

        break;
    case R.id.buttonHyp:
        if (inHyp == 0) {
            inHyp = 1;
            mHandler.onHypPress();
        } else {
            inHyp = 0;
            ScientificActivity.txtvHyp.setText("");
        }
        break;
    case R.id.buttonMS:
        mHandler.onEnter();
        String strDisplay = mHandler.getDisplayText();
        if (inShift == 0) {

            if (isValidNumber(strDisplay)) {

                PreferenceClass.setMyStringPref(ctx, strDisplay);
                Toast.makeText(ctx, "Memory Saved!", Toast.LENGTH_SHORT).show();
                mHandler.onClear();
            } else
                Toast.makeText(ctx, "Save Failed!", Toast.LENGTH_SHORT).show();

        } else {
            Memstore();
        }

        break;
    case R.id.buttonMR:
        if (inShift == 0) {
            String strPref = PreferenceClass.getMyStringPref(ctx);
            if (!strPref.equalsIgnoreCase("")) {
                mHandler.insert(strPref);
            } else
                Toast.makeText(ctx, "Empty", Toast.LENGTH_SHORT).show();
        } else {
            Memread();
            inShift = 0;

        }
        break;
    case R.id.buttonMp:
        mHandler.onEnter();
        String strDisplay2 = mHandler.getDisplayText();
        if (isValidNumber(strDisplay2)) {
            String strPref2 = PreferenceClass.getMyStringPref(ctx);
            if (!strPref2.equalsIgnoreCase("")) {
                if (inShift == 0) {
                    try {
                        PreferenceClass.setMyStringPref(ctx, "" + mSymbols.eval(strPref2 + "+" + strDisplay2));
                        mHandler.onClear();
                    } catch (SyntaxException e) {

                        e.printStackTrace();
                    }
                    Toast.makeText(ctx, "Value added", Toast.LENGTH_SHORT).show();
                } else {
                    Memplus();

                    inShift = 0;
                }
            }
        }
        break;

    default:
        if (vwView instanceof Button) {
            String strText = ((Button) vwView).getTag().toString();
            if (strText.contains(",")) {
                int inInComa = strText.lastIndexOf(",");
                if (inShift == 1) {
                    strText = strText.substring(inInComa + 1, strText.length());
                    inShift = 0;
                } else {
                    strText = strText.substring(0, inInComa);
                }

            }

            if (inHyp == 1) {

                if (strText.contains("sin(")) {
                    strText = strText.replace("sin(", "sinh(");
                }
                if (strText.contains("cos(")) {
                    strText = strText.replace("cos(", "cosh(");
                }
                if (strText.contains("tan(")) {
                    strText = strText.replace("tan(", "tanh(");
                }
                ScientificActivity.txtvHyp.setText("");
                inHyp = 0;
            }
            mHandler.insert(strText);

        }
    }
}

From source file:android.support.designox.widget.CoordinatorLayout.java

/**
 * Calculate the desired child rect relative to an anchor rect, respecting both
 * gravity and anchorGravity.//  ww w .  j av  a 2 s  .  co  m
 *
 * @param child child view to calculate a rect for
 * @param layoutDirection the desired layout direction for the CoordinatorLayout
 * @param anchorRect rect in CoordinatorLayout coordinates of the anchor view area
 * @param out rect to set to the output values
 */
void getDesiredAnchoredChildRect(View child, int layoutDirection, Rect anchorRect, Rect out) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity),
            layoutDirection);
    final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity),
            layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK;

    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();

    int left;
    int top;

    // Align to the anchor. This puts us in an assumed right/bottom child view gravity.
    // If this is not the case we will subtract out the appropriate portion of
    // the child size below.
    switch (anchorHgrav) {
    default:
    case Gravity.LEFT:
        left = anchorRect.left;
        break;
    case Gravity.RIGHT:
        left = anchorRect.right;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left = anchorRect.left + anchorRect.width() / 2;
        break;
    }

    switch (anchorVgrav) {
    default:
    case Gravity.TOP:
        top = anchorRect.top;
        break;
    case Gravity.BOTTOM:
        top = anchorRect.bottom;
        break;
    case Gravity.CENTER_VERTICAL:
        top = anchorRect.top + anchorRect.height() / 2;
        break;
    }

    // Offset by the child view's gravity itself. The above assumed right/bottom gravity.
    switch (hgrav) {
    default:
    case Gravity.LEFT:
        left -= childWidth;
        break;
    case Gravity.RIGHT:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_HORIZONTAL:
        left -= childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        top -= childHeight;
        break;
    case Gravity.BOTTOM:
        // Do nothing, we're already in position.
        break;
    case Gravity.CENTER_VERTICAL:
        top -= childHeight / 2;
        break;
    }

    final int width = getWidth();
    final int height = getHeight();

    // Obey margins and padding
    left = Math.max(getPaddingLeft() + lp.leftMargin,
            Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin));
    top = Math.max(getPaddingTop() + lp.topMargin,
            Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin));

    out.set(left, top, left + childWidth, top + childHeight);
}

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Sets section header or makes it invisible if the title is null.
 *///from w  w w.j  a v a  2s . c om
public void setSectionHeader(String title) {
    if (!TextUtils.isEmpty(title)) {
        if (mHeaderTextView == null) {
            mHeaderTextView = new TextView(getContext());
            mHeaderTextView.setTextAppearance(getContext(), R.style.SectionHeaderStyle);
            mHeaderTextView.setGravity(ViewUtil.isViewLayoutRtl(this) ? Gravity.RIGHT : Gravity.LEFT);
            addView(mHeaderTextView);
        }
        setMarqueeText(mHeaderTextView, title);
        mHeaderTextView.setVisibility(View.VISIBLE);
        mHeaderTextView.setAllCaps(true);
    } else if (mHeaderTextView != null) {
        mHeaderTextView.setVisibility(View.GONE);
    }
}

From source file:com.b44t.ui.Components.EmojiView.java

public EmojiView(boolean needStickers, boolean needGif, final Context context) {
    super(context);

    showStickers = needStickers;//w  w  w. j ava  2s .  co  m
    showGifs = needGif;

    for (int i = 0; i < EmojiData.dataColored.length + 1; i++) {
        GridView gridView = new GridView(context);
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1);
        gridView.setAdapter(emojiGridAdapter);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
        adapters.add(emojiGridAdapter);
    }

    if (showStickers) {
        //StickersQuery.checkStickers();
        stickersGridView = new GridView(context) {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent event) {
                boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event,
                        stickersGridView, EmojiView.this.getMeasuredHeight());
                return super.onInterceptTouchEvent(event) || result;
            }

            @Override
            public void setVisibility(int visibility) {
                if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
                    super.setVisibility(GONE);
                    return;
                }
                super.setVisibility(visibility);
            }
        };
        stickersGridView.setSelector(R.drawable.transparent);
        stickersGridView.setColumnWidth(AndroidUtilities.dp(72));
        stickersGridView.setNumColumns(-1);
        stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
        stickersGridView.setClipToPadding(false);
        views.add(stickersGridView);
        stickersGridAdapter = new StickersGridAdapter(context);
        stickersGridView.setAdapter(stickersGridAdapter);
        stickersGridView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView,
                        EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener);
            }
        });
        stickersOnItemClickListener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long i) {
                if (!(view instanceof StickerEmojiCell)) {
                    return;
                }
                StickerPreviewViewer.getInstance().reset();
                StickerEmojiCell cell = (StickerEmojiCell) view;
                if (cell.isDisabled()) {
                    return;
                }
                cell.disable();
                TLRPC.Document document = cell.getSticker();
                addRecentSticker(document);
                if (listener != null) {
                    listener.onStickerSelected(document);
                }
            }
        };
        stickersGridView.setOnItemClickListener(stickersOnItemClickListener);
        AndroidUtilities.setListViewEdgeEffectColor(stickersGridView, 0xfff5f6f7);

        stickersWrap = new FrameLayout(context);
        stickersWrap.addView(stickersGridView);

        if (needGif) {
            gifsGridView = new RecyclerListView(context);
            gifsGridView.setTag(11);
            gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) {

                private Size size = new Size();

                @Override
                protected Size getSizeForItem(int i) {
                    TLRPC.Document document = recentImages.get(i).document;
                    size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100;
                    size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100;
                    for (int b = 0; b < document.attributes.size(); b++) {
                        TLRPC.DocumentAttribute attribute = document.attributes.get(b);
                        if (attribute instanceof TLRPC.TL_documentAttributeImageSize
                                || attribute instanceof TLRPC.TL_documentAttributeVideo) {
                            size.width = attribute.w;
                            size.height = attribute.h;
                            break;
                        }
                    }
                    return size;
                }
            });
            flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    return flowLayoutManager.getSpanSizeForItem(position);
                }
            });
            gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent,
                        RecyclerView.State state) {
                    outRect.left = 0;
                    outRect.top = 0;
                    outRect.bottom = 0;
                    int position = parent.getChildAdapterPosition(view);
                    if (!flowLayoutManager.isFirstRow(position)) {
                        outRect.top = AndroidUtilities.dp(2);
                    }
                    outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2);
                }
            });
            gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
            gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context));
            gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    if (position < 0 || position >= recentImages.size() || listener == null) {
                        return;
                    }
                    TLRPC.Document document = recentImages.get(position).document;
                    listener.onGifSelected(document);
                }
            });
            gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
                @Override
                public boolean onItemClick(View view, int position) {
                    if (position < 0 || position >= recentImages.size()) {
                        return false;
                    }
                    final MediaController.SearchImage searchImage = recentImages.get(position);
                    AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
                    builder.setMessage(LocaleController.getString("DeleteGif", R.string.DeleteGif));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK).toUpperCase(),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    recentImages.remove(searchImage);
                                    /*TLRPC.TL_messages_saveGif req = new TLRPC.TL_messages_saveGif();
                                    req.id = new TLRPC.TL_inputDocument();
                                    req.id.id = searchImage.document.id;
                                    req.id.access_hash = searchImage.document.access_hash;
                                    req.unsave = true;
                                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public void run(TLObject response, TLRPC.TL_error error) {
                                            
                                    }
                                    });*/
                                    //MessagesStorage.getInstance().removeWebRecent(searchImage);
                                    if (gifsAdapter != null) {
                                        gifsAdapter.notifyDataSetChanged();
                                    }
                                    if (recentImages.isEmpty()) {
                                        updateStickerTabs();
                                    }
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    builder.show().setCanceledOnTouchOutside(true);
                    return true;
                }
            });
            gifsGridView.setVisibility(GONE);
            stickersWrap.addView(gifsGridView);
        }

        stickersEmptyView = new TextView(context);
        stickersEmptyView.setText(LocaleController.getString("NoStickers", R.string.NoStickers));
        stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        stickersEmptyView.setTextColor(0xff888888);
        stickersWrap.addView(stickersEmptyView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
        stickersGridView.setEmptyView(stickersEmptyView);

        scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) {

            boolean startedScroll;
            float lastX;
            float lastTranslateX;
            boolean first = true;

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                }
                return super.onInterceptTouchEvent(ev);
            }

            @Override
            public boolean onTouchEvent(MotionEvent ev) {
                if (first) {
                    first = false;
                    lastX = ev.getX();
                }
                float newTranslationX = scrollSlidingTabStrip.getTranslationX();
                if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) {
                    if (!startedScroll && lastX - ev.getX() < 0) {
                        if (pager.beginFakeDrag()) {
                            startedScroll = true;
                            lastTranslateX = scrollSlidingTabStrip.getTranslationX();
                        }
                    } else if (startedScroll && lastX - ev.getX() > 0) {
                        if (pager.isFakeDragging()) {
                            pager.endFakeDrag();
                            startedScroll = false;
                        }
                    }
                }
                if (startedScroll) {
                    int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX);
                    try {
                        pager.fakeDragBy(dx);
                        lastTranslateX = newTranslationX;
                    } catch (Exception e) {
                        try {
                            pager.endFakeDrag();
                        } catch (Exception e2) {
                            //don't promt
                        }
                        startedScroll = false;
                        FileLog.e("messenger", e);
                    }
                }
                lastX = ev.getX();
                if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
                    first = true;
                    if (startedScroll) {
                        pager.endFakeDrag();
                        startedScroll = false;
                    }
                }
                return startedScroll || super.onTouchEvent(ev);
            }
        };
        scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
        scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7);
        scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
        scrollSlidingTabStrip.setVisibility(INVISIBLE);
        addView(scrollSlidingTabStrip,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
        scrollSlidingTabStrip.setTranslationX(AndroidUtilities.displaySize.x);
        updateStickerTabs();
        scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() {
            @Override
            public void onPageSelected(int page) {
                if (gifsGridView != null) {
                    if (page == gifTabBum + 1) {
                        if (gifsGridView.getVisibility() != VISIBLE) {
                            listener.onGifTab(true);
                            showGifTab();
                        }
                    } else {
                        if (gifsGridView.getVisibility() == VISIBLE) {
                            listener.onGifTab(false);
                            gifsGridView.setVisibility(GONE);
                            stickersGridView.setVisibility(VISIBLE);
                            stickersEmptyView
                                    .setVisibility(stickersGridAdapter.getCount() != 0 ? GONE : VISIBLE);
                        }
                    }
                }
                if (page == 0) {
                    pager.setCurrentItem(0);
                    return;
                } else {
                    if (page == gifTabBum + 1) {
                        return;
                    } else {
                        if (page == recentTabBum + 1) {
                            views.get(6).setSelection(0);
                            return;
                        }
                    }
                }
                int index = page - 1 - stickersTabOffset;
                if (index == stickerSets.size()) {
                    if (listener != null) {
                        listener.onStickersSettingsClick();
                    }
                    return;
                }
                if (index >= stickerSets.size()) {
                    index = stickerSets.size() - 1;
                }
                views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index)));
            }
        });

        stickersGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                checkStickersScroll(firstVisibleItem);
            }
        });
    }

    setBackgroundColor(0xfff5f6f7);

    pager = new ViewPager(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (getParent() != null) {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.onInterceptTouchEvent(ev);
        }
    };
    pager.setAdapter(new EmojiPagesAdapter());

    pagerSlidingTabStripContainer = new LinearLayout(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (getParent() != null) {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.onInterceptTouchEvent(ev);
        }
    };
    pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL);
    pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7);
    addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48));

    PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context);
    pagerSlidingTabStrip.setViewPager(pager);
    pagerSlidingTabStrip.setShouldExpand(true);
    pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2));
    pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
    pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2);
    pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
    pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f));
    pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels);
        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    pagerSlidingTabStripContainer.addView(frameLayout, LayoutHelper.createLinear(52, 48));

    backspaceButton = new ImageView(context) {
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                backspacePressed = true;
                backspaceOnce = false;
                postBackspaceRunnable(350);
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL
                    || event.getAction() == MotionEvent.ACTION_UP) {
                backspacePressed = false;
                if (!backspaceOnce) {
                    if (listener != null && listener.onBackspace()) {
                        backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
                    }
                }
            }
            super.onTouchEvent(event);
            return true;
        }
    };
    backspaceButton.setImageResource(R.drawable.ic_smiles_backspace);
    backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace);
    backspaceButton.setScaleType(ImageView.ScaleType.CENTER);
    frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48));

    View view = new View(context);
    view.setBackgroundColor(0xffe2e5e7);
    frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM));

    recentsWrap = new FrameLayout(context);
    recentsWrap.addView(views.get(0));

    TextView textView = new TextView(context);
    textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    textView.setTextSize(18);
    textView.setTextColor(0xff888888);
    textView.setGravity(Gravity.CENTER);
    recentsWrap.addView(textView);
    views.get(0).setEmptyView(textView);

    addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
            Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0));

    emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32);
    pickerView = new EmojiColorPickerView(context);
    pickerViewPopup = new EmojiPopupWindow(pickerView,
            popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5),
            popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56));
    pickerViewPopup.setOutsideTouchable(true);
    pickerViewPopup.setClippingEnabled(true);
    pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED);
    pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
    pickerViewPopup.getContentView().setFocusableInTouchMode(true);
    pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0
                    && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null
                    && pickerViewPopup.isShowing()) {
                pickerViewPopup.dismiss();
                return true;
            }
            return false;
        }
    });

    loadRecents();
}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
    if (CHILDREN_DISALLOW_INTERCEPT) {
        // If we have an edge touch we want to skip this and track it for later instead.
        super.requestDisallowInterceptTouchEvent(disallowIntercept);
    }/*  ww  w. j  av  a2  s .  co m*/

    View drawerView = findDrawerView();
    if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) {
        super.requestDisallowInterceptTouchEvent(disallowIntercept);
    }

    if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.RIGHT)) {
        super.requestDisallowInterceptTouchEvent(disallowIntercept);
    }
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

void closeDrawers(boolean peekingOnly) {
    boolean needsInvalidate = false;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (!isDrawerView(child) || (peekingOnly && !lp.isPeeking)) {
            continue;
        }//from  w  w w .java 2s. co m

        final int childWidth = child.getWidth();

        if (checkDrawerViewGravity(child, Gravity.LEFT)) {
            needsInvalidate |= mLeftDragger.smoothSlideViewTo(child, -childWidth, child.getTop());
        } else {
            needsInvalidate |= mRightDragger.smoothSlideViewTo(child, getWidth(), child.getTop());
        }

        lp.isPeeking = false;
    }

    mLeftCallback.removeCallbacks();
    mRightCallback.removeCallbacks();

    if (needsInvalidate) {
        invalidate();
    }
}