Search in sources :

Example 51 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project AndroidChromium by JackyAndroid.

the class NewTabPageView method initialize.

/**
     * Initializes the NTP. This must be called immediately after inflation, before this object is
     * used in any other way.
     *
     * @param manager NewTabPageManager used to perform various actions when the user interacts
     *                with the page.
     * @param searchProviderHasLogo Whether the search provider has a logo.
     * @param scrollPosition The adapter scroll position to initialize to.
     */
public void initialize(NewTabPageManager manager, boolean searchProviderHasLogo, int scrollPosition) {
    mManager = manager;
    mUiConfig = new UiConfig(this);
    ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);
    mUseCardsUi = manager.getSuggestionsSource() != null;
    if (mUseCardsUi) {
        stub.setLayoutResource(R.layout.new_tab_page_recycler_view);
        mRecyclerView = (NewTabPageRecyclerView) stub.inflate();
        // Don't attach now, the recyclerView itself will determine when to do it.
        mNewTabPageLayout = (NewTabPageLayout) LayoutInflater.from(getContext()).inflate(R.layout.new_tab_page_layout, mRecyclerView, false);
        mNewTabPageLayout.setUseCardsUiEnabled(mUseCardsUi);
        mRecyclerView.setAboveTheFoldView(mNewTabPageLayout);
        // Tailor the LayoutParams for the snippets UI, as the configuration in the XML is
        // made for the ScrollView UI.
        ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        mRecyclerView.setItemAnimator(new DefaultItemAnimator() {

            @Override
            public void onAnimationFinished(ViewHolder viewHolder) {
                super.onAnimationFinished(viewHolder);
                // When removing sections, because the animations are all translations, the
                // scroll events don't fire and we can get in the situation where the toolbar
                // buttons disappear.
                updateSearchBoxOnScroll();
            }
        });
    } else {
        stub.setLayoutResource(R.layout.new_tab_page_scroll_view);
        mScrollView = (NewTabPageScrollView) stub.inflate();
        mScrollView.setBackgroundColor(NtpStyleUtils.getBackgroundColorResource(getResources(), false));
        mScrollView.enableBottomShadow(SHADOW_COLOR);
        mNewTabPageLayout = (NewTabPageLayout) findViewById(R.id.ntp_content);
    }
    mMostVisitedDesign = new MostVisitedDesign(getContext());
    mMostVisitedLayout = (MostVisitedLayout) mNewTabPageLayout.findViewById(R.id.most_visited_layout);
    mMostVisitedDesign.initMostVisitedLayout(searchProviderHasLogo);
    mSearchProviderLogoView = (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_logo);
    mSearchBoxView = (ViewGroup) mNewTabPageLayout.findViewById(R.id.search_box);
    mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo_spacer);
    initializeSearchBoxTextView();
    initializeVoiceSearchButton();
    initializeBottomToolbar();
    mNewTabPageLayout.addOnLayoutChangeListener(this);
    setSearchProviderHasLogo(searchProviderHasLogo);
    mPendingLoadTasks++;
    mManager.setMostVisitedURLsObserver(this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo));
    // Set up snippets
    if (mUseCardsUi) {
        mNewTabPageAdapter = NewTabPageAdapter.create(mManager, mNewTabPageLayout, mUiConfig);
        mRecyclerView.setAdapter(mNewTabPageAdapter);
        mRecyclerView.scrollToPosition(scrollPosition);
        if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) {
            int searchBoxHeight = NtpStyleUtils.getSearchBoxHeight(getResources());
            mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset(mNewTabPageAdapter.getFirstHeaderPosition(), searchBoxHeight);
        }
        // Set up swipe-to-dismiss
        ItemTouchHelper helper = new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks());
        helper.attachToRecyclerView(mRecyclerView);
        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            private boolean mScrolledOnce = false;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState != RecyclerView.SCROLL_STATE_DRAGGING)
                    return;
                RecordUserAction.record("MobileNTP.Snippets.Scrolled");
                if (mScrolledOnce)
                    return;
                mScrolledOnce = true;
                NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SCROLLED);
            }
        });
        initializeSearchBoxRecyclerViewScrollHandling();
    } else {
        initializeSearchBoxScrollHandling();
    }
}
Also used : ViewGroup(android.view.ViewGroup) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ViewStub(android.view.ViewStub) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) NewTabPageRecyclerView(org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView)

Example 52 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project MVPArms by JessYanCoding.

the class UiUtils method configRecycleView.

/**
     * 配置recycleview
     *
     * @param recyclerView
     * @param layoutManager
     */
