Exemplo n.º 1
0
  @SuppressLint("NewApi")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_stickylistheaders, container, false);
    StickyListHeadersListView listView =
        (StickyListHeadersListView) rootView.findViewById(R.id.activity_stickylistheaders_listview);
    listView.setFitsSystemWindows(true);

    AlphaInAnimationAdapter animationAdapter;

    MyStickyListHeadersTravelAdapter adapterTravel =
        new MyStickyListHeadersTravelAdapter(getActivity().getApplicationContext());
    animationAdapter = new AlphaInAnimationAdapter(adapterTravel);

    StickyListHeadersAdapterDecorator stickyListHeadersAdapterDecorator =
        new StickyListHeadersAdapterDecorator(animationAdapter);
    stickyListHeadersAdapterDecorator.setListViewWrapper(
        new StickyListHeadersListViewWrapper(listView));
    assert animationAdapter.getViewAnimator() != null;
    animationAdapter.getViewAnimator().setInitialDelayMillis(500);
    assert stickyListHeadersAdapterDecorator.getViewAnimator() != null;
    stickyListHeadersAdapterDecorator.getViewAnimator().setInitialDelayMillis(500);
    listView.setAdapter(stickyListHeadersAdapterDecorator);

    return rootView;
  }
  private void setupListView() {
    adapter = new ItemListApater(getActivity());
    mListview.setAdapter(adapter);
    // 出现item的效果
    AlphaInAnimationAdapter animationAdapter = new AlphaInAnimationAdapter(adapter);
    animationAdapter.setAbsListView(mListview);
    mListview.setAdapter(animationAdapter);
    // 点击事件
    mListview.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            startActivity(
                MessageDetailActivity.newIntent(
                    getContext(), index_messageList.get(position).getObjectId()));
          }
        });
    mListview.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            // 如果当前正在加载或是已经没有更多,则不继续请求
            boolean enable = false;
            if (mListview != null
                && mListview.getChildCount()
                    > mListview.getFooterViewsCount() + mListview.getHeaderViewsCount()) {

              boolean firstItemVisible = mListview.getFirstVisiblePosition() == 0;

              if (firstItemVisible) {
                View v = mListview.getChildAt(0);
                int offset = (v == null) ? view.getPaddingTop() : v.getTop();
                // Logger.d("offset:" + offset + "  paddingtop:" + view.getPaddingTop());
                if (offset == view.getPaddingTop()) {
                  enable = true;
                }
              }
            }
            // Logger.d("List Delegator refreshlayout enabled = " + enable);
            mSwipeLayout.setEnabled(enable);
            //                if (mFooter.getState() == LoadingFooter.State.Loading
            //                        || mFooter.getState() == LoadingFooter.State.TheEnd) {
            //                    return;
            //                }
            //
            //                //这里判断是否滑到了最低端
            //                if (firstVisibleItem + visibleItemCount >= totalItemCount
            //                        && totalItemCount != 0
            //                        && mAdapter.getCount() > 0) {
            //                    loadNextPage();
            //                }
          }
        });
  }
Exemplo n.º 3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    initializeInjector();
    View viewRoot = inflater.inflate(R.layout.fragment_all_events, null);
    ButterKnife.inject(this, viewRoot);
    final EventCollection eventCollection =
        (EventCollection) getArguments().getSerializable(KEY_EVENT);
    final List<Event> eventList = eventCollection.getCollection();
    final ListEventsAdapter adapter =
        new ListEventsAdapter(eventList, activity.getApplicationContext());
    AlphaInAnimationAdapter animationAdapter = new AlphaInAnimationAdapter(adapter);
    animationAdapter.setAbsListView(listAllEvents);
    listAllEvents.setAdapter(animationAdapter);
    listAllEvents.setAdapter(adapter);

    listAllEvents.enableSwipeToDismiss(
        new OnDismissCallback() {
          @Override
          public void onDismiss(@NonNull ViewGroup viewGroup, @NonNull int[] ints) {
            for (final int pos : ints) {
              eventDataSource.deleteEvent(
                  eventList.get(pos).getId(),
                  new EventCallbackBase() {
                    @Override
                    public void onSuccess() {
                      activity.runOnUiThread(
                          new Runnable() {
                            @Override
                            public void run() {
                              Toast.makeText(
                                      activity.getApplicationContext(),
                                      "Removed",
                                      Toast.LENGTH_SHORT)
                                  .show();
                              eventList.remove(pos);
                              adapter.notifyDataSetChanged();
                            }
                          });
                    }

                    @Override
                    public void onError() {}
                  });
            }
          }
        });

    listAllEvents.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            eventDataSource.getEvent(
                eventCollection.get(position),
                new AnEventCacheCallback() {
                  @Override
                  public void onSuccess(final Event event) {
                    Intent i =
                        new Intent(activity.getApplicationContext(), GenerateTeamActivity.class);
                    i.putExtra(KEY_EVENT, event);
                    startActivity(i);
                  }

                  @Override
                  public void onError() {
                    Toast.makeText(activity.getApplicationContext(), KEY_ERROR, Toast.LENGTH_SHORT)
                        .show();
                  }
                });
          }
        });

    return viewRoot;
  }