@Override
 public boolean isScrollableChildUnscrolled() {
   final AbsListView listView = getCurrentListView();
   return listView != null
       && (listView.getChildCount() == 0
           || listView.getChildAt(0).getTop() == listView.getPaddingTop());
 }
Example #2
0
  public static void scrollToPosition(
      final AbsListView listView,
      final SimpleFileListFragment.ScrollPosition pos,
      boolean immediate) {
    if (listView instanceof ListView) {
      listView.setSelectionFromTop(pos.index, pos.top);
    } else {
      listView.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              // Being unable to scroll to exact pixel without ListView
              // (or without having a god-awful animation forced)
              // we just scroll to the closest item
              int index = pos.index;
              listView.setSelection(index);
              View firstChild = listView.getChildAt(0);

              if (firstChild != null && abs(pos.top) > firstChild.getHeight() / 2) {
                listView.setSelection(index + 1);
              }
            }
          },
          immediate ? 0 : ANIM_START_DELAY);
    }
  }
  /**
   * Sets the selected view and optionally announces it through TalkBack.
   *
   * @param selectedView The {@link View} to set as the current selection.
   * @param announce Set to <code>true</code> to announce selection changes.
   */
  private void setSelectedView(View selectedView, boolean announce) {
    if (mSelectedView == selectedView) {
      return;
    }

    if (mSelectedView != null) {
      announceSelectionLost(mSelectedView);
    }

    if (selectedView != null) {
      if (selectedView instanceof AbsListView) {
        AbsListView absListView = (AbsListView) selectedView;
        View item = absListView.getSelectedView();

        if (item != null) {
          selectedView = item;
        } else {
          // We don't want to select list containers, so if there's no
          // selected element then we'll just select nothing.
          selectedView = null;
        }
      }

      if (selectedView != null && announce) {
        announceSelectionGained(selectedView);
      }
    }

    mSelectedView = selectedView;

    invalidate();
  }
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if (currentView == null) return;

    NodesAdapter nodesAdapter = new NodesAdapter(getActivity(), nodes, pickedFiles);

    if (viewType.equals(THUMBNAILS_VIEW)) nodesAdapter.setThumbnail(true);

    currentView.setAdapter(nodesAdapter);

    currentView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // Clicked node object
            Node node = (Node) parent.getAdapter().getItem(position);

            // If node is dir then open it
            if (node.isDir) {
              getContract().showNextNode(node);
            }
          }
        });

    currentView.setVisibility(View.VISIBLE);

    // Form consists of input for name, text with extension and save button
    initForm();
  }
  private static void setListener(
      Object injectedSource, Field field, String methodName, Method method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(injectedSource);

    switch (method) {
      case Click:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new EventListener(injectedSource).click(methodName));
        }
        break;
      case ItemClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new EventListener(injectedSource).itemClick(methodName));
        }
        break;
      case LongClick:
        if (obj instanceof View) {
          ((View) obj)
              .setOnLongClickListener(new EventListener(injectedSource).longClick(methodName));
        }
        break;
      case itemLongClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(
                  new EventListener(injectedSource).itemLongClick(methodName));
        }
        break;
      default:
        break;
    }
  }
  public static int getScrollY(AbsListView lv) {
    View c = lv.getChildAt(0);
    if (c == null) {
      return 0;
    }

    int firstVisiblePosition = lv.getFirstVisiblePosition();
    int scrollY = -(c.getTop());
    //        int scrollY = 0;

    sListViewItemHeights.put(lv.getFirstVisiblePosition(), c.getHeight());

    //        if(scrollY>0)
    //            Log.d("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));
    //        else
    //            Log.i("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));

    if (scrollY < 0) scrollY = 0;

    for (int i = 0; i < firstVisiblePosition; ++i) {
      //            Log.d("QuickReturnUtils", "getScrollY() : i - "+i);

      //            Log.d("QuickReturnUtils", "getScrollY() : sListViewItemHeights.get(i) -
      // "+sListViewItemHeights.get(i));

      if (sListViewItemHeights.get(i) != null) // (this is a sanity check)
      scrollY += sListViewItemHeights.get(i); // add all heights of the views that are gone
    }

    //        Log.d("QuickReturnUtils", "getScrollY() : scrollY - "+scrollY);

    return scrollY;
  }
 public ViewHolderHelper setClickListener(
     int viewId, AdapterView.OnItemClickListener listener, Object tag) {
   AbsListView absListView = findViewById(viewId);
   absListView.setOnItemClickListener(listener);
   absListView.setTag(tag);
   return this;
 }
 public DropdownContainer(
     Context context,
     int layout_id,
     Drawable background,
     DropdownAdapter adapter,
     OnItemClickListener listener) {
   super(context);
   int m = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
   AbsListView content = (AbsListView) LayoutInflater.from(context).inflate(layout_id, null);
   if (content instanceof ListView) {
     ((ListView) content).setAdapter((BaseAdapter) adapter);
   } else if (content instanceof GridView) {
     ((GridView) content).setAdapter((BaseAdapter) adapter);
   }
   content.setOnItemClickListener(listener);
   content.measure(m, m);
   if (adapter.getRows() > adapter.getWrapRow()) {
     init(
         content,
         LayoutParams.WRAP_CONTENT,
         content.getMeasuredHeight() * adapter.getWrapRow(),
         R.style.drop_down_anim,
         background);
   } else {
     init(
         content,
         LayoutParams.WRAP_CONTENT,
         LayoutParams.WRAP_CONTENT,
         R.style.drop_down_anim,
         background);
   }
 }
