Java Code Examples for android.view.ViewGroup#getLayoutParams()

The following examples show how to use android.view.ViewGroup#getLayoutParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntroScreenSlidePagerAdapter.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(19)
private void showFloatingFrameButton(View layout) {
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    boolean shouldHideFloatingFrame = false;

    ViewGroup frame = layout.findViewById(R.id.NL_frame);
    View floatingFrame = layout.findViewById(R.id.floating_frame);
    floatingFrame.setVisibility(nlEnabled && !shouldHideFloatingFrame ? View.VISIBLE : isLandscape ? View.GONE : View.INVISIBLE);
    if (frame != null) {
        frame.setVisibility(isLandscape && nlEnabled ? View.INVISIBLE : View.VISIBLE);
        RelativeLayout.LayoutParams frameParams = (RelativeLayout.LayoutParams) frame.getLayoutParams();

        frameParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        frameParams.setMargins(frameParams.leftMargin, frameParams.topMargin, frameParams.rightMargin, 0);
        frameParams.removeRule(RelativeLayout.CENTER_VERTICAL);
        frame.setLayoutParams(frameParams);
    }
}
 
Example 2
Source File: SwipeBackLayout.java    From ExpressHelper with GNU General Public License v3.0 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    LayoutParams p = (LayoutParams) decorChild.getLayoutParams();
    FrameLayout newRoot = new FrameLayout(getContext());
    decor.removeView(decorChild);
    newRoot.addView(decorChild, p);
    p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    addView(newRoot, p);
    setContentView(newRoot);
    setLayoutParams(p);
    decor.addView(this, p);
}
 
Example 3
Source File: DemoActivity_2.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
private void initView() {
    LayoutInflater inflater = getLayoutInflater();
    mListContainer = (HorizontalScrollViewEx) findViewById(R.id.container);
    final int screenWidth = MyUtils.getScreenMetrics(this).widthPixels;
    final int screenHeight = MyUtils.getScreenMetrics(this).heightPixels;
    for (int i = 0; i < 1; i++) {
        ViewGroup layout = (ViewGroup) inflater.inflate(
                R.layout.content_layout, mListContainer, false);
        layout.getLayoutParams().width = screenWidth;
        TextView textView = (TextView) layout.findViewById(R.id.title);
        textView.setText("page " + (i + 1));
        layout.setBackgroundColor(Color.rgb(255 / (i + 1), 255 / (i + 1), 0));
        createList(layout);
        mListContainer.addView(layout);
    }
}
 
Example 4
Source File: GroupedRecyclerViewItemFrameLayout.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup viewGroup) {
	viewGroup.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;

	final FrameLayout frameLayout = new FrameLayout(viewGroup.getContext());
	return new RecyclerView.ViewHolder(frameLayout) {};
}
 
Example 5
Source File: Tab.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @param manager The fullscreen manager that should be notified of changes to this tab (if
 *                set to null, no more updates will come from this tab).
 */
public void setFullscreenManager(FullscreenManager manager) {
    mFullscreenManager = manager;
    if (mFullscreenManager != null) {
        boolean topOffsetsInitialized = !Float.isNaN(mPreviousTopControlsOffsetY)
                && !Float.isNaN(mPreviousContentOffsetY);
        boolean bottomOffsetsInitialized =
                !Float.isNaN(mPreviousBottomControlsOffsetY);
        boolean isChromeHomeEnabled = FeatureUtilities.isChromeHomeEnabled();

        // Make sure the dominant control offsets have been set.
        if ((!topOffsetsInitialized && !isChromeHomeEnabled)
                || (!bottomOffsetsInitialized && isChromeHomeEnabled)) {
            mFullscreenManager.setPositionsForTabToNonFullscreen();
        } else {
            mFullscreenManager.setPositionsForTab(mPreviousTopControlsOffsetY,
                    mPreviousBottomControlsOffsetY,
                    mPreviousContentOffsetY);
        }
        updateFullscreenEnabledState();
    }

    // For blimp mode, offset the blimp view by the height of browser controls. This will ensure
    // that the view doesn't get clipped at the bottom of the page and also the touch offsets
    // would work correctly.
    if (getBlimpContents() != null && mFullscreenManager != null) {
        ViewGroup blimpView = getBlimpContents().getView();
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) blimpView.getLayoutParams();
        if (lp == null) {
            lp = new FrameLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        }

        lp.topMargin = mFullscreenManager.getTopControlsHeight();
        blimpView.setLayoutParams(lp);
    }
}
 
