Search in sources :

Example 16 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogOrContactPickerActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setTitle(LocaleController.getString("BlockUserMultiTitle", R.string.BlockUserMultiTitle));
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    actionBar.setExtraHeight(AndroidUtilities.dp(44));
    actionBar.setAllowOverlayTitle(false);
    actionBar.setAddToContainer(false);
    actionBar.setClipContent(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    hasOwnBackground = true;
    ActionBarMenu menu = actionBar.createMenu();
    searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            dialogsActivity.getActionBar().openSearchField("", false);
            contactsActivity.getActionBar().openSearchField("", false);
            searchItem.getSearchField().requestFocus();
        }

        @Override
        public void onSearchCollapse() {
            dialogsActivity.getActionBar().closeSearchField(false);
            contactsActivity.getActionBar().closeSearchField(false);
        }

        @Override
        public void onTextChanged(EditText editText) {
            dialogsActivity.getActionBar().setSearchFieldText(editText.getText().toString());
            contactsActivity.getActionBar().setSearchFieldText(editText.getText().toString());
        }
    });
    searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    scrollSlidingTextTabStrip = new ScrollSlidingTextTabStrip(context);
    scrollSlidingTextTabStrip.setUseSameWidth(true);
    actionBar.addView(scrollSlidingTextTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.BOTTOM));
    scrollSlidingTextTabStrip.setDelegate(new ScrollSlidingTextTabStrip.ScrollSlidingTabStripDelegate() {

        @Override
        public void onPageSelected(int id, boolean forward) {
            if (viewPages[0].selectedType == id) {
                return;
            }
            swipeBackEnabled = id == scrollSlidingTextTabStrip.getFirstTabId();
            viewPages[1].selectedType = id;
            viewPages[1].setVisibility(View.VISIBLE);
            switchToCurrentSelectedMode(true);
            animatingForward = forward;
        }

        @Override
        public void onPageScrolled(float progress) {
            if (progress == 1 && viewPages[1].getVisibility() != View.VISIBLE) {
                return;
            }
            if (animatingForward) {
                viewPages[0].setTranslationX(-progress * viewPages[0].getMeasuredWidth());
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() - progress * viewPages[0].getMeasuredWidth());
            } else {
                viewPages[0].setTranslationX(progress * viewPages[0].getMeasuredWidth());
                viewPages[1].setTranslationX(progress * viewPages[0].getMeasuredWidth() - viewPages[0].getMeasuredWidth());
            }
            if (progress == 1) {
                ViewPage tempPage = viewPages[0];
                viewPages[0] = viewPages[1];
                viewPages[1] = tempPage;
                viewPages[1].setVisibility(View.GONE);
            }
        }
    });
    ViewConfiguration configuration = ViewConfiguration.get(context);
    maximumVelocity = configuration.getScaledMaximumFlingVelocity();
    FrameLayout frameLayout;
    fragmentView = frameLayout = new FrameLayout(context) {

        private int startedTrackingPointerId;

        private boolean startedTracking;

        private boolean maybeStartTracking;

        private int startedTrackingX;

        private int startedTrackingY;

        private VelocityTracker velocityTracker;

        private boolean globalIgnoreLayout;

        private boolean prepareForMoving(MotionEvent ev, boolean forward) {
            int id = scrollSlidingTextTabStrip.getNextPageId(forward);
            if (id < 0) {
                return false;
            }
            getParent().requestDisallowInterceptTouchEvent(true);
            maybeStartTracking = false;
            startedTracking = true;
            startedTrackingX = (int) ev.getX();
            actionBar.setEnabled(false);
            scrollSlidingTextTabStrip.setEnabled(false);
            viewPages[1].selectedType = id;
            viewPages[1].setVisibility(View.VISIBLE);
            animatingForward = forward;
            switchToCurrentSelectedMode(true);
            if (forward) {
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
            } else {
                viewPages[1].setTranslationX(-viewPages[0].getMeasuredWidth());
            }
            return true;
        }

        @Override
        public void forceHasOverlappingRendering(boolean hasOverlappingRendering) {
            super.forceHasOverlappingRendering(hasOverlappingRendering);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(widthSize, heightSize);
            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int actionBarHeight = actionBar.getMeasuredHeight();
            globalIgnoreLayout = true;
            for (int a = 0; a < viewPages.length; a++) {
                if (viewPages[a] == null) {
                    continue;
                }
                if (viewPages[a].listView != null) {
                    viewPages[a].listView.setPadding(0, actionBarHeight, 0, 0);
                }
                if (viewPages[a].listView2 != null) {
                    viewPages[a].listView2.setPadding(0, actionBarHeight, 0, 0);
                }
            }
            globalIgnoreLayout = false;
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
            }
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            if (parentLayout != null) {
                parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight() + (int) actionBar.getTranslationY());
            }
        }

        @Override
        public void requestLayout() {
            if (globalIgnoreLayout) {
                return;
            }
            super.requestLayout();
        }

        public boolean checkTabsAnimationInProgress() {
            if (tabsAnimationInProgress) {
                boolean cancel = false;
                if (backAnimation) {
                    if (Math.abs(viewPages[0].getTranslationX()) < 1) {
                        viewPages[0].setTranslationX(0);
                        viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? 1 : -1));
                        cancel = true;
                    }
                } else if (Math.abs(viewPages[1].getTranslationX()) < 1) {
                    viewPages[0].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? -1 : 1));
                    viewPages[1].setTranslationX(0);
                    cancel = true;
                }
                if (cancel) {
                    if (tabsAnimation != null) {
                        tabsAnimation.cancel();
                        tabsAnimation = null;
                    }
                    tabsAnimationInProgress = false;
                }
                return tabsAnimationInProgress;
            }
            return false;
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return checkTabsAnimationInProgress() || scrollSlidingTextTabStrip.isAnimatingIndicator() || onTouchEvent(ev);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            backgroundPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            canvas.drawRect(0, actionBar.getMeasuredHeight() + actionBar.getTranslationY(), getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
        }

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            if (!parentLayout.checkTransitionAnimation() && !checkTabsAnimationInProgress()) {
                if (ev != null) {
                    if (velocityTracker == null) {
                        velocityTracker = VelocityTracker.obtain();
                    }
                    velocityTracker.addMovement(ev);
                }
                if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
                    startedTrackingPointerId = ev.getPointerId(0);
                    maybeStartTracking = true;
                    startedTrackingX = (int) ev.getX();
                    startedTrackingY = (int) ev.getY();
                    velocityTracker.clear();
                } else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
                    int dx = (int) (ev.getX() - startedTrackingX);
                    int dy = Math.abs((int) ev.getY() - startedTrackingY);
                    if (startedTracking && (animatingForward && dx > 0 || !animatingForward && dx < 0)) {
                        if (!prepareForMoving(ev, dx < 0)) {
                            maybeStartTracking = true;
                            startedTracking = false;
                            viewPages[0].setTranslationX(0);
                            viewPages[1].setTranslationX(animatingForward ? viewPages[0].getMeasuredWidth() : -viewPages[0].getMeasuredWidth());
                            scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, 0);
                        }
                    }
                    if (maybeStartTracking && !startedTracking) {
                        float touchSlop = AndroidUtilities.getPixelsInCM(0.3f, true);
                        if (Math.abs(dx) >= touchSlop && Math.abs(dx) > dy) {
                            prepareForMoving(ev, dx < 0);
                        }
                    } else if (startedTracking) {
                        viewPages[0].setTranslationX(dx);
                        if (animatingForward) {
                            viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
                        } else {
                            viewPages[1].setTranslationX(dx - viewPages[0].getMeasuredWidth());
                        }
                        float scrollProgress = Math.abs(dx) / (float) viewPages[0].getMeasuredWidth();
                        scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                } else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
                    velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
                    float velX;
                    float velY;
                    if (ev != null && ev.getAction() != MotionEvent.ACTION_CANCEL) {
                        velX = velocityTracker.getXVelocity();
                        velY = velocityTracker.getYVelocity();
                        if (!startedTracking) {
                            if (Math.abs(velX) >= 3000 && Math.abs(velX) > Math.abs(velY)) {
                                prepareForMoving(ev, velX < 0);
                            }
                        }
                    } else {
                        velX = 0;
                        velY = 0;
                    }
                    if (startedTracking) {
                        float x = viewPages[0].getX();
                        tabsAnimation = new AnimatorSet();
                        backAnimation = Math.abs(x) < viewPages[0].getMeasuredWidth() / 3.0f && (Math.abs(velX) < 3500 || Math.abs(velX) < Math.abs(velY));
                        float distToMove;
                        float dx;
                        if (backAnimation) {
                            dx = Math.abs(x);
                            if (animatingForward) {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, viewPages[1].getMeasuredWidth()));
                            } else {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, -viewPages[1].getMeasuredWidth()));
                            }
                        } else {
                            dx = viewPages[0].getMeasuredWidth() - Math.abs(x);
                            if (animatingForward) {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, -viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
                            } else {
                                tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
                            }
                        }
                        tabsAnimation.setInterpolator(interpolator);
                        int width = getMeasuredWidth();
                        int halfWidth = width / 2;
                        float distanceRatio = Math.min(1.0f, 1.0f * dx / (float) width);
                        float distance = (float) halfWidth + (float) halfWidth * AndroidUtilities.distanceInfluenceForSnapDuration(distanceRatio);
                        velX = Math.abs(velX);
                        int duration;
                        if (velX > 0) {
                            duration = 4 * Math.round(1000.0f * Math.abs(distance / velX));
                        } else {
                            float pageDelta = dx / getMeasuredWidth();
                            duration = (int) ((pageDelta + 1.0f) * 100.0f);
                        }
                        duration = Math.max(150, Math.min(duration, 600));
                        tabsAnimation.setDuration(duration);
                        tabsAnimation.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationEnd(Animator animator) {
                                tabsAnimation = null;
                                if (backAnimation) {
                                    viewPages[1].setVisibility(View.GONE);
                                } else {
                                    ViewPage tempPage = viewPages[0];
                                    viewPages[0] = viewPages[1];
                                    viewPages[1] = tempPage;
                                    viewPages[1].setVisibility(View.GONE);
                                    swipeBackEnabled = viewPages[0].selectedType == scrollSlidingTextTabStrip.getFirstTabId();
                                    scrollSlidingTextTabStrip.selectTabWithId(viewPages[0].selectedType, 1.0f);
                                }
                                tabsAnimationInProgress = false;
                                maybeStartTracking = false;
                                startedTracking = false;
                                actionBar.setEnabled(true);
                                scrollSlidingTextTabStrip.setEnabled(true);
                            }
                        });
                        tabsAnimation.start();
                        tabsAnimationInProgress = true;
                        startedTracking = false;
                    } else {
                        maybeStartTracking = false;
                        actionBar.setEnabled(true);
                        scrollSlidingTextTabStrip.setEnabled(true);
                    }
                    if (velocityTracker != null) {
                        velocityTracker.recycle();
                        velocityTracker = null;
                    }
                }
                return startedTracking;
            }
            return false;
        }
    };
    frameLayout.setWillNotDraw(false);
    dialogsActivity.setParentFragment(this);
    contactsActivity.setParentFragment(this);
    for (int a = 0; a < viewPages.length; a++) {
        viewPages[a] = new ViewPage(context) {

            @Override
            public void setTranslationX(float translationX) {
                super.setTranslationX(translationX);
                if (tabsAnimationInProgress) {
                    if (viewPages[0] == this) {
                        float scrollProgress = Math.abs(viewPages[0].getTranslationX()) / (float) viewPages[0].getMeasuredWidth();
                        scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                }
            }
        };
        frameLayout.addView(viewPages[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        if (a == 0) {
            viewPages[a].parentFragment = dialogsActivity;
            viewPages[a].listView = dialogsActivity.getListView();
            viewPages[a].listView2 = dialogsActivity.getSearchListView();
        } else if (a == 1) {
            viewPages[a].parentFragment = contactsActivity;
            viewPages[a].listView = contactsActivity.getListView();
            viewPages[a].setVisibility(View.GONE);
        }
        viewPages[a].listView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
        viewPages[a].fragmentView = (FrameLayout) viewPages[a].parentFragment.getFragmentView();
        viewPages[a].actionBar = viewPages[a].parentFragment.getActionBar();
        viewPages[a].addView(viewPages[a].fragmentView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPages[a].addView(viewPages[a].actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        viewPages[a].actionBar.setVisibility(View.GONE);
        for (int i = 0; i < 2; i++) {
            RecyclerListView listView = i == 0 ? viewPages[a].listView : viewPages[a].listView2;
            if (listView == null) {
                continue;
            }
            listView.setClipToPadding(false);
            RecyclerView.OnScrollListener onScrollListener = listView.getOnScrollListener();
            listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

                @Override
                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                    onScrollListener.onScrollStateChanged(recyclerView, newState);
                    if (newState != RecyclerView.SCROLL_STATE_DRAGGING) {
                        int scrollY = (int) -actionBar.getTranslationY();
                        int actionBarHeight = ActionBar.getCurrentActionBarHeight();
                        if (scrollY != 0 && scrollY != actionBarHeight) {
                            if (scrollY < actionBarHeight / 2) {
                                viewPages[0].listView.smoothScrollBy(0, -scrollY);
                                if (viewPages[0].listView2 != null) {
                                    viewPages[0].listView2.smoothScrollBy(0, -scrollY);
                                }
                            } else {
                                viewPages[0].listView.smoothScrollBy(0, actionBarHeight - scrollY);
                                if (viewPages[0].listView2 != null) {
                                    viewPages[0].listView2.smoothScrollBy(0, actionBarHeight - scrollY);
                                }
                            }
                        }
                    }
                }

                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    onScrollListener.onScrolled(recyclerView, dx, dy);
                    if (recyclerView == viewPages[0].listView || recyclerView == viewPages[0].listView2) {
                        float currentTranslation = actionBar.getTranslationY();
                        float newTranslation = currentTranslation - dy;
                        if (newTranslation < -ActionBar.getCurrentActionBarHeight()) {
                            newTranslation = -ActionBar.getCurrentActionBarHeight();
                        } else if (newTranslation > 0) {
                            newTranslation = 0;
                        }
                        if (newTranslation != currentTranslation) {
                            setScrollY(newTranslation);
                        }
                    }
                }
            });
        }
    }
    frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    updateTabs();
    switchToCurrentSelectedMode(false);
    swipeBackEnabled = scrollSlidingTextTabStrip.getCurrentTabId() == scrollSlidingTextTabStrip.getFirstTabId();
    return fragmentView;
}
Also used : EditText(android.widget.EditText) VelocityTracker(android.view.VelocityTracker) Canvas(android.graphics.Canvas) AnimatorSet(android.animation.AnimatorSet) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent) ViewConfiguration(android.view.ViewConfiguration) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) ScrollSlidingTextTabStrip(org.telegram.ui.Components.ScrollSlidingTextTabStrip) ActionBar(org.telegram.ui.ActionBar.ActionBar)

