void getHeaderViews(List<View> headers, List<Integer> positions) {
   final VerticalGridView listView = getVerticalGridView();
   if (listView == null) {
     return;
   }
   final int count = listView.getChildCount();
   for (int i = 0; i < count; i++) {
     View child = listView.getChildAt(i);
     headers.add(child);
     positions.add(listView.getChildViewHolder(child).getPosition());
   }
 }
  /** {@inheritDoc} */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (DEBUG) Log.v(TAG, "onCreateView");

    resolveTheme();
    inflater = getThemeInflater(inflater);

    View v = inflater.inflate(R.layout.lb_guidedstep_fragment, container, false);
    ViewGroup guidanceContainer = (ViewGroup) v.findViewById(R.id.content_fragment);
    ViewGroup actionContainer = (ViewGroup) v.findViewById(R.id.action_fragment);

    Guidance guidance = onCreateGuidance(savedInstanceState);
    View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
    guidanceContainer.addView(guidanceView);

    View actionsView = mActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(actionsView);

    GuidedActionAdapter.EditListener editListener =
        new GuidedActionAdapter.EditListener() {
          @Override
          public void onGuidedActionEdited(GuidedAction action, boolean entering) {
            runImeAnimations(entering);
            if (!entering) {
              GuidedStepSupportFragment.this.onGuidedActionEdited(action);
            }
          }
        };

    mAdapter = new GuidedActionAdapter(mActions, this, this, editListener, mActionsStylist);

    mListView = mActionsStylist.getActionsGridView();
    mListView.setAdapter(mAdapter);
    int pos =
        (mSelectedIndex >= 0 && mSelectedIndex < mActions.size())
            ? mSelectedIndex
            : getFirstCheckedAction();
    mListView.setSelectedPosition(pos);

    return v;
  }
  void setHeadersVisiblity(boolean show) {
    mShow = show;
    final VerticalGridView listView = getVerticalGridView();
    if (listView == null) {
      return;
    }
    final int count = listView.getChildCount();
    final int visibility = mShow ? View.VISIBLE : View.INVISIBLE;

    // we should set visibility of selected view first so that it can
    // regain the focus from parent (which is FOCUS_AFTER_DESCENDANT)
    final int selectedPosition = listView.getSelectedPosition();
    if (selectedPosition >= 0) {
      RecyclerView.ViewHolder vh = listView.findViewHolderForPosition(selectedPosition);
      if (vh != null) {
        vh.itemView.setVisibility(visibility);
      }
    }
    for (int i = 0; i < count; i++) {
      View child = listView.getChildAt(i);
      if (listView.getChildPosition(child) != selectedPosition) {
        child.setVisibility(visibility);
      }
    }
  }
Ejemplo n.º 4
0
  private void setActionView(View action) {
    mAdapter =
        new DialogActionAdapter(
            new Action.Listener() {
              @Override
              public void onActionClicked(Action action) {
                // eat events if action is disabled or only displays info
                if (!action.isEnabled() || action.infoOnly()) {
                  return;
                }

                /**
                 * If the custom lister has been set using {@link
                 * #setListener(DialogActionAdapter.Listener)}, use it. If not, use the activity's
                 * default listener.
                 */
                if (mListener != null) {
                  mListener.onActionClicked(action);
                } else if (getActivity() instanceof Action.Listener) {
                  Action.Listener listener = (Action.Listener) getActivity();
                  listener.onActionClicked(action);
                }
              }
            },
            new Action.OnFocusListener() {
              @Override
              public void onActionFocused(Action action) {
                if (getActivity() instanceof Action.OnFocusListener) {
                  Action.OnFocusListener listener = (Action.OnFocusListener) getActivity();
                  listener.onActionFocused(action);
                }
              }
            },
            mActions);

    if (action instanceof VerticalGridView) {
      mListView = (VerticalGridView) action;
    } else {
      mListView = (VerticalGridView) action.findViewById(R.id.list);
      if (mListView == null) {
        throw new IllegalStateException("No ListView exists.");
      }
      //            mListView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
      //            mListView.setWindowAlignmentOffsetPercent(0.5f);
      //            mListView.setItemAlignmentOffset(0);
      //
      // mListView.setItemAlignmentOffsetPercent(VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED);
      mListView.setWindowAlignmentOffset(0);
      mListView.setWindowAlignmentOffsetPercent(50f);
      mListView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
      View selectorView = action.findViewById(R.id.selector);
      if (selectorView != null) {
        mSelectorAnimator = new SelectorAnimator(selectorView, mListView);
        mListView.setOnScrollListener(mSelectorAnimator);
      }
    }

    mListView.requestFocusFromTouch();
    mListView.setAdapter(mAdapter);
    mListView.setSelectedPosition(
        (mSelectedIndex >= 0 && mSelectedIndex < mActions.size())
            ? mSelectedIndex
            : getFirstCheckedAction());

    action.setTag(R.id.list, mListView);
    action.setTag(R.id.selector, action.findViewById(R.id.selector));
  }
Ejemplo n.º 5
0
 public int getSelectedItemPosition() {
   return mListView.indexOfChild(mListView.getFocusedChild());
 }
Ejemplo n.º 6
0
 public void setSelectedPosition(int position) {
   mListView.setSelectedPosition(position);
 }
Ejemplo n.º 7
0
 public View getItemView(int position) {
   return mListView.getChildAt(position);
 }
 /**
  * Returns the position if the currently selected GuidedAction.
  *
  * @return position The integer position of the currently selected action.
  */
 public int getSelectedActionPosition() {
   return mListView.getSelectedPosition();
 }
 /**
  * Returns the view corresponding to the action at the indicated position in the list of actions
  * for this fragment.
  *
  * @param position The integer position of the action of interest.
  * @return The View corresponding to the action at the indicated position, or null if that action
  *     is not currently onscreen.
  */
 public View getActionItemView(int position) {
   return mListView.findViewHolderForPosition(position).itemView;
 }