Search in sources :

Example 6 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project Signal-Android by WhisperSystems.

the class StickerManagementActivity method initView.

private void initView() {
    this.list = findViewById(R.id.sticker_management_list);
    this.adapter = new StickerManagementAdapter(GlideApp.with(this), this, DeviceProperties.shouldAllowApngStickerAnimation(this));
    list.setLayoutManager(new LinearLayoutManager(this));
    list.setAdapter(adapter);
    new ItemTouchHelper(new StickerManagementItemTouchHelper(new ItemTouchCallback())).attachToRecyclerView(list);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 7 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project Signal-Android by WhisperSystems.

the class ConversationListFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    constraintLayout = view.findViewById(R.id.constraint_layout);
    list = view.findViewById(R.id.list);
    fab = view.findViewById(R.id.fab);
    cameraFab = view.findViewById(R.id.camera_fab);
    searchEmptyState = view.findViewById(R.id.search_no_results);
    searchAction = view.findViewById(R.id.search_action);
    toolbarShadow = view.findViewById(R.id.conversation_list_toolbar_shadow);
    notificationProfileStatus = view.findViewById(R.id.conversation_list_notification_profile_status);
    proxyStatus = view.findViewById(R.id.conversation_list_proxy_status);
    unreadPaymentsDot = view.findViewById(R.id.unread_payments_indicator);
    bottomActionBar = view.findViewById(R.id.conversation_list_bottom_action_bar);
    reminderView = new Stub<>(view.findViewById(R.id.reminder));
    emptyState = new Stub<>(view.findViewById(R.id.empty_state));
    searchToolbar = new Stub<>(view.findViewById(R.id.search_toolbar));
    megaphoneContainer = new Stub<>(view.findViewById(R.id.megaphone_container));
    paymentNotificationView = new Stub<>(view.findViewById(R.id.payments_notification));
    voiceNotePlayerViewStub = new Stub<>(view.findViewById(R.id.voice_note_player));
    Toolbar toolbar = getToolbar(view);
    toolbar.setVisibility(View.VISIBLE);
    ((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
    notificationProfileStatus.setOnClickListener(v -> handleNotificationProfile());
    proxyStatus.setOnClickListener(v -> onProxyStatusClicked());
    fab.show();
    cameraFab.show();
    archiveDecoration = new ConversationListArchiveItemDecoration(new ColorDrawable(getResources().getColor(R.color.conversation_list_archive_background_end)));
    itemAnimator = new ConversationListItemAnimator();
    list.setLayoutManager(new LinearLayoutManager(requireActivity()));
    list.setItemAnimator(itemAnimator);
    list.addOnScrollListener(new ScrollListener());
    list.addItemDecoration(archiveDecoration);
    snapToTopDataObserver = new SnapToTopDataObserver(list);
    new ItemTouchHelper(new ArchiveListenerCallback(getResources().getColor(R.color.conversation_list_archive_background_start), getResources().getColor(R.color.conversation_list_archive_background_end))).attachToRecyclerView(list);
    fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), NewConversationActivity.class)));
    cameraFab.setOnClickListener(v -> {
        Permissions.with(this).request(Manifest.permission.CAMERA).ifNecessary().withRationaleDialog(getString(R.string.ConversationActivity_to_capture_photos_and_video_allow_signal_access_to_the_camera), R.drawable.ic_camera_24).withPermanentDenialDialog(getString(R.string.ConversationActivity_signal_needs_the_camera_permission_to_take_photos_or_video)).onAllGranted(() -> startActivity(MediaSelectionActivity.camera(requireContext()))).onAnyDenied(() -> Toast.makeText(requireContext(), R.string.ConversationActivity_signal_needs_camera_permissions_to_take_photos_or_video, Toast.LENGTH_LONG).show()).execute();
    });
    initializeViewModel();
    initializeListAdapters();
    initializeTypingObserver();
    initializeSearchListener();
    initializeVoiceNotePlayer();
    RatingManager.showRatingDialogIfNecessary(requireContext());
    TooltipCompat.setTooltipText(searchAction, getText(R.string.SearchToolbar_search_for_conversations_contacts_and_messages));
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) ColorDrawable(android.graphics.drawable.ColorDrawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SearchToolbar(org.thoughtcrime.securesms.components.SearchToolbar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 8 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project xabber-android by redsolution.

the class AccountListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account_list);
    toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_clear_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NavUtils.navigateUpFromSameTask(AccountListActivity.this);
        }
    });
    toolbar.setTitle(R.string.title_reordering_account);
    toolbar.inflateMenu(R.menu.toolbar_account_list);
    toolbar.setOnMenuItemClickListener(this);
    barPainter = new BarPainter(this, toolbar);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.account_list_recycler_view);
    tvSummary = (TextView) findViewById(R.id.tvSummary);
    accountListAdapter = new AccountListReorderAdapter(this, this);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(accountListAdapter);
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(accountListAdapter);
    touchHelper = new ItemTouchHelper(callback);
    touchHelper.attachToRecyclerView(recyclerView);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) SimpleItemTouchHelperCallback(com.xabber.android.ui.widget.SimpleItemTouchHelperCallback) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AccountListReorderAdapter(com.xabber.android.ui.adapter.AccountListReorderAdapter) BarPainter(com.xabber.android.ui.color.BarPainter)