Example #9
0
  public void onScrollStateChanged(AbsListView view, int scrollState) {
    switch (scrollState) {
      case OnScrollListener.SCROLL_STATE_IDLE:
        mBusy = false;

        int first = view.getFirstVisiblePosition();
        int count = view.getChildCount();
        for (int i = 0; i < count; i++) {
          TextView t = (TextView) view.getChildAt(i);
          if (t.getTag() != null) {
            t.setText(mStrings[first + i]);
            t.setTag(null);
          }
        }

        mStatus.setText("Idle");
        break;
      case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
        mBusy = true;
        mStatus.setText("Touch scroll");
        break;
      case OnScrollListener.SCROLL_STATE_FLING:
        mBusy = true;
        mStatus.setText("Fling");
        break;
    }
  }
Example #10
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item, container, false);

    // Set the adapter
    if (mAdapter != null) {
      if (isNewData()) {
        createNewAdapter();
      }
      mListView = (AbsListView) view.findViewById(android.R.id.list);
      mListView.setAdapter(mAdapter);
      // Set OnItemClickListener so we can be notified on item clicks
      mListView.setOnItemClickListener(this);
    } else {
      TextView noRestaurantView = (TextView) view.findViewById(R.id.noRestaurantView);
      noRestaurantView.setText("There aren't  any restaurants.");
    }

    FloatingActionButton addRestaurantButton =
        (FloatingActionButton) view.findViewById(R.id.addRestaurant);
    addRestaurantButton.setOnClickListener(this);
    mListener = (OnFragmentInteractionListener) getActivity();
    return view;
  }
Example #11
0
  /**
   * 设置view的监听器.
   *
   * @param field the field
   * @param methodName the method name
   * @param method the method
   * @throws Exception the exception
   */
  private void setListener(Field field, String methodName, int method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(this);

    switch (method) {
      case AbIocEventListener.CLICK:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new AbIocEventListener(this).click(methodName));
        }
        break;
      case AbIocEventListener.ITEMCLICK:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new AbIocEventListener(this).itemClick(methodName));
        }
        break;
      case AbIocEventListener.LONGCLICK:
        if (obj instanceof View) {
          ((View) obj).setOnLongClickListener(new AbIocEventListener(this).longClick(methodName));
        }
        break;
      case AbIocEventListener.ITEMLONGCLICK:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(new AbIocEventListener(this).itemLongClick(methodName));
        }
        break;
      default:
        break;
    }
  }
  /** @see 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);
  }
Example #13
0
    @Override
    public void onScroll(
        AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
      //			Log.d(TAG, "loading: "+ Boolean.toString(loading) +"totalItemCount: "+totalItemCount+
      // "visibleItemCount: " +visibleItemCount+"firstVisibleItem: "+firstVisibleItem+
      // "visibleThreshold: "+visibleThreshold);
      if (adapter.buffer != null
          && !adapter.buffer.hasPendingBacklog()
          && (firstVisibleItem <= visibleThreshold)) {
        adapter.getMoreBacklog();
      }

      // This nasty little hack is required for emulating ListView.TRANSCRIPT_MODE_NORMAL
      // functionality on GB
      if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        if (visibleItemCount == 0
            || visibleItemCount == totalItemCount
            || firstVisibleItem + visibleItemCount == totalItemCount) {
          if (view.getTranscriptMode() != AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL) {
            view.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
          }
        } else {
          if (view.getTranscriptMode() != AbsListView.TRANSCRIPT_MODE_DISABLED) {
            view.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_DISABLED);
          }
        }
      }
    }
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
     // 判断是否滚动到底部
     if (view.getLastVisiblePosition() == view.getCount() - 1) {
       getResource();
     }
   }
 }
Example #15
0
  /**
   * 是否列表处于顶部 第一项也显示完全
   *
   * @param listView
   * @return
   */
  public static boolean isListViewInTop(AbsListView listView) {
    if (null == listView) return true;

    View firstVisibleItemView = listView.getChildAt(0);
    if (null == firstVisibleItemView) {
      return true;
    }
    return listView.getFirstVisiblePosition() == 0 && firstVisibleItemView.getTop() == 0;
  }