Example 6
Source File: MaterialViewPager.java    From MaterialViewPager with Apache License 2.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    //add @layout/material_view_pager_layout as child, containing all the MaterialViewPager views
    addView(LayoutInflater.from(getContext()).inflate(R.layout.material_view_pager_layout, this, false));

    headerBackgroundContainer = (ViewGroup) findViewById(R.id.headerBackgroundContainer);
    pagerTitleStripContainer = (ViewGroup) findViewById(R.id.pagerTitleStripContainer);
    viewpagerContainer = (ViewGroup) findViewById(R.id.viewpager_layout);
    logoContainer = (ViewGroup) findViewById(R.id.logoContainer);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (settings.disableToolbar) {
        mToolbar.setVisibility(INVISIBLE);
    }

    { //replace the viewpager ?
        int viewPagerLayoutId = settings.viewpagerId;
        if (viewPagerLayoutId != -1) {
            viewpagerContainer.removeAllViews();
            viewpagerContainer.addView(LayoutInflater.from(getContext()).inflate(viewPagerLayoutId, viewpagerContainer, false));
        }
    }

    mViewPager = (ViewPager) findViewById(R.id.materialviewpager_viewpager);

    mViewPager.addOnPageChangeListener(this);

    //inflate subviews defined in attributes

    {
        int headerId = settings.headerLayoutId;
        if (headerId == -1) {
            if (settings.animatedHeaderImage) {
                headerId = R.layout.material_view_pager_moving_header;
            } else {
                headerId = R.layout.material_view_pager_imageview_header;
            }
        }
        headerBackgroundContainer.addView(LayoutInflater.from(getContext()).inflate(headerId, headerBackgroundContainer, false));
    }

    if (isInEditMode()) { //preview titlestrip
        //add fake tabs on edit mode
        settings.pagerTitleStripId = R.layout.tools_material_view_pager_pagertitlestrip;
    }
    if (settings.pagerTitleStripId != -1) {
        pagerTitleStripContainer.addView(LayoutInflater.from(getContext()).inflate(settings.pagerTitleStripId, pagerTitleStripContainer, false));
    }

    if (settings.logoLayoutId != -1) {
        logoContainer.addView(LayoutInflater.from(getContext()).inflate(settings.logoLayoutId, logoContainer, false));
        if (settings.logoMarginTop != 0) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) logoContainer.getLayoutParams();
            layoutParams.setMargins(0, settings.logoMarginTop, 0, 0);
            logoContainer.setLayoutParams(layoutParams);
        }
    }

    headerBackground = findViewById(R.id.headerBackground);
    toolbarLayoutBackground = findViewById(R.id.toolbar_layout_background);

    initialiseHeights();

    //construct the materialViewPagerHeader with subviews
    if (!isInEditMode()) {
        materialViewPagerHeader = MaterialViewPagerHeader
            .withToolbar(mToolbar)
            .withToolbarLayoutBackground(toolbarLayoutBackground)
            .withPagerSlidingTabStrip(pagerTitleStripContainer)
            .withHeaderBackground(headerBackground)
            .withStatusBackground(findViewById(R.id.statusBackground))
            .withLogo(logoContainer);

        //and construct the MaterialViewPagerAnimator
        //attach it to the activity to enable MaterialViewPagerHeaderView.setMaterialHeight();
        MaterialViewPagerHelper.register(getContext(), new MaterialViewPagerAnimator(this));
    } else {

        //if in edit mode, add fake cardsviews
        View sample = LayoutInflater.from(getContext()).inflate(R.layout.tools_list_items, pagerTitleStripContainer, false);

        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) sample.getLayoutParams();
        int marginTop = Math.round(Utils.dpToPx(settings.headerHeight + 10, getContext()));
        params.setMargins(0, marginTop, 0, 0);
        super.setLayoutParams(params);

        addView(sample);
    }
}
 
