List of usage examples for android.view ViewGroup addView
public void addView(View child)
Adds a child view.
From source file:com.example.android.supportv7.widget.AnimatedRecyclerView.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animated_recycler_view); ViewGroup container = (ViewGroup) findViewById(R.id.container); mRecyclerView = new RecyclerView(this); mCachedAnimator = createAnimator();//from w ww . ja va2 s . co m mCachedAnimator.setChangeDuration(2000); mRecyclerView.setItemAnimator(mCachedAnimator); mRecyclerView.setLayoutManager(new MyLayoutManager(this)); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); for (int i = 0; i < 6; ++i) { mItems.add("Item #" + i); } mAdapter = new MyAdapter(mItems); mRecyclerView.setAdapter(mAdapter); container.addView(mRecyclerView); CheckBox enableAnimations = (CheckBox) findViewById(R.id.enableAnimations); enableAnimations.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked && mRecyclerView.getItemAnimator() == null) { mRecyclerView.setItemAnimator(mCachedAnimator); } else if (!isChecked && mRecyclerView.getItemAnimator() != null) { mRecyclerView.setItemAnimator(null); } mAnimationsEnabled = isChecked; } }); CheckBox enablePredictiveAnimations = (CheckBox) findViewById(R.id.enablePredictiveAnimations); enablePredictiveAnimations.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mPredictiveAnimationsEnabled = isChecked; } }); CheckBox enableInPlaceChange = (CheckBox) findViewById(R.id.enableInPlaceChange); enableInPlaceChange.setChecked(mEnableInPlaceChange); enableInPlaceChange.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mEnableInPlaceChange = isChecked; } }); }
From source file:com.grokkingandroid.sampleapp.samples.SampleBaseFragment.java
@SuppressLint("NewApi") protected void showLinks(ViewGroup container) { String[] linkTexts = getLinkTexts(); String[] linkTargets = getLinkTargets(); StringBuilder link = null;// w w w . j ava 2s . c o m for (int i = 0; i < linkTexts.length; i++) { // TODO: Use an inflater TextView tv = new TextView(getActivity()); LinearLayout.LayoutParams params = null; params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); if (i != linkTexts.length - 1) { int marginBottom = getResources().getDimensionPixelSize(R.dimen.linkSpacing); params.setMargins(0, 0, 0, marginBottom); } tv.setLayoutParams(params); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { tv.setTextIsSelectable(true); } tv.setTextAppearance(getActivity(), android.R.style.TextAppearance_Medium); link = new StringBuilder(100); link.append("<a href=\""); link.append(linkTargets[i]); link.append("\">"); link.append(linkTexts[i]); link.append("</a>"); Spanned spannedLink = Html.fromHtml(link.toString()); tv.setText(spannedLink); tv.setMovementMethod(LinkMovementMethod.getInstance()); container.addView(tv); } }
From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java
/** * Build and add "probes" tab./*from w ww .ja v a 2s. c o m*/ */ private void setupProbesTab(Ctlr ctlr) { /** * The tag we'll use to refer to this particular tab is the preface and the controllerId */ String tagSpec = TAG_PROBES + "_" + ctlr.mControllerId.toString().replace('-', 'n'); /** * We need to keep IDs for each tab withing each controller. I can't think of any way around this. * I should add error checking in case someone tries to add 11. */ int Rid; switch (ctlr.index) { case 0: Rid = R.id.fragment_probes_0; break; case 1: Rid = R.id.fragment_probes_1; break; case 2: Rid = R.id.fragment_probes_2; break; case 3: Rid = R.id.fragment_probes_3; break; case 4: Rid = R.id.fragment_probes_4; break; case 5: Rid = R.id.fragment_probes_5; break; case 6: Rid = R.id.fragment_probes_6; break; case 7: Rid = R.id.fragment_probes_7; break; case 8: Rid = R.id.fragment_probes_8; break; case 9: Rid = R.id.fragment_probes_9; break; default: Rid = 0; } /** * This is a unique layout for each probe tab within all of the probes tabs. Make a new blank * frame, set its ID and attach it to the tabcontent root. */ ctlr.probesFragmentContainer = new FrameLayout(this); ctlr.probesFragmentContainer.setId(Rid); ctlr.probesFragmentContainer.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); ViewGroup tabContentView = (ViewGroup) ctlr.mRootView.findViewById(android.R.id.tabcontent); tabContentView.addView(ctlr.probesFragmentContainer); /** * For the probe fragment, build a Uri pointing to this controller's probe list. */ final Intent intent = new Intent(Intent.ACTION_VIEW, Data.buildQueryPDataAtUri(ctlr.mControllerId, ctlr.mTimestamp)); /** * Kickoff the fragment */ final FragmentManager fm = getSupportFragmentManager(); ctlr.mProbesFragment = (ProbesFragment) fm.findFragmentByTag(tagSpec); if (ctlr.mProbesFragment != null && !ctlr.mProbesFragment.isDetached()) { fm.beginTransaction().detach(ctlr.mProbesFragment).commit(); } if (ctlr.mProbesFragment == null) { ctlr.mProbesFragment = new ProbesFragment(); ctlr.mProbesFragment.setArguments(intentToFragmentArguments(intent)); fm.beginTransaction().add(Rid, ctlr.mProbesFragment, tagSpec).commit(); } /** * Add the tab to the tabhost */ ctlr.mTabHost.addTab(ctlr.mTabHost.newTabSpec(tagSpec) .setIndicator(buildIndicator(ctlr, R.string.probes_tab_title)).setContent(Rid)); // /** we need to override the container ID now */ // ctlr.mTabManager.addTab(ctlr.mTabHost.newTabSpec(tagSpec) // .setIndicator("Probes"/*buildIndicator(ctlr, R.string.probes_tab_title)*/) // .setContent(Rid), /* is this duplicative with rid below?*/ // ProbesFragment.class, // Rid, // intentToFragmentArguments(intent)); }
From source file:cm.aptoide.pt.adapters.ViewPagerAdapterScreenshots.java
@Override public Object instantiateItem(ViewGroup container, final int position) { final View v = LayoutInflater.from(context).inflate(R.layout.row_item_screenshots_big, null); final ProgressBar pb = (ProgressBar) v.findViewById(R.id.screenshots_loading_big); imageLoader.displayImage(hd ? url.get(position) : screenshotToThumb(url.get(position)), (ImageView) v.findViewById(R.id.screenshot_image_big), options, new ImageLoadingListener() { @Override/*from w w w . jav a 2 s .co m*/ public void onLoadingStarted(String uri, View view) { pb.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String uri, View v, FailReason failReason) { ((ImageView) v.findViewById(R.id.screenshot_image_big)) .setImageResource(android.R.drawable.ic_delete); pb.setVisibility(View.GONE); } @Override public void onLoadingComplete(String uri, View v, Bitmap loadedImage) { pb.setVisibility(View.GONE); } @Override public void onLoadingCancelled(String uri, View v) { } }); container.addView(v); if (!hd) { v.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(context, ScreenshotsViewer.class); i.putStringArrayListExtra("url", url); i.putExtra("position", position); i.putExtra("hashCode", hashCode + ".hd"); context.startActivity(i); } }); } return v; }
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Adds an action button to the compatibility action bar, using menu information from a * {@link android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state * can be changed to show a loading spinner using * {@link ActivityHelper#setRefreshActionButtonCompatState(boolean)}. *///from w w w . j av a 2 s .c om private View addActionButtonCompatFromMenuItem(final MenuItem item) { final ViewGroup actionBar = getActionBarCompat(); if (actionBar == null) { return null; } // Create the separator ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle); separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT)); // Create the button ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle); actionButton.setId(item.getItemId()); actionButton.setLayoutParams(new ViewGroup.LayoutParams( (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT)); actionButton.setImageDrawable(item.getIcon()); actionButton.setScaleType(ImageView.ScaleType.CENTER); actionButton.setContentDescription(item.getTitle()); actionButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item); } }); actionBar.addView(separator); actionBar.addView(actionButton); if (item.getItemId() == R.id.menu_refresh) { // Refresh buttons should be stateful, and allow for indeterminate progress indicators, // so add those. int buttonWidth = mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height); int buttonWidthDiv3 = buttonWidth / 3; ProgressBar indicator = new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle); LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(buttonWidthDiv3, buttonWidthDiv3); indicatorLayoutParams.setMargins(buttonWidthDiv3, buttonWidthDiv3, buttonWidth - 2 * buttonWidthDiv3, 0); indicator.setLayoutParams(indicatorLayoutParams); indicator.setVisibility(View.GONE); indicator.setId(R.id.menu_refresh_progress); actionBar.addView(indicator); } return actionButton; }
From source file:com.android.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);//w w w.ja v a 2 s. c o m containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.announceForAccessibility(accessibilityText); mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java
void setFragmentContentView(View newView) { ViewGroup parent = (ViewGroup) this.getView(); parent.removeAllViews(); parent.addView(newView); }
From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);//from w w w.j av a 2 s .c o m containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { if (Build.VERSION.SDK_INT >= 16) { mAlertView.announceForAccessibility(accessibilityText); } mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:com.roughike.swipeselector.SwipeAdapter.java
/** * Override methods / listeners//from w ww. j a v a 2 s .com */ @Override public Object instantiateItem(ViewGroup container, int position) { LinearLayout layout = (LinearLayout) View.inflate(mContext, R.layout.swipeselector_content_item, null); TextView title = (TextView) layout.findViewById(R.id.swipeselector_content_title); TextView description = (TextView) layout.findViewById(R.id.swipeselector_content_description); SwipeItem slideItem = mItems.get(position); title.setText(slideItem.title); description.setText(slideItem.description); // We shouldn't get here if the typeface didn't exist. // But just in case, because we're paranoid. if (mCustomTypeFace != null) { title.setTypeface(mCustomTypeFace); description.setTypeface(mCustomTypeFace); } if (mTitleTextAppearance != -1) { setTextAppearanceCompat(title, mTitleTextAppearance); } if (mDescriptionTextAppearance != -1) { setTextAppearanceCompat(description, mDescriptionTextAppearance); } layout.setPadding(mContentLeftPadding, mSweetSixteen, mContentRightPadding, mSweetSixteen); container.addView(layout); return layout; }
From source file:com.app.blockydemo.ui.adapter.BrickAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (draggedBrick != null && dragTargetPosition == position) { return insertionView; }//from ww w .j a v a2 s.com listItemCount = position + 1; Object item = getItem(position); if (item instanceof ScriptBrick && (!initInsertedBrick || position != positionOfInsertedBrick)) { View scriptBrickView = ((Brick) item).getView(context, position, this); if (draggedBrick == null) { scriptBrickView.setOnClickListener(this); } return scriptBrickView; } View currentBrickView; // dirty HACK // without the footer, position can be 0, and list.get(-1) caused an Indexoutofboundsexception // no clean solution was found if (position == 0) { if (item instanceof AllowedAfterDeadEndBrick && brickList.get(position) instanceof DeadEndBrick) { currentBrickView = ((AllowedAfterDeadEndBrick) item).getNoPuzzleView(context, position, this); } else { currentBrickView = ((Brick) item).getView(context, position, this); } } else { if (item instanceof AllowedAfterDeadEndBrick && brickList.get(position - 1) instanceof DeadEndBrick) { currentBrickView = ((AllowedAfterDeadEndBrick) item).getNoPuzzleView(context, position, this); } else { currentBrickView = ((Brick) item).getView(context, position, this); } } // this one is working but causes null pointer exceptions on movement and control bricks?! // currentBrickView.setOnLongClickListener(longClickListener); // Hack!!! // if wrapper isn't used the longClick event won't be triggered ViewGroup wrapper = (ViewGroup) View.inflate(context, R.layout.brick_wrapper, null); if (currentBrickView.getParent() != null) { ((ViewGroup) currentBrickView.getParent()).removeView(currentBrickView); } wrapper.addView(currentBrickView); if (draggedBrick == null) { if ((selectMode == ListView.CHOICE_MODE_NONE)) { wrapper.setOnClickListener(this); if (!(item instanceof DeadEndBrick)) { wrapper.setOnLongClickListener(dragAndDropListView); } } } if (position == positionOfInsertedBrick && initInsertedBrick && (selectMode == ListView.CHOICE_MODE_NONE)) { initInsertedBrick = false; addingNewBrick = true; dragAndDropListView.setInsertedBrick(position); dragAndDropListView.setDraggingNewBrick(); dragAndDropListView.onLongClick(currentBrickView); return insertionView; } if (animatedBricks.contains(brickList.get(position))) { Animation animation = AnimationUtils.loadAnimation(context, R.anim.blink); wrapper.startAnimation(animation); animatedBricks.remove(brickList.get(position)); } return wrapper; }