public static void configRecycleView(final RecyclerView recyclerView, RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
Also used : DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 53 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project LeafPic by HoraApps.

the class MainActivity method initUI.

private void initUI() {
    /**** TOOLBAR ****/
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    /**** RECYCLER VIEW ****/
    rvAlbums = (RecyclerView) findViewById(R.id.grid_albums);
    rvMedia = ((RecyclerView) findViewById(R.id.grid_photos));
    rvAlbums.setHasFixedSize(true);
    rvAlbums.setItemAnimator(new DefaultItemAnimator());
    rvMedia.setHasFixedSize(true);
    rvMedia.setItemAnimator(new DefaultItemAnimator());
    albumsAdapter = new AlbumsAdapter(getAlbums().dispAlbums, MainActivity.this);
    albumsAdapter.setOnClickListener(albumOnClickListener);
    albumsAdapter.setOnLongClickListener(albumOnLongCLickListener);
    rvAlbums.setAdapter(albumsAdapter);
    mediaAdapter = new MediaAdapter(getAlbum().getMedia(), MainActivity.this);
    mediaAdapter.setOnClickListener(photosOnClickListener);
    mediaAdapter.setOnLongClickListener(photosOnLongClickListener);
    rvMedia.setAdapter(mediaAdapter);
    int spanCount = SP.getInt("n_columns_folders", 2);
    rvAlbumsDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
    rvAlbums.addItemDecoration(rvAlbumsDecoration);
    rvAlbums.setLayoutManager(new GridLayoutManager(this, spanCount));
    spanCount = SP.getInt("n_columns_media", 3);
    rvMediaDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
    rvMedia.setLayoutManager(new GridLayoutManager(getApplicationContext(), spanCount));
    rvMedia.addItemDecoration(rvMediaDecoration);
    /**** SWIPE TO REFRESH ****/
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setColorSchemeColors(getAccentColor());
    swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getBackgroundColor());
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (albumsMode) {
                getAlbums().clearSelectedAlbums();
                new PrepareAlbumTask().execute();
            } else {
                getAlbum().clearSelectedPhotos();
                new PreparePhotosTask().execute();
            }
        }
    });
    /**** DRAWER ****/
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.addDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

        public void onDrawerClosed(View view) {
        //Put your code here
        // materialMenu.animateIconState(MaterialMenuDrawable.IconState.BURGER);
        }

        public void onDrawerOpened(View drawerView) {
        //Put your code here
        //materialMenu.animateIconState(MaterialMenuDrawable.IconState.ARROW);
        }
    });
    /**** FAB ***/
    fabCamera = (FloatingActionButton) findViewById(R.id.fab_camera);
    fabCamera.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_camera_alt).color(Color.WHITE));
    fabCamera.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
        }
    });
    //region TESTING
    fabCamera.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // NOTE: this is used to acquire write permission on sd with api 21
            // TODO call this one when unable to write on sd
            requestSdCardPermissions();
            return false;
        }
    });
    //endregion
    setRecentApp(getString(R.string.app_name));
    setupUI();
}
Also used : AlbumsAdapter(org.horaapps.leafpic.adapters.AlbumsAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) MediaAdapter(org.horaapps.leafpic.adapters.MediaAdapter) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SearchView(android.support.v7.widget.SearchView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) GridSpacingItemDecoration(org.horaapps.leafpic.views.GridSpacingItemDecoration)

Example 54 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project LeafPic by HoraApps.

the class ExcludedAlbumsActivity method initUI.