Example 7
Source File: LabelView.java    From labelview with Apache License 2.0 5 votes vote down vote up
public void remove() {
    if (getParent() == null || _labelViewContainerID == -1) {
        return;
    }

    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;
}
 
Example 8
Source File: SwipeableLayout.java    From SwipeableLayout with GNU General Public License v2.0 5 votes vote down vote up
private void resetForContainer(ViewGroup aContainer, View aChild) {
    if (aContainer.getChildAt(0).getTag() == null) return;

    aContainer.removeViewAt(0);
    aContainer.addView(aChild, 0, aChild.getLayoutParams());
    aContainer.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
    aContainer.requestLayout();
}
 
Example 9
Source File: LayoutWrapContentUpdater.java    From android-layout-wrap-content-updater with MIT License 5 votes vote down vote up
/**
 * Same as previous, but with given size in case subTreeRoot itself has layout_width or layout_height = "wrap_content"
 */
public static void wrapContentAgain( ViewGroup subTreeRoot, boolean relayoutAllNodes,
		int subTreeRootWidthMeasureSpec, int subTreeRootHeightMeasureSpec  )
{
	Log.d(TAG, "+++ LayoutWrapContentUpdater wrapContentAgain on subTreeRoot=["+ subTreeRoot +"], with w="
			+ subTreeRootWidthMeasureSpec +" and h="+ subTreeRootHeightMeasureSpec );
	assert( "main".equals( Thread.currentThread().getName() ) );
	
	if (subTreeRoot == null)
		return;
	LayoutParams layoutParams = subTreeRoot.getLayoutParams();

	// --- First, we force measure on the subTree
	int widthMeasureSpec 	= subTreeRootWidthMeasureSpec;
	// When LayoutParams.MATCH_PARENT and Width > 0, we apply measured width to avoid getting dimensions too big
	if ( layoutParams.width  != LayoutParams.WRAP_CONTENT && subTreeRoot.getWidth() > 0 )
		widthMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getWidth(), MeasureSpec.EXACTLY );
	int heightMeasureSpec 	= subTreeRootHeightMeasureSpec;
	// When LayoutParams.MATCH_PARENT and Height > 0, we apply measured height to avoid getting dimensions too big
	if ( layoutParams.height != LayoutParams.WRAP_CONTENT && subTreeRoot.getHeight() > 0 )
		heightMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getHeight(), MeasureSpec.EXACTLY );
	// This measure recursively the whole sub-tree
	subTreeRoot.measure( widthMeasureSpec, heightMeasureSpec ); 

	// --- Then recurse on all children to correct the sizes 
	recurseWrapContent( subTreeRoot, relayoutAllNodes );

	// --- RequestLayout to finish properly
	subTreeRoot.requestLayout();		
	return;
}
 
Example 10
Source File: LayoutWrapContentUpdater.java    From MaterialScrollBar with Apache License 2.0 5 votes vote down vote up
/**
 * Same as previous, but with given size in case subTreeRoot itself has layout_width or layout_height = "wrap_content"
 */
