use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.
the class ViewPagerTabActivity method adjustToolbarForListViews.
private void adjustToolbarForListViews(ScrollState scrollState, View view) {
int toolbarHeight = mToolbarView.getHeight();
final ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
if (listView == null) {
return;
}
if (scrollState == ScrollState.UP) {
if (toolbarHeight < listView.getCurrentScrollY()) {
hideToolbar();
} else if (listView.getCurrentScrollY() < toolbarHeight) {
showToolbar();
}
} else if (scrollState == ScrollState.DOWN) {
if (toolbarHeight < listView.getCurrentScrollY()) {
showToolbar();
}
}
}
use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.
the class ViewPagerTabListViewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.observable_scroll_view_fragment_listview, container, false);
Activity parentActivity = getActivity();
final ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
listView.addHeaderView(inflater.inflate(R.layout.observable_scroll_view_padding, null));
List<String> items = new ArrayList<String>();
for (int i = 1; i <= 100; i++) {
items.add("Item " + i);
}
listView.setAdapter(new ArrayAdapter<String>(parentActivity, android.R.layout.simple_list_item_1, items));
if (parentActivity instanceof ObservableScrollViewCallbacks) {
// Scroll to the specified position after layout
Bundle args = getArguments();
if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
ViewTreeObserver vto = listView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
// scrollTo() doesn't work, should use setSelection()
listView.setSelection(initialPosition);
}
});
}
listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
}
return view;
}
use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.
the class ActionBarControlListViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.observable_scroll_view_activity_actionbarcontrollistview);
ObservableListView listView = (ObservableListView) findViewById(R.id.list);
listView.setScrollViewCallbacks(this);
List<String> items = new ArrayList<String>();
for (int i = 1; i <= 100; i++) {
items.add("Item " + i);
}
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
// ObservableListView uses setOnScrollListener, but it still works.
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
Log.v(TAG, "onScrollStateChanged: " + scrollState);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.v(TAG, "onScroll: firstVisibleItem: " + firstVisibleItem + " visibleItemCount: " + visibleItemCount + " totalItemCount: " + totalItemCount);
}
});
}
use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project Android-ObservableScrollView by ksoichiro.
the class ListViewScrollFromBottomActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ObservableListView scrollable = (ObservableListView) findViewById(R.id.scrollable);
ScrollUtils.addOnGlobalLayoutListener(scrollable, new Runnable() {
@Override
public void run() {
int count = scrollable.getAdapter().getCount() - 1;
int position = count == 0 ? 1 : count > 0 ? count : 0;
scrollable.smoothScrollToPosition(position);
scrollable.setSelection(position);
}
});
}
use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project Android-ObservableScrollView by ksoichiro.
the class ViewPagerTabListViewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_listview, container, false);
Activity parentActivity = getActivity();
final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
UiTestUtils.setDummyDataWithHeader(getActivity(), listView, inflater.inflate(R.layout.padding, null));
if (parentActivity instanceof ObservableScrollViewCallbacks) {
// Scroll to the specified position after layout
Bundle args = getArguments();
if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
ScrollUtils.addOnGlobalLayoutListener(listView, new Runnable() {
@Override
public void run() {
// scrollTo() doesn't work, should use setSelection()
listView.setSelection(initialPosition);
}
});
}
listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
}
return view;
}
Aggregations