Exemplo n.º 1
0
 /**
  * 添加半透明矩形条
  *
  * @param activity 需要设置的 activity
  * @param statusBarAlpha 透明值
  */
 private static void addTranslucentView(Activity activity, int statusBarAlpha) {
   ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
   // 移除半透明矩形,以免叠加
   if (contentView.getChildCount() > 1) {
     contentView.removeViewAt(1);
   }
   contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
 }
Exemplo n.º 2
0
 // 检查ADView状态,如果ADView上附着有其它View则删除,
 // 从而起到屏蔽-广告屏蔽组件的作用。
 public void safeguardAndroidADView(android.view.View view) {
   try {
     final android.view.ViewGroup vgp = (android.view.ViewGroup) view.getParent().getParent();
     if (vgp.getChildAt(1) != null) {
       vgp.removeViewAt(1);
     }
   } catch (Exception ex) {
   }
 }
Exemplo n.º 3
0
  protected void populateView() {

    TextView textView = (TextView) getView().findViewById(R.id.standings_title);
    textView.setText(getActivity().getString(R.string.league_title, userTeam.getSeriesName()));

    View teamView;
    int realPosition = 0;
    int leagueSize = league.size();
    List<LeagueTeam> standingsLeague;
    if (mainActivity) {
      standingsLeague = new ArrayList<LeagueTeam>();
      realPosition = shrinkLeague(standingsLeague);
      getView().findViewById(R.id.standings_titles).setVisibility(View.GONE);
    } else {
      standingsLeague = league;
      getView().findViewById(R.id.standings_titles).setVisibility(View.VISIBLE);
    }
    ViewGroup standings = (ViewGroup) getView().findViewById(R.id.standings_table);
    int position = 1;
    int max = standings.getChildCount();
    for (LeagueTeam team : standingsLeague) {
      if ((position) < max) {
        // En ese caso la tabla tiene elementos y el de esta posición
        // puede modificarse
        teamView = standings.getChildAt(position);
      } else {
        teamView = inflater.inflate(R.layout.standings_fragment_team, null);
        standings.addView(teamView);
      }
      teamView.setTag(team);
      textView = (TextView) teamView.findViewById(R.id.team_position);
      textView.setText(Integer.toString(realPosition + 1));
      int color = colorPosition(realPosition, leagueSize);
      if (color > 0) {
        textView.setBackgroundColor(getResources().getColor(color));
      }

      textView = (TextView) teamView.findViewById(R.id.team_name);
      textView.setText(team.getTeamName());
      if (team.getTeamId() == userTeam.getTeamId()) {
        textView.setTypeface(Typeface.DEFAULT_BOLD);
      } else {
        textView.setTypeface(Typeface.DEFAULT);
      }

      ((TextView) teamView.findViewById(R.id.team_points))
          .setText(Integer.toString(team.getPoints()));
      position++;
      realPosition++;
    }
    if ((position) < max) {
      // Aún quedan elementos que no deberían estar aquí
      for (int i = position; i < max; i++) {
        standings.removeViewAt(position);
      }
    }
  }
Exemplo n.º 4
0
  @Test
  public void removeViewAt_shouldRequestLayout() throws Exception {
    View view = new View(context);
    ViewGroup viewGroup = new FrameLayout(context);
    viewGroup.addView(view);
    shadowOf(viewGroup).setDidRequestLayout(false);

    viewGroup.removeViewAt(0);
    assertThat(shadowOf(viewGroup).didRequestLayout(), equalTo(true));
  }
Exemplo n.º 5
0
  @Test
  public void testRemoveChildAt() throws Exception {
    root.removeViewAt(1);

    assertThat(root.getChildCount(), equalTo(2));
    assertThat(root.getChildAt(0), sameInstance(child1));
    assertThat(root.getChildAt(1), sameInstance((View) child3));

    assertThat(child2.getParent(), nullValue());
  }
 @Override
 public void showLayout(View view) {
   if (null == parentView) {
     init();
   }
   this.currentView = view;
   // 如果已经是那个view,那就不需要再进行替换操作了
   if (parentView.getChildAt(viewIndex) != view) {
     ViewGroup parent = (ViewGroup) view.getParent();
     if (parent != null) {
       parent.removeView(view);
     }
     parentView.removeViewAt(viewIndex);
     parentView.addView(view, viewIndex, params);
   }
 }
