Search in sources :

Example 21 with StateListAnimator

use of android.animation.StateListAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class ContactsActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (destroyAfterSelect) {
        if (returnAsResult) {
            actionBar.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
        } else {
            if (createSecretChat) {
                actionBar.setTitle(LocaleController.getString("NewSecretChat", R.string.NewSecretChat));
            } else {
                actionBar.setTitle(LocaleController.getString("NewMessageTitle", R.string.NewMessageTitle));
            }
        }
    } else {
        actionBar.setTitle(LocaleController.getString("Contacts", R.string.Contacts));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == sort_button) {
                SharedConfig.toggleSortContactsByName();
                sortByName = SharedConfig.sortContactsByName;
                listViewAdapter.setSortType(sortByName ? 1 : 2, false);
                sortItem.setIcon(sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            searching = true;
            if (floatingButtonContainer != null) {
                floatingButtonContainer.setVisibility(View.GONE);
            }
            if (sortItem != null) {
                sortItem.setVisibility(View.GONE);
            }
        }

        @Override
        public void onSearchCollapse() {
            searchListViewAdapter.searchDialogs(null);
            searching = false;
            searchWas = false;
            listView.setAdapter(listViewAdapter);
            listView.setSectionsType(1);
            listViewAdapter.notifyDataSetChanged();
            listView.setFastScrollVisible(true);
            listView.setVerticalScrollBarEnabled(false);
            // emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
            if (floatingButtonContainer != null) {
                floatingButtonContainer.setVisibility(View.VISIBLE);
                floatingHidden = true;
                floatingButtonContainer.setTranslationY(AndroidUtilities.dp(100));
                hideFloatingButton(false);
            }
            if (sortItem != null) {
                sortItem.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onTextChanged(EditText editText) {
            if (searchListViewAdapter == null) {
                return;
            }
            String text = editText.getText().toString();
            if (text.length() != 0) {
                searchWas = true;
                if (listView != null) {
                    listView.setAdapter(searchListViewAdapter);
                    listView.setSectionsType(0);
                    searchListViewAdapter.notifyDataSetChanged();
                    listView.setFastScrollVisible(false);
                    listView.setVerticalScrollBarEnabled(true);
                }
                emptyView.showProgress(true, true);
                searchListViewAdapter.searchDialogs(text);
            } else {
                if (listView != null) {
                    listView.setAdapter(listViewAdapter);
                    listView.setSectionsType(1);
                }
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    item.setContentDescription(LocaleController.getString("Search", R.string.Search));
    if (!createSecretChat && !returnAsResult) {
        sortItem = menu.addItem(sort_button, sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
        sortItem.setContentDescription(LocaleController.getString("AccDescrContactSorting", R.string.AccDescrContactSorting));
    }
    searchListViewAdapter = new SearchAdapter(context, ignoreUsers, allowUsernameSearch, false, false, allowBots, allowSelf, true, 0) {

        @Override
        protected void onSearchProgressChanged() {
            if (!searchInProgress() && getItemCount() == 0) {
                emptyView.showProgress(false, true);
            }
            showItemsAnimated();
        }
    };
    int inviteViaLink;
    if (chatId != 0) {
        TLRPC.Chat chat = getMessagesController().getChat(chatId);
        inviteViaLink = ChatObject.canUserDoAdminAction(chat, ChatObject.ACTION_INVITE) ? 1 : 0;
    } else if (channelId != 0) {
        TLRPC.Chat chat = getMessagesController().getChat(channelId);
        inviteViaLink = ChatObject.canUserDoAdminAction(chat, ChatObject.ACTION_INVITE) && TextUtils.isEmpty(chat.username) ? 2 : 0;
    } else {
        inviteViaLink = 0;
    }
    try {
        hasGps = ApplicationLoader.applicationContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
    } catch (Throwable e) {
        hasGps = false;
    }
    listViewAdapter = new ContactsAdapter(context, onlyUsers ? 1 : 0, needPhonebook, ignoreUsers, inviteViaLink, hasGps) {

        @Override
        public void notifyDataSetChanged() {
            super.notifyDataSetChanged();
            if (listView != null && listView.getAdapter() == this) {
                int count = super.getItemCount();
                if (needPhonebook) {
                    // emptyView.setVisibility(count == 2 ? View.VISIBLE : View.GONE);
                    listView.setFastScrollVisible(count != 2);
                } else {
                    // emptyView.setVisibility(count == 0 ? View.VISIBLE : View.GONE);
                    listView.setFastScrollVisible(count != 0);
                }
            }
        }
    };
    listViewAdapter.setSortType(sortItem != null ? (sortByName ? 1 : 2) : 0, false);
    listViewAdapter.setDisableSections(disableSections);
    fragmentView = new FrameLayout(context) {

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            if (listView.getAdapter() == listViewAdapter) {
                if (emptyView.getVisibility() == VISIBLE) {
                    emptyView.setTranslationY(AndroidUtilities.dp(74));
                }
            } else {
                emptyView.setTranslationY(AndroidUtilities.dp(0));
            }
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    FlickerLoadingView flickerLoadingView = new FlickerLoadingView(context);
    flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
    flickerLoadingView.showDate(false);
    emptyView = new StickerEmptyView(context, flickerLoadingView, StickerEmptyView.STICKER_TYPE_SEARCH);
    emptyView.addView(flickerLoadingView, 0);
    emptyView.setAnimateLayoutChange(true);
    emptyView.showProgress(true, false);
    emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context) {

        @Override
        public void setPadding(int left, int top, int right, int bottom) {
            super.setPadding(left, top, right, bottom);
            if (emptyView != null) {
                emptyView.setPadding(left, top, right, bottom);
            }
        }
    };
    listView.setSectionsType(1);
    listView.setVerticalScrollBarEnabled(false);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(listViewAdapter);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setEmptyView(emptyView);
    listView.setAnimateEmptyView(true, 0);
    listView.setOnItemClickListener((view, position) -> {
        if (listView.getAdapter() == searchListViewAdapter) {
            Object object = searchListViewAdapter.getItem(position);
            if (object instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) object;
                if (searchListViewAdapter.isGlobalSearch(position)) {
                    ArrayList<TLRPC.User> users = new ArrayList<>();
                    users.add(user);
                    getMessagesController().putUsers(users, false);
                    MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, false, true);
                }
                if (returnAsResult) {
                    if (ignoreUsers != null && ignoreUsers.indexOfKey(user.id) >= 0) {
                        return;
                    }
                    didSelectResult(user, true, null);
                } else {
                    if (createSecretChat) {
                        if (user.id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                            return;
                        }
                        creatingChat = true;
                        SecretChatHelper.getInstance(currentAccount).startSecretChat(getParentActivity(), user);
                    } else {
                        Bundle args = new Bundle();
                        args.putLong("user_id", user.id);
                        if (getMessagesController().checkCanOpenChat(args, ContactsActivity.this)) {
                            presentFragment(new ChatActivity(args), true);
                        }
                    }
                }
            } else if (object instanceof String) {
                String str = (String) object;
                if (!str.equals("section")) {
                    NewContactActivity activity = new NewContactActivity();
                    activity.setInitialPhoneNumber(str, true);
                    presentFragment(activity);
                }
            }
        } else {
            int section = listViewAdapter.getSectionForPosition(position);
            int row = listViewAdapter.getPositionInSectionForPosition(position);
            if (row < 0 || section < 0) {
                return;
            }
            if ((!onlyUsers || inviteViaLink != 0) && section == 0) {
                if (needPhonebook) {
                    if (row == 0) {
                        presentFragment(new InviteContactsActivity());
                    } else if (row == 1 && hasGps) {
                        if (Build.VERSION.SDK_INT >= 23) {
                            Activity activity = getParentActivity();
                            if (activity != null) {
                                if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                                    presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ACCESS));
                                    return;
                                }
                            }
                        }
                        boolean enabled = true;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                            LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
                            enabled = lm.isLocationEnabled();
                        } else if (Build.VERSION.SDK_INT >= 19) {
                            try {
                                int mode = Settings.Secure.getInt(ApplicationLoader.applicationContext.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
                                enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
                            } catch (Throwable e) {
                                FileLog.e(e);
                            }
                        }
                        if (!enabled) {
                            presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ENABLED));
                            return;
                        }
                        presentFragment(new PeopleNearbyActivity());
                    }
                } else if (inviteViaLink != 0) {
                    if (row == 0) {
                        presentFragment(new GroupInviteActivity(chatId != 0 ? chatId : channelId));
                    }
                } else {
                    if (row == 0) {
                        Bundle args = new Bundle();
                        presentFragment(new GroupCreateActivity(args), false);
                    } else if (row == 1) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("createSecretChat", true);
                        args.putBoolean("allowBots", false);
                        args.putBoolean("allowSelf", false);
                        presentFragment(new ContactsActivity(args), false);
                    } else if (row == 2) {
                        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                        if (!BuildVars.DEBUG_VERSION && preferences.getBoolean("channel_intro", false)) {
                            Bundle args = new Bundle();
                            args.putInt("step", 0);
                            presentFragment(new ChannelCreateActivity(args));
                        } else {
                            presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANNEL_CREATE));
                            preferences.edit().putBoolean("channel_intro", true).commit();
                        }
                    }
                }
            } else {
                Object item1 = listViewAdapter.getItem(section, row);
                if (item1 instanceof TLRPC.User) {
                    TLRPC.User user = (TLRPC.User) item1;
                    if (returnAsResult) {
                        if (ignoreUsers != null && ignoreUsers.indexOfKey(user.id) >= 0) {
                            return;
                        }
                        didSelectResult(user, true, null);
                    } else {
                        if (createSecretChat) {
                            creatingChat = true;
                            SecretChatHelper.getInstance(currentAccount).startSecretChat(getParentActivity(), user);
                        } else {
                            Bundle args = new Bundle();
                            args.putLong("user_id", user.id);
                            if (getMessagesController().checkCanOpenChat(args, ContactsActivity.this)) {
                                presentFragment(new ChatActivity(args), true);
                            }
                        }
                    }
                } else if (item1 instanceof ContactsController.Contact) {
                    ContactsController.Contact contact = (ContactsController.Contact) item1;
                    String usePhone = null;
                    if (!contact.phones.isEmpty()) {
                        usePhone = contact.phones.get(0);
                    }
                    if (usePhone == null || getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser));
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    final String arg1 = usePhone;
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                        try {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null));
                            intent.putExtra("sms_body", ContactsController.getInstance(currentAccount).getInviteText(1));
                            getParentActivity().startActivityForResult(intent, 500);
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        private boolean scrollingManually;

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                if (searching && searchWas) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
                scrollingManually = true;
            } else {
                scrollingManually = false;
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (floatingButtonContainer != null && floatingButtonContainer.getVisibility() != View.GONE) {
                int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
                final View topChild = recyclerView.getChildAt(0);
                int firstViewTop = 0;
                if (topChild != null) {
                    firstViewTop = topChild.getTop();
                }
                boolean goingDown;
                boolean changed = true;
                if (prevPosition == firstVisibleItem) {
                    final int topDelta = prevTop - firstViewTop;
                    goingDown = firstViewTop < prevTop;
                    changed = Math.abs(topDelta) > 1;
                } else {
                    goingDown = firstVisibleItem > prevPosition;
                }
                if (changed && scrollUpdated && (goingDown || scrollingManually)) {
                    hideFloatingButton(goingDown);
                }
                prevPosition = firstVisibleItem;
                prevTop = firstViewTop;
                scrollUpdated = true;
            }
        }
    });
    if (!createSecretChat && !returnAsResult) {
        floatingButtonContainer = new FrameLayout(context);
        frameLayout.addView(floatingButtonContainer, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 4 : 0, 0, LocaleController.isRTL ? 0 : 4, 0));
        floatingButtonContainer.setOnClickListener(v -> presentFragment(new NewContactActivity()));
        floatingButton = new RLottieImageView(context);
        floatingButton.setScaleType(ImageView.ScaleType.CENTER);
        Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
        if (Build.VERSION.SDK_INT < 21) {
            Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
            shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
            CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
            combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            drawable = combinedDrawable;
        }
        floatingButton.setBackgroundDrawable(drawable);
        floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        boolean configAnimationsEnabled = preferences.getBoolean("view_animations", true);
        floatingButton.setAnimation(configAnimationsEnabled ? R.raw.write_contacts_fab_icon : R.raw.write_contacts_fab_icon_reverse, 52, 52);
        floatingButtonContainer.setContentDescription(LocaleController.getString("CreateNewContact", R.string.CreateNewContact));
        if (Build.VERSION.SDK_INT >= 21) {
            StateListAnimator animator = new StateListAnimator();
            animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
            animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
            floatingButton.setStateListAnimator(animator);
            floatingButton.setOutlineProvider(new ViewOutlineProvider() {

                @SuppressLint("NewApi")
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        floatingButtonContainer.addView(floatingButton, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60), (Build.VERSION.SDK_INT >= 21 ? 56 : 60), Gravity.LEFT | Gravity.TOP, 10, 6, 10, 0));
    }
    if (initialSearchString != null) {
        actionBar.openSearchField(initialSearchString, false);
        initialSearchString = null;
    }
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) StateListAnimator(android.animation.StateListAnimator) TextCell(org.telegram.ui.Cells.TextCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContactsAdapter(org.telegram.ui.Adapters.ContactsAdapter) TargetApi(android.annotation.TargetApi) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Utilities(org.telegram.messenger.Utilities) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) UserConfig(org.telegram.messenger.UserConfig) SecretChatHelper(org.telegram.messenger.SecretChatHelper) LetterSectionCell(org.telegram.ui.Cells.LetterSectionCell) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LocationManager(android.location.LocationManager) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) TextWatcher(android.text.TextWatcher) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Dialog(android.app.Dialog) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) Settings(android.provider.Settings) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) LongSparseArray(androidx.collection.LongSparseArray) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) SearchAdapter(org.telegram.ui.Adapters.SearchAdapter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ValueAnimator(android.animation.ValueAnimator) ArrayList(java.util.ArrayList) Activity(android.app.Activity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ContactsAdapter(org.telegram.ui.Adapters.ContactsAdapter) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) ContactsController(org.telegram.messenger.ContactsController) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StateListAnimator(android.animation.StateListAnimator) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) LocationManager(android.location.LocationManager) SearchAdapter(org.telegram.ui.Adapters.SearchAdapter) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent) Outline(android.graphics.Outline) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) FrameLayout(android.widget.FrameLayout) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 22 with StateListAnimator

