Example usage for android.app DatePickerDialog setButton

List of usage examples for android.app DatePickerDialog setButton

Introduction

In this page you can find the example usage for android.app DatePickerDialog setButton.

Prototype

public void setButton(int whichButton, CharSequence text, Message msg) 

Source Link

Document

Set a message to be sent when a button is pressed.

Usage

From source file:org.akop.crosswords.fragment.DatePickerFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    DateTime dateTime = null;/*ww w. j  ava2 s  .c  om*/
    Bundle args = getArguments();
    if (args != null) {
        long dateMillis = args.getLong("dateMillis", -1);
        if (dateMillis != -1) {
            dateTime = new DateTime(dateMillis);
        }
    }

    if (dateTime == null) {
        dateTime = DateTime.now();
    }

    final DatePickerDialog pickerDialog = new DatePickerDialog(getActivity(),
            R.style.Theme_Crosswords_Default_Dialog, null, dateTime.getYear(), dateTime.getMonthOfYear() - 1,
            dateTime.getDayOfMonth());

    // Workaround for the JellyBean bug
    // http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel
    pickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    notifyListener(pickerDialog.getDatePicker());
                }
            });
    pickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel),
            (DialogInterface.OnClickListener) null);

    return pickerDialog;
}

From source file:uk.ac.horizon.artcodes.fragment.AvailabilityEditDialogFragment.java

private void selectDate(Long timestamp, final DateListener listener) {
    final Calendar calendar = Calendar.getInstance();
    if (timestamp != null) {
        calendar.setTimeInMillis(timestamp);
    } else {//w  ww .j av a  2 s. com
        calendar.setTimeInMillis(System.currentTimeMillis());
    }
    int mYear = calendar.get(Calendar.YEAR);
    int mMonth = calendar.get(Calendar.MONTH);
    int mDay = calendar.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            final Calendar calendar = Calendar.getInstance();
            calendar.set(year, monthOfYear, dayOfMonth);
            listener.dateSelected(calendar.getTimeInMillis());
        }
    }, mYear, mMonth, mDay);
    dialog.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.clear),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    listener.dateSelected(null);
                }
            });
    dialog.show();
}

From source file:com.gatesnfc.existing.DatePicker_Fix.java

@TargetApi(11)
@Override//from  w  w  w  . j a v a  2s.c om
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Jelly Bean introduced a bug in DatePickerDialog (and possibly 
    // TimePickerDialog as well), and one of the possible solutions is 
    // to postpone the creation of both the listener and the BUTTON_* .
    // 
    // Passing a null here won't harm because DatePickerDialog checks for a null
    // whenever it reads the listener that was passed here. >>> This seems to be 
    // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now.
    //
    // See my own question and answer, and details I included for the issue:
    //
    // http://stackoverflow.com/a/11493752/489607
    // http://code.google.com/p/android/issues/detail?id=34833
    //
    // Of course, suggestions welcome.

    final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), year, month,
            day);

    if (hasJellyBeanAndAbove()) {
        /*
         * Restriction of Date from 1980 Jan 1st to Current Date
         */
        Calendar c = Calendar.getInstance();
        picker.getDatePicker().setMaxDate(c.getTimeInMillis());
        c.set(Calendar.YEAR, 1980);
        c.set(Calendar.MONTH, c.getMinimum(Calendar.MONTH));
        c.set(Calendar.DATE, c.getMinimum(Calendar.DATE));
        c.set(Calendar.HOUR_OF_DAY, c.getMinimum(Calendar.HOUR_OF_DAY));
        c.set(Calendar.MINUTE, c.getMinimum(Calendar.MINUTE));
        c.set(Calendar.SECOND, c.getMinimum(Calendar.SECOND));
        c.set(Calendar.MILLISECOND, c.getMinimum(Calendar.MILLISECOND));
        picker.getDatePicker().setMinDate(c.getTimeInMillis());
        picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DatePicker dp = picker.getDatePicker();
                        mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
                    }
                });
        picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
    }
    return picker;
}