private static void wrapContentAgain(ViewGroup subTreeRoot, boolean relayoutAllNodes,
                                     int subTreeRootWidthMeasureSpec, int subTreeRootHeightMeasureSpec)
{
    assert( "main".equals( Thread.currentThread().getName() ) );

    if(subTreeRoot == null)
        return;
    LayoutParams layoutParams = subTreeRoot.getLayoutParams();

    // --- First, we force measure on the subTree
    int widthMeasureSpec 	= subTreeRootWidthMeasureSpec;
    // When LayoutParams.MATCH_PARENT and Width > 0, we apply measured width to avoid getting dimensions too big
    if( layoutParams.width  != LayoutParams.WRAP_CONTENT && subTreeRoot.getWidth() > 0 )
        widthMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getWidth(), MeasureSpec.EXACTLY );
    int heightMeasureSpec 	= subTreeRootHeightMeasureSpec;
    // When LayoutParams.MATCH_PARENT and Height > 0, we apply measured height to avoid getting dimensions too big
    if( layoutParams.height != LayoutParams.WRAP_CONTENT && subTreeRoot.getHeight() > 0 )
        heightMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getHeight(), MeasureSpec.EXACTLY );
    // This measure recursively the whole sub-tree
    subTreeRoot.measure( widthMeasureSpec, heightMeasureSpec );

    // --- Then recurse on all children to correct the sizes
    recurseWrapContent( subTreeRoot, relayoutAllNodes );

    // --- RequestLayout to finish properly
    subTreeRoot.requestLayout();
}
 
Example 11
Source File: StateViewHelper.java    From StateManager with Apache License 2.0 5 votes vote down vote up
/**
 * 显示视图
 * 如果stateView为null,则需要创建
 *
 * @return
 */
