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

The following examples show how to use android.widget.listview#getPositionForView() . 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 check out the related API usage on the sidebar.
Example 1
Source File: Transition.java    From android_9.0.0_r45 with 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 File: ViewUnit.java    From Dashchan with 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
Source File: ListBuddiesLayout.java    From UltimateAndroid with 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 4
Source File: ListBuddiesLayout.java    From UltimateAndroid with 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 5
Source File: ListBuddiesLayout.java    From ListBuddies with 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
Source File: WaypointList.java    From Androzic with 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);
	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 File: TrackList.java    From Androzic with 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 File: RouteList.java    From Androzic with 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
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
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);
            }
        }
    }
}