private void initUI() {
    RecyclerView mRecyclerView;
    Toolbar toolbar;
    /** TOOLBAR **/
    toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
    /** RECYCLE VIEW**/
    mRecyclerView = (RecyclerView) findViewById(org.horaapps.leafpic.R.id.excluded_albums);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(new ExcludedItemsAdapter());
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setBackgroundColor(getBackgroundColor());
    /**SET UP UI COLORS**/
    toolbar.setBackgroundColor(getPrimaryColor());
    toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    setStatusBarColor();
    setNavBarColor();
    setRecentApp(getString(org.horaapps.leafpic.R.string.excluded_albums));
    findViewById(org.horaapps.leafpic.R.id.rl_ea).setBackgroundColor(getBackgroundColor());
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Toolbar(android.support.v7.widget.Toolbar)

Example 55 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project MultiPhotoPicker by wangeason.

the class PhotoPickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    showCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, true);
    boolean showGif = getIntent().getBooleanExtra(EXTRA_SHOW_GIF, false);
    multiChoose = getIntent().getBooleanExtra(EXTRA_MULTI_CHOOSE, false);
    setShowGif(showGif);
    setContentView(R.layout.activity_photo_picker);
    captureManager = new ImageCaptureManager(getActivity());
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle(R.string.images);
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        actionBar.setElevation(25);
    }
    maxCount = getIntent().getIntExtra(EXTRA_MAX_COUNT, DEFAULT_MAX_COUNT);
    minCount = getIntent().getIntExtra(EXTRA_MIN_COUNT, DEFAULT_MIN_COUNT);
    btnDoneItem = (Button) findViewById(R.id.done);
    btnDoneItem.setText(getString(R.string.done_with_count, 0, maxCount));
    btnDoneItem.setEnabled(false);
    btnDoneItem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            ArrayList<String> selectedPhotos = pickerFragment.getPhotoGridAdapter().getSelectedPhotoPaths();
            if (selectedPhotos.size() >= minCount) {
                intent.putStringArrayListExtra(KEY_SELECTED_PHOTOS, selectedPhotos);
                setResult(RESULT_OK, intent);
                finish();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(PhotoPickerActivity.this);
                builder.setTitle(R.string.choose_more).setCancelable(true).setMessage(getString(R.string.min_count_tips, minCount)).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
            }
        }
    });
    final Button btSwitchDirectory = (Button) findViewById(R.id.button);
    pickerFragment = (PhotoPickerFragment) getSupportFragmentManager().findFragmentById(R.id.photoPickerFragment);
    final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
    listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    listPopupWindow.setAnchorView(findViewById(R.id.ll_control));
    listPopupWindow.setAdapter(pickerFragment.getListAdapter());
    listPopupWindow.setModal(true);
    listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
    listPopupWindow.setAnimationStyle(R.style.Animation_AppCompat_DropDownUp);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            PhotoDirectory directory = pickerFragment.getDirectories().get(position);
            btSwitchDirectory.setText(directory.getName());
            pickerFragment.getPhotoGridAdapter().setCurrentDirectoryIndex(position);
            pickerFragment.getPhotoGridAdapter().notifyDataSetChanged();
        }
    });
    btSwitchDirectory.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (listPopupWindow.isShowing()) {
                listPopupWindow.dismiss();
            } else if (!getActivity().isFinishing()) {
                listPopupWindow.setHeight(Math.round(pickerFragment.getView().getHeight() * 0.8f));
                listPopupWindow.show();
            }
        }
    });
    multiGridAdapter = pickerFragment.getPhotoGridAdapter();
    multiGridAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, Photo photo, int selectedItemCount, int selectTimes) {
            if (multiChoose) {
                if (photo.getSelectedTimes() > 0) {
                    if (selectedItemCount >= maxCount) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                } else {
                    if (selectedItemCount >= maxCount) {
                        Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                }
            } else {
                if (maxCount <= 1) {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(0);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.clearSelection();
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        if (selectedItemCount >= maxCount) {
                            Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                        } else {
                            multiGridAdapter.add(photo);
                            multiGridAdapter.notifyItemChanged(position);
                        }
                    }
                }
            }
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
    selectedPhotoAdapter = new PhotoSelectedAdapter(getActivity(), multiGridAdapter.getSelectedPhotos());
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.selected_photos);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(selectedPhotoAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    selectedPhotoAdapter.setOnSelectedItemClickListener(new OnSelectedItemClickListener() {

        @Override
        public void onClick(View v, int position) {
            if (selectedPagerFragment != null && selectedPagerFragment.isVisible()) {
                selectedPagerFragment.getViewPager().setCurrentItem(position);
            } else {
                List<String> photos = multiGridAdapter.getSelectedPhotoPaths();
                int[] screenLocation = new int[2];
                v.getLocationOnScreen(screenLocation);
                ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, position, screenLocation, v.getWidth(), v.getHeight());
                addImagePagerFragment(imagePagerFragment, true);
            }
        }
    });
    selectedPhotoAdapter.setOnSelectedItemDelListener(new OnSelectedItemDelListener() {

        @Override
        public void onClick(int position, MultiSelectedPhoto path) {
            multiGridAdapter.getSelectedPhotos().get(position).getPhoto().del();
            multiGridAdapter.getSelectedPhotos().remove(position);
            multiGridAdapter.notifyDataSetChanged();
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ImagePagerFragment(io.github.wangeason.multiphotopicker.fragment.ImagePagerFragment) Photo(io.github.wangeason.multiphotopicker.entity.Photo) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Button(android.widget.Button) PhotoSelectedAdapter(io.github.wangeason.multiphotopicker.adapter.PhotoSelectedAdapter) OnSelectedItemClickListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemClickListener) ArrayList(java.util.ArrayList) List(java.util.List) ImageCaptureManager(io.github.wangeason.multiphotopicker.utils.ImageCaptureManager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) PhotoDirectory(io.github.wangeason.multiphotopicker.entity.PhotoDirectory) OnItemClickListener(io.github.wangeason.multiphotopicker.event.OnItemClickListener) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) OnSelectedItemDelListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemDelListener) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)103 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)71 RecyclerView (android.support.v7.widget.RecyclerView)63 View (android.view.View)55 TextView (android.widget.TextView)30 ImageView (android.widget.ImageView)25 ArrayList (java.util.ArrayList)16 GridLayoutManager (android.support.v7.widget.GridLayoutManager)14 ClickItemTouchListener (com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)14 Toolbar (android.support.v7.widget.Toolbar)13 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 FastAdapter (com.mikepenz.fastadapter.FastAdapter)10 UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)10 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)9 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)8 LocalTrack (com.sdsmdg.harjot.MusicDNA.models.LocalTrack)8 DividerItemDecoration (de.madcyph3r.example.DividerItemDecoration)8 Button (android.widget.Button)7 Random (java.util.Random)6 Intent (android.content.Intent)5