Java Code Examples for android.widget.ListView#getPositionForView()

The following examples show how to use android.widget.ListView#getPositionForView() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: android_9.0.0_r45   File: Transition.java    License: Apache License 2.0 5 votes vote down vote up
static void addViewValues(TransitionValuesMaps transitionValuesMaps,
        View view, TransitionValues transitionValues) {
    transitionValuesMaps.viewValues.put(view, transitionValues);
    int id = view.getId();
    if (id >= 0) {
        if (transitionValuesMaps.idValues.indexOfKey(id) >= 0) {
            // Duplicate IDs cannot match by ID.
            transitionValuesMaps.idValues.put(id, null);
        } else {
            transitionValuesMaps.idValues.put(id, view);
        }
    }
    String name = view.getTransitionName();
    if (name != null) {
        if (transitionValuesMaps.nameValues.containsKey(name)) {
            // Duplicate transitionNames: cannot match by transitionName.
            transitionValuesMaps.nameValues.put(name, null);
        } else {
            transitionValuesMaps.nameValues.put(name, view);
        }
    }
    if (view.getParent() instanceof ListView) {
        ListView listview = (ListView) view.getParent();
        if (listview.getAdapter().hasStableIds()) {
            int position = listview.getPositionForView(view);
            long itemId = listview.getItemIdAtPosition(position);
            if (transitionValuesMaps.itemIdValues.indexOfKey(itemId) >= 0) {
                // Duplicate item IDs: cannot match by item ID.
                View alreadyMatched = transitionValuesMaps.itemIdValues.get(itemId);
                if (alreadyMatched != null) {
                    alreadyMatched.setHasTransientState(false);
                    transitionValuesMaps.itemIdValues.put(itemId, null);
                }
            } else {
                view.setHasTransientState(true);
                transitionValuesMaps.itemIdValues.put(itemId, view);
            }
        }
    }
}
 
Example 2
Source Project: Dashchan   File: ViewUnit.java    License: Apache License 2.0 5 votes vote down vote up
boolean handlePostForDoubleClick(final View view) {
	final PostViewHolder holder = ListViewUtils.getViewHolder(view, PostViewHolder.class);
	if (holder != null) {
		if (holder.comment.getVisibility() != View.VISIBLE || holder.comment.isSelectionEnabled()) {
			return false;
		}
		long t = System.currentTimeMillis();
		long timeout = holder.comment.getPreferredDoubleTapTimeout();
		if (t - holder.lastCommentClick > timeout) {
			holder.lastCommentClick = t;
		} else {
			final ListView listView = (ListView) view.getParent();
			final int position = listView.getPositionForView(view);
			holder.comment.startSelection();
			int padding = holder.comment.getSelectionPadding();
			if (padding > 0) {
				final int listHeight = listView.getHeight() - listView.getPaddingTop() -
						listView.getPaddingBottom();
				listView.post(() -> {
					int end = holder.comment.getSelectionEnd();
					if (end >= 0) {
						Layout layout = holder.comment.getLayout();
						int line = layout.getLineForOffset(end);
						int count = layout.getLineCount();
						if (count - line <= 4) {
							listView.setSelectionFromTop(position, listHeight - view.getHeight());
						}
					}
				});
			}
		}
		return true;
	} else {
		return false;
	}
}
 
Example 3
private void setSelectorPressed(ListView list) {
    if (mDownView != null) {
        mDownPosition = list.getPositionForView(mDownView);
        mDownView.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isUserInteracting) {
                    if (mDownView != null) {
                        mDownView.setPressed(true);
                    }
                }
            }
        }, PRESS_DELAY);
    }
}
 
Example 4
private void setSelectorPressed(ListView list) {
    if (mDownView != null) {
        mDownPosition = list.getPositionForView(mDownView);
        mDownView.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isUserInteracting) {
                    if (mDownView != null) {
                        mDownView.setPressed(true);
                    }
                }
            }
        }, PRESS_DELAY);
    }
}
 
Example 5
Source Project: ListBuddies   File: ListBuddiesLayout.java    License: Apache License 2.0 5 votes vote down vote up
private void setSelectorPressed(ListView list) {
    if (mDownView != null) {
        mDownPosition = list.getPositionForView(mDownView);
        mDownView.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isUserInteracting) {
                    if (mDownView != null) {
                        mDownView.setPressed(true);
                    }
                }
            }
        }, PRESS_DELAY);
    }
}
 