Example 9 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project UltimateRecyclerView by cymcsg.

the class LauncherActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    ultimateRecyclerView = (UltimateRecyclerView) findViewById(R.id.ultimate_recycler_view);
    ultimateRecyclerView.setHasFixedSize(false);
    final List<String> stringList = new ArrayList<>();
    stringList.add("111");
    stringList.add("aaa");
    stringList.add("222");
    stringList.add("33");
    stringList.add("44");
    stringList.add("55");
    stringList.add("66");
    stringList.add("11771");
    simpleRecyclerViewAdapter = new SimpleAdapter(stringList);
    linearLayoutManager = new LinearLayoutManager(this);
    ultimateRecyclerView.setLayoutManager(linearLayoutManager);
    StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(simpleRecyclerViewAdapter);
    ultimateRecyclerView.addItemDecoration(headersDecor);
    // //        ultimateRecyclerView.setEmptyView(getResources().getIdentifier("empty_view","layout",getPackageName()));
    // ultimateRecyclerView.showEmptyView();
    // ultimateRecyclerView.enableLoadmore();
    // simpleRecyclerViewAdapter.setCustomLoadMoreView(LayoutInflater.from(this)
    // .inflate(R.layout.custom_bottom_progressbar, null));
    ultimateRecyclerView.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.custom_bottom_progressbar, null));
    ultimateRecyclerView.setParallaxHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
    // //   ultimateRecyclerView.setNormalHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
    ultimateRecyclerView.setOnParallaxScroll(new UltimateRecyclerView.OnParallaxScroll() {

        @Override
        public void onParallaxScroll(float percentage, float offset, View parallax) {
            Drawable c = toolbar.getBackground();
            c.setAlpha(Math.round(127 + percentage * 128));
            toolbar.setBackgroundDrawable(c);
        }
    });
    ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff"));
    ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    simpleRecyclerViewAdapter.insert(moreNum++ + "  Refresh things", 0);
                    ultimateRecyclerView.setRefreshing(false);
                    // ultimateRecyclerView.scrollBy(0, -50);
                    linearLayoutManager.scrollToPosition(0);
                // ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
                // simpleRecyclerViewAdapter.notifyDataSetChanged();
                }
            }, 1000);
        }
    });
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(simpleRecyclerViewAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(ultimateRecyclerView.mRecyclerView);
    simpleRecyclerViewAdapter.setOnDragStartListener(new SimpleAdapter.OnStartDragListener() {

        @Override
        public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
            mItemTouchHelper.startDrag(viewHolder);
        }
    });
    ultimateRecyclerView.reenableLoadmore();
    ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
    ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {

        @Override
        public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                public void run() {
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                    simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
                // linearLayoutManager.scrollToPositionWithOffset(maxLastVisiblePosition,-1);
                // linearLayoutManager.scrollToPosition(maxLastVisiblePosition);
                }
            }, 1000);
        }
    });
    // ultimateRecyclerView.setDefaultSwipeToRefreshColorScheme(getResources().getColor(android.R.color.holo_blue_bright),
    // getResources().getColor(android.R.color.holo_green_light),
    // getResources().getColor(android.R.color.holo_orange_light),
    // getResources().getColor(android.R.color.holo_red_light));
    // ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
    // @Override
    // public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // 
    // }
    // 
    // @Override
    // public void onDownMotionEvent() {
    // 
    // }
    // 
    // @Override
    // public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
    // //                if (observableScrollState == ObservableScrollState.DOWN) {
    // //                    ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // //                    ultimateRecyclerView.showFloatingActionMenu();
    // //                } else if (observableScrollState == ObservableScrollState.UP) {
    // //                    ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // //                    ultimateRecyclerView.hideFloatingActionMenu();
    // //                } else if (observableScrollState == ObservableScrollState.STOP) {
    // //                }
    // URLogs.d("onUpOrCancelMotionEvent");
    // if (observableScrollState == ObservableScrollState.UP) {
    // ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // ultimateRecyclerView.hideFloatingActionMenu();
    // } else if (observableScrollState == ObservableScrollState.DOWN) {
    // ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
    // ultimateRecyclerView.showFloatingActionMenu();
    // }
    // }
    // });
    ultimateRecyclerView.showFloatingButtonView();
    // 
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
    for (Type type : Type.values()) {
        spinnerAdapter.add(type.name());
    }
    spinner.setAdapter(spinnerAdapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ultimateRecyclerView.setItemAnimator(Type.values()[position].getAnimator());
            ultimateRecyclerView.getItemAnimator().setAddDuration(500);
            ultimateRecyclerView.getItemAnimator().setRemoveDuration(500);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleRecyclerViewAdapter.insert("newly added item", 1);
        }
    });
    findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleRecyclerViewAdapter.remove(1);
        }
    });