public static boolean showStater(Context context, ViewGroup overallView, IState stater) {

    if (stater == null || overallView ==null) {
        return false;
    }
    View staterView = stater.getView();
    if (staterView == null) {
        stater.onStateCreate(context, overallView);
        staterView = stater.getView();
        if (staterView == null) {
            return false;
        }
    }

    ViewGroup.LayoutParams layoutParams = overallView.getLayoutParams();
    if (layoutParams == null) {
        layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
    layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    if (overallView.indexOfChild(staterView) < 0 && staterView.getParent() == null) {
        overallView.addView(staterView, layoutParams);
    }
    stater.getView().setVisibility(View.VISIBLE);
    stater.onStateResume();
    return true;
}
 
Example 12
Source File: DragLayoutOne.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mIsOnce) {
        mWapper = (LinearLayout) getChildAt(0);
        mMenuViewGroup = (ViewGroup) mWapper.getChildAt(0);
        mContentViewGroup = (ViewGroup) mWapper.getChildAt(1);
        mMenuWidth = mMenuViewGroup.getLayoutParams().width = mScreenWidth - mMenuRightPadding;
        mContentViewGroup.getLayoutParams().width = mScreenWidth;
        mIsOnce = false;
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
 
Example 13
Source File: DynamicDrawerActivity.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Configure navigation drawer for the persistent mode.
 */
private void configureDrawer() {
    if (isPersistentDrawer()) {
        mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
        mDrawer.setScrimColor(Color.TRANSPARENT);
        mDrawerToggle.setDrawerIndicatorEnabled(false);

        ViewGroup frame = findViewById(R.id.ads_activity_root);

        if (frame != null && frame.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams params =
                    (ViewGroup.MarginLayoutParams) frame.getLayoutParams();

            if (DynamicLocaleUtils.isLayoutRtl()) {
                params.rightMargin = getResources().getDimensionPixelOffset(
                        R.dimen.ads_margin_content_start);
            } else {
                params.leftMargin = getResources().getDimensionPixelOffset(
                        R.dimen.ads_margin_content_start);
            }

            frame.setLayoutParams(params);
        }
    } else {
        if (isDrawerLocked()) {
            mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            getContentView().post(new Runnable() {
                @Override
                public void run() {
                    mDrawer.closeDrawers();
                }
            });
        }
    }
}
 
Example 14
Source File: TipsUtils.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void removeContainerView(ViewGroup tipsContainerView, View targetView) {
    ViewGroup parent = (ViewGroup) tipsContainerView.getParent();
    ViewGroup.LayoutParams targetParams = tipsContainerView.getLayoutParams();
    int index = parent.indexOfChild(tipsContainerView);
    parent.removeViewAt(index);
    if (targetView.getParent() != null) {
        ((ViewGroup) targetView.getParent()).removeView(targetView);
    }
    parent.addView(targetView, index, targetParams);
}
 
Example 15
Source File: DefaultHeaderTransformer.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onViewCreated(Activity activity, View headerView) {
    // Get ProgressBar and TextView. Also set initial text on TextView
    mHeaderProgressBar = (ProgressBar) headerView.findViewById(R.id.ptr_progress);
    mHeaderTextView = (TextView) headerView.findViewById(R.id.ptr_text);

    // Apply any custom ProgressBar colors
    applyProgressBarColor();

    // Labels to display
    mPullRefreshLabel = activity.getString(R.string.pull_to_refresh_pull_label);
    mRefreshingLabel = activity.getString(R.string.pull_to_refresh_refreshing_label);
    mReleaseLabel = activity.getString(R.string.pull_to_refresh_release_label);

    // Retrieve the Action Bar size from the Activity's theme
    mContentLayout = (ViewGroup) headerView.findViewById(R.id.ptr_content);
    if (mContentLayout != null) {
        mContentLayout.getLayoutParams().height = getActionBarSize(activity);
        mContentLayout.requestLayout();
    }

    // Retrieve the Action Bar background from the Activity's theme (see #93).
    Drawable abBg = getActionBarBackground(activity);
    if (abBg != null) {
        // If we do not have a opaque background we just display a solid solid behind it
        if (abBg.getOpacity() != PixelFormat.OPAQUE) {
            View view = headerView.findViewById(R.id.ptr_text_opaque_bg);
            if (view != null) {
                view.setVisibility(View.VISIBLE);
            }
        }

        mHeaderTextView.setBackgroundDrawable(abBg);
    }

    // Retrieve the Action Bar Title Style from the Action Bar's theme
    Context abContext = headerView.getContext();
    final int titleTextStyle = getActionBarTitleStyle(abContext);
    if (titleTextStyle != 0) {
        mHeaderTextView.setTextAppearance(abContext, titleTextStyle);
    }

    // Call onReset to make sure that the View is consistent
    onReset();
}
 
Example 16
Source File: AbstractMessage.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
@CallSuper
protected void updateLayoutForReceive(VH holder) {
    ViewGroup frameLayout = (ViewGroup) holder.itemView.findViewById(R.id.mainContainer);
    ImageView imgTick = (ImageView) holder.itemView.findViewById(R.id.cslr_txt_tic);
    TextView messageText = (TextView) holder.itemView.findViewById(R.id.messageSenderTextMessage);

    LinearLayout root = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer);
    LinearLayout timeLayout = (LinearLayout) root.getParent();
    timeLayout.setGravity(Gravity.LEFT);

    if (messageText != null) {
        messageText.setTextColor(Color.parseColor(G.textBubble));
    }
    //   ProtoGlobal.RoomMessageType messageType = mMessage.forwardedFrom == null ? mMessage.messageType : mMessage.forwardedFrom.getMessageType();

    if (G.isDarkTheme) {
        setTextColor(imgTick, R.color.white);
    } else {
        setTextColor(imgTick, R.color.colorOldBlack);
    }


    ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).gravity = Gravity.LEFT;

    ((LinearLayout.LayoutParams) root.getLayoutParams()).gravity = Gravity.LEFT;

    if (G.isDarkTheme) {
        ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangel_white_round_dark);
    } else {
        ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangel_white_round);
    }

    /**
     * add main layout margin to prevent getting match parent completely
     * set to mainContainer not itemView because of selecting item foreground
     */

    GradientDrawable circleDarkColor = (GradientDrawable) ((View) root.getParent()).getBackground();
    circleDarkColor.setColor(Color.parseColor(G.bubbleChatReceive));

    ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).leftMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp10);
    ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).rightMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp28);
}
 