Example 6
@Override
public void onClick(View v)
{
	ListView lv = getListView();
	int position = lv.getPositionForView((View) v.getParent());
	closeItem(position);
	Waypoint waypoint = getItem(position);

	switch (v.getId())
	{
		case R.id.action_view:
			waypointActionsCallback.onWaypointView(waypoint);
			break;
		case R.id.action_navigate:
			waypointActionsCallback.onWaypointNavigate(waypoint);
			break;
		case R.id.action_edit:
			waypointActionsCallback.onWaypointEdit(waypoint);
			break;
		case R.id.action_share:
			waypointActionsCallback.onWaypointShare(waypoint);
			break;
		case R.id.action_delete:
			waypointActionsCallback.onWaypointRemove(waypoint);
			adapter.notifyDataSetChanged();
			break;
	}
}
 
Example 7
Source Project: Androzic   File: TrackList.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v)
{
	ListView lv = getListView();
	int position = lv.getPositionForView((View) v.getParent());
	closeItem(position);
	final Track track = application.getTrack(position);
	
	switch (v.getId())
	{
		case R.id.action_view:
			trackActionsCallback.onTrackView(track);
			break;
		case R.id.action_edit:
			trackActionsCallback.onTrackEdit(track);
			break;
		case R.id.action_edit_path:
			trackActionsCallback.onTrackEditPath(track);
			break;
		case R.id.action_track_to_route:
			trackActionsCallback.onTrackToRoute(track);
			break;
		case R.id.action_save:
			trackActionsCallback.onTrackSave(track);
			break;
		case R.id.action_remove:
			application.removeTrack(track);
			adapter.notifyDataSetChanged();
			break;
	}
}
 
Example 8
Source Project: Androzic   File: RouteList.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v)
{
	ListView lv = getListView();
	int position = lv.getPositionForView((View) v.getParent());
	closeItem(position);
	final Route route = getItem(position);
	
	switch (v.getId())
	{
		case R.id.action_navigate:
			routeActionsCallback.onRouteNavigate(route);
			break;
		case R.id.action_edit:
			routeActionsCallback.onRouteEdit(route);
			break;
		case R.id.action_edit_path:
			routeActionsCallback.onRouteEditPath(route);
			break;
		case R.id.action_save:
			routeActionsCallback.onRouteSave(route);
			break;
		case R.id.action_remove:
			application.removeRoute(route);
			adapter.notifyDataSetChanged();
			break;
	}
}
 
Example 9
static void addViewValues(@NonNull TransitionValuesMaps transitionValuesMaps,
                          @NonNull View view,
                          @NonNull TransitionValues transitionValues) {
    transitionValuesMaps.viewValues.put(view, transitionValues);
    int id = view.getId();
    if (id >= 0) {
        if (transitionValuesMaps.idValues.indexOfKey(id) >= 0) {
            // Duplicate IDs cannot match by ID.
            transitionValuesMaps.idValues.put(id, null);
        } else {
            transitionValuesMaps.idValues.put(id, view);
        }
    }
    String name = ViewUtils.getTransitionName(view);
    if (name != null) {
        if (transitionValuesMaps.nameValues.containsKey(name)) {
            // Duplicate transitionNames: cannot match by transitionName.
            transitionValuesMaps.nameValues.put(name, null);
        } else {
            transitionValuesMaps.nameValues.put(name, view);
        }
    }
    if (view.getParent() instanceof ListView) {
        ListView listview = (ListView) view.getParent();
        if (listview.getAdapter().hasStableIds()) {
            int position = listview.getPositionForView(view);
            long itemId = listview.getItemIdAtPosition(position);
            if (transitionValuesMaps.itemIdValues.indexOfKey(itemId) >= 0) {
                // Duplicate item IDs: cannot match by item ID.
                View alreadyMatched = transitionValuesMaps.itemIdValues.get(itemId);
                if (alreadyMatched != null) {
                    ViewUtils.setHasTransientState(alreadyMatched, false);
                    transitionValuesMaps.itemIdValues.put(itemId, null);
                }
            } else {
                ViewUtils.setHasTransientState(view, true);
                transitionValuesMaps.itemIdValues.put(itemId, view);
            }
        }
    }
}