private void applyTo(View target) { LayoutParams lp = target.getLayoutParams(); ViewParent parent = target.getParent(); FrameLayout container = new FrameLayout(context); if (target instanceof TabWidget) { // set target to the relevant tab child container target = ((TabWidget) target).getChildTabViewAt(targetTabIndex); this.target = target; ((ViewGroup) target) .addView(container, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); this.setVisibility(View.GONE); container.addView(this); } else { // TODO verify that parent is indeed a ViewGroup ViewGroup group = (ViewGroup) parent; int index = group.indexOfChild(target); group.removeView(target); group.addView(container, index, lp); container.addView(target); this.setVisibility(View.GONE); container.addView(this); group.invalidate(); } }
private void buildHistoryLayout(Player player) { ViewGroup parent = (ViewGroup) findViewById(R.id.profile_history_layout); // result: layout_height=wrap_content layout_width=match_parent view = LayoutInflater.from(getBaseContext()).inflate(R.layout.simple_item, null); TextView heading = (TextView) view.findViewById(R.id.simple_item_text1); TextView details = (TextView) view.findViewById(R.id.simple_item_text2); heading.setText("NFL"); details.setText(player.getAllTeams()); parent.addView(view); view = LayoutInflater.from(getBaseContext()).inflate(R.layout.simple_item, null); heading = (TextView) view.findViewById(R.id.simple_item_text1); details = (TextView) view.findViewById(R.id.simple_item_text2); heading.setText("College"); details.setText(player.college); parent.addView(view); view = LayoutInflater.from(getBaseContext()).inflate(R.layout.simple_item, null); heading = (TextView) view.findViewById(R.id.simple_item_text1); details = (TextView) view.findViewById(R.id.simple_item_text2); heading.setText("Draft"); details.setText(player.drafted); parent.addView(view); }
public final View inflate() { ViewParent viewParent = getParent(); if (viewParent == null || !(viewParent instanceof ViewGroup)) { throw new IllegalStateException("ViewStub must have a non-null ViewGroup viewParent"); } else if (this.mLayoutResource != 0) { LayoutInflater factory; ViewGroup parent = (ViewGroup) viewParent; if (this.mInflater != null) { factory = this.mInflater; } else { factory = LayoutInflater.from(getContext()); } View view = factory.inflate(this.mLayoutResource, parent, false); if (this.mInflatedId != -1) { view.setId(this.mInflatedId); } int index = parent.indexOfChild(this); parent.removeViewInLayout(this); LayoutParams layoutParams = getLayoutParams(); if (layoutParams != null) { parent.addView(view, index, layoutParams); } else { parent.addView(view, index); } this.mInflatedViewRef = new WeakReference(view); if (this.mInflateListener != null) { this.mInflateListener.onInflate(this, view); } return view; } else { throw new IllegalArgumentException("ViewStub must have a valid layoutResource"); } }
private void createListView() { root = (FrameLayout) inflater.inflate(R.layout.qrh__listview_container, null); root.addView(content); listView.getViewTreeObserver().addOnGlobalLayoutListener(this); ListViewScrollObserver observer = new ListViewScrollObserver(listView); // listView.setOnScrollListener(this); observer.setOnScrollUpAndDownListener( new OnListViewScrollListener() { @Override public void onScrollUpDownChanged(int delta, int scrollPosition, boolean exact) { onNewScroll(delta); snap(headerTop == scrollPosition); } @Override public void onScrollIdle() { QuickReturnHeaderHelper.this.onScrollIdle(); } }); root.addView(realHeader, realHeaderLayoutParams); dummyHeader = new View(context); AbsListView.LayoutParams params = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, headerHeight); dummyHeader.setLayoutParams(params); listView.addHeaderView(dummyHeader); }
@Override public Object instantiateItem(ViewGroup container, int position) { Context context = ImageShowActivity.this; int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium); ImageLocation imageLocation = imageLocations.get(position); if (imageLocation.isLocal()) { ImageView imageView = new ImageView(context); imageView.setPadding(padding, padding, padding, padding); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setImageURI(imageLocation.getUri()); container.addView(imageView, 0); return imageView; } else { NetworkImageView imageView = new NetworkImageView(context); imageView.setPadding(padding, padding, padding, padding); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setImageUrl( API_IMAGE_GET + imageLocation.getId(), BaseApplication.baseApplication.mImageLoader); container.addView(imageView, 0); return imageView; } }
@Override protected void onFinishInflate() { super.onFinishInflate(); ButterKnife.inject(this); String pickedview = settings.getString(NOW_PLAYING_VIEW, NOW_PLAYING_VIEW_ARTWORK); switch (pickedview) { case NOW_PLAYING_VIEW_VIS_CIRCLE: case NOW_PLAYING_VIEW_VIS_CIRCLE_BAR: case NOW_PLAYING_VIEW_VIS_LINES: visualizerView = ViewUtils.inflate(getContext(), R.layout.now_playing_visualization, placeholder, false); placeholder.addView(visualizerView); initVisualizer(pickedview); break; case NOW_PLAYING_VIEW_ARTWORK: default: artwork = ViewUtils.inflate(getContext(), R.layout.now_playing_artwork, placeholder, false); placeholder.addView(artwork); initArtwork(); break; } if (!VersionUtils.hasLollipop()) { seekBar .getThumb() .mutate() .setColorFilter(ThemeUtils.getColorAccent(getContext()), PorterDuff.Mode.SRC_IN); } PlaybackDrawableTint.repeatDrawable36(repeat); PlaybackDrawableTint.shuffleDrawable36(shuffle); if (!isInEditMode()) presenter.takeView(this); }
public void addTabs(TabInfo... tabInfos) { if (tabInfos == null || tabInfos.length < 1) { return; } for (TabInfo tabInfo : tabInfos) { if (tabInfo == null) { break; } View page = tabInfo.getPage(); View item = tabInfo.getItem(); item.setOnClickListener(onSelectorClickListener); if (page instanceof Pageable) { Pageable pageable = (Pageable) page; pageable.onInit(this); } ViewGroup.LayoutParams itemParams = tabInfo.getItemParams(); if (itemParams == null) { itemBar.addView(item); } else { itemBar.addView(item, itemParams); } adapter.add(page); tabs.add(new Pair<View, View>(item, page)); } onGlobalLayout(); }
@Override protected void populateContent(ViewGroup content) { activity.findViewById(R.id.wonder).setEnabled(false); activity.findViewById(R.id.summary).setEnabled(true); activity.findViewById(R.id.hand).setEnabled(true); activity .findViewById(R.id.help) .setOnClickListener( view -> { DialogFragment helpDialog = new HelpDialog(); Bundle bundle = new Bundle(); bundle.putString(HelpDialog.TITLE, activity.getString(R.string.help_wonder_title)); bundle.putString(HelpDialog.MESSAGE, activity.getString(R.string.help_wonder)); helpDialog.setArguments(bundle); helpDialog.show(activity.getFragmentManager(), "helpDialog"); }); for (Card card : playerViewing.getWonder().getStages()) { CardView cv = new CardView(card, activity, playerViewing, false, false); if (!playerViewing.getPlayedCards().contains(card)) { cv.setText(activity.getString(R.string.not_built, cv.getText())); } content.addView(cv); } for (Card card : playerViewing.getPlayedCards()) { if (card.getType() == Card.Type.STAGE) continue; CardView cv = new CardView(card, activity, playerViewing, false, false); content.addView(cv); } }
public void onCreate(ViewGroup groupView) { log.pushTimer(this, "start"); // Create OpenCV part: if (RUN_OPENCV) { opencv = new OpenCVInterface(this, this.mainActivity); JavaCameraView cameraView = new JavaCameraView(mainActivity, JavaCameraView.CAMERA_ID_ANY); cameraView.setLayoutParams( new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); cameraView.enableFpsMeter(); cameraView.setVisibility(JavaCameraView.GONE); groupView.addView(cameraView); opencv.onCreate(cameraView); } // Create OpenGL render part: if (RUN_RENDERER) { render = new RenderInterface(this); GLSurfaceView renderView = new GLSurfaceView(mainActivity.getApplicationContext()); renderView.setLayoutParams( new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); groupView.addView(renderView); render.onCreate(renderView); } // Set layout things: mainActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); log.log(TAG, "Framework created in " + log.popTimer(this).time + "ms."); }
@Override protected void performTraversal( final ViewGroup containerView, final TraversalState traversalState, final Flow.Direction direction, final Flow.TraversalCallback callback) { final PathContext context; final PathContext oldPath; if (containerView.getChildCount() > 0) { oldPath = PathContext.get(containerView.getChildAt(0).getContext()); } else { oldPath = PathContext.root(containerView.getContext()); } Path to = traversalState.toPath(); View newView; context = PathContext.create(oldPath, to, contextFactory); int layout = getLayout(to); newView = LayoutInflater.from(context).cloneInContext(context).inflate(layout, containerView, false); View fromView = null; if (traversalState.fromPath() != null) { fromView = containerView.getChildAt(0); traversalState.saveViewState(fromView); } traversalState.restoreViewState(newView); if (fromView == null || direction == REPLACE) { containerView.removeAllViews(); containerView.addView(newView); oldPath.destroyNotIn(context, contextFactory); callback.onTraversalCompleted(); } else { containerView.addView(newView); final View finalFromView = fromView; Utils.waitForMeasure( newView, new Utils.OnMeasuredCallback() { @Override public void onMeasured(View view, int width, int height) { runAnimation( containerView, finalFromView, view, direction, new Flow.TraversalCallback() { @Override public void onTraversalCompleted() { containerView.removeView(finalFromView); oldPath.destroyNotIn(context, contextFactory); callback.onTraversalCompleted(); } }); } }); } }
public FacebookSetting(String title, String key) { this.key = key; view = LayoutInflater.from(SettingsActivity.this).inflate(R.layout.list_item_setting, null); TextView titleView = (TextView) view.findViewById(R.id.textview_setting); titleView.setText(title); LayoutParams iconParams = new LayoutParams(64, 64); icon = new ImageView(SettingsActivity.this); icon.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_facebook)); icon.setLayoutParams(iconParams); loginDetails = new TextView(SettingsActivity.this); icon.setFocusable(false); loginDetails.setFocusable(false); titleView.setFocusable(false); loginDetails.setPadding( 0, 0, (int) SettingsActivity.this.getResources().getDimension(R.dimen.default_margin), 0); ((ViewGroup) view).addView(loginDetails); ((ViewGroup) view).addView(icon); saveState(); }
public void setMainView(int id) { ViewGroup viewGroup = (ViewGroup) this.activity.findViewById(rootViewId); if (id != this.currentMainViewId) { for (int index = 0; index < this.topViewArray.length; index++) { viewGroup.removeView(this.topViewArray[index]); } for (int index = 0; index < this.mainViewArray.length; index++) { if (id != this.mainViewArray[index].getId()) { viewGroup.removeView(this.mainViewArray[index]); } } for (int index = 0; index < this.mainViewArray.length; index++) { if (id == this.mainViewArray[index].getId()) { viewGroup.addView(this.mainViewArray[index]); this.currentMainViewId = id; } } for (int index = 0; index < this.topViewArray.length; index++) { viewGroup.addView(this.topViewArray[index]); } } }
public void showDigitalRead(DigitalValue newValue) { this.digitalValue = newValue; ViewGroup parent = (ViewGroup) view.getParent(); if (digitalReadView == null) { digitalReadView = Ui.findView(parent, R.id.tinker_digital_write_main); } // If the view does not exist, inflate it if (digitalReadView == null) { LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); digitalReadView = inflater.inflate(R.layout.tinker_digital_read, parent, false); if (pinType == PinType.A) { parent.addView(digitalReadView); } else if (pinType == PinType.D) { parent.addView(digitalReadView, 0); } } digitalReadView.setVisibility(View.VISIBLE); final TextView value = Ui.findView(digitalReadView, R.id.tinker_digital_read_value); value.setText(newValue.name()); // fade(value, newValue); updatePinColor(); if (!stopAnimating()) { getCancelAnimator().start(); } }
@Test public void testRemoveViewsInLayout() { root.removeViewsInLayout(0, 0); assertThat(root.getChildCount(), equalTo(3)); root.removeViewsInLayout(2, 1); assertThat(root.getChildCount(), equalTo(2)); assertThat(root.getChildAt(0), sameInstance(child1)); assertThat(root.getChildAt(1), sameInstance(child2)); root.removeViewsInLayout(0, 1); assertThat(root.getChildCount(), equalTo(1)); assertThat(root.getChildAt(0), sameInstance(child2)); root.removeViewsInLayout(0, 1); assertThat(root.getChildCount(), equalTo(0)); root.addView(child1); root.addView(child2); root.addView(child3); root.removeViewsInLayout(1, 1); assertThat(root.getChildCount(), equalTo(2)); assertThat(root.getChildAt(0), sameInstance(child1)); assertThat(root.getChildAt(1), sameInstance((View) child3)); root.removeViewsInLayout(0, 2); assertThat(root.getChildCount(), equalTo(0)); }
@Override public Object instantiateItem(View container, int position) { synchronized (viewsLock) { ViewGroup pager = (ViewGroup) container; TiViewProxy tiProxy = mViews.get(position); TiUIView tiView = tiProxy.getOrCreateView(); View view = tiView.getOuterView(); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); TiCompositeLayout layout = new TiCompositeLayout(tiProxy.getActivity()); ViewParent parent = view.getParent(); if (parent instanceof ViewGroup) { pager.removeView((View) parent); ViewGroup group = (ViewGroup) parent; group.removeView(view); } layout.addView(view, tiView.getLayoutParams()); if (position < pager.getChildCount()) { pager.addView(layout, position, params); } else { pager.addView(layout, params); } return tiProxy; } }
private void initView() { // 添加贴纸水印的画布 View overlay = LayoutInflater.from(PhotoProcessActivity.this) .inflate(R.layout.view_drawable_overlay, null); mImageView = (MyImageViewDrawableOverlay) overlay.findViewById(R.id.drawable_overlay); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(App.getApp().getScreenWidth(), App.getApp().getScreenWidth()); mImageView.setLayoutParams(params); overlay.setLayoutParams(params); drawArea.addView(overlay); // 添加标签选择器 RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( App.getApp().getScreenWidth(), App.getApp().getScreenWidth()); // 初始化滤镜图片 imageView.setLayoutParams(rparams); // 初始化推荐标签栏 commonLabelArea = LayoutInflater.from(PhotoProcessActivity.this).inflate(R.layout.view_label_bottom, null); commonLabelArea.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); toolArea.addView(commonLabelArea); commonLabelArea.setVisibility(View.GONE); }
/** * Constructor * * @param parent the container view of this one * @param tabId drawable for the tab * @param barId drawable for the bar * @param targetId drawable for the target */ Slider(ViewGroup parent, int tabId, int barId, int targetId) { // Create tab tab = new ImageView(parent.getContext()); tab.setBackgroundResource(tabId); tab.setScaleType(ScaleType.CENTER); tab.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // Create hint TextView text = new TextView(parent.getContext()); text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); text.setBackgroundResource(barId); text.setTextAppearance(parent.getContext(), R.style.TextAppearance_SlidingTabNormal); // hint.setSingleLine(); // Hmm.. this causes the text to disappear off-screen // Create target target = new ImageView(parent.getContext()); target.setImageResource(targetId); target.setScaleType(ScaleType.CENTER); target.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); target.setVisibility(View.INVISIBLE); parent.addView(target); // this needs to be first - relies on painter's algorithm parent.addView(tab); parent.addView(text); }
private void addInterestTypeView( InterestType interestType, LayoutInflater inflater, ViewGroup parent) { UserInterest[] interests = interestType != null ? interestType.getUserInterests() : null; if (interests == null || interests.length <= 0) { return; } InterestTypeProperty property = InterestUtils.getTypeProperty(interestType.getTypeId()); View rootView = inflater.inflate(R.layout.user_info_favourite_interest, parent, false); ImageView typeIconView = (ImageView) rootView.findViewById(R.id.interest_icon); ViewGroup interestParent = (ViewGroup) rootView.findViewById(R.id.interest_content); typeIconView.setImageResource(property.getTypeIconResId()); for (final UserInterest interest : interests) { if (interest == null) { continue; } TextView interestView = (TextView) inflater.inflate(R.layout.interest_name, interestParent, false); InterestUtils.setInterestColor(mContext, interestView, property); interestView.setText(interest.getInterestName()); interestView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (interactListener != null) { interactListener.onClick(v, new Interact(interest)); } } }); interestParent.addView(interestView); } parent.addView(rootView); }
public void addDivider(View divider, int index, ViewGroup.LayoutParams params) { if (index < 0 || index >= itemBar.getChildCount()) { itemBar.addView(divider, params); } else { itemBar.addView(divider, index, params); } onGlobalLayout(); }
public void reconfigureViewHierarchy() { final DisplayMetrics dm = getResources().getDisplayMetrics(); final int widthPixels = dm.widthPixels; if (mDecorView == null) { return; } if (mDrawerContent != null) { removeView(mDrawerContent); } if (mDecorContent != null) { /* * Add the window/content (whatever it is at the time) back to its original parent. */ removeView(mDecorContent); mDecorContentParent.addView(mDecorContent); /* * Reset the window/content's OnClickListener/background color to default values as well */ mDecorContent.setOnClickListener(null); mDecorContent.setBackgroundColor(Color.TRANSPARENT); } if (mAdded) { mDecorContentParent.removeView(this); } if (mSlideTarget == SLIDE_TARGET_CONTENT) { mDecorContent = mContentTarget; mDecorContentParent = mContentTargetParent; } else if (mSlideTarget == SLIDE_TARGET_WINDOW) { mDecorContent = mWindowTarget; mDecorContentParent = mWindowTargetParent; } else { throw new IllegalArgumentException( "Slide target must be one of SLIDE_TARGET_CONTENT or SLIDE_TARGET_WINDOW."); } ((ViewGroup) mDecorContent.getParent()).removeView(mDecorContent); addView(mDrawerContent, new ViewGroup.LayoutParams(mDrawerMaxWidth, MATCH_PARENT)); addView(mDecorContent, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); mDecorContentParent.addView(this); mAdded = true; /* Set background color of the content view (it shouldn't be transparent) */ mDecorContent.setBackgroundColor(mDecorContentBackgroundColor); /* Reset shadow bounds */ mShadowDrawable.setBounds(-mTouchTargetWidth / 6, 0, 0, dm.heightPixels); /* * Set an empty onClickListener on the Decor content parent to prevent any touch events * from escaping and passing through to the drawer even while it's closed. */ mDecorContent.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) {} }); }
@Override public Object instantiateItem(ViewGroup container, int position) { View courseView = container.getChildAt(position); Course course = this.course.get(position); if (courseView == null) { if (course.getCourseType() == Course.TYPE) { courseView = mInflater.inflate(R.layout.item_dialog_schedule, container, false); TextView name = (TextView) courseView.findViewById(R.id.dialog_course_name); TextView teacher = (TextView) courseView.findViewById(R.id.dialog_course_teacher); TextView classroom = (TextView) courseView.findViewById(R.id.dialog_course_classroom); TextView weeks = (TextView) courseView.findViewById(R.id.dialog_course_weeks); TextView time = (TextView) courseView.findViewById(R.id.dialog_course_time); TextView timenum = (TextView) courseView.findViewById(R.id.dialog_course_time_num); TextView type = (TextView) courseView.findViewById(R.id.dialog_course_type); name.setText(course.course); teacher.setText(course.teacher); classroom.setText(course.classroom); time.setText( context.getResources().getStringArray(R.array.schedule_weekday)[course.hash_day] + " ~ " + course.begin_lesson + "-" + (course.begin_lesson + course.period - 1) + "节"); String timeStr = context.getResources().getStringArray(R.array.schedule_time)[course.hash_lesson]; if (course.period == 2) { timenum.setText(timeStr); } else { timenum.setText(timeStr.substring(0, timeStr.indexOf("~") + 1) + "下课"); } type.setText(course.type); weeks.setText(course.rawWeek); container.addView(courseView); } else { courseView = mInflater.inflate(R.layout.item_dialog_affair, container, false); TextView name = (TextView) courseView.findViewById(R.id.dialog_course_name); TextView teacher = (TextView) courseView.findViewById(R.id.dialog_course_teacher); Button delete = (Button) courseView.findViewById(R.id.dialog_affair_delete); Button modify = (Button) courseView.findViewById(R.id.dialog_affair_modify); delete.setOnClickListener( (view -> { EventBus.getDefault().post(new AffairDeleteEvent(course)); dialog.dismiss(); })); modify.setOnClickListener( (view -> { dialog.dismiss(); Affair affair = (Affair) course; EditAffairActivity.editAffairActivityStart(context, affair); })); name.setText(course.course); teacher.setText(course.teacher); container.addView(courseView); } } return courseView; }
private void doShowAnalogValue(int newValue) { if (analogWriteView != null) { analogWriteView.setVisibility(View.GONE); analogWriteView = null; } ViewGroup parent = (ViewGroup) view.getParent(); if (pinBackgroundAnim != null) { pinBackgroundAnim.cancel(); } if (analogReadView == null) { analogReadView = Ui.findView(parent, R.id.tinker_analog_read_main); } // If the view does not exist, inflate it if (analogReadView == null) { LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (pinType == PinType.A) { analogReadView = inflater.inflate(R.layout.tinker_analog_read_left, parent, false); parent.addView(analogReadView); } else if (pinType == PinType.D) { analogReadView = inflater.inflate(R.layout.tinker_analog_read_right, parent, false); parent.addView(analogReadView, 0); } else if (pinType == PinType.T) { analogReadView = inflater.inflate(R.layout.tinker_analog_read_right, parent, false); parent.addView(analogReadView, 0); } } analogReadView.setVisibility(View.VISIBLE); // Find the existing views and set the values ProgressBar barGraph = Ui.findView(analogReadView, R.id.tinker_analog_read_progress); TextView readValue = Ui.findView(analogReadView, R.id.tinker_analog_read_value); if (PinAction.ANALOG_READ.equals(configuredAction)) { barGraph.setProgressDrawable( view.getContext().getResources().getDrawable(R.drawable.progress_emerald)); } else { barGraph.setProgressDrawable( view.getContext().getResources().getDrawable(R.drawable.progress_sunflower)); } int max = 1; if (configuredAction == PinAction.ANALOG_READ) { max = ANALOG_READ_MAX; } else if (configuredAction == PinAction.ANALOG_WRITE) { max = ANALOG_WRITE_MAX; } barGraph.setMax(max); barGraph.setProgress(newValue); readValue.setText(String.valueOf(newValue)); }
/** Attaches the menu drawer to the window. */ private void attachToDecor() { ViewGroup decorView = (ViewGroup) mActivity.getWindow().getDecorView(); ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0); decorView.removeAllViews(); decorView.addView(mMenuDrawer, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mContentContainer.addView(decorChild, decorChild.getLayoutParams()); }
@Test public void testAddViewAt() throws Exception { root.removeAllViews(); root.addView(child1); root.addView(child2); root.addView(child3, 1); assertThat(root.getChildAt(0), sameInstance(child1)); assertThat(root.getChildAt(1), sameInstance((View) child3)); assertThat(root.getChildAt(2), sameInstance(child2)); }
@Test(expected = RuntimeException.class) public void checkedClick_shouldThrowIfViewIsNotVisible() throws Exception { ViewGroup grandParent = new LinearLayout(null); ViewGroup parent = new LinearLayout(null); grandParent.addView(parent); parent.addView(view); grandParent.setVisibility(View.GONE); shadowOf(view).checkedPerformClick(); }
public void setContentView(View view) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); initTitleBar(); ViewGroup root = getRootView(); View paramView = view; root.addView( mTitleBar, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); root.addView( paramView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); super.setContentView(root); }
public void showAnalogWrite(final OnAnalogWriteListener listener) { if (analogReadView != null) { analogReadView.setVisibility(View.GONE); analogReadView = null; } final ViewGroup parent = (ViewGroup) view.getParent(); if (analogWriteView == null) { analogWriteView = Ui.findView(parent, R.id.tinker_analog_write_main); } // If the view does not exist, inflate it if (analogWriteView == null) { LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (pinType == PinType.A) { analogWriteView = inflater.inflate(R.layout.tinker_analog_write_left, parent, false); parent.addView(analogWriteView); } else if (pinType == PinType.D) { analogWriteView = inflater.inflate(R.layout.tinker_analog_write_right, parent, false); parent.addView(analogWriteView, 0); } } analogWriteView.setVisibility(View.VISIBLE); final SeekBar seekBar = Ui.findView(analogWriteView, R.id.tinker_analog_write_seekbar); final TextView valueText = Ui.findView(analogWriteView, R.id.tinker_analog_write_value); if (pinBackgroundAnim != null) { pinBackgroundAnim.cancel(); pinBackgroundAnim = null; } parent.setBackgroundColor(0x4C000000); seekBar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { int value = seekBar.getProgress(); parent.setBackgroundColor(0); showAnalogWriteValue(); listener.onAnalogWrite(value); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { valueText.setText(String.valueOf(progress)); } }); }
public static void replaceView(View oldChild, View newChild, boolean transferLayoutParams) { final ViewGroup parent = oldChild.getParent() instanceof ViewGroup ? (ViewGroup) oldChild.getParent() : null; final int index = parent.indexOfChild(oldChild); parent.removeViewInLayout(oldChild); final LayoutParams layoutParams = (transferLayoutParams ? oldChild.getLayoutParams() : null); if (layoutParams != null) parent.addView(newChild, index, layoutParams); else parent.addView(newChild, index); }
@Test public void shouldNotfindViewWithTagReturnNull() { root.removeAllViews(); child1.setTag("tag1"); child2.setTag("tag2"); child3.setTag("tag3"); root.addView(child1); root.addView(child2); root.addView(child3, 1); assertThat(root.findViewWithTag("tag21"), equalTo(null)); assertThat((ViewGroup) root.findViewWithTag("tag23"), equalTo(null)); }
private void inflatePreviews() { mPhonePreview = mPreviewInflater.inflatePreview(PHONE_INTENT); mCameraPreview = mPreviewInflater.inflatePreview(getCameraIntent()); if (mPhonePreview != null) { mPreviewContainer.addView(mPhonePreview); mPhonePreview.setVisibility(View.INVISIBLE); } if (mCameraPreview != null) { mPreviewContainer.addView(mCameraPreview); mCameraPreview.setVisibility(View.INVISIBLE); } }