use of android.animation.StateListAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupCreateActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    allSpans.clear();
    selectedContacts.clear();
    currentDeletingSpan = null;
    doneButtonVisible = chatType == ChatObject.CHAT_TYPE_CHANNEL;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (chatType == ChatObject.CHAT_TYPE_CHANNEL) {
        actionBar.setTitle(LocaleController.getString("ChannelAddSubscribers", R.string.ChannelAddSubscribers));
    } else {
        if (addToGroup) {
            if (channelId != 0) {
                actionBar.setTitle(LocaleController.getString("ChannelAddSubscribers", R.string.ChannelAddSubscribers));
            } else {
                actionBar.setTitle(LocaleController.getString("GroupAddMembers", R.string.GroupAddMembers));
            }
        } else if (isAlwaysShare) {
            if (chatAddType == 2) {
                actionBar.setTitle(LocaleController.getString("FilterAlwaysShow", R.string.FilterAlwaysShow));
            } else if (chatAddType == 1) {
                actionBar.setTitle(LocaleController.getString("AlwaysAllow", R.string.AlwaysAllow));
            } else {
                actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
            }
        } else if (isNeverShare) {
            if (chatAddType == 2) {
                actionBar.setTitle(LocaleController.getString("FilterNeverShow", R.string.FilterNeverShow));
            } else if (chatAddType == 1) {
                actionBar.setTitle(LocaleController.getString("NeverAllow", R.string.NeverAllow));
            } else {
                actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
            }
        } else {
            actionBar.setTitle(chatType == ChatObject.CHAT_TYPE_CHAT ? LocaleController.getString("NewGroup", R.string.NewGroup) : LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
        }
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                onDonePressed(true);
            }
        }
    });
    fragmentView = new ViewGroup(context) {

        private VerticalPositionAutoAnimator verticalPositionAutoAnimator;

        @Override
        public void onViewAdded(View child) {
            if (child == floatingButton && verticalPositionAutoAnimator == null) {
                verticalPositionAutoAnimator = VerticalPositionAutoAnimator.attach(child);
            }
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            if (verticalPositionAutoAnimator != null) {
                verticalPositionAutoAnimator.ignoreNextLayout();
            }
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(width, height);
            if (AndroidUtilities.isTablet() || height > width) {
                maxSize = AndroidUtilities.dp(144);
            } else {
                maxSize = AndroidUtilities.dp(56);
            }
            scrollView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
            listView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight(), MeasureSpec.EXACTLY));
            emptyView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight(), MeasureSpec.EXACTLY));
            if (floatingButton != null) {
                int w = AndroidUtilities.dp(Build.VERSION.SDK_INT >= 21 ? 56 : 60);
                floatingButton.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY));
            }
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            scrollView.layout(0, 0, scrollView.getMeasuredWidth(), scrollView.getMeasuredHeight());
            listView.layout(0, scrollView.getMeasuredHeight(), listView.getMeasuredWidth(), scrollView.getMeasuredHeight() + listView.getMeasuredHeight());
            emptyView.layout(0, scrollView.getMeasuredHeight(), emptyView.getMeasuredWidth(), scrollView.getMeasuredHeight() + emptyView.getMeasuredHeight());
            if (floatingButton != null) {
                int l = LocaleController.isRTL ? AndroidUtilities.dp(14) : (right - left) - AndroidUtilities.dp(14) - floatingButton.getMeasuredWidth();
                int t = bottom - top - AndroidUtilities.dp(14) - floatingButton.getMeasuredHeight();
                floatingButton.layout(l, t, l + floatingButton.getMeasuredWidth(), t + floatingButton.getMeasuredHeight());
            }
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            parentLayout.drawHeaderShadow(canvas, Math.min(maxSize, measuredContainerHeight + containerHeight - measuredContainerHeight));
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            if (child == listView) {
                canvas.save();
                canvas.clipRect(child.getLeft(), Math.min(maxSize, measuredContainerHeight + containerHeight - measuredContainerHeight), child.getRight(), child.getBottom());
                boolean result = super.drawChild(canvas, child, drawingTime);
                canvas.restore();
                return result;
            } else if (child == scrollView) {
                canvas.save();
                canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), Math.min(maxSize, measuredContainerHeight + containerHeight - measuredContainerHeight));
                boolean result = super.drawChild(canvas, child, drawingTime);
                canvas.restore();
                return result;
            } else {
                return super.drawChild(canvas, child, drawingTime);
            }
        }
    };
    ViewGroup frameLayout = (ViewGroup) fragmentView;
    frameLayout.setFocusableInTouchMode(true);
    frameLayout.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    scrollView = new ScrollView(context) {

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (ignoreScrollEvent) {
                ignoreScrollEvent = false;
                return false;
            }
            rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
            rectangle.top += fieldY + AndroidUtilities.dp(20);
            rectangle.bottom += fieldY + AndroidUtilities.dp(50);
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }
    };
    scrollView.setClipChildren(false);
    frameLayout.setClipChildren(false);
    scrollView.setVerticalScrollBarEnabled(false);
    AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_windowBackgroundWhite));
    frameLayout.addView(scrollView);
    spansContainer = new SpansContainer(context);
    scrollView.addView(spansContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    spansContainer.setOnClickListener(v -> {
        editText.clearFocus();
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    });
    editText = new EditTextBoldCursor(context) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (currentDeletingSpan != null) {
                currentDeletingSpan.cancelDeleteAnimation();
                currentDeletingSpan = null;
            }
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!AndroidUtilities.showKeyboard(this)) {
                    clearFocus();
                    requestFocus();
                }
            }
            return super.onTouchEvent(event);
        }
    };
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setHintColor(Theme.getColor(Theme.key_groupcreate_hintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorColor(Theme.getColor(Theme.key_groupcreate_cursor));
    editText.setCursorWidth(1.5f);
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    editText.setSingleLine(true);
    editText.setBackgroundDrawable(null);
    editText.setVerticalScrollBarEnabled(false);
    editText.setHorizontalScrollBarEnabled(false);
    editText.setTextIsSelectable(false);
    editText.setPadding(0, 0, 0, 0);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    editText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    spansContainer.addView(editText);
    updateEditTextHint();
    editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    editText.setOnEditorActionListener((v, actionId, event) -> actionId == EditorInfo.IME_ACTION_DONE && onDonePressed(true));
    editText.setOnKeyListener(new View.OnKeyListener() {

        private boolean wasEmpty;

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    wasEmpty = editText.length() == 0;
                } else if (event.getAction() == KeyEvent.ACTION_UP && wasEmpty && !allSpans.isEmpty()) {
                    spansContainer.removeSpan(allSpans.get(allSpans.size() - 1));
                    updateHint();
                    checkVisibleRows();
                    return true;
                }
            }
            return false;
        }
    });
    editText.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editText.length() != 0) {
                if (!adapter.searching) {
                    searching = true;
                    searchWas = true;
                    adapter.setSearching(true);
                    itemDecoration.setSearching(true);
                    listView.setFastScrollVisible(false);
                    listView.setVerticalScrollBarEnabled(true);
                }
                adapter.searchDialogs(editText.getText().toString());
                emptyView.showProgress(true, false);
            } else {
                closeSearch();
            }
        }
    });
    FlickerLoadingView flickerLoadingView = new FlickerLoadingView(context);
    flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
    flickerLoadingView.showDate(false);
    emptyView = new StickerEmptyView(context, flickerLoadingView, StickerEmptyView.STICKER_TYPE_SEARCH);
    emptyView.addView(flickerLoadingView);
    emptyView.showProgress(true, false);
    emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
    frameLayout.addView(emptyView);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    listView = new RecyclerListView(context);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setEmptyView(emptyView);
    listView.setAdapter(adapter = new GroupCreateAdapter(context));
    listView.setLayoutManager(linearLayoutManager);
    listView.setVerticalScrollBarEnabled(false);
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT);
    listView.addItemDecoration(itemDecoration = new GroupCreateDividerItemDecoration());
    frameLayout.addView(listView);
    listView.setOnItemClickListener((view, position) -> {
        if (position == 0 && adapter.inviteViaLink != 0 && !adapter.searching) {
            sharedLinkBottomSheet = new PermanentLinkBottomSheet(context, false, this, info, chatId, channelId != 0);
            showDialog(sharedLinkBottomSheet);
        } else if (view instanceof GroupCreateUserCell) {
            GroupCreateUserCell cell = (GroupCreateUserCell) view;
            Object object = cell.getObject();
            long id;
            if (object instanceof TLRPC.User) {
                id = ((TLRPC.User) object).id;
            } else if (object instanceof TLRPC.Chat) {
                id = -((TLRPC.Chat) object).id;
            } else {
                return;
            }
            if (ignoreUsers != null && ignoreUsers.indexOfKey(id) >= 0) {
                return;
            }
            boolean exists;
            if (exists = selectedContacts.indexOfKey(id) >= 0) {
                GroupCreateSpan span = selectedContacts.get(id);
                spansContainer.removeSpan(span);
            } else {
                if (maxCount != 0 && selectedContacts.size() == maxCount) {
                    return;
                }
                if (chatType == ChatObject.CHAT_TYPE_CHAT && selectedContacts.size() == getMessagesController().maxGroupCount) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(LocaleController.getString("SoftUserLimitAlert", R.string.SoftUserLimitAlert));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    showDialog(builder.create());
                    return;
                }
                if (object instanceof TLRPC.User) {
                    TLRPC.User user = (TLRPC.User) object;
                    if (addToGroup && user.bot) {
                        if (channelId == 0 && user.bot_nochats) {
                            try {
                                BulletinFactory.of(this).createErrorBulletin(LocaleController.getString("BotCantJoinGroups", R.string.BotCantJoinGroups)).show();
                            } catch (Exception e) {
                                FileLog.e(e);
                            }
                            return;
                        }
                        if (channelId != 0) {
                            TLRPC.Chat chat = getMessagesController().getChat(channelId);
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            if (ChatObject.canAddAdmins(chat)) {
                                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                builder.setMessage(LocaleController.getString("AddBotAsAdmin", R.string.AddBotAsAdmin));
                                builder.setPositiveButton(LocaleController.getString("MakeAdmin", R.string.MakeAdmin), (dialogInterface, i) -> {
                                    delegate2.needAddBot(user);
                                    if (editText.length() > 0) {
                                        editText.setText(null);
                                    }
                                });
                                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                            } else {
                                builder.setMessage(LocaleController.getString("CantAddBotAsAdmin", R.string.CantAddBotAsAdmin));
                                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                            }
                            showDialog(builder.create());
                            return;
                        }
                    }
                    getMessagesController().putUser(user, !searching);
                } else {
                    TLRPC.Chat chat = (TLRPC.Chat) object;
                    getMessagesController().putChat(chat, !searching);
                }
                GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), object);
                spansContainer.addSpan(span);
                span.setOnClickListener(GroupCreateActivity.this);
            }
            updateHint();
            if (searching || searchWas) {
                AndroidUtilities.showKeyboard(editText);
            } else {
                cell.setChecked(!exists, true);
            }
            if (editText.length() > 0) {
                editText.setText(null);
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                editText.hideActionMode();
                AndroidUtilities.hideKeyboard(editText);
            }
        }
    });
    listView.setAnimateEmptyView(true, 0);
    floatingButton = new ImageView(context);
    floatingButton.setScaleType(ImageView.ScaleType.CENTER);
    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButton.setBackgroundDrawable(drawable);
    floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    if (isNeverShare || isAlwaysShare || addToGroup) {
        floatingButton.setImageResource(R.drawable.floating_check);
    } else {
        BackDrawable backDrawable = new BackDrawable(false);
        backDrawable.setArrowRotation(180);
        floatingButton.setImageDrawable(backDrawable);
    }
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
        floatingButton.setStateListAnimator(animator);
        floatingButton.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    frameLayout.addView(floatingButton);
    floatingButton.setOnClickListener(v -> onDonePressed(true));
    if (chatType != ChatObject.CHAT_TYPE_CHANNEL) {
        floatingButton.setVisibility(View.INVISIBLE);
        floatingButton.setScaleX(0.0f);
        floatingButton.setScaleY(0.0f);
        floatingButton.setAlpha(0.0f);
    }
    floatingButton.setContentDescription(LocaleController.getString("Next", R.string.Next));
    updateHint();
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Rect(android.graphics.Rect) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) Keep(androidx.annotation.Keep) StateListAnimator(android.animation.StateListAnimator) TextCell(org.telegram.ui.Cells.TextCell) View(android.view.View) GroupCreateDividerItemDecoration(org.telegram.ui.Components.GroupCreateDividerItemDecoration) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) VerticalPositionAutoAnimator(org.telegram.ui.Components.VerticalPositionAutoAnimator) ForegroundColorSpan(android.text.style.ForegroundColorSpan) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Utilities(org.telegram.messenger.Utilities) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan) GroupCreateUserCell(org.telegram.ui.Cells.GroupCreateUserCell) PermanentLinkBottomSheet(org.telegram.ui.Components.PermanentLinkBottomSheet) ObjectAnimator(android.animation.ObjectAnimator) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) SearchAdapterHelper(org.telegram.ui.Adapters.SearchAdapterHelper) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) EditorInfo(android.view.inputmethod.EditorInfo) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) TextWatcher(android.text.TextWatcher) Context(android.content.Context) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) LocaleController(org.telegram.messenger.LocaleController) GroupCreateSectionCell(org.telegram.ui.Cells.GroupCreateSectionCell) Editable(android.text.Editable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) Menu(android.view.Menu) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) Build(android.os.Build) LongSparseArray(androidx.collection.LongSparseArray) DialogObject(org.telegram.messenger.DialogObject) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) ContactsController(org.telegram.messenger.ContactsController) ViewTreeObserver(android.view.ViewTreeObserver) Comparator(java.util.Comparator) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SpannableStringBuilder(android.text.SpannableStringBuilder) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) VerticalPositionAutoAnimator(org.telegram.ui.Components.VerticalPositionAutoAnimator) ImageView(android.widget.ImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) ActionMode(android.view.ActionMode) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TLObject(org.telegram.tgnet.TLObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan) StateListAnimator(android.animation.StateListAnimator) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) GroupCreateUserCell(org.telegram.ui.Cells.GroupCreateUserCell) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) KeyEvent(android.view.KeyEvent) PermanentLinkBottomSheet(org.telegram.ui.Components.PermanentLinkBottomSheet) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Menu(android.view.Menu) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) Outline(android.graphics.Outline) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) GroupCreateDividerItemDecoration(org.telegram.ui.Components.GroupCreateDividerItemDecoration) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 23 with StateListAnimator

