public View getContentView() {
      if (mLocalActivityManager == null) {
        throw new IllegalStateException(
            "Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?");
      }
      final Window w = mLocalActivityManager.startActivity(mTag, mIntent);
      final View wd = w != null ? w.getDecorView() : null;
      if (mLaunchedView != wd && mLaunchedView != null) {
        if (mLaunchedView.getParent() != null) {
          mTabContent.removeView(mLaunchedView);
        }
      }
      mLaunchedView = wd;

      // XXX Set FOCUS_AFTER_DESCENDANTS on embedded activities for now so they can get
      // focus if none of their children have it. They need focus to be able to
      // display menu items.
      //
      // Replace this with something better when Bug 628886 is fixed...
      //
      if (mLaunchedView != null) {
        mLaunchedView.setVisibility(View.VISIBLE);
        mLaunchedView.setFocusableInTouchMode(true);
        ((ViewGroup) mLaunchedView).setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
      }
      return mLaunchedView;
    }
Example #2
0
 @Override
 public ViewHolder onCreateViewHolder(ViewGroup parent, int itemViewType) {
   View convertView = null;
   Context context = parent.getContext();
   if (type == RosterHelper.ACTIVE_CONTACTS) {
     convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext());
   }
   if (itemViewType == ITEM_PROTOCOL) {
     convertView = new LinearLayout(context);
     RosterItemView rosterItemView = new RosterItemView(context);
     MyImageButton imageButton = new MyImageButton(context);
     ProgressBar progressBar =
         new ProgressBar(context, null, android.R.attr.progressBarStyleInverse);
     LinearLayout.LayoutParams progressLinearLayout =
         new LinearLayout.LayoutParams(
             ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
     progressLinearLayout.gravity = Gravity.RIGHT;
     progressBar.setLayoutParams(progressLinearLayout);
     progressBar.setMax(100);
     LinearLayout.LayoutParams buttonLinearLayout =
         new LinearLayout.LayoutParams(
             ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
     buttonLinearLayout.gravity = Gravity.RIGHT;
     imageButton.setLayoutParams(buttonLinearLayout);
     LinearLayout.LayoutParams rosterLinearLayout =
         new LinearLayout.LayoutParams(
             LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
     rosterLinearLayout.gravity = Gravity.LEFT;
     rosterLinearLayout.weight = 1;
     convertView.setBackgroundColor(Scheme.getColor(R.attr.item_selected));
     rosterItemView.setLayoutParams(rosterLinearLayout);
     imageButton.setImageDrawable(SawimResources.MENU_ICON);
     ((ViewGroup) convertView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
     ((ViewGroup) convertView).addView(rosterItemView);
     ((ViewGroup) convertView).addView(progressBar);
     ((ViewGroup) convertView).addView(imageButton);
   }
   if (itemViewType == ITEM_GROUP) {
     convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext());
   }
   if (itemViewType == ITEM_CONTACT) {
     convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext());
   }
   return new ViewHolder(convertView);
 }
  @SuppressWarnings({"deprecation", "unchecked"})
  @Override
  public View onCreateView(
      final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
    final Intent intent = new Intent(getActivity(), getActivityClass());
    final Bundle args = getArguments();
    if (args != null) {
      intent.putExtras(args);
    }

    final Window w = getLocalActivityManager().startActivity(ACTIVITY_TAG, intent);
    mAttachedActivity = null;
    final Context context = w.getContext();
    if (context instanceof Activity) {
      try {
        mAttachedActivity = (A) context;
        if (context instanceof FragmentCallback) {
          ((FragmentCallback<A>) context).setCallbackFragment(this);
        }
      } catch (final ClassCastException e) {
        // This should't happen.
        e.printStackTrace();
      }
    }
    final View wd = w != null ? w.getDecorView() : null;

    if (wd != null) {
      final ViewParent parent = wd.getParent();
      if (parent != null) {
        final ViewGroup v = (ViewGroup) parent;
        v.removeView(wd);
      }

      wd.setVisibility(View.VISIBLE);
      wd.setFocusableInTouchMode(true);
      if (wd instanceof ViewGroup) {
        ((ViewGroup) wd).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
      }
    }
    return wd;
  }
Example #4
0
  /**
   * Updates scrolling, creates views if necessary .
   *
   * @param layout whether we need to update layout (remeasure).
   */
  private void update(boolean layout) {
    // Process data change.
    final int count = getCount();
    if (dataChanged) {
      if (previousSelectedObject != null)
        for (int position = 0; position < count; position++)
          if (adapter.getItem(position).equals(previousSelectedObject)) {
            selectedPosition = position;
            if (LOG) LogManager.i(this, "Found selected position: " + selectedPosition);
            break;
          }
      selectedPosition = correntPosition(selectedPosition);
    }

    // Process scrolling.
    final int width = getWidth();
    int scrollX = getScrollX();
    if (width != 0) {
      while (scrollX >= width) {
        scrollX -= width;
        initialScrollX -= width;
        selectedPosition = correntPosition(selectedPosition + 1);
        if (LOG) LogManager.i(this, "scrollX >= width: " + selectedPosition);
      }
      while (scrollX <= -width) {
        scrollX += width;
        initialScrollX += width;
        selectedPosition = correntPosition(selectedPosition - 1);
        if (LOG) LogManager.i(this, "scrollX <= -width: " + selectedPosition);
      }
    }

    // Process low count.
    if (count < 2) {
      if (LOG) LogManager.i(this, "count < 2");
      dragWasCanceled = true;
      isBeingDragged = false;
      if (!scroller.isFinished()) scroller.abortAnimation();
      if (scrollX != 0) scrollX = 0;
    }

    // Store focus.
    final View focus;
    if (selectedView != null) focus = selectedView.findFocus();
    else focus = null;

    // Process selected view.
    if (count == 0) {
      if (LOG) LogManager.i(this, "count == 0");
      selectedPosition = -1;
      if (selectedView != null) {
        if (onSelectListener != null) onSelectListener.onUnselect();
        adapter.saveState(selectedView);
        removeViewInLayout(selectedView);
        selectedView = null;
        // We must invalidate to update view.
        invalidate();
      }
    } else {
      if (LOG) LogManager.i(this, "count > 0");

      // Exchange visible and selected views and previous objects.
      final Object selectedObject = adapter.getItem(selectedPosition);
      final boolean exchange =
          previousSelectedObject != null
              && previousVisibleObject != null
              && !previousSelectedObject.equals(selectedObject)
              && previousVisibleObject.equals(selectedObject);
      if (exchange) {
        Object tempObject = previousSelectedObject;
        previousSelectedObject = previousVisibleObject;
        previousVisibleObject = tempObject;
        View view = selectedView;
        selectedView = visibleView;
        visibleView = view;
      }

      // Update view.
      final boolean update =
          dataChanged
              || previousSelectedObject == null
              || !previousSelectedObject.equals(selectedObject);
      selectedView = getView(selectedPosition, 0, selectedView, update, layout);
      previousSelectedObject = selectedObject;
      if (update || exchange) if (onSelectListener != null) onSelectListener.onSelect();

      // Enable focusable.
      if (selectedView instanceof ViewGroup)
        ((ViewGroup) selectedView).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
      else selectedView.setFocusable(true);
    }

    // Process visible (not selected) view.
    if (count < 2) {
      if (LOG) LogManager.i(this, "count < 2 || scrollX == 0");
      visiblePosition = -1;
      if (visibleView != null) {
        adapter.saveState(visibleView);
        removeViewInLayout(visibleView);
        visibleView = null;
      }
    } else {
      // Calculate position.
      final int visibleX;
      if (scrollX > 0) {
        if (LOG) LogManager.i(this, "scrollX > 0");
        visiblePosition = correntPosition(selectedPosition + 1);
        visibleX = width;
      } else {
        if (LOG) LogManager.i(this, "scrollX < 0");
        visiblePosition = correntPosition(selectedPosition - 1);
        visibleX = -width;
      }

      // Update view.
      final Object visibleObject = adapter.getItem(visiblePosition);
      final boolean update =
          dataChanged
              || previousVisibleObject == null
              || !previousVisibleObject.equals(visibleObject);
      visibleView = getView(visiblePosition, visibleX, visibleView, update, layout);
      previousVisibleObject = visibleObject;

      // Disable focusable.
      if (visibleView instanceof ViewGroup)
        ((ViewGroup) visibleView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
      else visibleView.setFocusable(false);
    }

    // Restore focus by ID.
    if (selectedView != null) {
      View target;
      if (focus == null || focus.getId() == View.NO_ID) target = null;
      else target = selectedView.findViewById(focus.getId());
      if (target == null) target = selectedView.findViewById(R.id.chat_input);
      target.requestFocus();
    }

    if (scrollX == 0) {
      if (LOG) LogManager.i(this, "Scroll X == 0");
      hidePages();
    } else {
      if (LOG) LogManager.i(this, "Scroll X != 0");
      showPages();
    }

    super.scrollTo(scrollX, 0);

    dataChanged = false;
  }