Search in sources :

Example 96 with ListView

use of android.widget.ListView in project Klyph by jonathangerbaud.

the class MultiSelectDragListPreference method onPrepareDialogBuilder.

@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);
    if (mEntries == null || mEntryValues == null) {
        throw new IllegalStateException("MultiSelectListPreference requires an entries array and " + "an entryValues array.");
    }
    String[] entries = new String[mEntries.length];
    for (int i = 0; i < mEntries.length; i++) {
        entries[i] = mEntries[i].toString();
    }
    boolean[] selectedItems = getSelectedItems();
    ArrayList<String> orderedList = new ArrayList<String>();
    int n = selectedItems.length;
    for (String value : mValues) {
        int index = ArrayUtils.indexOf(mEntryValues, value);
        orderedList.add(mEntries[index].toString());
    }
    for (int i = 0; i < mEntries.length; i++) {
        if (!mValues.contains(mEntryValues[i]))
            orderedList.add(mEntries[i].toString());
    }
    adapter = new ArrayAdapter<String>(getContext(), R.layout.item_list_preference_multi_drag, R.id.text, orderedList);
    listView = new DragSortListView(getContext(), null);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    listView.setDragEnabled(true);
    listView.setFloatAlpha(0.8f);
    DragSortController controller = new DragSortController(listView);
    controller.setDragHandleId(R.id.drag_handle);
    controller.setRemoveEnabled(false);
    controller.setSortEnabled(true);
    controller.setBackgroundColor(0xFFFFFF);
    controller.setDragInitMode(DragSortController.ON_DOWN);
    listView.setFloatViewManager(controller);
    listView.setOnTouchListener(controller);
    builder.setView(listView);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mPreferenceChanged = true;
            refreshNewValues();
        }
    });
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    for (int i = 0; i < n; i++) {
        listView.setItemChecked(i, i < mValues.size());
    }
    /*
		 * boolean [] checkedItems = getSelectedItems();
		 * builder.setMultiChoiceItems(mEntries, checkedItems,
		 * new DialogInterface.OnMultiChoiceClickListener() {
		 * public void onClick(DialogInterface dialog, int which, boolean 
		 * isChecked) {
		 * if (isChecked) {
		 * mPreferenceChanged |= mNewValues.add(mEntryValues[which].toString());
		 * } else {
		 * mPreferenceChanged |=
		 * mNewValues.remove(mEntryValues[which].toString());
		 * }
		 * }
		 * });
		 */
    mNewValues.clear();
    mNewValues.addAll(mValues);
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ArrayList(java.util.ArrayList) DragSortListView(com.mobeta.android.dslv.DragSortListView) DragSortListView(com.mobeta.android.dslv.DragSortListView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) DragSortController(com.mobeta.android.dslv.DragSortController)

Example 97 with ListView

use of android.widget.ListView in project SmartAndroidSource by jaychou2012.

the class AutoViewHelper method createAutoViewOnListView.

// for ListView
public View createAutoViewOnListView(int listViewId, int autoViewResId, OnScrollListener onScrollListener) {
    final ListView listView = (ListView) mActivity.findViewById(listViewId);
    if (listView.getHeaderViewsCount() != 0) {
        throw new IllegalArgumentException("use createAutoViewOnListView with headerResId parameter");
    }
    if (listView.getFooterViewsCount() != 0) {
        throw new IllegalArgumentException("autoview library doesn't support listview with footer");
    }
    mPoppyView = mLayoutInflater.inflate(autoViewResId, null);
    initAutoViewOnListView(listView, onScrollListener);
    return mPoppyView;
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Example 98 with ListView

use of android.widget.ListView in project SmartAndroidSource by jaychou2012.

the class AutoViewHelper method initAutoViewOnListView.

// for ListView
private void initAutoViewOnListView(ListView listView, final OnScrollListener onScrollListener) {
    setAutoViewOnView(listView);
    listView.setOnScrollListener(new OnScrollListener() {

        int mScrollPosition;

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (onScrollListener != null) {
                onScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
            }
            View topChild = view.getChildAt(0);
            int newScrollPosition = 0;
            if (topChild == null) {
                newScrollPosition = 0;
            } else {
                newScrollPosition = -topChild.getTop() + view.getFirstVisiblePosition() * topChild.getHeight();
            }
            if (Math.abs(newScrollPosition - mScrollPosition) >= SCROLL_DIRECTION_CHANGE_THRESHOLD) {
                onScrollPositionChanged(mScrollPosition, newScrollPosition);
            }
            mScrollPosition = newScrollPosition;
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (onScrollListener != null) {
                onScrollListener.onScrollStateChanged(view, scrollState);
            }
        }
    });
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView) AbsListView(android.widget.AbsListView) ScrollView(android.widget.ScrollView) View(android.view.View) ListView(android.widget.ListView)

