List of usage examples for android.view ViewGroup removeView
@Override public void removeView(View view)
Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.
From source file:gr.plushost.prototypeapp.widgets.LabelView.java
private boolean replaceLayout(View target) { if (getParent() != null || target == null || target.getParent() == null || _labelViewContainerID != -1) { return false; }// www . j a va 2s . c om ViewGroup parentContainer = (ViewGroup) target.getParent(); if (target.getParent() instanceof FrameLayout) { ((FrameLayout) target.getParent()).addView(this); } else if (target.getParent() instanceof ViewGroup) { int groupIndex = parentContainer.indexOfChild(target); _labelViewContainerID = generateViewId(); // relativeLayout need copy rule if (target.getParent() instanceof RelativeLayout) { for (int i = 0; i < parentContainer.getChildCount(); i++) { if (i == groupIndex) { continue; } View view = parentContainer.getChildAt(i); RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams(); for (int j = 0; j < para.getRules().length; j++) { if (para.getRules()[j] == target.getId()) { para.getRules()[j] = _labelViewContainerID; } } view.setLayoutParams(para); } } parentContainer.removeView(target); // new dummy layout FrameLayout labelViewContainer = new FrameLayout(getContext()); ViewGroup.LayoutParams targetLayoutParam = target.getLayoutParams(); labelViewContainer.setLayoutParams(targetLayoutParam); target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // add target and label in dummy layout labelViewContainer.addView(target); labelViewContainer.addView(this); labelViewContainer.setId(_labelViewContainerID); // add dummy layout in parent container parentContainer.addView(labelViewContainer, groupIndex, targetLayoutParam); } return true; }
From source file:lewa.support.v7.internal.widget.ActionBarContextView.java
@Override public void setSplitToolbar(boolean split) { if (mSplitActionBar != split) { if (mActionMenuPresenter != null) { // Mode is already active; move everything over and adjust the menu itself. final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); if (!split) { mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(null); final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); if (oldParent != null) oldParent.removeView(mMenuView); addView(mMenuView, layoutParams); } else { // Allow full screen width in split mode. mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);// w w w .ja va 2s . co m // No limit to the item count; use whatever will fit. mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); // Span the whole width layoutParams.width = LayoutParams.MATCH_PARENT; layoutParams.height = mContentHeight; ///LEWA BEGIN Injector.resetSplitActionBarHeight(getContext(), layoutParams); ///LEWA END mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(mSplitBackground); final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); if (oldParent != null) oldParent.removeView(mMenuView); mSplitView.addView(mMenuView, layoutParams); } } super.setSplitToolbar(split); } }
From source file:gr.plushost.prototypeapp.widgets.LabelView.java
public void remove() { if (getParent() == null || _labelViewContainerID == -1) { return;//from www . j a va 2 s .c o m } ViewGroup frameContainer = (ViewGroup) getParent(); assert (frameContainer.getChildCount() == 2); View target = frameContainer.getChildAt(0); ViewGroup parentContainer = (ViewGroup) frameContainer.getParent(); int groupIndex = parentContainer.indexOfChild(frameContainer); if (frameContainer.getParent() instanceof RelativeLayout) { for (int i = 0; i < parentContainer.getChildCount(); i++) { if (i == groupIndex) { continue; } View view = parentContainer.getChildAt(i); RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams(); for (int j = 0; j < para.getRules().length; j++) { if (para.getRules()[j] == _labelViewContainerID) { para.getRules()[j] = target.getId(); } } view.setLayoutParams(para); } } ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams(); target.setLayoutParams(frameLayoutParam); parentContainer.removeViewAt(groupIndex); frameContainer.removeView(target); frameContainer.removeView(this); parentContainer.addView(target, groupIndex); _labelViewContainerID = -1; }
From source file:it.gmariotti.cardslib.library.view.CardViewNative.java
/** * Setup All listeners//from www. ja v a 2 s . c o m */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") protected void setupListeners() { //Swipe listener if (mCard.isSwipeable()) { this.setOnTouchListener(new SwipeDismissViewTouchListener(this, mCard, new SwipeDismissViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(Card card) { return card.isSwipeable(); } @Override public void onDismiss(CardViewWrapper cardView, Card card) { final ViewGroup vg = (ViewGroup) (((View) cardView).getParent()); if (vg != null) { vg.removeView((View) cardView); card.onSwipeCard(); } } })); } else { this.setOnTouchListener(null); } //OnClick listeners and partial listener //Reset Partial Listeners resetPartialListeners(); if (mCard.isClickable()) { //Set the onClickListener if (!mCard.isMultiChoiceEnabled()) { if (mCard.getOnClickListener() != null) { this.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mCard.getOnClickListener() != null) mCard.getOnClickListener().onClick(mCard, v); } }); //Prevent multiple events //if (!mCard.isSwipeable() && mCard.getOnSwipeListener() == null) { // this.setClickable(true); //} } else { HashMap<Integer, Card.OnCardClickListener> mMultipleOnClickListner = mCard .getMultipleOnClickListener(); if (mMultipleOnClickListner != null && !mMultipleOnClickListner.isEmpty()) { for (int key : mMultipleOnClickListner.keySet()) { View viewClickable = decodeAreaOnClickListener(key); final Card.OnCardClickListener mListener = mMultipleOnClickListner.get(key); if (viewClickable != null) { //Add listener to this view viewClickable.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Callback to card listener if (mListener != null) mListener.onClick(mCard, v); } }); //Add Selector to this view if (key > Card.CLICK_LISTENER_ALL_VIEW) { mHelperImpl.setBackground(viewClickable, mHelperImpl.getResourceFromAttrs( getContext(), android.R.attr.selectableItemBackground)); } } } } else { //There aren't listners this.setClickable(false); } } } } else { this.setClickable(false); } //LongClick listener if (mCard.isLongClickable()) { this.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { if (mCard.getOnLongClickListener() != null) return mCard.getOnLongClickListener().onLongClick(mCard, v); return false; } }); } else { this.setLongClickable(false); } }
From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java
@Override public void destroyItem(ViewGroup container, int position, Object object) { FrameLayout frameLayout = (FrameLayout) object; if (DEBUG)//w w w.ja va 2 s . c om Log.d(TAG, "Removing page #" + (position + 1)); frameLayout.removeAllViews(); Integer indexI = mViewIndexes.get(position); if (indexI != null) { int index = indexI; ReflowWebView webView = mWebViewRepository.getWebView(index); webView.loadUrl("about:blank"); mWebViewRepository.push(index); } else { if (DEBUG) Log.d(TAG, "calling destroyItem for second time at one position"); } mViewHolders.put(position, null); mViewIndexes.put(position, null); container.removeView(frameLayout); }
From source file:at.jclehner.rxdroid.DrugListActivity.java
@TargetApi(11) private void setDate(Date date, int flags) { if (DEBUG_DATE_MISMATCH) Log.d(TAG, "setDate(" + date + ", " + flags + ")"); if (!mIsShowing) { if (LOGV) Log.v(TAG, "setDate: activity is not showing; ignoring"); return;/*from w w w. java 2 s .c o m*/ } if (toastIfPastMaxHistoryAge(date)) return; mCurrentDate = date; getIntent().putExtra(EXTRA_DATE, date); if ((flags & PAGER_INIT) != 0) { mOriginalDate = date; mSwipeDirection = 0; mPager.setOnPageChangeListener(null); mPager.removeAllViews(); final int drugCount = Database.countAll(Drug.class); if (drugCount != 0) { final boolean smoothScroll = (flags & PAGER_SCROLL) != 0; mPager.setAdapter(new InfiniteViewPagerAdapter(this)); mPager.setCurrentItem(InfiniteViewPagerAdapter.CENTER, smoothScroll); mLastPage = InfiniteViewPagerAdapter.CENTER; if (drugCount == 1 && !Settings.wasDisplayedOnce("date_swipe")) { ShowcaseViewBuilder2 svb = new ShowcaseViewBuilder2(this); svb.setText(R.string._help_title_swipe_date, R.string._help_msg_swipe_date); svb.setShotType(ShowcaseView.TYPE_ONE_SHOT); svb.setShowcaseId(0xdeadbeef + 0); svb.setShowcaseItem(ShowcaseView.ITEM_TITLE, 0, this); final DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); final float w = metrics.widthPixels; final float h = metrics.heightPixels; final float y = h * 0.6f; svb.setAnimatedGesture(-100, y, w, y); mShowcaseQueue.add(svb.build()); svb = new ShowcaseViewBuilder2(this); svb.setText(R.string._help_title_edit_drug, R.string._help_msg_edit_drug); svb.setShotType(ShowcaseView.TYPE_ONE_SHOT); svb.setShowcaseId(0xdeadbeef + 1); svb.setShowcaseView(R.id.drug_name, this); mShowcaseQueue.add(svb.build()); } else if (drugCount >= 2 && !Settings.wasDisplayedOnce(Settings.OnceIds.DRAG_DROP_SORTING)) { ShowcaseViewBuilder2 svb = new ShowcaseViewBuilder2(this); svb.setShowcaseView(R.id.drug_icon, this); svb.setText(R.string._help_title_drag_drop_sort, R.string._msg_drag_drop_sorting); svb.setShotType(ShowcaseView.TYPE_ONE_SHOT); svb.setShowcaseId(0xdeadbeef + 2); svb.setRelativeAnimatedGesture(0, 200); mShowcaseQueue.add(svb.build()); } } else { mPager.setAdapter(new PagerAdapter() { @Override public boolean isViewFromObject(View v, Object o) { return v == (View) o; } @Override public int getCount() { // TODO Auto-generated method stub return 1; } @Override public Object instantiateItem(ViewGroup container, int position) { final View v = makeView(0); Util.detachFromParent(v); container.addView(v); return v; } @Override public void destroyItem(ViewGroup container, int position, Object item) { container.removeView((View) item); } }); mPager.setCurrentItem(0); mLastPage = 0; } mPager.setOnPageChangeListener(mPageListener); } supportInvalidateOptionsMenu(); updateDateString(); }
From source file:org.telegram.ui.ActionBar.ActionBarLayout.java
public void closeLastFragment(boolean animated) { if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation() || fragmentsStack.isEmpty()) { return;/* www . j a v a2 s .co m*/ } if (parentActivity.getCurrentFocus() != null) { AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus()); } setInnerTranslationX(0); boolean needAnimation = animated && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE) .getBoolean("view_animations", true); final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1); BaseFragment previousFragment = null; if (fragmentsStack.size() > 1) { previousFragment = fragmentsStack.get(fragmentsStack.size() - 2); } if (previousFragment != null) { LinearLayoutContainer temp = containerView; containerView = containerViewBack; containerViewBack = temp; containerView.setVisibility(View.VISIBLE); previousFragment.setParentLayout(this); View fragmentView = previousFragment.fragmentView; if (fragmentView == null) { fragmentView = previousFragment.createView(parentActivity); } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) { if (removeActionBarExtraHeight) { previousFragment.actionBar.setOccupyStatusBar(false); } ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent(); if (parent != null) { parent.removeView(previousFragment.actionBar); } containerView.addView(previousFragment.actionBar); previousFragment.actionBar.setTitleOverlayText(titleOverlayText); } containerView.addView(fragmentView); ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; fragmentView.setLayoutParams(layoutParams); previousFragment.onTransitionAnimationStart(true, true); currentFragment.onTransitionAnimationStart(false, false); previousFragment.onResume(); currentActionBar = previousFragment.actionBar; if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) { fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background)); } if (!needAnimation) { closeLastFragmentInternalRemoveOld(currentFragment); } if (needAnimation) { transitionAnimationStartTime = System.currentTimeMillis(); transitionAnimationInProgress = true; final BaseFragment previousFragmentFinal = previousFragment; onCloseAnimationEndRunnable = new Runnable() { @Override public void run() { if (Build.VERSION.SDK_INT > 15) { containerView.setLayerType(LAYER_TYPE_NONE, null); containerViewBack.setLayerType(LAYER_TYPE_NONE, null); } closeLastFragmentInternalRemoveOld(currentFragment); containerViewBack.setTranslationX(0); currentFragment.onTransitionAnimationEnd(false, false); previousFragmentFinal.onTransitionAnimationEnd(true, true); previousFragmentFinal.onBecomeFullyVisible(); } }; AnimatorSet animation = currentFragment.onCustomTransitionAnimation(false, new Runnable() { @Override public void run() { onAnimationEndCheck(false); } }); if (animation == null) { if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) { waitingForKeyboardCloseRunnable = new Runnable() { @Override public void run() { if (waitingForKeyboardCloseRunnable != this) { return; } startLayoutAnimation(false, true); } }; AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200); } else { startLayoutAnimation(false, true); } } else { if (Build.VERSION.SDK_INT > 15) { //containerView.setLayerType(LAYER_TYPE_HARDWARE, null); //containerViewBack.setLayerType(LAYER_TYPE_HARDWARE, null); } currentAnimation = animation; } } else { currentFragment.onTransitionAnimationEnd(false, false); previousFragment.onTransitionAnimationEnd(true, true); previousFragment.onBecomeFullyVisible(); } } else { if (useAlphaAnimations) { transitionAnimationStartTime = System.currentTimeMillis(); transitionAnimationInProgress = true; onCloseAnimationEndRunnable = new Runnable() { @Override public void run() { removeFragmentFromStackInternal(currentFragment); setVisibility(GONE); if (backgroundView != null) { backgroundView.setVisibility(GONE); } if (drawerLayoutContainer != null) { drawerLayoutContainer.setAllowOpenDrawer(true, false); } } }; ArrayList<Animator> animators = new ArrayList<>(); animators.add(ObjectAnimator.ofFloat(this, "alpha", 1.0f, 0.0f)); if (backgroundView != null) { animators.add(ObjectAnimator.ofFloat(backgroundView, "alpha", 1.0f, 0.0f)); } currentAnimation = new AnimatorSet(); currentAnimation.playTogether(animators); currentAnimation.setInterpolator(accelerateDecelerateInterpolator); currentAnimation.setDuration(200); currentAnimation.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationStart(Animator animation) { transitionAnimationStartTime = System.currentTimeMillis(); } @Override public void onAnimationEnd(Animator animation) { onAnimationEndCheck(false); } }); currentAnimation.start(); } else { removeFragmentFromStackInternal(currentFragment); setVisibility(GONE); if (backgroundView != null) { backgroundView.setVisibility(GONE); } } } }
From source file:org.telegram.ui.ActionBar.ActionBarLayout.java
public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation, boolean check) { if (checkTransitionAnimation() || delegate != null && check && !delegate.needPresentFragment(fragment, removeLast, forceWithoutAnimation, this) || !fragment.onFragmentCreate()) { return false; }//from w w w .j a va 2 s . c o m if (parentActivity.getCurrentFocus() != null) { AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus()); } boolean needAnimation = !forceWithoutAnimation && parentActivity .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true); final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null; fragment.setParentLayout(this); View fragmentView = fragment.fragmentView; if (fragmentView == null) { fragmentView = fragment.createView(parentActivity); } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } if (fragment.actionBar != null && fragment.actionBar.getAddToContainer()) { if (removeActionBarExtraHeight) { fragment.actionBar.setOccupyStatusBar(false); } ViewGroup parent = (ViewGroup) fragment.actionBar.getParent(); if (parent != null) { parent.removeView(fragment.actionBar); } containerViewBack.addView(fragment.actionBar); fragment.actionBar.setTitleOverlayText(titleOverlayText); } containerViewBack.addView(fragmentView); ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; fragmentView.setLayoutParams(layoutParams); fragmentsStack.add(fragment); fragment.onResume(); currentActionBar = fragment.actionBar; if (!fragment.hasOwnBackground && fragmentView.getBackground() == null) { fragmentView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.background)); } LinearLayoutContainer temp = containerView; containerView = containerViewBack; containerViewBack = temp; containerView.setVisibility(View.VISIBLE); setInnerTranslationX(0); bringChildToFront(containerView); if (!needAnimation) { presentFragmentInternalRemoveOld(removeLast, currentFragment); if (backgroundView != null) { backgroundView.setVisibility(VISIBLE); } } if (needAnimation) { if (useAlphaAnimations && fragmentsStack.size() == 1) { presentFragmentInternalRemoveOld(removeLast, currentFragment); transitionAnimationStartTime = System.currentTimeMillis(); transitionAnimationInProgress = true; onOpenAnimationEndRunnable = new Runnable() { @Override public void run() { fragment.onTransitionAnimationEnd(true, false); fragment.onBecomeFullyVisible(); } }; ArrayList<Animator> animators = new ArrayList<>(); animators.add(ObjectAnimator.ofFloat(this, "alpha", 0.0f, 1.0f)); if (backgroundView != null) { backgroundView.setVisibility(VISIBLE); animators.add(ObjectAnimator.ofFloat(backgroundView, "alpha", 0.0f, 1.0f)); } fragment.onTransitionAnimationStart(true, false); currentAnimation = new AnimatorSet(); currentAnimation.playTogether(animators); currentAnimation.setInterpolator(accelerateDecelerateInterpolator); currentAnimation.setDuration(200); currentAnimation.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animation) { onAnimationEndCheck(false); } }); currentAnimation.start(); } else { transitionAnimationStartTime = System.currentTimeMillis(); transitionAnimationInProgress = true; onOpenAnimationEndRunnable = new Runnable() { @Override public void run() { if (Build.VERSION.SDK_INT > 15) { containerView.setLayerType(LAYER_TYPE_NONE, null); containerViewBack.setLayerType(LAYER_TYPE_NONE, null); } presentFragmentInternalRemoveOld(removeLast, currentFragment); fragment.onTransitionAnimationEnd(true, false); fragment.onBecomeFullyVisible(); containerView.setTranslationX(0); } }; fragment.onTransitionAnimationStart(true, false); AnimatorSet animation = fragment.onCustomTransitionAnimation(true, new Runnable() { @Override public void run() { onAnimationEndCheck(false); } }); if (animation == null) { containerView.setAlpha(0.0f); containerView.setTranslationX(48.0f); if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) { waitingForKeyboardCloseRunnable = new Runnable() { @Override public void run() { if (waitingForKeyboardCloseRunnable != this) { return; } startLayoutAnimation(true, true); } }; AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200); } else if (fragment.needDelayOpenAnimation()) { delayedOpenAnimationRunnable = new Runnable() { @Override public void run() { if (delayedOpenAnimationRunnable != this) { return; } delayedOpenAnimationRunnable = null; startLayoutAnimation(true, true); } }; AndroidUtilities.runOnUIThread(delayedOpenAnimationRunnable, 200); } else { startLayoutAnimation(true, true); } } else { if (Build.VERSION.SDK_INT > 15) { //containerView.setLayerType(LAYER_TYPE_HARDWARE, null); //containerViewBack.setLayerType(LAYER_TYPE_HARDWARE, null); } containerView.setAlpha(1.0f); containerView.setTranslationX(0.0f); currentAnimation = animation; } } } else { if (backgroundView != null) { backgroundView.setAlpha(1.0f); backgroundView.setVisibility(VISIBLE); } fragment.onTransitionAnimationStart(true, false); fragment.onTransitionAnimationEnd(true, false); fragment.onBecomeFullyVisible(); } return true; }
From source file:org.telegram.ui.ThemePreviewActivity.java
@Override public View createView(Context context) { page1 = new FrameLayout(context); ActionBarMenu menu = actionBar.createMenu(); final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override//w w w.j av a 2 s . c o m public void onSearchExpand() { } @Override public boolean canCollapseSearch() { return true; } @Override public void onSearchCollapse() { } @Override public void onTextChanged(EditText editText) { } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); actionBar.setBackButtonDrawable(new MenuDrawable()); actionBar.setAddToContainer(false); actionBar.setTitle(LocaleController.getString("ThemePreview", R.string.ThemePreview)); page1 = new FrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar.getMeasuredHeight(); if (actionBar.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.topMargin = actionBarHeight; listView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); measureChildWithMargins(floatingButton, widthMeasureSpec, 0, heightMeasureSpec, 0); } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0); } return result; } }; page1.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setLayoutAnimation(null); listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT); page1.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); floatingButton = new ImageView(context); floatingButton.setScaleType(ImageView.ScaleType.CENTER); Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground)); if (Build.VERSION.SDK_INT < 21) { Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate(); shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY)); CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0); combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56)); drawable = combinedDrawable; } floatingButton.setBackgroundDrawable(drawable); floatingButton.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY)); floatingButton.setImageResource(R.drawable.floating_pencil); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); floatingButton.setStateListAnimator(animator); floatingButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } page1.addView(floatingButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); dialogsAdapter = new DialogsAdapter(context); listView.setAdapter(dialogsAdapter); page2 = new SizeNotifierFrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); measureChildWithMargins(actionBar2, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar2.getMeasuredHeight(); if (actionBar2.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView2.getLayoutParams(); layoutParams.topMargin = actionBarHeight; listView2.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar2 && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar2.getVisibility() == VISIBLE ? actionBar2.getMeasuredHeight() : 0); } return result; } }; page2.setBackgroundImage(Theme.getCachedWallpaper()); actionBar2 = createActionBar(context); actionBar2.setBackButtonDrawable(new BackDrawable(false)); actionBar2.setTitle("Reinhardt"); actionBar2.setSubtitle(LocaleController.formatDateOnline(System.currentTimeMillis() / 1000 - 60 * 60)); page2.addView(actionBar2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); listView2 = new RecyclerListView(context); listView2.setVerticalScrollBarEnabled(true); listView2.setItemAnimator(null); listView2.setLayoutAnimation(null); listView2.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4)); listView2.setClipToPadding(false); listView2.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)); listView2.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT); page2.addView(listView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); messagesAdapter = new MessagesAdapter(context); listView2.setAdapter(messagesAdapter); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; final ViewPager viewPager = new ViewPager(context); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { dotsContainer.invalidate(); } @Override public void onPageScrollStateChanged(int state) { } }); viewPager.setAdapter(new PagerAdapter() { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(View view, Object object) { return object == view; } @Override public int getItemPosition(Object object) { return POSITION_UNCHANGED; } @Override public Object instantiateItem(ViewGroup container, int position) { View view = position == 0 ? page1 : page2; container.addView(view); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { if (observer != null) { super.unregisterDataSetObserver(observer); } } }); AndroidUtilities.setViewPagerEdgeEffectColor(viewPager, Theme.getColor(Theme.key_actionBarDefault)); frameLayout.addView(viewPager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48)); View shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow_reverse); frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48)); FrameLayout bottomLayout = new FrameLayout(context); bottomLayout.setBackgroundColor(0xffffffff); frameLayout.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM)); dotsContainer = new View(context) { private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); @Override protected void onDraw(Canvas canvas) { int selected = viewPager.getCurrentItem(); for (int a = 0; a < 2; a++) { paint.setColor(a == selected ? 0xff999999 : 0xffcccccc); canvas.drawCircle(AndroidUtilities.dp(3 + 15 * a), AndroidUtilities.dp(4), AndroidUtilities.dp(3), paint); } } }; bottomLayout.addView(dotsContainer, LayoutHelper.createFrame(22, 8, Gravity.CENTER)); TextView cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(0xff19a7e8); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0)); cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Theme.applyPreviousTheme(); parentLayout.rebuildAllFragmentViews(false); finishFragment(); } }); TextView doneButton = new TextView(context); doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButton.setTextColor(0xff19a7e8); doneButton.setGravity(Gravity.CENTER); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0)); doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); doneButton.setText(LocaleController.getString("ApplyTheme", R.string.ApplyTheme).toUpperCase()); doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { applied = true; parentLayout.rebuildAllFragmentViews(false); Theme.applyThemeFile(themeFile, applyingTheme.name, false); finishFragment(); } }); return fragmentView; }
From source file:com.taobao.weex.ui.component.WXComponent.java
private void setFixedHostLayoutParams(T host, int width, int height, int left, int right, int top, int bottom) { if (host.getParent() instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) host.getParent(); viewGroup.removeView(host); }// ww w. ja v a 2s .c o m FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.width = width; params.height = height; params.setMargins(left, top, right, bottom); host.setLayoutParams(params); mInstance.addFixedView(host); if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("Weex_Fixed_Style", "WXComponent:setLayout :" + left + " " + top + " " + width + " " + height); WXLogUtils.d("Weex_Fixed_Style", "WXComponent:setLayout Left:" + mDomObj.getStyles().getLeft() + " " + (int) mDomObj.getStyles().getTop()); } }