Example #16
0
 /**
  * Sets up various helpers for both the list and grid
  *
  * @param list The list or grid
  */
 private void initAbsListView(final AbsListView list) {
   // Release any references to the recycled Views
   list.setRecyclerListener(new RecycleHolder());
   // Listen for ContextMenus to be created
   list.setOnCreateContextMenuListener(this);
   // Show the albums and songs from the selected artist
   list.setOnItemClickListener(this);
   // To help make scrolling smooth
   list.setOnScrollListener(this);
 }
  @Override
  public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (scrollState == SCROLL_STATE_IDLE
        && view.getLastVisiblePosition() >= view.getCount() - THRESHOLD
        && !mLoding) {
      mLoding = true;

      loadPhotos();
    }
  }
 @Override
 public void onScrollStateChanged(AbsListView listView, int scrollState) {
   if (scrollState == SCROLL_STATE_IDLE) {
     // load 3 (4-1) items before we reach the end of the list
     if (listView.getLastVisiblePosition() >= listView.getCount() - 4) {
       currentPage++;
       getLoaderManager().restartLoader(0, null, this);
     }
   }
 }
 public KJAdapter(AbsListView view, Collection<T> mDatas, int itemLayoutId) {
   this.mInflater = LayoutInflater.from(view.getContext());
   if (mDatas == null) {
     mDatas = new ArrayList<T>(0);
   }
   this.mDatas = mDatas;
   this.mItemLayoutId = itemLayoutId;
   this.mList = view;
   mList.setOnScrollListener(this);
 }
 @Override
 public boolean isScrolledToTop(View view) {
   AbsListView absListView = (AbsListView) view;
   if (absListView.getCount() == 0) {
     return true;
   } else if (absListView.getFirstVisiblePosition() == 0) {
     final View firstVisibleChild = absListView.getChildAt(0);
     return firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
   }
   return false;
 }
 @Override
 public void setAbsListView(AbsListView listView) {
   super.setAbsListView(listView);
   mContextualUndoListViewTouchListener = new ContextualUndoListViewTouchListener(listView, this);
   mContextualUndoListViewTouchListener.setIsParentHorizontalScrollContainer(
       isParentHorizontalScrollContainer());
   mContextualUndoListViewTouchListener.setTouchChild(getTouchChild());
   listView.setOnTouchListener(mContextualUndoListViewTouchListener);
   listView.setOnScrollListener(mContextualUndoListViewTouchListener.makeScrollListener());
   listView.setRecyclerListener(new RecycleViewListener());
 }
  public static int getScrollY(AbsListView lv) {
    View c = lv.getChildAt(0);
    if (c == null) {
      return 0;
    }

    int firstVisiblePosition = lv.getFirstVisiblePosition();
    int top = c.getTop();

    int scrollY = -top + firstVisiblePosition * c.getHeight();
    return scrollY;
  }
Example #23
0
 @Override
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   mFirstVisibleItem = firstVisibleItem;
   if (view.getFirstVisiblePosition() == 1) {
     mIsTop = true;
   } else if (view.getLastVisiblePosition() == view.getCount() - 1) {
     mIsBottom = true;
   } else {
     mIsTop = false;
     mIsBottom = false;
   }
 }