Example 99 with ListView

use of android.widget.ListView in project Klyph by jonathangerbaud.

the class HListView method layoutChildren.

@Override
protected void layoutChildren() {
    final boolean blockLayoutRequests = mBlockLayoutRequests;
    if (!blockLayoutRequests) {
        mBlockLayoutRequests = true;
    } else {
        return;
    }
    try {
        super.layoutChildren();
        invalidate();
        if (mAdapter == null) {
            resetList();
            invokeOnItemScrollListener();
            return;
        }
        int childrenLeft = mListPadding.left;
        int childrenRight = getRight() - getLeft() - mListPadding.right;
        int childCount = getChildCount();
        int index = 0;
        int delta = 0;
        View sel;
        View oldSel = null;
        View oldFirst = null;
        View newSel = null;
        View focusLayoutRestoreView = null;
        // Remember stuff we will need down below
        switch(mLayoutMode) {
            case LAYOUT_SET_SELECTION:
                index = mNextSelectedPosition - mFirstPosition;
                if (index >= 0 && index < childCount) {
                    newSel = getChildAt(index);
                }
                break;
            case LAYOUT_FORCE_LEFT:
            case LAYOUT_FORCE_RIGHT:
            case LAYOUT_SPECIFIC:
            case LAYOUT_SYNC:
                break;
            case LAYOUT_MOVE_SELECTION:
            default:
                // Remember the previously selected view
                index = mSelectedPosition - mFirstPosition;
                if (index >= 0 && index < childCount) {
                    oldSel = getChildAt(index);
                }
                // Remember the previous first child
                oldFirst = getChildAt(0);
                if (mNextSelectedPosition >= 0) {
                    delta = mNextSelectedPosition - mSelectedPosition;
                }
                // Caution: newSel might be null
                newSel = getChildAt(index + delta);
        }
        boolean dataChanged = mDataChanged;
        if (dataChanged) {
            handleDataChanged();
        }
        // and calling it a day
        if (mItemCount == 0) {
            resetList();
            invokeOnItemScrollListener();
            return;
        } else if (mItemCount != mAdapter.getCount()) {
            throw new IllegalStateException("The content of the adapter has changed but " + "ListView did not receive a notification. Make sure the content of " + "your adapter is not modified from a background thread, but only " + "from the UI thread. [in ListView(" + getId() + ", " + getClass() + ") with Adapter(" + mAdapter.getClass() + ")]");
        }
        setSelectedPositionInt(mNextSelectedPosition);
        // Pull all children into the RecycleBin.
        // These views will be reused if possible
        final int firstPosition = mFirstPosition;
        final RecycleBin recycleBin = mRecycler;
        // reset the focus restoration
        View focusLayoutRestoreDirectChild = null;
        // already cached in mHeaderViews;
        if (dataChanged) {
            for (int i = 0; i < childCount; i++) {
                recycleBin.addScrapView(getChildAt(i), firstPosition + i);
            }
        } else {
            recycleBin.fillActiveViews(childCount, firstPosition);
        }
        // take focus back to us temporarily to avoid the eventual
        // call to clear focus when removing the focused child below
        // from messing things up when ViewAncestor assigns focus back
        // to someone else
        final View focusedChild = getFocusedChild();
        if (focusedChild != null) {
            // data hasn't changed, or if the focused position is a header or footer
            if (!dataChanged || isDirectChildHeaderOrFooter(focusedChild)) {
                focusLayoutRestoreDirectChild = focusedChild;
                // remember the specific view that had focus
                focusLayoutRestoreView = findFocus();
                if (focusLayoutRestoreView != null) {
                    // tell it we are going to mess with it
                    focusLayoutRestoreView.onStartTemporaryDetach();
                }
            }
            requestFocus();
        }
        /*
			 * // Remember which child, if any, had accessibility focus. final ViewRootImpl viewRootImpl = getViewRootImpl(); if (
			 * viewRootImpl != null ) { final View accessFocusedView = viewRootImpl.getAccessibilityFocusedHost(); if (
			 * accessFocusedView != null ) { final View accessFocusedChild = findAccessibilityFocusedChild( accessFocusedView ); if (
			 * accessFocusedChild != null ) { if ( !dataChanged || isDirectChildHeaderOrFooter( accessFocusedChild ) ) { // If the
			 * views won't be changing, try to maintain // focus on the current view host and (if // applicable) its virtual view.
			 * accessibilityFocusLayoutRestoreView = accessFocusedView; accessibilityFocusLayoutRestoreNode = viewRootImpl
			 * .getAccessibilityFocusedVirtualView(); } else { // Otherwise, try to maintain focus at the same // position.
			 * accessibilityFocusPosition = getPositionForView( accessFocusedChild ); } } } }
			 */
        // Clear out old views
        detachAllViewsFromParent();
        recycleBin.removeSkippedScrap();
        switch(mLayoutMode) {
            case LAYOUT_SET_SELECTION:
                if (newSel != null) {
                    sel = fillFromSelection(newSel.getLeft(), childrenLeft, childrenRight);
                } else {
                    sel = fillFromMiddle(childrenLeft, childrenRight);
                }
                break;
            case LAYOUT_SYNC:
                sel = fillSpecific(mSyncPosition, mSpecificLeft);
                break;
            case LAYOUT_FORCE_RIGHT:
                sel = fillLeft(mItemCount - 1, childrenRight);
                adjustViewsLeftOrRight();
                break;
            case LAYOUT_FORCE_LEFT:
                mFirstPosition = 0;
                sel = fillFromLeft(childrenLeft);
                adjustViewsLeftOrRight();
                break;
            case LAYOUT_SPECIFIC:
                sel = fillSpecific(reconcileSelectedPosition(), mSpecificLeft);
                break;
            case LAYOUT_MOVE_SELECTION:
                sel = moveSelection(oldSel, newSel, delta, childrenLeft, childrenRight);
                break;
            default:
                if (childCount == 0) {
                    if (!mStackFromRight) {
                        final int position = lookForSelectablePosition(0, true);
                        setSelectedPositionInt(position);
                        sel = fillFromLeft(childrenLeft);
                    } else {
                        final int position = lookForSelectablePosition(mItemCount - 1, false);
                        setSelectedPositionInt(position);
                        sel = fillLeft(mItemCount - 1, childrenRight);
                    }
                } else {
                    if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
                        sel = fillSpecific(mSelectedPosition, oldSel == null ? childrenLeft : oldSel.getLeft());
                    } else if (mFirstPosition < mItemCount) {
                        sel = fillSpecific(mFirstPosition, oldFirst == null ? childrenLeft : oldFirst.getLeft());
                    } else {
                        sel = fillSpecific(0, childrenLeft);
                    }
                }
                break;
        }
        // Flush any cached views that did not get reused above
        recycleBin.scrapActiveViews();
        if (sel != null) {
            // are focusable
            if (mItemsCanFocus && hasFocus() && !sel.hasFocus()) {
                final boolean focusWasTaken = (sel == focusLayoutRestoreDirectChild && focusLayoutRestoreView != null && focusLayoutRestoreView.requestFocus()) || sel.requestFocus();
                if (!focusWasTaken) {
                    // selected item didn't take focus, fine, but still want
                    // to make sure something else outside of the selected view
                    // has focus
                    final View focused = getFocusedChild();
                    if (focused != null) {
                        focused.clearFocus();
                    }
                    positionSelector(INVALID_POSITION, sel);
                } else {
                    sel.setSelected(false);
                    mSelectorRect.setEmpty();
                }
            } else {
                positionSelector(INVALID_POSITION, sel);
            }
            mSelectedLeft = sel.getLeft();
        } else {
            if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
                View child = getChildAt(mMotionPosition - mFirstPosition);
                if (child != null)
                    positionSelector(mMotionPosition, child);
            } else {
                mSelectedLeft = 0;
                mSelectorRect.setEmpty();
            }
            // focus (i.e. something focusable in touch mode)
            if (hasFocus() && focusLayoutRestoreView != null) {
                focusLayoutRestoreView.requestFocus();
            }
        }
        // our view hierarchy.
        if (focusLayoutRestoreView != null && focusLayoutRestoreView.getWindowToken() != null) {
            focusLayoutRestoreView.onFinishTemporaryDetach();
        }
        mLayoutMode = LAYOUT_NORMAL;
        mDataChanged = false;
        if (mPositionScrollAfterLayout != null) {
            post(mPositionScrollAfterLayout);
            mPositionScrollAfterLayout = null;
        }
        mNeedSync = false;
        setNextSelectedPositionInt(mSelectedPosition);
        updateScrollIndicators();
        if (mItemCount > 0) {
            checkSelectionChanged();
        }
        invokeOnItemScrollListener();
    } finally {
        if (!blockLayoutRequests) {
            mBlockLayoutRequests = false;
        }
    }
}
Also used : RemoteView(android.widget.RemoteViews.RemoteView) View(android.view.View) ListView(android.widget.ListView) Paint(android.graphics.Paint)