use of android.animation.StateListAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class GroupCreateFinalActivity method createView.

@Override
public View createView(Context context) {
    if (editText != null) {
        editText.onDestroy();
    }
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    SizeNotifierFrameLayout sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {

        private boolean ignoreLayout;

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(widthSize, heightSize);
            heightSize -= getPaddingTop();
            measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
            int keyboardSize = measureKeyboardHeight();
            if (keyboardSize > AndroidUtilities.dp(20)) {
                ignoreLayout = true;
                editText.hideEmojiView();
                ignoreLayout = false;
            }
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE || child == actionBar) {
                    continue;
                }
                if (editText != null && editText.isPopupView(child)) {
                    if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
                        if (AndroidUtilities.isTablet()) {
                            child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
                        } else {
                            child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
                        }
                    } else {
                        child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
                    }
                } 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();
            int keyboardSize = measureKeyboardHeight();
            int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? editText.getEmojiPadding() : 0;
            setBottomClip(paddingBottom);
            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();
                        break;
                    case Gravity.CENTER_VERTICAL:
                        childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                        break;
                    case Gravity.BOTTOM:
                        childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
                        break;
                    default:
                        childTop = lp.topMargin;
                }
                if (editText != null && editText.isPopupView(child)) {
                    if (AndroidUtilities.isTablet()) {
                        childTop = getMeasuredHeight() - child.getMeasuredHeight();
                    } else {
                        childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
                    }
                }
                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }
            notifyHeightChanged();
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }
    };
    fragmentView = sizeNotifierFrameLayout;
    fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    fragmentView.setOnTouchListener((v, event) -> true);
    shadowDrawable = context.getResources().getDrawable(R.drawable.greydivider_top).mutate();
    LinearLayout linearLayout = new LinearLayout(context) {

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == listView && shadowDrawable != null) {
                int y = editTextContainer.getMeasuredHeight();
                shadowDrawable.setBounds(0, y, getMeasuredWidth(), y + shadowDrawable.getIntrinsicHeight());
                shadowDrawable.draw(canvas);
            }
            return result;
        }
    };
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    sizeNotifierFrameLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    editTextContainer = new FrameLayout(context);
    linearLayout.addView(editTextContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    avatarImage = new BackupImageView(context) {

        @Override
        public void invalidate() {
            if (avatarOverlay != null) {
                avatarOverlay.invalidate();
            }
            super.invalidate();
        }

        @Override
        public void invalidate(int l, int t, int r, int b) {
            if (avatarOverlay != null) {
                avatarOverlay.invalidate();
            }
            super.invalidate(l, t, r, b);
        }
    };
    avatarImage.setRoundRadius(AndroidUtilities.dp(32));
    avatarDrawable.setInfo(5, null, null);
    avatarImage.setImageDrawable(avatarDrawable);
    avatarImage.setContentDescription(LocaleController.getString("ChoosePhoto", R.string.ChoosePhoto));
    editTextContainer.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 16, LocaleController.isRTL ? 16 : 0, 16));
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0x55000000);
    avatarOverlay = new View(context) {

        @Override
        protected void onDraw(Canvas canvas) {
            if (avatarImage != null && avatarProgressView.getVisibility() == VISIBLE) {
                paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha() * avatarProgressView.getAlpha()));
                canvas.drawCircle(getMeasuredWidth() / 2.0f, getMeasuredHeight() / 2.0f, getMeasuredWidth() / 2.0f, paint);
            }
        }
    };
    editTextContainer.addView(avatarOverlay, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 16, LocaleController.isRTL ? 16 : 0, 16));
    avatarOverlay.setOnClickListener(view -> {
        imageUpdater.openMenu(avatar != null, () -> {
            avatar = null;
            avatarBig = null;
            inputPhoto = null;
            inputVideo = null;
            inputVideoPath = null;
            videoTimestamp = 0;
            showAvatarProgress(false, true);
            avatarImage.setImage(null, null, avatarDrawable, null);
            avatarEditor.setAnimation(cameraDrawable);
            cameraDrawable.setCurrentFrame(0);
        }, dialog -> {
            if (!imageUpdater.isUploadingImage()) {
                cameraDrawable.setCustomEndFrame(86);
                avatarEditor.playAnimation();
            } else {
                cameraDrawable.setCurrentFrame(0, false);
            }
        });
        cameraDrawable.setCurrentFrame(0);
        cameraDrawable.setCustomEndFrame(43);
        avatarEditor.playAnimation();
    });
    cameraDrawable = new RLottieDrawable(R.raw.camera, "" + R.raw.camera, AndroidUtilities.dp(60), AndroidUtilities.dp(60), false, null);
    avatarEditor = new RLottieImageView(context) {

        @Override
        public void invalidate(int l, int t, int r, int b) {
            super.invalidate(l, t, r, b);
            avatarOverlay.invalidate();
        }

        @Override
        public void invalidate() {
            super.invalidate();
            avatarOverlay.invalidate();
        }
    };
    avatarEditor.setScaleType(ImageView.ScaleType.CENTER);
    avatarEditor.setAnimation(cameraDrawable);
    avatarEditor.setEnabled(false);
    avatarEditor.setClickable(false);
    avatarEditor.setPadding(AndroidUtilities.dp(2), 0, 0, AndroidUtilities.dp(1));
    editTextContainer.addView(avatarEditor, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 16, LocaleController.isRTL ? 16 : 0, 16));
    avatarProgressView = new RadialProgressView(context) {

        @Override
        public void setAlpha(float alpha) {
            super.setAlpha(alpha);
            avatarOverlay.invalidate();
        }
    };
    avatarProgressView.setSize(AndroidUtilities.dp(30));
    avatarProgressView.setProgressColor(0xffffffff);
    avatarProgressView.setNoProgress(false);
    editTextContainer.addView(avatarProgressView, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 16, LocaleController.isRTL ? 16 : 0, 16));
    showAvatarProgress(false, false);
    editText = new EditTextEmoji(context, sizeNotifierFrameLayout, this, EditTextEmoji.STYLE_FRAGMENT);
    editText.setHint(chatType == ChatObject.CHAT_TYPE_CHAT || chatType == ChatObject.CHAT_TYPE_MEGAGROUP ? LocaleController.getString("EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder) : LocaleController.getString("EnterListName", R.string.EnterListName));
    if (nameToSet != null) {
        editText.setText(nameToSet);
        nameToSet = null;
    }
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(100);
    editText.setFilters(inputFilters);
    editTextContainer.addView(editText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 5 : 96, 0, LocaleController.isRTL ? 96 : 5, 0));
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    listView = new RecyclerListView(context);
    listView.setAdapter(adapter = new GroupCreateAdapter(context));
    listView.setLayoutManager(linearLayoutManager);
    listView.setVerticalScrollBarEnabled(false);
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT);
    GroupCreateDividerItemDecoration decoration = new GroupCreateDividerItemDecoration();
    decoration.setSkipRows(currentGroupCreateAddress != null ? 5 : 2);
    listView.addItemDecoration(decoration);
    linearLayout.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(editText);
            }
        }
    });
    listView.setOnItemClickListener((view, position) -> {
        if (view instanceof TextSettingsCell) {
            if (!AndroidUtilities.isGoogleMapsInstalled(GroupCreateFinalActivity.this)) {
                return;
            }
            LocationActivity fragment = new LocationActivity(LocationActivity.LOCATION_TYPE_GROUP);
            fragment.setDialogId(0);
            fragment.setDelegate((location, live, notify, scheduleDate) -> {
                currentGroupCreateLocation.setLatitude(location.geo.lat);
                currentGroupCreateLocation.setLongitude(location.geo._long);
                currentGroupCreateAddress = location.address;
            });
            presentFragment(fragment);
        }
    });
    floatingButtonContainer = new FrameLayout(context);
    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButtonContainer.setBackgroundDrawable(drawable);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
        floatingButtonContainer.setStateListAnimator(animator);
        floatingButtonContainer.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    VerticalPositionAutoAnimator.attach(floatingButtonContainer);
    sizeNotifierFrameLayout.addView(floatingButtonContainer, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
    floatingButtonContainer.setOnClickListener(view -> {
        if (donePressed) {
            return;
        }
        if (editText.length() == 0) {
            Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
            if (v != null) {
                v.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        donePressed = true;
        AndroidUtilities.hideKeyboard(editText);
        editText.setEnabled(false);
        if (imageUpdater.isUploadingImage()) {
            createAfterUpload = true;
        } else {
            showEditDoneProgress(true);
            reqId = getMessagesController().createChat(editText.getText().toString(), selectedContacts, null, chatType, forImport, currentGroupCreateLocation, currentGroupCreateAddress, GroupCreateFinalActivity.this);
        }
    });
    floatingButtonIcon = new ImageView(context);
    floatingButtonIcon.setScaleType(ImageView.ScaleType.CENTER);
    floatingButtonIcon.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    floatingButtonIcon.setImageResource(R.drawable.checkbig);
    floatingButtonIcon.setPadding(0, AndroidUtilities.dp(2), 0, 0);
    floatingButtonContainer.setContentDescription(LocaleController.getString("Done", R.string.Done));
    floatingButtonContainer.addView(floatingButtonIcon, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60));
    progressView = new ContextProgressView(context, 1);
    progressView.setAlpha(0.0f);
    progressView.setScaleX(0.1f);
    progressView.setScaleY(0.1f);
    progressView.setVisibility(View.INVISIBLE);
    floatingButtonContainer.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    return fragmentView;
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StateListAnimator(android.animation.StateListAnimator) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerListView(org.telegram.ui.Components.RecyclerListView) BackupImageView(org.telegram.ui.Components.BackupImageView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) InputFilter(android.text.InputFilter) RadialProgressView(org.telegram.ui.Components.RadialProgressView) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) Outline(android.graphics.Outline) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) GroupCreateDividerItemDecoration(org.telegram.ui.Components.GroupCreateDividerItemDecoration) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) Vibrator(android.os.Vibrator) EditTextEmoji(org.telegram.ui.Components.EditTextEmoji) LinearLayout(android.widget.LinearLayout)

