use of android.widget.AbsListView in project Osmand by osmandapp.
the class QuickSearchListFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListView listView = getListView();
if (listView != null) {
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
scrolling = (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_IDLE);
if (scrolling) {
dialogFragment.hideKeyboard();
}
}
});
View header = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_header, null);
View footer = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_footer, null);
listView.addHeaderView(header, null, false);
listView.addFooterView(footer, null, false);
}
}
use of android.widget.AbsListView in project AndFrameWorks by scwang90.
the class AfLoadHelper method findContentView.
// <editor-fold desc="初始化布局">
public View findContentView() {
Class<?> stop = mPager instanceof Activity ? AfLoadActivity.class : AfLoadFragment.class;
LoadContentViewId id = AfReflecter.getAnnotation(mPager.getClass(), stop, LoadContentViewId.class);
if (id != null) {
return mPager.findViewById(id.value());
}
LoadContentViewId$ id$ = AfReflecter.getAnnotation(mPager.getClass(), stop, LoadContentViewId$.class);
if (id$ != null) {
Context context = AfApp.get();
if (context != null) {
int idv = context.getResources().getIdentifier(id$.value(), "id", context.getPackageName());
if (idv > 0) {
return mPager.findViewById(idv);
}
}
}
LoadContentViewType type = AfReflecter.getAnnotation(mPager.getClass(), stop, LoadContentViewType.class);
if (type != null) {
return AfApp.get().newViewQuery(mPager).$(type.value()).view();
}
Queue<View> views = new LinkedBlockingQueue<>(Collections.singletonList(mPager.getView()));
do {
View view = views.poll();
if (view != null) {
if (view instanceof AbsListView || view instanceof RecyclerView || view instanceof ScrollView || view instanceof WebView || view instanceof NestedScrollView || view instanceof ViewPager) {
return view;
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int j = 0; j < group.getChildCount(); j++) {
views.add(group.getChildAt(j));
}
}
}
} while (!views.isEmpty());
return null;
}
use of android.widget.AbsListView in project PhoneProfilesPlus by henrichg.
the class ActivateProfileListFragment method onDestroy.
@Override
public void onDestroy() {
if (isAsyncTaskPendingOrRunning()) {
this.asyncTaskContext.get().cancel(true);
}
AbsListView absListView;
if (!ApplicationPreferences.applicationActivatorGridLayout(activityDataWrapper.context))
absListView = listView;
else
absListView = gridView;
if (absListView != null)
absListView.setAdapter(null);
if (profileListAdapter != null)
profileListAdapter.release();
if (activityDataWrapper != null)
activityDataWrapper.invalidateDataWrapper();
activityDataWrapper = null;
super.onDestroy();
}
use of android.widget.AbsListView in project PhoneProfilesPlus by henrichg.
the class ActivateProfileListFragment method doOnViewCreated.
private void doOnViewCreated(View view) /*, Bundle savedInstanceState*/
{
activeProfileName = view.findViewById(R.id.act_prof_activated_profile_name);
activeProfileIcon = view.findViewById(R.id.act_prof_activated_profile_icon);
if (!ApplicationPreferences.applicationActivatorGridLayout(activityDataWrapper.context))
listView = view.findViewById(R.id.act_prof_profiles_list);
else
gridView = view.findViewById(R.id.act_prof_profiles_grid);
textViewNoData = view.findViewById(R.id.act_prof_list_empty);
progressBar = view.findViewById(R.id.act_prof_list_linla_progress);
AbsListView absListView;
if (!ApplicationPreferences.applicationActivatorGridLayout(activityDataWrapper.context))
absListView = listView;
else
absListView = gridView;
// absListView.setLongClickable(false);
absListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (!ApplicationPreferences.applicationLongClickActivation(activityDataWrapper.context))
// activateProfileWithAlert(position);
activateProfile((Profile) profileListAdapter.getItem(position));
}
});
absListView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ApplicationPreferences.applicationLongClickActivation(activityDataWrapper.context))
// activateProfileWithAlert(position);
activateProfile((Profile) profileListAdapter.getItem(position));
return false;
}
});
if (!activityDataWrapper.profileListFilled) {
LoadProfileListAsyncTask asyncTask = new LoadProfileListAsyncTask(this);
this.asyncTaskContext = new WeakReference<>(asyncTask);
asyncTask.execute();
} else {
absListView.setAdapter(profileListAdapter);
doOnStart();
}
}
use of android.widget.AbsListView in project cardslib by gabrielemariotti.
the class SwipeDismissListViewTouchListener method onTouch.
/**
* Returns an {@link AbsListView.OnScrollListener} to be added to the {@link
* ListView} using {@link ListView#setOnScrollListener(AbsListView.OnScrollListener)}.
* If a scroll listener is already assigned, the caller should still pass scroll changes through
* to this listener. This will ensure that this {@link SwipeDismissListViewTouchListener} is
* paused during list view scrolling.</p>
*
* @see SwipeDismissListViewTouchListener
*/
/*
public AbsListView.OnScrollListener makeScrollListener() {
return new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
}
@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {
}
};
}*/
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (mViewWidth < 2) {
mViewWidth = mListView.getWidth();
}
switch(motionEvent.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
{
if (mPaused) {
return false;
}
if (mSwiping) {
return true;
}
// TODO: ensure this is a finger, and set a flag
// Find the child view that was touched (perform a hit test)
Rect rect = new Rect();
int childCount = mListView.getChildCount();
int headerCount = mListView.getHeaderViewsCount();
int footerCount = mListView.getFooterViewsCount();
int[] listViewCoords = new int[2];
mListView.getLocationOnScreen(listViewCoords);
int x = (int) motionEvent.getRawX() - listViewCoords[0];
int y = (int) motionEvent.getRawY() - listViewCoords[1];
View child = null;
for (int i = headerCount; i < (childCount - footerCount); i++) {
child = mListView.getChildAt(i);
child.getHitRect(rect);
if (rect.contains(x, y)) {
mDownView = child;
break;
}
}
if (mDownView != null) {
mDownX = motionEvent.getRawX();
mDownY = motionEvent.getRawY();
mDownPosition = mListView.getPositionForView(mDownView);
if (mDownPosition != ListView.INVALID_POSITION && mDownPosition < mListView.getAdapter().getCount()) {
if (mListView.getAdapter().getItem(mDownPosition) instanceof Card) {
if (mCallbacks.canDismiss(mDownPosition, (Card) mListView.getAdapter().getItem(mDownPosition))) {
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(motionEvent);
} else {
mDownView = null;
}
} else {
mDownView = null;
}
} else {
mDownView = null;
}
}
view.onTouchEvent(motionEvent);
return true;
// return false;
}
case MotionEvent.ACTION_UP:
{
if (mVelocityTracker == null) {
break;
}
float deltaX = motionEvent.getRawX() - mDownX;
mVelocityTracker.addMovement(motionEvent);
mVelocityTracker.computeCurrentVelocity(1000);
float velocityX = mVelocityTracker.getXVelocity();
float absVelocityX = Math.abs(velocityX);
float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
boolean dismiss = false;
boolean dismissRight = false;
if (Math.abs(deltaX) > mViewWidth / swipeDistanceDivisor && mSwiping) {
dismiss = true;
dismissRight = deltaX > 0;
} else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX && mSwiping) {
// dismiss only if flinging in the same direction as dragging
dismiss = (velocityX < 0) == (deltaX < 0);
dismissRight = mVelocityTracker.getXVelocity() > 0;
}
if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
// dismiss
dismiss(mDownView, mDownPosition - mListView.getHeaderViewsCount(), dismissRight);
} else {
// cancel
mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
}
mVelocityTracker.recycle();
mVelocityTracker = null;
mDownX = 0;
mDownY = 0;
mDownView = null;
mDownPosition = ListView.INVALID_POSITION;
if (mSwiping) {
// To prevent onClick event with a fast swipe
mSwiping = false;
return true;
}
mSwiping = false;
break;
}
case MotionEvent.ACTION_CANCEL:
{
if (mVelocityTracker == null) {
break;
}
if (mDownView != null) {
// cancel
mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
}
mVelocityTracker.recycle();
mVelocityTracker = null;
mDownX = 0;
mDownY = 0;
mDownView = null;
mDownPosition = ListView.INVALID_POSITION;
mSwiping = false;
break;
}
case MotionEvent.ACTION_MOVE:
{
if (mVelocityTracker == null || mPaused) {
break;
}
mVelocityTracker.addMovement(motionEvent);
float deltaX = motionEvent.getRawX() - mDownX;
float deltaY = motionEvent.getRawY() - mDownY;
boolean movementAllowed = isSwipeMovementAllowed(deltaX);
if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2 && movementAllowed) {
mSwiping = true;
mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
mListView.requestDisallowInterceptTouchEvent(true);
// Cancel ListView's touch (un-highlighting the item)
MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
mListView.onTouchEvent(cancelEvent);
view.onTouchEvent(cancelEvent);
cancelEvent.recycle();
}
if (mSwiping) {
mDownView.setTranslationX(deltaX - mSwipingSlop);
mDownView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
return true;
}
break;
}
}
return false;
}
Aggregations