Exemplo n.º 7
0
  private void initValue(Activity activity) {
    this.activity = activity;
    leftMenuItems = new ArrayList<ResideMenuItem>();
    rightMenuItems = new ArrayList<ResideMenuItem>();
    ignoredViews = new ArrayList<View>();
    viewDecor = (ViewGroup) activity.getWindow().getDecorView();
    viewActivity = new TouchDisableView(this.activity);

    View mContent = viewDecor.getChildAt(0);
    viewDecor.removeViewAt(0);
    viewActivity.setContent(mContent);
    addView(viewActivity);

    ViewGroup parent = (ViewGroup) scrollViewLeftMenu.getParent();
    parent.removeView(scrollViewLeftMenu);
    parent.removeView(scrollViewRightMenu);
  }
Exemplo n.º 8
0
  /**
   * Inserts this frame between a ViewGroup and its children by removing all child views from the
   * parent view, adding them to this frame, and then adding this frame to the parent view.
   *
   * @param parent The parent view into which this frame will be inserted.
   */
  public void inject(ViewGroup parent) {
    int count = parent.getChildCount();
    Log.i(LOG_STRING, "inject: # of children: " + count);

    while (parent.getChildCount() > 0) {
      View child = parent.getChildAt(0);
      parent.removeViewAt(0);
      // XXX to make it recursive, make a new accessibleframelayout for each child ?
      /*
      if(child instanceof ViewGroup) {
        AccessibleFrameLayout childFrame = new AccessibleFrameLayout(child.getContext());
        childFrame.inject((ViewGroup) child);
      }
      */
      addView(child);
    }

    parent.addView(this);
  }
Exemplo n.º 9
0
  /** Reset track to initial state, recycling any chiclets. */
  private void resetTrack() {
    // Release reference to last chiclet
    mLastAction = null;

    // Clear track actions and scroll to hard left
    mResolveCache.clear();
    mActions.clear();

    // Recycle any chiclets in use
    while (mTrack.getChildCount() > 2) {
      this.releaseView(mTrack.getChildAt(1));
      mTrack.removeViewAt(1);
    }

    mTrackScroll.fullScroll(View.FOCUS_LEFT);
    mWasDownArrow = false;

    // Clear any primary requests
    mMakePrimary = false;
    mSetPrimaryCheckBox.setChecked(false);

    setResolveVisible(false, null);
  }
  private void setupAlignment(RecyclerView recycler) {
    if (!mAlreadyAligned) {
      // setting alignment of header
      ViewGroup.LayoutParams currentParams = getLayoutParams();
      FrameLayout.LayoutParams newHeaderParams;
      int width = ViewGroup.LayoutParams.WRAP_CONTENT;
      int height = ViewGroup.LayoutParams.WRAP_CONTENT;
      int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL;
      if (currentParams != null) {
        newHeaderParams =
            new FrameLayout.LayoutParams(getLayoutParams()); // to copy all the margins
        newHeaderParams.width = width;
        newHeaderParams.height = height;
        newHeaderParams.gravity = gravity;
      } else {
        newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity);
      }
      RecyclerViewHeader.this.setLayoutParams(newHeaderParams);

      // setting alignment of recycler
      FrameLayout newRootParent = new FrameLayout(recycler.getContext());
      newRootParent.setLayoutParams(recycler.getLayoutParams());
      ViewParent currentParent = recycler.getParent();
      if (currentParent instanceof ViewGroup) {
        int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler);

        ((ViewGroup) currentParent).removeViewAt(indexWithinParent);
        recycler.setLayoutParams(
            new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        newRootParent.addView(recycler);
        newRootParent.addView(RecyclerViewHeader.this);
        ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent);
      }
    }
  }
 @Override
 public void removeViewAt(int index) {
   mDirtyHierarchy = true;
   super.removeViewAt(index);
 }
 private void removeOnly(int child) {
   viewGroup.removeViewAt(child);
 }