Example 24 with StateListAnimator

use of android.animation.StateListAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class LoginActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                onDoneButtonPressed();
            } else if (id == -1) {
                if (onBackPressed()) {
                    finishFragment();
                }
            }
        }
    });
    currentDoneType = DONE_TYPE_FLOATING;
    doneButtonVisible[DONE_TYPE_FLOATING] = true;
    doneButtonVisible[DONE_TYPE_ACTION] = false;
    ActionBarMenu menu = actionBar.createMenu();
    actionBar.setAllowOverlayTitle(true);
    doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneProgressView = new ContextProgressView(context, 1);
    doneProgressView.setAlpha(0.0f);
    doneProgressView.setScaleX(0.1f);
    doneProgressView.setScaleY(0.1f);
    doneProgressView.setVisibility(View.INVISIBLE);
    doneItem.setAlpha(0.0f);
    doneItem.setScaleX(0.1f);
    doneItem.setScaleY(0.1f);
    doneItem.addView(doneProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    doneItem.setContentDescription(LocaleController.getString("Done", R.string.Done));
    doneItem.setVisibility(doneButtonVisible[DONE_TYPE_ACTION] ? View.VISIBLE : View.GONE);
    FrameLayout container = new FrameLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) floatingButtonContainer.getLayoutParams();
            if (Bulletin.getVisibleBulletin() != null && Bulletin.getVisibleBulletin().isShowing()) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                marginLayoutParams.bottomMargin = AndroidUtilities.dp(14) + Bulletin.getVisibleBulletin().getLayout().getMeasuredHeight() - AndroidUtilities.dp(10);
            } else {
                marginLayoutParams.bottomMargin = AndroidUtilities.dp(14);
            }
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    fragmentView = container;
    ScrollView scrollView = new ScrollView(context) {

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

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));
    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);
    views[5] = new LoginActivityRegisterView(context);
    views[6] = new LoginActivityPasswordView(context);
    views[7] = new LoginActivityRecoverView(context);
    views[8] = new LoginActivityResetWaitView(context);
    views[9] = new LoginActivityNewPasswordView(context, 0);
    views[10] = new LoginActivityNewPasswordView(context, 1);
    views[11] = new LoginActivitySmsView(context, 11);
    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }
    Bundle savedInstanceState = loadCurrentState();
    if (savedInstanceState != null) {
        currentViewNum = savedInstanceState.getInt("currentViewNum", 0);
        syncContacts = savedInstanceState.getInt("syncContacts", 1) == 1;
        if (currentViewNum >= 1 && currentViewNum <= 4) {
            int time = savedInstanceState.getInt("open");
            if (time != 0 && Math.abs(System.currentTimeMillis() / 1000 - time) >= 24 * 60 * 60) {
                currentViewNum = 0;
                savedInstanceState = null;
                clearCurrentState();
            }
        } else if (currentViewNum == 6) {
            LoginActivityPasswordView view = (LoginActivityPasswordView) views[6];
            if (view.currentPassword == null) {
                currentViewNum = 0;
                savedInstanceState = null;
                clearCurrentState();
            }
        } else if (currentViewNum == 7) {
            LoginActivityRecoverView view = (LoginActivityRecoverView) views[7];
            if (view.passwordString == null) {
                currentViewNum = 0;
                savedInstanceState = null;
                clearCurrentState();
            }
        }
    }
    floatingButtonContainer = new FrameLayout(context);
    floatingButtonContainer.setVisibility(doneButtonVisible[DONE_TYPE_FLOATING] ? View.VISIBLE : View.GONE);
    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButtonContainer.setBackgroundDrawable(drawable);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
        floatingButtonContainer.setStateListAnimator(animator);
        floatingButtonContainer.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    VerticalPositionAutoAnimator.attach(floatingButtonContainer);
    container.addView(floatingButtonContainer, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 14, 14));
    floatingButtonContainer.setOnClickListener(view -> onDoneButtonPressed());
    floatingButtonIcon = new ImageView(context);
    floatingButtonIcon.setScaleType(ImageView.ScaleType.CENTER);
    floatingButtonIcon.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    floatingButtonIcon.setImageResource(R.drawable.actionbtn_next);
    floatingButtonContainer.setContentDescription(LocaleController.getString("Done", R.string.Done));
    floatingButtonContainer.addView(floatingButtonIcon, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60));
    floatingProgressView = new RadialProgressView(context);
    floatingProgressView.setSize(AndroidUtilities.dp(22));
    floatingProgressView.setProgressColor(Theme.getColor(Theme.key_chats_actionIcon));
    floatingProgressView.setAlpha(0.0f);
    floatingProgressView.setScaleX(0.1f);
    floatingProgressView.setScaleY(0.1f);
    floatingProgressView.setVisibility(View.INVISIBLE);
    floatingButtonContainer.addView(floatingProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    if (savedInstanceState != null) {
        restoringState = true;
    }
    for (int a = 0; a < views.length; a++) {
        if (savedInstanceState != null) {
            if (a >= 1 && a <= 4) {
                if (a == currentViewNum) {
                    views[a].restoreStateParams(savedInstanceState);
                }
            } else {
                views[a].restoreStateParams(savedInstanceState);
            }
        }
        if (currentViewNum == a) {
            actionBar.setBackButtonImage(views[a].needBackButton() || newAccount ? R.drawable.ic_ab_back : 0);
            views[a].setVisibility(View.VISIBLE);
            views[a].onShow();
            currentDoneType = DONE_TYPE_FLOATING;
            if (a == 1 || a == 2 || a == 3 || a == 4 || a == 8) {
                showDoneButton(false, false);
            } else {
                showDoneButton(true, false);
            }
            if (a == 1 || a == 2 || a == 3 || a == 4) {
                currentDoneType = DONE_TYPE_ACTION;
            }
        } else {
            views[a].setVisibility(View.GONE);
        }
    }
    restoringState = false;
    actionBar.setTitle(views[currentViewNum].getHeaderName());
    return fragmentView;
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) StateListAnimator(android.animation.StateListAnimator) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) RadialProgressView(org.telegram.ui.Components.RadialProgressView) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) Outline(android.graphics.Outline) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) SlideView(org.telegram.ui.Components.SlideView) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) BackupImageView(org.telegram.ui.Components.BackupImageView) ViewOutlineProvider(android.view.ViewOutlineProvider) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) SuppressLint(android.annotation.SuppressLint)