// 
}
Also used : SimpleItemTouchHelperCallback(com.marshalchen.ultimaterecyclerview.itemTouchHelper.SimpleItemTouchHelperCallback) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) StickyRecyclerHeadersDecoration(com.marshalchen.ultimaterecyclerview.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 10 with ItemTouchHelper

use of androidx.recyclerview.widget.ItemTouchHelper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ContextualCardsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getContext();
    final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
    mCardsContainer = rootView.findViewById(R.id.card_container);
    mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false);
    mCardsContainer.setLayoutManager(mLayoutManager);
    mContextualCardsAdapter = new ContextualCardsAdapter(context, this, /* lifecycleOwner */
    mContextualCardManager);
    mCardsContainer.setAdapter(mContextualCardsAdapter);
    mContextualCardManager.setListener(mContextualCardsAdapter);
    mCardsContainer.setListener(this);
    mItemTouchHelper = new ItemTouchHelper(new SwipeDismissalDelegate(mContextualCardsAdapter));
    mItemTouchHelper.attachToRecyclerView(mCardsContainer);
    return rootView;
}
Also used : Context(android.content.Context) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SwipeDismissalDelegate(com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate) View(android.view.View)

Aggregations

ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)24 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 View (android.view.View)10 Intent (android.content.Intent)3 Canvas (android.graphics.Canvas)3 NonNull (androidx.annotation.NonNull)3 Context (android.content.Context)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 Toolbar (androidx.appcompat.widget.Toolbar)2 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)2 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)2 BindView (butterknife.BindView)2 SwipeDismissalDelegate (com.android.settings.homepage.contextualcards.slices.SwipeDismissalDelegate)2 EpisodeItemViewHolder (de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder)2 ArrayList (java.util.ArrayList)2