Example 17 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsActivity method createActionMode.

private void createActionMode(String tag) {
    if (actionBar.actionModeIsExist(tag)) {
        return;
    }
    final ActionBarMenu actionMode = actionBar.createActionMode(false, tag);
    actionMode.setBackground(null);
    selectedDialogsCountTextView = new NumberTextView(actionMode.getContext());
    selectedDialogsCountTextView.setTextSize(18);
    selectedDialogsCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedDialogsCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
    actionMode.addView(selectedDialogsCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 72, 0, 0, 0));
    selectedDialogsCountTextView.setOnTouchListener((v, event) -> true);
    pinItem = actionMode.addItemWithWidth(pin, R.drawable.msg_pin, AndroidUtilities.dp(54));
    muteItem = actionMode.addItemWithWidth(mute, R.drawable.msg_mute, AndroidUtilities.dp(54));
    archive2Item = actionMode.addItemWithWidth(archive2, R.drawable.msg_archive, AndroidUtilities.dp(54));
    deleteItem = actionMode.addItemWithWidth(delete, R.drawable.msg_delete, AndroidUtilities.dp(54), LocaleController.getString("Delete", R.string.Delete));
    ActionBarMenuItem otherItem = actionMode.addItemWithWidth(0, R.drawable.ic_ab_other, AndroidUtilities.dp(54), LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
    archiveItem = otherItem.addSubItem(archive, R.drawable.msg_archive, LocaleController.getString("Archive", R.string.Archive));
    pin2Item = otherItem.addSubItem(pin2, R.drawable.msg_pin, LocaleController.getString("DialogPin", R.string.DialogPin));
    addToFolderItem = otherItem.addSubItem(add_to_folder, R.drawable.msg_addfolder, LocaleController.getString("FilterAddTo", R.string.FilterAddTo));
    removeFromFolderItem = otherItem.addSubItem(remove_from_folder, R.drawable.msg_removefolder, LocaleController.getString("FilterRemoveFrom", R.string.FilterRemoveFrom));
    readItem = otherItem.addSubItem(read, R.drawable.msg_markread, LocaleController.getString("MarkAsRead", R.string.MarkAsRead));
    clearItem = otherItem.addSubItem(clear, R.drawable.msg_clear, LocaleController.getString("ClearHistory", R.string.ClearHistory));
    blockItem = otherItem.addSubItem(block, R.drawable.msg_block, LocaleController.getString("BlockUser", R.string.BlockUser));
    actionModeViews.add(pinItem);
    actionModeViews.add(archive2Item);
    actionModeViews.add(muteItem);
    actionModeViews.add(deleteItem);
    actionModeViews.add(otherItem);
    if (tag == null) {
        actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

            @Override
            public void onItemClick(int id) {
                if (id == SearchViewPager.forwardItemId || id == SearchViewPager.gotoItemId && searchViewPager != null) {
                    searchViewPager.onActionBarItemClick(id);
                    return;
                }
                if (id == -1) {
                    if (filterTabsView != null && filterTabsView.isEditing()) {
                        filterTabsView.setIsEditing(false);
                        showDoneItem(false);
                    } else if (actionBar.isActionModeShowed()) {
                        if (searchViewPager != null && searchViewPager.getVisibility() == View.VISIBLE && searchViewPager.actionModeShowing()) {
                            searchViewPager.hideActionMode();
                        } else {
                            hideActionMode(true);
                        }
                    } else if (onlySelect || folderId != 0) {
                        finishFragment();
                    } else if (parentLayout != null) {
                        parentLayout.getDrawerLayoutContainer().openDrawer(false);
                    }
                } else if (id == 1) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    SharedConfig.appLocked = true;
                    SharedConfig.saveConfig();
                    int[] position = new int[2];
                    passcodeItem.getLocationInWindow(position);
                    ((LaunchActivity) getParentActivity()).showPasscodeActivity(false, true, position[0] + passcodeItem.getMeasuredWidth() / 2, position[1] + passcodeItem.getMeasuredHeight() / 2, () -> passcodeItem.setAlpha(1.0f), () -> passcodeItem.setAlpha(0.0f));
                    updatePasscodeButton();
                } else if (id == 2) {
                    presentFragment(new ProxyListActivity());
                } else if (id >= 10 && id < 10 + UserConfig.MAX_ACCOUNT_COUNT) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    DialogsActivityDelegate oldDelegate = delegate;
                    LaunchActivity launchActivity = (LaunchActivity) getParentActivity();
                    launchActivity.switchToAccount(id - 10, true);
                    DialogsActivity dialogsActivity = new DialogsActivity(arguments);
                    dialogsActivity.setDelegate(oldDelegate);
                    launchActivity.presentFragment(dialogsActivity, false, true);
                } else if (id == add_to_folder) {
                    FiltersListBottomSheet sheet = new FiltersListBottomSheet(DialogsActivity.this, selectedDialogs);
                    sheet.setDelegate(filter -> {
                        ArrayList<Long> alwaysShow = FiltersListBottomSheet.getDialogsCount(DialogsActivity.this, filter, selectedDialogs, true, false);
                        int currentCount;
                        if (filter != null) {
                            currentCount = filter.alwaysShow.size();
                        } else {
                            currentCount = 0;
                        }
                        if (currentCount + alwaysShow.size() > 100) {
                            showDialog(AlertsCreator.createSimpleAlert(getParentActivity(), LocaleController.getString("FilterAddToAlertFullTitle", R.string.FilterAddToAlertFullTitle), LocaleController.getString("FilterRemoveFromAlertFullText", R.string.FilterRemoveFromAlertFullText)).create());
                            return;
                        }
                        if (filter != null) {
                            if (!alwaysShow.isEmpty()) {
                                for (int a = 0; a < alwaysShow.size(); a++) {
                                    filter.neverShow.remove(alwaysShow.get(a));
                                }
                                filter.alwaysShow.addAll(alwaysShow);
                                FilterCreateActivity.saveFilterToServer(filter, filter.flags, filter.name, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, true, false, DialogsActivity.this, null);
                            }
                            long did;
                            if (alwaysShow.size() == 1) {
                                did = alwaysShow.get(0);
                            } else {
                                did = 0;
                            }
                            getUndoView().showWithAction(did, UndoView.ACTION_ADDED_TO_FOLDER, alwaysShow.size(), filter, null, null);
                        } else {
                            presentFragment(new FilterCreateActivity(null, alwaysShow));
                        }
                        hideActionMode(true);
                    });
                    showDialog(sheet);
                } else if (id == remove_from_folder) {
                    MessagesController.DialogFilter filter = getMessagesController().dialogFilters.get(viewPages[0].selectedType);
                    ArrayList<Long> neverShow = FiltersListBottomSheet.getDialogsCount(DialogsActivity.this, filter, selectedDialogs, false, false);
                    int currentCount;
                    if (filter != null) {
                        currentCount = filter.neverShow.size();
                    } else {
                        currentCount = 0;
                    }
                    if (currentCount + neverShow.size() > 100) {
                        showDialog(AlertsCreator.createSimpleAlert(getParentActivity(), LocaleController.getString("FilterAddToAlertFullTitle", R.string.FilterAddToAlertFullTitle), LocaleController.getString("FilterAddToAlertFullText", R.string.FilterAddToAlertFullText)).create());
                        return;
                    }
                    if (!neverShow.isEmpty()) {
                        filter.neverShow.addAll(neverShow);
                        for (int a = 0; a < neverShow.size(); a++) {
                            Long did = neverShow.get(a);
                            filter.alwaysShow.remove(did);
                            filter.pinnedDialogs.delete(did);
                        }
                        FilterCreateActivity.saveFilterToServer(filter, filter.flags, filter.name, filter.alwaysShow, filter.neverShow, filter.pinnedDialogs, false, false, true, false, false, DialogsActivity.this, null);
                    }
                    long did;
                    if (neverShow.size() == 1) {
                        did = neverShow.get(0);
                    } else {
                        did = 0;
                    }
                    getUndoView().showWithAction(did, UndoView.ACTION_REMOVED_FROM_FOLDER, neverShow.size(), filter, null, null);
                    hideActionMode(false);
                } else if (id == pin || id == read || id == delete || id == clear || id == mute || id == archive || id == block || id == archive2 || id == pin2) {
                    performSelectedDialogsAction(selectedDialogs, id, true);
                }
            }
        });
    }
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) StickersAlert(org.telegram.ui.Components.StickersAlert) RecyclerAnimationScrollHelper(org.telegram.ui.Components.RecyclerAnimationScrollHelper) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) Bulletin(org.telegram.ui.Components.Bulletin) Property(android.util.Property) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) MediaActionDrawable(org.telegram.ui.Components.MediaActionDrawable) FilterTabsView(org.telegram.ui.Components.FilterTabsView) Manifest(android.Manifest) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) StateListAnimator(android.animation.StateListAnimator) DrawerProfileCell(org.telegram.ui.Cells.DrawerProfileCell) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) Shader(android.graphics.Shader) Canvas(android.graphics.Canvas) TargetApi(android.annotation.TargetApi) NotificationsController(org.telegram.messenger.NotificationsController) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Interpolator(android.view.animation.Interpolator) UndoView(org.telegram.ui.Components.UndoView) AnimationProperties(org.telegram.ui.Components.AnimationProperties) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) MenuDrawable(org.telegram.ui.ActionBar.MenuDrawable) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) DialogsAdapter(org.telegram.ui.Adapters.DialogsAdapter) TextPaint(android.text.TextPaint) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerCell(org.telegram.ui.Cells.DividerCell) FileLoader(org.telegram.messenger.FileLoader) ViewParent(android.view.ViewParent) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) DialogsSearchAdapter(org.telegram.ui.Adapters.DialogsSearchAdapter) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) FragmentContextView(org.telegram.ui.Components.FragmentContextView) TLRPC(org.telegram.tgnet.TLRPC) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) DialogsEmptyCell(org.telegram.ui.Cells.DialogsEmptyCell) FilesMigrationService(org.telegram.messenger.FilesMigrationService) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) JoinGroupAlert(org.telegram.ui.Components.JoinGroupAlert) SearchViewPager(org.telegram.ui.Components.SearchViewPager) ViewPagerFixed(org.telegram.ui.Components.ViewPagerFixed) LinearGradient(android.graphics.LinearGradient) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) DialogsItemAnimator(org.telegram.ui.Components.DialogsItemAnimator) File(java.io.File) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) DrawerAddCell(org.telegram.ui.Cells.DrawerAddCell) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) ContactsController(org.telegram.messenger.ContactsController) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) ValueAnimator(android.animation.ValueAnimator) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) FiltersView(org.telegram.ui.Adapters.FiltersView) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) RadialProgress2(org.telegram.ui.Components.RadialProgress2) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ViewConfiguration(android.view.ViewConfiguration) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) PacmanAnimation(org.telegram.ui.Components.PacmanAnimation) TextCell(org.telegram.ui.Cells.TextCell) ArchiveHintInnerCell(org.telegram.ui.Cells.ArchiveHintInnerCell) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Matrix(android.graphics.Matrix) RectF(android.graphics.RectF) ImageLoader(org.telegram.messenger.ImageLoader) DrawerUserCell(org.telegram.ui.Cells.DrawerUserCell) Utilities(org.telegram.messenger.Utilities) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ViewGroup(android.view.ViewGroup) StateSet(android.util.StateSet) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) VelocityTracker(android.view.VelocityTracker) XiaomiUtilities(org.telegram.messenger.XiaomiUtilities) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) FiltersListBottomSheet(org.telegram.ui.Components.FiltersListBottomSheet) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearSmoothScrollerCustom(androidx.recyclerview.widget.LinearSmoothScrollerCustom) TLObject(org.telegram.tgnet.TLObject) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) DrawerActionCell(org.telegram.ui.Cells.DrawerActionCell) DialogInterface(android.content.DialogInterface) ChatAvatarContainer(org.telegram.ui.Components.ChatAvatarContainer) DialogObject(org.telegram.messenger.DialogObject) BackupImageView(org.telegram.ui.Components.BackupImageView) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) NumberTextView(org.telegram.ui.Components.NumberTextView) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) Bitmap(android.graphics.Bitmap) ViewTreeObserver(android.view.ViewTreeObserver) Vibrator(android.os.Vibrator) ProxyDrawable(org.telegram.ui.Components.ProxyDrawable) Activity(android.app.Activity) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LoadingCell(org.telegram.ui.Cells.LoadingCell) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) ArrayList(java.util.ArrayList) MessagesController(org.telegram.messenger.MessagesController) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) NumberTextView(org.telegram.ui.Components.NumberTextView) FiltersListBottomSheet(org.telegram.ui.Components.FiltersListBottomSheet) ActionBar(org.telegram.ui.ActionBar.ActionBar)