Example #24
0
  protected void whichShow(int size) {
    if (size > 0) {
      base_listview_zero_bg.setVisibility(View.GONE);
      absListView.setVisibility(View.VISIBLE);
    } else {
      base_zero_button.setText(zero_button_hint);
      base_zero_imageview.setImageResource(zero_imageview_hint);
      base_zero_textview.setText(zero_text_hint);

      base_listview_zero_bg.setVisibility(View.VISIBLE);
      absListView.setVisibility(View.INVISIBLE);
    }
  }
  /** 重新获取嵌套的内容视图 */
  private void regetNestedContentView() {
    int currentItem = mDirectViewPager.getCurrentItem();
    PagerAdapter adapter = mDirectViewPager.getAdapter();
    if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
      Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
      mNestedContentView = item.getView();

      // 清空之前的
      mNestedNormalView = null;
      mNestedAbsListView = null;
      mNestedRecyclerView = null;
      mNestedScrollView = null;
      mNestedWebView = null;

      if (mNestedContentView instanceof AbsListView) {
        mNestedAbsListView = (AbsListView) mNestedContentView;
        mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);

        if (!isHeaderViewCompleteInvisible()) {
          mNestedAbsListView.setSelection(0);
        }
      } else if (mNestedContentView instanceof RecyclerView) {
        mNestedRecyclerView = (RecyclerView) mNestedContentView;
        mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
        mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);

        if (!isHeaderViewCompleteInvisible()) {
          mNestedRecyclerView.scrollToPosition(0);
        }
      } else if (mNestedContentView instanceof ScrollView) {
        mNestedScrollView = (ScrollView) mNestedContentView;

        if (!isHeaderViewCompleteInvisible()) {
          mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
        }
      } else if (mNestedContentView instanceof WebView) {
        mNestedWebView = (WebView) mNestedContentView;

        if (!isHeaderViewCompleteInvisible()) {
          mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
        }
      } else {
        mNestedNormalView = mNestedContentView;
      }
    } else {
      throw new IllegalStateException(
          BGAStickyNavLayout.class.getSimpleName()
              + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_usercontent, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    return view;
  }
  public boolean canChildScrollUp() {
    if (Build.VERSION.SDK_INT < 14) {
      if ((this.mTarget instanceof AbsListView)) {
        AbsListView absListView = (AbsListView) this.mTarget;
        return (absListView.getChildCount() > 0)
            && ((absListView.getFirstVisiblePosition() > 0)
                || (absListView.getChildAt(0).getTop() < absListView.getPaddingTop()));
      }

      return (ViewCompat.canScrollVertically(this.mTarget, -1)) || (this.mTarget.getScrollY() > 0);
    }

    return ViewCompat.canScrollVertically(this.mTarget, -1);
  }
 /**
  * @return Whether it is possible for the child view of this layout to scroll up. Override this if
  *     the child view is a custom view.
  */
 public boolean canChildScrollUp() {
   if (android.os.Build.VERSION.SDK_INT < 14) {
     if (mTarget instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) mTarget;
       return absListView.getChildCount() > 0
           && (absListView.getFirstVisiblePosition() > 0
               || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
     } else {
       return mTarget.getScrollY() > 0;
     }
   } else {
     return ViewCompat.canScrollVertically(mTarget, -1);
   }
 }
Example #29
0
 public static boolean canChildScrollUp(View view) {
   if (android.os.Build.VERSION.SDK_INT < 14) {
     if (view instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) view;
       return absListView.getChildCount() > 0
           && (absListView.getFirstVisiblePosition() > 0
               || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
     } else {
       return view.getScrollY() > 0;
     }
   } else {
     return view.canScrollVertically(-1);
   }
 }
 private void checkAbsListView(Context context, AttributeSet attrs, View view) {
   if (view instanceof AbsListView) {
     AbsListView listView = (AbsListView) view;
     final TypedValue value = new TypedValue();
     TypedArray array =
         context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.AbsListView, 0, 0);
     array.getValue(com.android.internal.R.styleable.AbsListView_listSelector, value);
     EnvRes listSelectorRes = new EnvRes(value.resourceId);
     if (listSelectorRes.isValid()) {
       listView.setSelector(context.getResources().getDrawable(listSelectorRes.getResid()));
     }
     array.recycle();
   }
 }