use of android.widget.AbsListView.OnScrollListener in project Rashr by DsLNeXuS.
the class CardUI method setHeader.
public void setHeader(View header) {
mPlaceholderView.setVisibility(View.VISIBLE);
mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mQuickReturnHeight = mQuickReturnView.getHeight();
mListView.computeScrollY();
mCachedVerticalScrollRange = mListView.getListHeight();
}
});
mListView.setOnScrollListener(new OnScrollListener() {
@SuppressLint("NewApi")
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mScrollY = 0;
int translationY = 0;
if (mListView.scrollYIsComputed()) {
mScrollY = mListView.getComputedScrollY();
}
int rawY = mPlaceholderView.getTop() - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);
switch(mState) {
case STATE_OFFSCREEN:
if (rawY <= mMinRawY) {
mMinRawY = rawY;
} else {
mState = STATE_RETURNING;
}
translationY = rawY;
break;
case STATE_ONSCREEN:
if (rawY < -mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
}
translationY = rawY;
break;
case STATE_RETURNING:
translationY = (rawY - mMinRawY) - mQuickReturnHeight;
if (translationY > 0) {
translationY = 0;
mMinRawY = rawY - mQuickReturnHeight;
}
if (rawY > 0) {
mState = STATE_ONSCREEN;
translationY = rawY;
}
if (translationY < -mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
}
break;
}
/** this can be used if the build is below honeycomb **/
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
TranslateAnimation anim = new TranslateAnimation(0, 0, translationY, translationY);
anim.setFillAfter(true);
anim.setDuration(0);
mQuickReturnView.startAnimation(anim);
} else {
mQuickReturnView.setTranslationY(translationY);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
if (header != null) {
try {
mQuickReturnView.removeAllViews();
} catch (Exception e) {
e.printStackTrace();
}
mQuickReturnView.addView(header);
}
}
use of android.widget.AbsListView.OnScrollListener in project little-bear-dictionary by daimajia.
the class CalendarView method setUpListView.
@SuppressLint("NewApi")
private void setUpListView() {
mListView.setDivider(null);
mListView.setItemsCanFocus(true);
mListView.setVerticalScrollBarEnabled(false);
mListView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
CalendarView.this.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
CalendarView.this.onScrollStateChanged(view, scrollState);
}
});
if (VERSION.SDK_INT >= 11) {
mListView.setFriction(mFriction);
mListView.setVelocityScale(mVelocityScale);
}
}
use of android.widget.AbsListView.OnScrollListener in project MultiImageChooser by derosa.
the class MultiImageChooserActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int theme = getIntent().getIntExtra("THEME", R.style.CollageTheme);
setTheme(theme);
setContentView(R.layout.multiselectorgrid);
fileNames.clear();
maxImages = getIntent().getIntExtra(MAX_IMAGES_KEY, NOLIMIT);
unlimitedImages = maxImages == NOLIMIT;
if (!unlimitedImages) {
freeLabel = (TextView) findViewById(R.id.label_images_left);
freeLabel.setVisibility(View.VISIBLE);
updateLabel();
}
colWidth = getIntent().getIntExtra(COL_WIDTH_KEY, DEFAULT_COLUMN_WIDTH);
Display display = getWindowManager().getDefaultDisplay();
int width = 0;
if (Build.VERSION.SDK_INT >= 13) {
Point p = new Point();
display.getSize(p);
width = p.x;
} else {
width = display.getWidth();
}
gridView = (GridView) findViewById(R.id.gridview);
gridView.setColumnWidth(width / 3);
gridView.setNumColumns(3);
gridView.setOnItemClickListener(this);
gridView.setOnScrollListener(new OnScrollListener() {
private int lastFirstItem = 0;
private long timestamp = System.currentTimeMillis();
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_IDLE) {
Log.d(TAG, "IDLE - Reload!");
shouldRequestThumb = true;
ia.notifyDataSetChanged();
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
float dt = System.currentTimeMillis() - timestamp;
if (firstVisibleItem != lastFirstItem) {
double speed = 1 / dt * 1000;
lastFirstItem = firstVisibleItem;
timestamp = System.currentTimeMillis();
Log.d(TAG, "Speed: " + speed + " elements/second");
// Limitarlo si vamos a más de una página por segundo...
shouldRequestThumb = speed < visibleItemCount;
}
}
});
selectedColor = 0xff32b2e1;
// selectedColor = Color.RED;
// gridView.setBackgroundColor(bgColor);
// gridView.setBackgroundResource(R.drawable.grid_background);
ia = new ImageAdapter(this);
gridView.setAdapter(ia);
LoaderManager.enableDebugLogging(false);
getSupportLoaderManager().initLoader(CURSORLOADER_THUMBS, null, this);
getSupportLoaderManager().initLoader(CURSORLOADER_REAL, null, this);
setupHeader();
updateAcceptButton();
}
Aggregations