Example 18 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupStickersActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("GroupStickers", R.string.GroupStickers));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                donePressed = true;
                if (searching) {
                    showEditDoneProgress(true);
                    return;
                }
                saveStickerSet();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
    progressView = new ContextProgressView(context, 1);
    progressView.setAlpha(0.0f);
    progressView.setScaleX(0.1f);
    progressView.setScaleY(0.1f);
    progressView.setVisibility(View.INVISIBLE);
    doneItem.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    nameContainer = new LinearLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onDraw(Canvas canvas) {
            if (selectedStickerSet != null) {
                canvas.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1, Theme.dividerPaint);
            }
        }
    };
    nameContainer.setWeightSum(1.0f);
    nameContainer.setWillNotDraw(false);
    nameContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    nameContainer.setOrientation(LinearLayout.HORIZONTAL);
    nameContainer.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(14), 0);
    editText = new EditTextBoldCursor(context);
    editText.setText(MessagesController.getInstance(currentAccount).linkPrefix + "/addstickers/");
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setEnabled(false);
    editText.setFocusable(false);
    editText.setBackgroundDrawable(null);
    editText.setPadding(0, 0, 0, 0);
    editText.setGravity(Gravity.CENTER_VERTICAL);
    editText.setSingleLine(true);
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    nameContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 42));
    usernameTextView = new EditTextBoldCursor(context);
    usernameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    usernameTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usernameTextView.setCursorSize(AndroidUtilities.dp(20));
    usernameTextView.setCursorWidth(1.5f);
    usernameTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    usernameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usernameTextView.setMaxLines(1);
    usernameTextView.setLines(1);
    usernameTextView.setBackgroundDrawable(null);
    usernameTextView.setPadding(0, 0, 0, 0);
    usernameTextView.setSingleLine(true);
    usernameTextView.setGravity(Gravity.CENTER_VERTICAL);
    usernameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    usernameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    usernameTextView.setHint(LocaleController.getString("ChooseStickerSetPlaceholder", R.string.ChooseStickerSetPlaceholder));
    usernameTextView.addTextChangedListener(new TextWatcher() {

        boolean ignoreTextChange;

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (eraseImageView != null) {
                eraseImageView.setVisibility(s.length() > 0 ? View.VISIBLE : View.INVISIBLE);
            }
            if (ignoreTextChange || ignoreTextChanges) {
                return;
            }
            if (s.length() > 5) {
                ignoreTextChange = true;
                try {
                    Uri uri = Uri.parse(s.toString());
                    if (uri != null) {
                        List<String> segments = uri.getPathSegments();
                        if (segments.size() == 2) {
                            if (segments.get(0).toLowerCase().equals("addstickers")) {
                                usernameTextView.setText(segments.get(1));
                                usernameTextView.setSelection(usernameTextView.length());
                            }
                        }
                    }
                } catch (Exception ignore) {
                }
                ignoreTextChange = false;
            }
            resolveStickerSet();
        }
    });
    nameContainer.addView(usernameTextView, LayoutHelper.createLinear(0, 42, 1.0f));
    eraseImageView = new ImageView(context);
    eraseImageView.setScaleType(ImageView.ScaleType.CENTER);
    eraseImageView.setImageResource(R.drawable.ic_close_white);
    eraseImageView.setPadding(AndroidUtilities.dp(16), 0, 0, 0);
    eraseImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3), PorterDuff.Mode.MULTIPLY));
    eraseImageView.setVisibility(View.INVISIBLE);
    eraseImageView.setOnClickListener(v -> {
        searchWas = false;
        selectedStickerSet = null;
        usernameTextView.setText("");
        updateRows();
    });
    nameContainer.addView(eraseImageView, LayoutHelper.createLinear(42, 42, 0.0f));
    if (info != null && info.stickerset != null) {
        ignoreTextChanges = true;
        usernameTextView.setText(info.stickerset.short_name);
        usernameTextView.setSelection(usernameTextView.length());
        ignoreTextChanges = false;
    }
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setFocusable(true);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    layoutManager = new LinearLayoutManager(context) {

        @Override
        public boolean requestChildRectangleOnScreen(RecyclerView parent, View child, Rect rect, boolean immediate, boolean focusedChildVisible) {
            return false;
        }

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    };
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    listView.setLayoutManager(layoutManager);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null) {
            return;
        }
        if (position == selectedStickerRow) {
            if (selectedStickerSet == null) {
                return;
            }
            showDialog(new StickersAlert(getParentActivity(), GroupStickersActivity.this, null, selectedStickerSet, null));
        } else if (position >= stickersStartRow && position < stickersEndRow) {
            boolean needScroll = selectedStickerRow == -1;
            int row = layoutManager.findFirstVisibleItemPosition();
            int top = Integer.MAX_VALUE;
            RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.findViewHolderForAdapterPosition(row);
            if (holder != null) {
                top = holder.itemView.getTop();
            }
            selectedStickerSet = MediaDataController.getInstance(currentAccount).getStickerSets(MediaDataController.TYPE_IMAGE).get(position - stickersStartRow);
            ignoreTextChanges = true;
            usernameTextView.setText(selectedStickerSet.set.short_name);
            usernameTextView.setSelection(usernameTextView.length());
            ignoreTextChanges = false;
            AndroidUtilities.hideKeyboard(usernameTextView);
            updateRows();
            if (needScroll && top != Integer.MAX_VALUE) {
                layoutManager.scrollToPositionWithOffset(row + 1, top);
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        }
    });
    return fragmentView;
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Uri(android.net.Uri) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) StickersAlert(org.telegram.ui.Components.StickersAlert) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayout(android.widget.LinearLayout)

