Search in sources :

Example 76 with AbsListView

use of android.widget.AbsListView in project XhsEmoticonsKeyboard by w446108264.

the class QqActivity method initListView.

private void initListView() {
    chattingListAdapter = new QqChattingListAdapter(this);
    List<ImMsgBean> beanList = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        ImMsgBean bean = new ImMsgBean();
        bean.setContent("Test:" + i);
        beanList.add(bean);
    }
    chattingListAdapter.addData(beanList);
    lvChat.setAdapter(chattingListAdapter);
    lvChat.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            switch(scrollState) {
                case SCROLL_STATE_FLING:
                    break;
                case SCROLL_STATE_IDLE:
                    break;
                case SCROLL_STATE_TOUCH_SCROLL:
                    ekBar.reset();
                    break;
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
}
Also used : ImMsgBean(com.xhsemoticonskeyboard.common.data.ImMsgBean) ArrayList(java.util.ArrayList) AbsListView(android.widget.AbsListView)

Example 77 with AbsListView

use of android.widget.AbsListView in project Lazy by l123456789jy.

the class ViewUtils method getAbsListViewHeightBasedOnChildren.

/**
 * get AbsListView height according to every children
 *
 * @param view view
 * @return int
 */
public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
        return 0;
    }
    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View item = adapter.getView(i, null, view);
        if (item instanceof ViewGroup) {
            item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        item.measure(0, 0);
        height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
}
Also used : LayoutParams(android.widget.RelativeLayout.LayoutParams) ViewGroup(android.view.ViewGroup) GridView(android.widget.GridView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter) Point(android.graphics.Point)

Example 78 with AbsListView

use of android.widget.AbsListView in project SeaStar by 13120241790.

the class MultiImageSelectorFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // 选择图片数量
    mDesireImageCount = getArguments().getInt(EXTRA_SELECT_COUNT);
    // 图片选择模式
    final int mode = getArguments().getInt(EXTRA_SELECT_MODE);
    // 默认选择
    if (mode == MODE_MULTI) {
        ArrayList<String> tmp = getArguments().getStringArrayList(EXTRA_DEFAULT_SELECTED_LIST);
        if (tmp != null && tmp.size() > 0) {
            resultList = tmp;
        }
    }
    mIsShowCamera = getArguments().getBoolean(EXTRA_SHOW_CAMERA, true);
    mImageAdapter = new ImageGridAdapter(getActivity(), mIsShowCamera);
    // 是否显示选择指示器
    mImageAdapter.showSelectIndicator(mode == MODE_MULTI);
    mPopupAnchorView = view.findViewById(R.id.footer);
    mTimeLineText = (TextView) view.findViewById(R.id.timeline_area);
    // 初始化,先隐藏当前timeline
    mTimeLineText.setVisibility(View.GONE);
    mCategoryText = (TextView) view.findViewById(R.id.category_btn);
    // 初始化,加载所有图片
    mCategoryText.setText(R.string.folder_all);
    mCategoryText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mFolderPopupWindow == null) {
                createPopupFolderList(mGridWidth, mGridHeight);
            }
            if (mFolderPopupWindow.isShowing()) {
                mFolderPopupWindow.dismiss();
            } else {
                mFolderPopupWindow.show();
                int index = mFolderAdapter.getSelectIndex();
                index = index == 0 ? index : index - 1;
                mFolderPopupWindow.getListView().setSelection(index);
            }
        }
    });
    mPreviewBtn = (Button) view.findViewById(R.id.preview);
    mPreviewBtn.setVisibility(View.VISIBLE);
    // 初始化,按钮状态初始化
    if (resultList == null || resultList.size() <= 0) {
        mPreviewBtn.setText(R.string.preview);
        mPreviewBtn.setEnabled(false);
    }
    mPreviewBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // TODO 预览
            Intent mIntent = new Intent(getActivity(), PreviewActivity.class);
            mIntent.putStringArrayListExtra("resultList", resultList);
            startActivityForResult(mIntent, PREVIEW_SHOW);
        }
    });
    mGridView = (GridView) view.findViewById(R.id.grid);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int state) {
            final Picasso picasso = Picasso.with(getActivity());
            if (state == SCROLL_STATE_IDLE || state == SCROLL_STATE_TOUCH_SCROLL) {
                picasso.resumeTag(getActivity());
            } else {
                picasso.pauseTag(getActivity());
            }
            if (state == SCROLL_STATE_IDLE) {
            // 停止滑动,日期指示器消失
            // mTimeLineText.setVisibility(View.GONE);
            } else if (state == SCROLL_STATE_FLING) {
                mTimeLineText.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (mTimeLineText.getVisibility() == View.VISIBLE) {
                int index = firstVisibleItem + 1 == view.getAdapter().getCount() ? view.getAdapter().getCount() - 1 : firstVisibleItem + 1;
                Image image = (Image) view.getAdapter().getItem(index);
                if (image != null) {
                    mTimeLineText.setText(TimeUtils.formatPhotoDate(image.path));
                }
            }
        }
    });
    mGridView.setAdapter(mImageAdapter);
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        public void onGlobalLayout() {
            final int width = mGridView.getWidth();
            final int height = mGridView.getHeight();
            mGridWidth = width;
            mGridHeight = height;
            final int desireSize = getResources().getDimensionPixelOffset(R.dimen.image_size);
            final int numCount = width / desireSize;
            final int columnSpace = getResources().getDimensionPixelOffset(R.dimen.space_size);
            int columnWidth = (width - columnSpace * (numCount - 1)) / numCount;
            mImageAdapter.setItemSize(columnWidth);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (mImageAdapter.isShowCamera()) {
                // 如果显示照相机,则第一个Grid显示为照相机,处理特殊逻辑
                if (i == 0) {
                    showCameraAction();
                } else {
                    // 正常操作
                    Image image = (Image) adapterView.getAdapter().getItem(i);
                    selectImageFromGrid(image, mode);
                }
            } else {
                // 正常操作
                Image image = (Image) adapterView.getAdapter().getItem(i);
                selectImageFromGrid(image, mode);
            }
        }
    });
    mFolderAdapter = new FolderAdapter(getActivity());
}
Also used : AbsListView(android.widget.AbsListView) Intent(android.content.Intent) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) Picasso(com.squareup.picasso.Picasso) AdapterView(android.widget.AdapterView) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi)