Example 100 with ListView

use of android.widget.ListView in project SmartAndroidSource by jaychou2012.

the class FadingActionBarHelperBase method createView.

public final View createView(LayoutInflater inflater) {
    //
    // Prepare everything
    mInflater = inflater;
    if (mContentView == null) {
        mContentView = inflater.inflate(mContentLayoutResId, null);
    }
    if (mHeaderView == null) {
        mHeaderView = inflater.inflate(mHeaderLayoutResId, null, false);
    }
    //
    // See if we are in a ListView, WebView or ScrollView scenario
    ListView listView = (ListView) mContentView.findViewById(android.R.id.list);
    View root;
    if (listView != null) {
        root = createListView(listView);
    } else if (mContentView instanceof ObservableWebViewWithHeader) {
        root = createWebView();
    } else {
        root = createScrollView();
    }
    if (mHeaderOverlayView == null && mHeaderOverlayLayoutResId != 0) {
        mHeaderOverlayView = inflater.inflate(mHeaderOverlayLayoutResId, mMarginView, false);
    }
    if (mHeaderOverlayView != null) {
        mMarginView.addView(mHeaderOverlayView);
    }
    // Use measured height here as an estimate of the header height, later
    // on after the layout is complete
    // we'll use the actual height
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY);
    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY);
    mHeaderView.measure(widthMeasureSpec, heightMeasureSpec);
    updateHeaderHeight(mHeaderView.getMeasuredHeight());
    root.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            int headerHeight = mHeaderContainer.getHeight();
            if (!mFirstGlobalLayoutPerformed && headerHeight != 0) {
                updateHeaderHeight(headerHeight);
                mFirstGlobalLayoutPerformed = true;
            }
        }
    });
    return root;
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) AbsListView(android.widget.AbsListView) View(android.view.View) ListView(android.widget.ListView)

Aggregations

ListView (android.widget.ListView)1104 View (android.view.View)714 AdapterView (android.widget.AdapterView)425 TextView (android.widget.TextView)371 ImageView (android.widget.ImageView)163 Intent (android.content.Intent)144 AbsListView (android.widget.AbsListView)134 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)93 ArrayAdapter (android.widget.ArrayAdapter)93 ArrayList (java.util.ArrayList)80 ViewGroup (android.view.ViewGroup)70 ListAdapter (android.widget.ListAdapter)70 OnClickListener (android.view.View.OnClickListener)65 LayoutInflater (android.view.LayoutInflater)59 Bundle (android.os.Bundle)57 Button (android.widget.Button)55 LinearLayout (android.widget.LinearLayout)47 SuppressLint (android.annotation.SuppressLint)34 DialogInterface (android.content.DialogInterface)32 ScrollView (android.widget.ScrollView)31