Example 19 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class MemberRequestsDelegate method hideChatJoinRequest.

private void hideChatJoinRequest(TLRPC.TL_chatInviteImporter importer, boolean isApproved) {
    TLRPC.User user = users.get(importer.user_id);
    if (user == null) {
        return;
    }
    TLRPC.TL_messages_hideChatJoinRequest req = new TLRPC.TL_messages_hideChatJoinRequest();
    req.approved = isApproved;
    req.peer = MessagesController.getInstance(currentAccount).getInputPeer(-chatId);
    req.user_id = MessagesController.getInstance(currentAccount).getInputUser(user);
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (error == null) {
            TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
            MessagesController.getInstance(currentAccount).processUpdates(updates, false);
        }
        AndroidUtilities.runOnUIThread(() -> {
            if (error == null) {
                TLRPC.TL_updates updates = (TLRPC.TL_updates) response;
                if (!updates.chats.isEmpty()) {
                    TLRPC.Chat chat = updates.chats.get(0);
                    MessagesController.getInstance(currentAccount).loadFullChat(chat.id, 0, true);
                }
                for (int i = 0; i < allImporters.size(); ++i) {
                    if (allImporters.get(i).user_id == importer.user_id) {
                        allImporters.remove(i);
                        break;
                    }
                }
                adapter.removeItem(importer);
                onImportersChanged(query, false, true);
                if (isApproved) {
                    Bulletin.MultiLineLayout layout = new Bulletin.MultiLineLayout(fragment.getParentActivity(), fragment.getResourceProvider());
                    layout.imageView.setRoundRadius(AndroidUtilities.dp(15));
                    layout.imageView.setForUserOrChat(user, new AvatarDrawable(user));
                    String userName = UserObject.getFirstName(user);
                    String message = isChannel ? LocaleController.formatString("HasBeenAddedToChannel", R.string.HasBeenAddedToChannel, userName) : LocaleController.formatString("HasBeenAddedToGroup", R.string.HasBeenAddedToGroup, userName);
                    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(message);
                    int start = message.indexOf(userName);
                    stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), start, start + userName.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                    layout.textView.setText(stringBuilder);
                    if (allImporters.isEmpty()) {
                        Bulletin.make(fragment, layout, Bulletin.DURATION_LONG).show();
                    } else {
                        Bulletin.make(layoutContainer, layout, Bulletin.DURATION_LONG).show();
                    }
                }
                ActionBarMenu menu = fragment.getActionBar().createMenu();
                if (TextUtils.isEmpty(query) && showSearchMenu) {
                    menu.getItem(MemberRequestsActivity.searchMenuItem).setVisibility(allImporters.isEmpty() ? GONE : VISIBLE);
                }
            } else {
                AlertsCreator.processError(currentAccount, error, fragment, req);
            }
        });
    });
}
Also used : ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) TLRPC(org.telegram.tgnet.TLRPC) SuppressLint(android.annotation.SuppressLint) Bulletin(org.telegram.ui.Components.Bulletin) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) SpannableStringBuilder(android.text.SpannableStringBuilder) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan)

