Exemplo n.º 1
0
  /**
   * Refreshes the content of the parent list view while maintaining the current vertical position
   * in the list view.
   */
  private void refreshListView(ViewGroup parent, Group updatedGroup) {

    // Get position of first and last visible list items
    AbsListView parentListView = (AbsListView) parent.findViewById(android.R.id.list);
    int firstVisible = parentListView.getFirstVisiblePosition();
    int lastVisible = parentListView.getLastVisiblePosition();

    // Populate list view
    mItems.clear();
    List<Group> groups = Group.getAllSortedByDisplayOrder();
    for (Group group : groups) {
      mItems.add(group.name);
    }
    notifyDataSetChanged();

    // Handle case where item is at visible top and moved up.
    if (firstVisible >= updatedGroup.getDisplayOrder()) {
      parentListView.setSelection(updatedGroup.getDisplayOrder() - 1);
      // Handle case where item is at visible bottom and moved down.
    } else if (lastVisible < updatedGroup.getDisplayOrder()) {
      parentListView.setSelection(firstVisible + 1);
      // Handle move cases in the middle of viewable listview.
    } else {
      parentListView.setSelection(firstVisible);
    }
  }
Exemplo n.º 2
0
 /** Sets up the buttons for changing the display order. TODO Replace with drag and drop handles */
 private void setupMoveButtons(int position) {
   // Stop buttons from preventing list item click event
   mMoveDown.setFocusable(false);
   mMoveDown.setFocusableInTouchMode(false);
   mMoveUp.setFocusable(false);
   mMoveUp.setFocusableInTouchMode(false);
   // Disable move down buttons for first list items.
   if (position == 0) {
     mMoveUp.setEnabled(false);
     mMoveUp.setVisibility(View.INVISIBLE);
   }
   // Disable move up button for last list item
   int last = Group.getLast().getDisplayOrder();
   if (position + 1 == last) {
     mMoveDown.setEnabled(false);
     mMoveDown.setVisibility(View.INVISIBLE);
     if (last == 2) mMoveDown.setVisibility(View.GONE);
   }
 }
Exemplo n.º 3
0
 private void setupTextLabels(int position) {
   mGroupName.setText(mItems.get(position));
   // Hide default label for non-default groups
   Group current = Group.getByDisplayOrder(position + 1);
   if (!current.isDefault()) mDefaultGroup.setVisibility(View.GONE);
 }