Example 17
Source File: AbstractMessage.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
@CallSuper
    protected void updateLayoutForSend(VH holder) {

        ViewGroup frameLayout = (ViewGroup) holder.itemView.findViewById(R.id.mainContainer);
        ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).gravity = Gravity.RIGHT;
        LinearLayout root = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer);

        ((LinearLayout.LayoutParams) root.getLayoutParams()).gravity = Gravity.RIGHT;

        LinearLayout timeLayout = (LinearLayout) root.getParent();
        timeLayout.setGravity(Gravity.RIGHT);

        ImageView imgTick = (ImageView) holder.itemView.findViewById(R.id.cslr_txt_tic);
        TextView messageText = (TextView) holder.itemView.findViewById(R.id.messageSenderTextMessage);
        //  TextView iconHearing = (TextView) holder.itemView.findViewById(R.id.cslr_txt_hearing);

        if (messageText != null) {
            messageText.setTextColor(Color.parseColor(G.textBubble));
        }
        //   ProtoGlobal.RoomMessageType messageType = mMessage.forwardedFrom == null ? mMessage.messageType : mMessage.forwardedFrom.getMessageType();


        ProtoGlobal.RoomMessageStatus status = ProtoGlobal.RoomMessageStatus.UNRECOGNIZED;
        if (mMessage.status != null) {
            try {
                status = ProtoGlobal.RoomMessageStatus.valueOf(mMessage.status);
            } catch (RuntimeException e) {
                e.printStackTrace();
            }
        }

        if (status == ProtoGlobal.RoomMessageStatus.SEEN) {
            if (G.isDarkTheme) {
                setTextColor(imgTick, R.color.iGapColor);
            } else {
                setTextColor(imgTick, R.color.backgroundColorCall2);
            }

        } else if (status == ProtoGlobal.RoomMessageStatus.LISTENED) {
            // iconHearing.setVisibility(View.VISIBLE);
            if (G.isDarkTheme) {
                setTextColor(imgTick, R.color.iGapColor);
            } else {
                setTextColor(imgTick, R.color.backgroundColorCall2);
            }

            imgTick.setVisibility(View.VISIBLE);
        } else {
//            setTextColor(imgTick, Color.parseColor(G.txtIconCheck));
            imgTick.setColorFilter(Color.parseColor(G.txtIconCheck));
        }


        if (G.isDarkTheme) {
            ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangle_send_round_color_dark);
        } else {
            ((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangle_send_round_color);
        }
        GradientDrawable circleDarkColor = (GradientDrawable) ((View) root.getParent()).getBackground();
        circleDarkColor.setColor(Color.parseColor(G.bubbleChatSend));

        /**
         * add main layout margin to prevent getting match parent completely
         * set to mainContainer not itemView because of selecting item foreground
         */
        ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).leftMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp28);
        ((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).rightMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp10);

        //((LinearLayout.LayoutParams) (holder.itemView.findViewById(R.id.contentContainer).getLayoutParams())).rightMargin = (int) holder.itemView.getResources().getDimension(R.dimen.messageBox_minusLeftRightMargin);
        //((LinearLayout.LayoutParams) (holder.itemView.findViewById(R.id.contentContainer).getLayoutParams())).leftMargin = 0;
    }
 