Example 20 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class CountrySelectActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            searching = true;
        }

        @Override
        public void onSearchCollapse() {
            searchListViewAdapter.search(null);
            searching = false;
            searchWas = false;
            listView.setAdapter(listViewAdapter);
            listView.setFastScrollVisible(true);
        }

        @Override
        public void onTextChanged(EditText editText) {
            String text = editText.getText().toString();
            searchListViewAdapter.search(text);
            if (text.length() != 0) {
                searchWas = true;
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    searching = false;
    searchWas = false;
    listViewAdapter = new CountryAdapter(context, existingCountries);
    searchListViewAdapter = new CountrySearchAdapter(context, listViewAdapter.getCountries());
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    emptyView = new EmptyTextProgressView(context);
    emptyView.showTextView();
    emptyView.setShowAtCenter(true);
    emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context);
    listView.setSectionsType(1);
    listView.setEmptyView(emptyView);
    listView.setVerticalScrollBarEnabled(false);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(listViewAdapter);
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener((view, position) -> {
        Country country;
        if (searching && searchWas) {
            country = searchListViewAdapter.getItem(position);
        } else {
            int section = listViewAdapter.getSectionForPosition(position);
            int row = listViewAdapter.getPositionInSectionForPosition(position);
            if (row < 0 || section < 0) {
                return;
            }
            country = listViewAdapter.getItem(section, row);
        }
        if (position < 0) {
            return;
        }
        finishFragment();
        if (country != null && delegate != null) {
            delegate.didSelectCountry(country);
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }
    });
    return fragmentView;
}
Also used : EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) ActionBar(org.telegram.ui.ActionBar.ActionBar)

Aggregations

ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)60 ActionBar (org.telegram.ui.ActionBar.ActionBar)52 FrameLayout (android.widget.FrameLayout)48 View (android.view.View)39 TextView (android.widget.TextView)39 TLRPC (org.telegram.tgnet.TLRPC)35 RecyclerListView (org.telegram.ui.Components.RecyclerListView)33 RecyclerView (androidx.recyclerview.widget.RecyclerView)31 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)30 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)30 Paint (android.graphics.Paint)29 ActionBarMenuItem (org.telegram.ui.ActionBar.ActionBarMenuItem)28 ArrayList (java.util.ArrayList)27 Canvas (android.graphics.Canvas)25 ViewGroup (android.view.ViewGroup)25 EditTextBoldCursor (org.telegram.ui.Components.EditTextBoldCursor)25 ImageView (android.widget.ImageView)24 LinearLayout (android.widget.LinearLayout)24 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)24 Animator (android.animation.Animator)23