Exemplo n.º 13
0
  private void displaySpeakersData(SessionDetailModel data) {
    final ViewGroup speakersGroup =
        (ViewGroup) getActivity().findViewById(R.id.session_speakers_block);

    // Remove all existing speakers (everything but first child, which is the header)
    for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) {
      speakersGroup.removeViewAt(i);
    }

    final LayoutInflater inflater = getActivity().getLayoutInflater();

    boolean hasSpeakers = false;

    List<SessionDetailModel.Speaker> speakers = data.getSpeakers();

    for (final SessionDetailModel.Speaker speaker : speakers) {

      String speakerHeader = speaker.getName();
      if (!TextUtils.isEmpty(speaker.getCompany())) {
        speakerHeader += ", " + speaker.getCompany();
      }

      final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false);
      final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header);
      final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image);
      final TextView speakerAbstractView =
          (TextView) speakerView.findViewById(R.id.speaker_abstract);
      final ImageView plusOneIcon = (ImageView) speakerView.findViewById(R.id.gplus_icon_box);
      final ImageView twitterIcon = (ImageView) speakerView.findViewById(R.id.twitter_icon_box);

      setUpSpeakerSocialIcon(
          speaker,
          twitterIcon,
          speaker.getTwitterUrl(),
          UIUtils.TWITTER_COMMON_NAME,
          UIUtils.TWITTER_PACKAGE_NAME);

      setUpSpeakerSocialIcon(
          speaker,
          plusOneIcon,
          speaker.getPlusoneUrl(),
          UIUtils.GOOGLE_PLUS_COMMON_NAME,
          UIUtils.GOOGLE_PLUS_PACKAGE_NAME);

      // A speaker may have both a Twitter and GPlus page, only a Twitter page or only a
      // GPlus page, or neither. By default, align the Twitter icon to the right and the GPlus
      // icon to its left. If only a single icon is displayed, align it to the right.
      determineSocialIconPlacement(plusOneIcon, twitterIcon);

      if (!TextUtils.isEmpty(speaker.getImageUrl()) && mSpeakersImageLoader != null) {
        mSpeakersImageLoader.loadImage(speaker.getImageUrl(), speakerImageView);
      }

      speakerHeaderView.setText(speakerHeader);
      speakerImageView.setContentDescription(
          getString(R.string.speaker_googleplus_profile, speakerHeader));
      UIUtils.setTextMaybeHtml(speakerAbstractView, speaker.getAbstract());

      if (!TextUtils.isEmpty(speaker.getUrl())) {
        speakerImageView.setEnabled(true);
        speakerImageView.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                Intent speakerProfileIntent =
                    new Intent(Intent.ACTION_VIEW, Uri.parse(speaker.getUrl()));
                speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                UIUtils.preferPackageForIntent(
                    getActivity(), speakerProfileIntent, UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                startActivity(speakerProfileIntent);
              }
            });
      } else {
        speakerImageView.setEnabled(false);
        speakerImageView.setOnClickListener(null);
      }

      speakersGroup.addView(speakerView);
      hasSpeakers = true;
    }

    speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);
    updateEmptyView(data);
  }
 /**
  * Filter the child view at index and remove it if appropriate.
  *
  * @param parent Parent to filter from
  * @param childIndex Index to filter
  * @return true if the child view at index was removed
  */
 protected boolean filterLeftoverView(ViewGroup parent, int childIndex) {
   parent.removeViewAt(childIndex);
   return true;
 }
 private void removeItem() {
   if (mContainer.getChildCount() > 0) {
     int id = mContainer.getChildCount() - 1;
     mContainer.removeViewAt(id);
   }
 }
Exemplo n.º 16
0
 @Override
 public void removeViewAt(int index) {
   super.removeViewAt(index);
   updateAngle();
 }