Example 18
Source File: DynamicAlertController.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
private void setupCustomContent(ViewGroup customPanel) {
    final View customView;
    if (mView != null) {
        customView = mView;
    } else if (mViewLayoutResId != 0) {
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        customView = inflater.inflate(mViewLayoutResId, customPanel, false);
    } else {
        customView = null;
    }

    if (customView != null && mViewRoot == null) {
        if (mViewRootId != 0) {
            mViewRoot = customView.findViewById(mViewRootId);

            if (mViewRoot == null) {
                throw new NullPointerException("Unable to find root view for the supplied id "
                        + mViewRootId + ".");
            }
        }
    }

    final boolean hasCustomView = customView != null;
    if (!hasCustomView || !canTextInput(customView)) {
        mWindow.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }

    if (hasCustomView) {
        final FrameLayout custom = mWindow.findViewById(R.id.custom);
        custom.addView(customView, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

        if (mViewSpacingSpecified) {
            custom.setPadding(
                    mViewSpacingLeft, mViewSpacingTop, mViewSpacingRight, mViewSpacingBottom);
        }

        if (mListView != null) {
            ((LinearLayout.LayoutParams) customPanel.getLayoutParams()).weight = 0;
        }
    } else {
        customPanel.setVisibility(View.GONE);
    }
}
 
Example 19
Source File: ASViewGroupUtil.java    From AutoScalingLayout with MIT License 4 votes vote down vote up
/**
 * 测量宽高(只有一方数值确定,另一方为WRAP_CONTENT才需要测量,用于保持纵横比)
 * @param vg ViewGroup
 * @param widthMeasureSpec  宽度
 * @param heightMeasureSpec 高度
 * @return 测量好的宽高
 */
public int[] onMeasure(ViewGroup vg, int widthMeasureSpec, int heightMeasureSpec) {
    int measureSpecs[] = new int[2];
    measureSpecs[0] = widthMeasureSpec;
    measureSpecs[1] = heightMeasureSpec;

    if (!mAutoScaleEnable)
        return measureSpecs;

    int widthMode = View.MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = View.MeasureSpec.getMode(heightMeasureSpec);

    int width = View.MeasureSpec.getSize(widthMeasureSpec);
    int height = View.MeasureSpec.getSize(heightMeasureSpec);

    ViewGroup.LayoutParams params = vg.getLayoutParams();

    // 已知宽度
    boolean bScalingWidth = widthMode == View.MeasureSpec.EXACTLY && ViewGroup.LayoutParams.MATCH_PARENT == params.width;
    // 已知高度
    boolean bScalingHeight = heightMode == View.MeasureSpec.EXACTLY && ViewGroup.LayoutParams.MATCH_PARENT == params.height;

    if (bScalingHeight && bScalingWidth && TYPE_FIT_INSIDE == mScaleType){
        scaleSize(vg, width, height, TYPE_FIT_INSIDE);
    }
    else if (bScalingHeight && TYPE_FIT_HEIGHT == mScaleType){
        scaleSize(vg, width, height, TYPE_FIT_HEIGHT);
    }
    else if (bScalingWidth && TYPE_FIT_WIDTH == mScaleType){
        scaleSize(vg, width, height, TYPE_FIT_WIDTH);
    }

    if (0 == mDesignWidth || 0 == mDesignHeight)
        return measureSpecs;

    if ( TYPE_FIT_INSIDE != mScaleType)
        return measureSpecs;

    if (widthMode != View.MeasureSpec.EXACTLY
            && heightMode == View.MeasureSpec.EXACTLY
            && ViewGroup.LayoutParams.WRAP_CONTENT == params.width) {
        // 高度为match_parent或具体值,宽度wrap_content
        width = (height * mDesignWidth / mDesignHeight);
        measureSpecs[0] = View.MeasureSpec.makeMeasureSpec(width,
                View.MeasureSpec.EXACTLY);
    }else if (widthMode == View.MeasureSpec.EXACTLY
            && heightMode != View.MeasureSpec.EXACTLY
            && ViewGroup.LayoutParams.WRAP_CONTENT == params.height) {
        // 宽度为match_parent或具体值,高度为wrap_content
        height = (width * mDesignHeight / mDesignWidth);
        measureSpecs[1] = View.MeasureSpec.makeMeasureSpec(height,
                View.MeasureSpec.EXACTLY);
    }

    return measureSpecs;
}
 
Example 20
Source File: EasyAlertDialog.java    From NIM_Android_UIKit with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(resourceId);
    try {
        ViewGroup root = (ViewGroup) findViewById(R.id.easy_alert_dialog_layout);
        if (root != null) {
            ViewGroup.LayoutParams params = root.getLayoutParams();
            params.width = (int) ScreenUtil.getDialogWidth();
            root.setLayoutParams(params);
        }

        titleView = findViewById(R.id.easy_dialog_title_view);
        if (titleView != null) {
            setTitleVisible(isTitleVisible);
        }
        titleBtn = (ImageButton) findViewById(R.id.easy_dialog_title_button);
        if (titleBtn != null) {
            setTitleBtnVisible(isTitleBtnVisible);
        }
        titleTV = (TextView) findViewById(R.id.easy_dialog_title_text_view);
        if (titleTV != null) {
            titleTV.setText(title);
            if (NO_TEXT_COLOR != titleTextColor)
                titleTV.setTextColor(titleTextColor);
            if (NO_TEXT_SIZE != titleTextSize)
                titleTV.setTextSize(titleTextSize);
        }

        messageTV = (TextView) findViewById(R.id.easy_dialog_message_text_view);
        if (messageTV != null) {
            messageTV.setText(message);
            setMessageVisible(isMessageVisble);
            if (NO_TEXT_COLOR != msgTextColor)
                messageTV.setTextColor(msgTextColor);
            if (NO_TEXT_SIZE != msgTextSize)
                messageTV.setTextSize(msgTextSize);
        }

        message2TV = (TextView) findViewById(R.id.easy_dialog_message_2);
        if (message2TV != null && !TextUtils.isEmpty(message2)) {
            message2TV.setVisibility(View.VISIBLE);
            message2TV.setText(message2);
        }

        positiveBtn = (Button) findViewById(R.id.easy_dialog_positive_btn);
        if (isPositiveBtnVisible && positiveBtn != null) {
            positiveBtn.setVisibility(View.VISIBLE);
            if (NO_TEXT_COLOR != positiveBtnTitleTextColor) {
                positiveBtn.setTextColor(positiveBtnTitleTextColor);
            }
            if (NO_TEXT_SIZE != positiveBtnTitleTextSize) {
                positiveBtn.setTextSize(positiveBtnTitleTextSize);
            }
            positiveBtn.setText(positiveBtnTitle);
            positiveBtn.setOnClickListener(positiveBtnListener);
        }

        negativeBtn = (Button) findViewById(R.id.easy_dialog_negative_btn);
        btnDivideView = findViewById(R.id.easy_dialog_btn_divide_view);
        if (isNegativeBtnVisible) {
            negativeBtn.setVisibility(View.VISIBLE);
            btnDivideView.setVisibility(View.VISIBLE);
            if (NO_TEXT_COLOR != this.negativeBtnTitleTextColor) {
                negativeBtn.setTextColor(negativeBtnTitleTextColor);
            }
            if (NO_TEXT_SIZE != this.negativeBtnTitleTextSize) {
                negativeBtn.setTextSize(negativeBtnTitleTextSize);
            }
            negativeBtn.setText(negativeBtnTitle);
            negativeBtn.setOnClickListener(negativeBtnListener);
        }

        if (mViewListener != null && mViewListener.size() != 0) {
            Iterator iter = mViewListener.entrySet().iterator();
            View view = null;
            while (iter.hasNext()) {
                Map.Entry<Integer, View.OnClickListener> entry = (Map.Entry) iter.next();
                view = findViewById(entry.getKey());
                if (view != null && entry.getValue() != null) {
                    view.setOnClickListener(entry.getValue());
                }
            }
        }

    } catch (Exception e) {

    }
}