Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

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

Prototype

int CENTER_VERTICAL

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

Click Source Link

Document

Place object in the vertical center of its container, not changing its size.

Usage

From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java

public void toastsettext(String string1) {
    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_activity,
            (ViewGroup) ((Activity) context).findViewById(R.id.toast_rl));
    TextView txt = (TextView) layout.findViewById(R.id.toast_txt);
    txt.setText(string1);/*from  www . j av  a2  s . c om*/
    Toast tst = new Toast(context);
    tst.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    tst.setDuration(Toast.LENGTH_SHORT);
    tst.setView(layout);
    tst.show();
}

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

@Override
public View createView(Context context) {
    if (chatMessageCellsCache.isEmpty()) {
        for (int a = 0; a < 8; a++) {
            chatMessageCellsCache.add(new ChatMessageCell(context));
        }//  w w w.  j a v a 2s .  c o m
    }

    searchWas = false;
    hasOwnBackground = true;

    Theme.createChatResources(context, false);

    actionBar.setAddToContainer(false);
    actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(final int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    avatarContainer = new ChatAvatarContainer(context, null, false);
    avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet());
    actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));

    ActionBarMenu menu = actionBar.createMenu();
    searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

                @Override
                public void onSearchCollapse() {
                    searchQuery = "";
                    avatarContainer.setVisibility(View.VISIBLE);
                    if (searchWas) {
                        searchWas = false;
                        loadMessages(true);
                    }
                    /*highlightMessageId = Integer.MAX_VALUE;
                    updateVisibleRows();
                    scrollToLastMessage(false);
                    */
                    updateBottomOverlay();
                }

                @Override
                public void onSearchExpand() {
                    avatarContainer.setVisibility(View.GONE);
                    updateBottomOverlay();
                }

                @Override
                public void onSearchPressed(EditText editText) {
                    searchWas = true;
                    searchQuery = editText.getText().toString();
                    loadMessages(true);
                    //updateSearchButtons(0, 0, 0);
                }
            });
    searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));

    avatarContainer.setEnabled(false);

    avatarContainer.setTitle(currentChat.title);
    avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
    avatarContainer.setChatAvatar(currentChat);

    fragmentView = new SizeNotifierFrameLayout(context) {

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0
                    && messageObject.getDialogId() == -currentChat.id) {
                MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout,
                        roundVideoContainer, true);
            }
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == actionBar && parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas,
                        actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0);
            }
            return result;
        }

        @Override
        protected boolean isActionBarVisible() {
            return actionBar.getVisibility() == VISIBLE;
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int allHeight;
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);

            setMeasuredDimension(widthSize, heightSize);
            heightSize -= getPaddingTop();

            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            if (actionBar.getVisibility() == VISIBLE) {
                heightSize -= actionBarHeight;
            }

            int keyboardSize = getKeyboardHeight();

            int childCount = getChildCount();

            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                if (child == chatListView || child == progressView) {
                    int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
                    int contentHeightSpec = MeasureSpec.makeMeasureSpec(
                            Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)),
                            MeasureSpec.EXACTLY);
                    child.measure(contentWidthSpec, contentHeightSpec);
                } else if (child == emptyViewContainer) {
                    int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
                    int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
                    child.measure(contentWidthSpec, contentHeightSpec);
                } else {
                    measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                }
            }
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            final int count = getChildCount();

            for (int i = 0; i < count; i++) {
                final View child = getChildAt(i);
                if (child.getVisibility() == GONE) {
                    continue;
                }
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();

                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();

                int childLeft;
                int childTop;

                int gravity = lp.gravity;
                if (gravity == -1) {
                    gravity = Gravity.TOP | Gravity.LEFT;
                }

                final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                    break;
                case Gravity.RIGHT:
                    childLeft = r - width - lp.rightMargin;
                    break;
                case Gravity.LEFT:
                default:
                    childLeft = lp.leftMargin;
                }

                switch (verticalGravity) {
                case Gravity.TOP:
                    childTop = lp.topMargin + getPaddingTop();
                    if (child != actionBar && actionBar.getVisibility() == VISIBLE) {
                        childTop += actionBar.getMeasuredHeight();
                    }
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                    break;
                case Gravity.BOTTOM:
                    childTop = (b - t) - height - lp.bottomMargin;
                    break;
                default:
                    childTop = lp.topMargin;
                }

                if (child == emptyViewContainer) {
                    childTop -= AndroidUtilities.dp(24)
                            - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0);
                } else if (child == actionBar) {
                    childTop -= getPaddingTop();
                }
                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }

            updateMessagesVisisblePart();
            notifyHeightChanged();
        }
    };

    contentView = (SizeNotifierFrameLayout) fragmentView;

    contentView.setOccupyStatusBar(!AndroidUtilities.isTablet());
    contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());

    emptyViewContainer = new FrameLayout(context);
    emptyViewContainer.setVisibility(View.INVISIBLE);
    contentView.addView(emptyViewContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    emptyViewContainer.setOnTouchListener((v, event) -> true);

    emptyView = new TextView(context);
    emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText));
    emptyView.setBackgroundDrawable(
            Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getServiceMessageColor()));
    emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16),
            AndroidUtilities.dp(16));
    emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0));

    chatListView = new RecyclerListView(context) {

        @Override
        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child instanceof ChatMessageCell) {
                ChatMessageCell chatMessageCell = (ChatMessageCell) child;
                ImageReceiver imageReceiver = chatMessageCell.getAvatarImage();
                if (imageReceiver != null) {
                    int top = child.getTop();
                    if (chatMessageCell.isPinnedBottom()) {
                        ViewHolder holder = chatListView.getChildViewHolder(child);
                        if (holder != null) {
                            holder = chatListView
                                    .findViewHolderForAdapterPosition(holder.getAdapterPosition() + 1);
                            if (holder != null) {
                                imageReceiver.setImageY(-AndroidUtilities.dp(1000));
                                imageReceiver.draw(canvas);
                                return result;
                            }
                        }
                    }
                    if (chatMessageCell.isPinnedTop()) {
                        ViewHolder holder = chatListView.getChildViewHolder(child);
                        if (holder != null) {
                            while (true) {
                                holder = chatListView
                                        .findViewHolderForAdapterPosition(holder.getAdapterPosition() - 1);
                                if (holder != null) {
                                    top = holder.itemView.getTop();
                                    if (!(holder.itemView instanceof ChatMessageCell)
                                            || !((ChatMessageCell) holder.itemView).isPinnedTop()) {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                    int y = child.getTop() + chatMessageCell.getLayoutHeight();
                    int maxY = chatListView.getHeight() - chatListView.getPaddingBottom();
                    if (y > maxY) {
                        y = maxY;
                    }
                    if (y - AndroidUtilities.dp(48) < top) {
                        y = top + AndroidUtilities.dp(48);
                    }
                    imageReceiver.setImageY(y - AndroidUtilities.dp(44));
                    imageReceiver.draw(canvas);
                }
            }
            return result;
        }
    };
    chatListView.setOnItemClickListener((view, position) -> createMenu(view));
    chatListView.setTag(1);
    chatListView.setVerticalScrollBarEnabled(true);
    chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context));
    chatListView.setClipToPadding(false);
    chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
    chatListView.setItemAnimator(null);
    chatListView.setLayoutAnimation(null);
    chatLayoutManager = new LinearLayoutManager(context) {
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }

        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
            LinearSmoothScrollerMiddle linearSmoothScroller = new LinearSmoothScrollerMiddle(
                    recyclerView.getContext());
            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        }
    };
    chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    chatLayoutManager.setStackFromEnd(true);
    chatListView.setLayoutManager(chatLayoutManager);
    contentView.addView(chatListView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        private float totalDy = 0;
        private final int scrollValue = AndroidUtilities.dp(100);

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                scrollingFloatingDate = true;
                checkTextureViewPosition = true;
            } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                scrollingFloatingDate = false;
                checkTextureViewPosition = false;
                hideFloatingDateView(true);
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            chatListView.invalidate();
            if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) {
                if (floatingDateView.getTag() == null) {
                    if (floatingDateAnimation != null) {
                        floatingDateAnimation.cancel();
                    }
                    floatingDateView.setTag(1);
                    floatingDateAnimation = new AnimatorSet();
                    floatingDateAnimation.setDuration(150);
                    floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f));
                    floatingDateAnimation.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (animation.equals(floatingDateAnimation)) {
                                floatingDateAnimation = null;
                            }
                        }
                    });
                    floatingDateAnimation.start();
                }
            }
            checkScrollForLoad(true);
            updateMessagesVisisblePart();
        }
    });
    if (scrollToPositionOnRecreate != -1) {
        chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
        scrollToPositionOnRecreate = -1;
    }

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    progressView2 = new View(context);
    progressView2.setBackgroundResource(R.drawable.system_loader);
    progressView2.getBackground().setColorFilter(Theme.colorFilter);
    progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    progressBar = new RadialProgressView(context);
    progressBar.setSize(AndroidUtilities.dp(28));
    progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText));
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    floatingDateView = new ChatActionCell(context);
    floatingDateView.setAlpha(0.0f);
    contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0));

    contentView.addView(actionBar);

    bottomOverlayChat = new FrameLayout(context) {
        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(),
                    Theme.chat_composeBackgroundPaint);
        }
    };
    bottomOverlayChat.setWillNotDraw(false);
    bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    contentView.addView(bottomOverlayChat,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
    bottomOverlayChat.setOnClickListener(view -> {
        if (getParentActivity() == null) {
            return;
        }
        AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter,
                selectedAdmins, currentChat.megagroup);
        adminLogFilterAlert.setCurrentAdmins(admins);
        adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> {
            currentFilter = filter;
            selectedAdmins = admins;
            if (currentFilter != null || selectedAdmins != null) {
                avatarContainer.setSubtitle(
                        LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents));
            } else {
                avatarContainer.setSubtitle(
                        LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
            }
            loadMessages(true);
        });
        showDialog(adminLogFilterAlert);
    });

    bottomOverlayChatText = new TextView(context);
    bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText));
    bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase());
    bottomOverlayChat.addView(bottomOverlayChatText,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    bottomOverlayImage = new ImageView(context);
    bottomOverlayImage.setImageResource(R.drawable.log_info);
    bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText),
            PorterDuff.Mode.MULTIPLY));
    bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER);
    bottomOverlayChat.addView(bottomOverlayImage,
            LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0));
    bottomOverlayImage.setOnClickListener(v -> {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        if (currentChat.megagroup) {
            builder.setMessage(AndroidUtilities.replaceTags(
                    LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail)));
        } else {
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController
                    .getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel)));
        }
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle));
        showDialog(builder.create());
    });

    searchContainer = new FrameLayout(context) {
        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(),
                    Theme.chat_composeBackgroundPaint);
        }
    };
    searchContainer.setWillNotDraw(false);
    searchContainer.setVisibility(View.INVISIBLE);
    searchContainer.setFocusable(true);
    searchContainer.setFocusableInTouchMode(true);
    searchContainer.setClickable(true);
    searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    contentView.addView(searchContainer,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));

    /*searchUpButton = new ImageView(context);
    searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
    searchUpButton.setImageResource(R.drawable.search_up);
    searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48));
    searchUpButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1);
    }
    });
            
    searchDownButton = new ImageView(context);
    searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
    searchDownButton.setImageResource(R.drawable.search_down);
    searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0));
    searchDownButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2);
    }
    });*/

    searchCalendarButton = new ImageView(context);
    searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER);
    searchCalendarButton.setImageResource(R.drawable.search_calendar);
    searchCalendarButton.setColorFilter(new PorterDuffColorFilter(
            Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
    searchContainer.addView(searchCalendarButton,
            LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
    searchCalendarButton.setOnClickListener(view -> {
        if (getParentActivity() == null) {
            return;
        }
        AndroidUtilities.hideKeyboard(searchItem.getSearchField());
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        try {
            DatePickerDialog dialog = new DatePickerDialog(getParentActivity(),
                    (view1, year1, month, dayOfMonth1) -> {
                        Calendar calendar1 = Calendar.getInstance();
                        calendar1.clear();
                        calendar1.set(year1, month, dayOfMonth1);
                        int date = (int) (calendar1.getTime().getTime() / 1000);
                        loadMessages(true);
                    }, year, monthOfYear, dayOfMonth);
            final DatePicker datePicker = dialog.getDatePicker();
            datePicker.setMinDate(1375315200000L);
            datePicker.setMaxDate(System.currentTimeMillis());
            dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                    LocaleController.getString("JumpToDate", R.string.JumpToDate), dialog);
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                    LocaleController.getString("Cancel", R.string.Cancel), (dialog12, which) -> {

                    });
            if (Build.VERSION.SDK_INT >= 21) {
                dialog.setOnShowListener(dialog1 -> {
                    int count = datePicker.getChildCount();
                    for (int a = 0; a < count; a++) {
                        View child = datePicker.getChildAt(a);
                        ViewGroup.LayoutParams layoutParams = child.getLayoutParams();
                        layoutParams.width = LayoutHelper.MATCH_PARENT;
                        child.setLayoutParams(layoutParams);
                    }
                });
            }
            showDialog(dialog);
        } catch (Exception e) {
            FileLog.e(e);
        }
    });

    searchCountText = new SimpleTextView(context);
    searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText));
    searchCountText.setTextSize(15);
    searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0));

    chatAdapter.updateRows();
    if (loading && messages.isEmpty()) {
        progressView.setVisibility(View.VISIBLE);
        chatListView.setEmptyView(null);
    } else {
        progressView.setVisibility(View.INVISIBLE);
        chatListView.setEmptyView(emptyViewContainer);
    }

    updateEmptyPlaceholder();

    return fragmentView;
}

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from ww  w  .  j a v  a2  s. co  m*/
    final int width = r - l;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;

            final float newOffset;
            if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
                childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                newOffset = (float) (childWidth + childLeft) / childWidth;
            } else { // Right; onMeasure checked for us.
                childLeft = width - (int) (childWidth * lp.onScreen);
                newOffset = (float) (width - childLeft) / childWidth;
            }

            final boolean changeOffset = newOffset != lp.onScreen;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin) {
                    childTop = lp.topMargin;
                } else if (childTop + childHeight > height - lp.bottomMargin) {
                    childTop = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

/**
 * 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- left = 0
 * -- top = 0 -- right = 1080 -- b = 1675 12-03 22:59:19.686:
 * I/BottomDrawerLayout(12480): onLayout() -- childWidth = 750 --
 * childHeight = 1675 -- lp.onScreen = 0.0 12-03 22:59:19.686:
 * I/BottomDrawerLayout(12480): onLayout() -- childLeft = -750 -- newOffset
 * = 0.0 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() --
 * childWidth = 750 -- childHeight = 1675 -- lp.onScreen = 0.0 12-03
 * 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- childLeft = 1080
 * -- newOffset = 0.0//from w ww. j a va2s.  co  m
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.i(TAG, "onLayout() -- left = " + l + " -- top = " + t + " -- right = " + r + " -- b = " + b);
    mInLayout = true;
    final int width = r - l;// 
    final int height = b - t;// 
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else {
            // ?view
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            // Log.i(TAG, "onLayout() -- childWidth = " + childWidth +
            // " -- childHeight = " + childHeight
            // + " -- lp.onScreen = " + lp.onScreen);
            int childLeft = 0;// 
            int childTop = 0;// 
            float newOffset = 0;// 

            switch (getDrawerViewAbsoluteGravity(child)) {
            case Gravity.LEFT:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
                    // Log.i(TAG, "onLayout() -- 1");
                    childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                    newOffset = (float) (childWidth + childLeft) / childWidth;// ?
                }
                break;
            case Gravity.RIGHT:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
                    // Log.i(TAG, "onLayout() -- 2");
                    childLeft = width - (int) (childWidth * lp.onScreen);
                    newOffset = (float) (width - childLeft) / childWidth;// ?
                }
                break;
            case Gravity.TOP:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
                    // Log.i(TAG, "onLayout() -- 3");
                    childTop = -childHeight + (int) (childHeight * lp.onScreen);
                    newOffset = (float) (childHeight + childTop) / childHeight;// ?
                }
                break;
            case Gravity.BOTTOM:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
                    // Log.i(TAG, "onLayout() -- 4");
                    childTop = height - (int) (childHeight * lp.onScreen);
                    newOffset = (float) (height - childTop) / childHeight;// ?
                }
                break;
            default:
                childTop = height - (int) (childHeight * lp.onScreen);
                newOffset = (float) (height - childTop) / childHeight;// ?
                break;
            }
            // /////////////////////////////////////////
            // Log.i(TAG, "onLayout() -- childLeft = " + childLeft +
            // " -- newOffset = " + newOffset);
            final boolean changeOffset = newOffset != lp.onScreen;
            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
            switch (vgrav) {
            // case Gravity.TOP: {
            // Log.i(TAG, "onLayout() -- Gravity.TOP");
            // child.layout(childLeft, lp.topMargin, childLeft + childWidth,
            // lp.topMargin + childHeight);
            // break;
            // }
            // case Gravity.BOTTOM: {
            // Log.i(TAG, "onLayout() -- Gravity.BOTTOM");
            // child.layout(childLeft, height - lp.bottomMargin -
            // child.getMeasuredHeight(), childLeft
            // + childWidth, height - lp.bottomMargin);
            // break;
            // }
            case Gravity.CENTER_VERTICAL: {
                // Log.i(TAG, "onLayout() -- Gravity.CENTER_VERTICAL");
                int childTop_cv = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop_cv < lp.topMargin) {
                    childTop_cv = lp.topMargin;
                } else if (childTop_cv + childHeight > height - lp.bottomMargin) {
                    childTop_cv = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop_cv, childLeft + childWidth, childTop_cv + childHeight);
                break;
            }
            }

            // /////////////////////////////////////////

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:edu.cens.loci.ui.PlaceViewActivity.java

private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) {

    ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>();

    HashMap<String, APInfoMapItem> apMap = wifi.getAps();
    Set<String> keys = apMap.keySet();
    Iterator<String> iter = keys.iterator();
    while (iter.hasNext()) {
        String bssid = iter.next();
        APInfoMapItem ap = apMap.get(bssid);
        items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets));
    }//  w ww .j  av  a  2 s. co m

    Collections.sort(items);

    table.setColumnCollapsed(0, false);
    table.setColumnCollapsed(1, true);
    table.setColumnShrinkable(0, true);

    for (int i = 0; i < mAddedRows.size(); i++) {
        table.removeView(mAddedRows.get(i));
    }
    mAddedRows.clear();

    int totalCount = wifi.getScanCount();

    for (WifiViewListItem item : items) {
        TableRow row = new TableRow(this);

        TextView ssidView = new TextView(this);
        ssidView.setText(item.ssid);
        //ssidView.setText("very very very veryvery very very very very very");
        ssidView.setPadding(2, 2, 2, 2);
        ssidView.setTextColor(0xffffffff);

        TextView bssidView = new TextView(this);
        bssidView.setText(item.bssid);
        bssidView.setPadding(2, 2, 2, 2);
        bssidView.setTextColor(0xffffffff);

        TextView cntView = new TextView(this);
        cntView.setText("" + (item.count * 100) / totalCount);
        cntView.setPadding(2, 2, 2, 2);
        cntView.setGravity(Gravity.CENTER);
        cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        TextView rssView = new TextView(this);
        rssView.setText("" + item.rss);
        rssView.setPadding(2, 2, 6, 2);
        rssView.setGravity(Gravity.CENTER);
        rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);

        row.addView(ssidView, new TableRow.LayoutParams(0));
        row.addView(bssidView, new TableRow.LayoutParams(1));
        row.addView(cntView, new TableRow.LayoutParams(2));
        row.addView(rssView, new TableRow.LayoutParams(3));

        //Log.d(TAG, item.ssid);
        for (int i = 0; i < item.rssBuckets.length; i++) {
            TextView box = new TextView(this);
            box.setText("  ");
            box.setGravity(Gravity.RIGHT);
            box.setPadding(2, 2, 2, 2);
            box.setHeight(15);
            box.setGravity(Gravity.CENTER_VERTICAL);

            float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount());
            //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]);
            int colorValInt = ((int) colorVal) - 1;
            if (colorValInt < 0)
                colorValInt = 0;

            box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan));
            box.setTextColor(0xffffffff);

            row.addView(box, new TableRow.LayoutParams(4 + i));
        }

        row.setGravity(Gravity.CENTER);

        table.addView(row, new TableLayout.LayoutParams());
        table.setColumnStretchable(3, true);
        mAddedRows.add(row);
    }

}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

private void makeToast(String msg, int mode) {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.ic_launcher);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(msg);/*from   w ww .  ja  v  a2s . c  om*/

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    if (mode == 1) {
        text.setTextColor(Color.WHITE);
        toast.getView().setBackgroundColor(Color.RED);
        toast.setDuration(Toast.LENGTH_LONG);
    }
    if (mode == 2) {
        text.setTextColor(Color.WHITE);
        toast.getView().setBackgroundColor(Color.GREEN);
    }
    toast.show();
}

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    int opticalInsetLeft = 0;
    int opticalInsetRight = 0;
    if (mThumbDrawable != null) {
        final Rect trackPadding = mTempRect;
        if (mTrackDrawable != null) {
            mTrackDrawable.getPadding(trackPadding);
        } else {//from ww w  . jav a 2  s  . c  o  m
            trackPadding.setEmpty();
        }

        opticalInsetLeft = 0;
        opticalInsetRight = 0;
    }

    final int switchRight;
    final int switchLeft;
    if (ViewUtils.isLayoutRtl(this)) {
        switchLeft = getPaddingLeft() + opticalInsetLeft;
        switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight;
    } else {
        switchRight = getWidth() - getPaddingRight() - opticalInsetRight;
        switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight;
    }

    final int switchTop;
    final int switchBottom;
    switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
    default:
    case Gravity.TOP:
        switchTop = getPaddingTop();
        switchBottom = switchTop + mSwitchHeight;
        break;

    case Gravity.CENTER_VERTICAL:
        switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2;
        switchBottom = switchTop + mSwitchHeight;
        break;

    case Gravity.BOTTOM:
        switchBottom = getHeight() - getPaddingBottom();
        switchTop = switchBottom - mSwitchHeight;
        break;
    }

    mSwitchLeft = switchLeft;
    mSwitchTop = switchTop;
    mSwitchBottom = switchBottom;
    mSwitchRight = switchRight;
}

From source file:com.example.drugsformarinemammals.Dose_Information.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//from   w  ww. j ava2  s .com
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("Synchronization");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:ab.util.AbDialogUtil.java

/**
 * popupwindow//w  w w  .ja va 2  s  .  co  m
 */
public static PopupWindow showPopWindow3(Context context, View targetView, View contentView, Integer width) {
    PopupWindow popupWindow = null;
    popupWindow = new PopupWindow(contentView, -2, -2);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    if (width != null) {
        popupWindow.setWidth(width);
    }
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(targetView, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    return popupWindow;
}

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

/**
 * Calculate the desired child rect relative to an anchor rect, respecting both
 * gravity and anchorGravity./*  w w w  .ja v  a2  s .c o 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);
}