Example 79 with AbsListView

use of android.widget.AbsListView in project SunDay by iQuick.

the class JazzyHelper method onScroll.

/**
 * @see android.widget.AbsListView.OnScrollListener#onScroll
 */
@Override
public final void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    boolean shouldAnimateItems = (mFirstVisibleItem != -1 && mLastVisibleItem != -1);
    int lastVisibleItem = firstVisibleItem + visibleItemCount - 1;
    if (mIsScrolling && shouldAnimateItems) {
        setVelocity(firstVisibleItem, totalItemCount);
        int indexAfterFirst = 0;
        while (firstVisibleItem + indexAfterFirst < mFirstVisibleItem) {
            View item = view.getChildAt(indexAfterFirst);
            doJazziness(item, firstVisibleItem + indexAfterFirst, -1);
            indexAfterFirst++;
        }
        int indexBeforeLast = 0;
        while (lastVisibleItem - indexBeforeLast > mLastVisibleItem) {
            View item = view.getChildAt(lastVisibleItem - firstVisibleItem - indexBeforeLast);
            doJazziness(item, lastVisibleItem - indexBeforeLast, 1);
            indexBeforeLast++;
        }
    } else if (!shouldAnimateItems) {
        for (int i = firstVisibleItem; i < visibleItemCount; i++) {
            mAlreadyAnimatedItems.add(i);
        }
    }
    mFirstVisibleItem = firstVisibleItem;
    mLastVisibleItem = lastVisibleItem;
    notifyAdditionalOnScrollListener(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView)

Example 80 with AbsListView

use of android.widget.AbsListView in project SunDay by iQuick.

the class SwipeListViewTouchListener method makeScrollListener.

/**
 * Return ScrollListener for ListView
 *
 * @return OnScrollListener
 */
public AbsListView.OnScrollListener makeScrollListener() {
    return new AbsListView.OnScrollListener() {

        private boolean isFirstItem = false;

        private boolean isLastItem = false;

        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            if (swipeClosesAllItemsWhenListMoves && scrollState == SCROLL_STATE_TOUCH_SCROLL) {
                closeOpenedItems();
            }
            if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
                listViewMoving = true;
                setEnabled(false);
            }
            if (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_FLING && scrollState != SCROLL_STATE_TOUCH_SCROLL) {
                listViewMoving = false;
                downPosition = ListView.INVALID_POSITION;
                swipeListView.resetScrolling();
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        setEnabled(true);
                    }
                }, 500);
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (isFirstItem) {
                boolean onSecondItemList = firstVisibleItem == 1;
                if (onSecondItemList) {
                    isFirstItem = false;
                }
            } else {
                boolean onFirstItemList = firstVisibleItem == 0;
                if (onFirstItemList) {
                    isFirstItem = true;
                    swipeListView.onFirstListItem();
                }
            }
            if (isLastItem) {
                boolean onBeforeLastItemList = firstVisibleItem + visibleItemCount == totalItemCount - 1;
                if (onBeforeLastItemList) {
                    isLastItem = false;
                }
            } else {
                boolean onLastItemList = firstVisibleItem + visibleItemCount >= totalItemCount;
                if (onLastItemList) {
                    isLastItem = true;
                    swipeListView.onLastListItem();
                }
            }
        }
    };
}
Also used : AbsListView(android.widget.AbsListView) Handler(android.os.Handler)

Aggregations

AbsListView (android.widget.AbsListView)223 View (android.view.View)126 ListView (android.widget.ListView)80 AdapterView (android.widget.AdapterView)54 TextView (android.widget.TextView)46 ViewGroup (android.view.ViewGroup)33 ImageView (android.widget.ImageView)29 ScrollView (android.widget.ScrollView)23 RecyclerView (android.support.v7.widget.RecyclerView)21 GridView (android.widget.GridView)21 SuppressLint (android.annotation.SuppressLint)20 OnScrollListener (android.widget.AbsListView.OnScrollListener)19 Intent (android.content.Intent)17 ArrayList (java.util.ArrayList)16 Context (android.content.Context)12 Point (android.graphics.Point)12 Handler (android.os.Handler)12 WebView (android.webkit.WebView)12 ExpandableListView (android.widget.ExpandableListView)12 ArrayListLoader (com.klinker.android.twitter.adapters.ArrayListLoader)10