From source file:in.andres.kandroid.ui.TaskEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_edit);
    setupActionBar();/*ww  w.j  ava 2 s  .  c  om*/

    editTextTitle = (EditText) findViewById(R.id.edit_task_title);
    editTextDescription = (EditText) findViewById(R.id.edit_task_description);
    btnStartDate = (Button) findViewById(R.id.btn_start_date);
    btnDueDate = (Button) findViewById(R.id.btn_due_date);
    btnColor = (Button) findViewById(R.id.color_button);
    btnColor.setOnClickListener(btnColorClick);
    btnColor.setText(Utils.fromHtml(getString(R.string.taskedit_color, "")));
    editHoursEstimated = (EditText) findViewById(R.id.edit_hours_estimated);
    editHoursSpent = (EditText) findViewById(R.id.edit_hours_spent);
    spinnerProjectUsers = (Spinner) findViewById(R.id.user_spinner);

    if (getIntent().hasExtra("task")) {
        isNewTask = false;
        task = (KanboardTask) getIntent().getSerializableExtra("task");
        taskTitle = task.getTitle();
        taskDescription = task.getDescription();
        startDate = task.getDateStarted();
        dueDate = task.getDateDue();
        timeEstimated = task.getTimeEstimated();
        timeSpent = task.getTimeSpent();
        ownerId = task.getOwnerId();
        colorId = task.getColorId();
        setActionBarTitle(getString(R.string.taskview_fab_edit_task));
    } else {
        isNewTask = true;
        projectid = getIntent().getIntExtra("projectid", 0);
        //            colorId = getIntent().getIntExtra("colorid", 0);
        creatorId = getIntent().getIntExtra("creatorid", 0);
        ownerId = getIntent().getIntExtra("ownerid", 0);
        columnId = getIntent().getIntExtra("columnid", 0);
        swimlaneId = getIntent().getIntExtra("swimlaneid", 0);
        setActionBarTitle(getString(R.string.taskedit_new_task));
    }

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext());
    try {
        kanboardAPI = new KanboardAPI(preferences.getString("serverurl", ""),
                preferences.getString("username", ""), preferences.getString("password", ""));
        kanboardAPI.addOnCreateTaskListener(this);
        kanboardAPI.addOnUpdateTaskListener(this);
        kanboardAPI.addOnGetDefaultColorListener(this);
        kanboardAPI.addOnGetDefaultColorsListener(this);
        kanboardAPI.addOnGetVersionListener(this);
        kanboardAPI.getDefaultTaskColor();
        kanboardAPI.getDefaultTaskColors();
        kanboardAPI.getVersion();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (getIntent().hasExtra("projectusers")) {
        if (getIntent().getSerializableExtra("projectusers") instanceof HashMap) {
            projectUsers = new Hashtable<>(
                    (HashMap<Integer, String>) getIntent().getSerializableExtra("projectusers"));
            ArrayList<String> possibleOwners = Collections.list(projectUsers.elements());
            possibleOwners.add(0, "");
            ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
                    possibleOwners);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnerProjectUsers.setAdapter(adapter);
            if (ownerId != 0) {
                spinnerProjectUsers.setSelection(possibleOwners.indexOf(projectUsers.get(ownerId)));
            }
        }
    }

    editTextTitle.setText(taskTitle);
    editTextDescription.setText(taskDescription);
    editHoursEstimated.setText(Double.toString(timeEstimated));
    editHoursSpent.setText(Double.toString(timeSpent));
    btnStartDate.setText(Utils.fromHtml(getString(R.string.taskview_date_start, startDate)));
    btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate)));

    btnStartDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            if (startDate != null)
                calendar.setTime(startDate);

            DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                            Calendar calendar = Calendar.getInstance();
                            calendar.set(Calendar.YEAR, year);
                            calendar.set(Calendar.MONTH, month);
                            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                            startDate = calendar.getTime();
                            btnStartDate.setText(
                                    Utils.fromHtml(getString(R.string.taskview_date_start, startDate)));
                        }
                    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            startDate = null;
                            btnStartDate.setText(
                                    Utils.fromHtml(getString(R.string.taskview_date_start, startDate)));
                        }
                    });
            dlgDate.show();
        }
    });
    btnDueDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            if (dueDate != null)
                calendar.setTime(dueDate);

            DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                            Calendar calendar = Calendar.getInstance();
                            calendar.set(Calendar.YEAR, year);
                            calendar.set(Calendar.MONTH, month);
                            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                            dueDate = calendar.getTime();
                            btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate)));
                        }
                    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dueDate = null;
                            btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate)));
                        }
                    });
            dlgDate.show();
        }
    });
}

From source file:dev.memento.MainActivity.java

public void showDatePicker(View v) {

    // Date picker's months range from 0-11
    final DatePickerDialog dateDialog = new DatePickerDialog(this, null, mDateChosen.getYear(),
            mDateChosen.getMonth() - 1, mDateChosen.getDay());

    // Have to set positive and negative buttons because only a positive button
    // will be displayed by default, and there is a bug in Android that causes
    // the Back button (which should normally be used to cancel) to cause
    // the onDateTime event handler to be triggered.  
    // http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel

    // If either of the buttons are set with .setButton(), the OnDateSetListener is 
    // not triggered on my Galaxy Tab (Android 4.0.4), so implement listening here instead.

    dateDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.button_set),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    DatePicker dp = dateDialog.getDatePicker();
                    dateSelected(dp.getDayOfMonth(), dp.getMonth(), dp.getYear());
                }/*from  ww  w . j  av a 2s .  c om*/
            });

    dateDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // Nothing to do
                    if (Log.LOG)
                        Log.d(LOG_TAG, "Cancel was pressed");
                }
            });

    dateDialog.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));
        }// www .ja va 2  s  .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;
}