Example 25 with StateListAnimator

use of android.animation.StateListAnimator in project GreenHouse by utsanjan.

the class ViewUtilsLollipop method setStateListAnimatorFromAttrs.

/* JADX INFO: Access modifiers changed from: package-private */
public static void setStateListAnimatorFromAttrs(View view, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    Context context = view.getContext();
    TypedArray a = ThemeEnforcement.obtainStyledAttributes(context, attrs, STATE_LIST_ANIM_ATTRS, defStyleAttr, defStyleRes, new int[0]);
    try {
        if (a.hasValue(0)) {
            StateListAnimator sla = AnimatorInflater.loadStateListAnimator(context, a.getResourceId(0, 0));
            view.setStateListAnimator(sla);
        }
    } finally {
        a.recycle();
    }
}
Also used : Context(android.content.Context) TypedArray(android.content.res.TypedArray) StateListAnimator(android.animation.StateListAnimator)

Aggregations

StateListAnimator (android.animation.StateListAnimator)25 SuppressLint (android.annotation.SuppressLint)11 Drawable (android.graphics.drawable.Drawable)10 View (android.view.View)10 ImageView (android.widget.ImageView)10 Outline (android.graphics.Outline)9 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)9 ViewOutlineProvider (android.view.ViewOutlineProvider)9 ActionBar (org.telegram.ui.ActionBar.ActionBar)9 CombinedDrawable (org.telegram.ui.Components.CombinedDrawable)9 AnimatorSet (android.animation.AnimatorSet)8 Context (android.content.Context)8 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 RecyclerListView (org.telegram.ui.Components.RecyclerListView)8 Paint (android.graphics.Paint)7 ViewGroup (android.view.ViewGroup)7 FrameLayout (android.widget.FrameLayout)7 Animator (android.animation.Animator)6 ObjectAnimator (android.animation.ObjectAnimator)6