Java Code Examples for android.widget.RelativeLayout#setBackground()

The following examples show how to use android.widget.RelativeLayout#setBackground() . 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: MyAttentionAdapter.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 改变关注状态
 *
 * @param isAttention 是否关注
 * @param button      关注按钮
 * @param add         +图片
 * @param layout      父布局
 */
private void changeBtnAttention(boolean isAttention, TextView button, ImageView add, RelativeLayout layout) {
    if (!isAttention) {
        layout.setVisibility(View.VISIBLE);
        layout.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_blue_rect));
        button.setText(R.string.personal_focus_someone);
        add.setVisibility(View.VISIBLE);
        button.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
    } else {
        layout.setVisibility(View.VISIBLE);
        layout.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_dark_gray_fill_4dp));
        button.setText(R.string.personal_focused);
        button.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) button.getLayoutParams();
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        add.setVisibility(View.GONE);
    }
}
 
Example 2
Source File: MyFansAdapter.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 改变关注状态
 *
 * @param isAttention 是否关注
 * @param button      关注按钮
 * @param add         +图片
 * @param layout      父布局
 */
private void changeBtnAttention(boolean isAttention, TextView button, ImageView add, RelativeLayout layout) {
    if (!isAttention) {
        layout.setVisibility(View.VISIBLE);
        layout.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_blue_rect));
        button.setText(R.string.personal_focus_someone);
        add.setVisibility(View.VISIBLE);
        button.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
    } else {
        layout.setVisibility(View.VISIBLE);
        layout.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_dark_gray_fill_4dp));
        button.setText(R.string.personal_focused);
        button.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) button.getLayoutParams();
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        add.setVisibility(View.GONE);
    }
}
 
Example 3
Source File: GuardaInputLayout.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private View getEraseView(Context context) {
    GridLayout.LayoutParams params = new GridLayout.LayoutParams();
    params.setGravity(Gravity.FILL);
    params.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
    params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);

    RelativeLayout relativeLayout = new RelativeLayout(context);
    relativeLayout.setLayoutParams(params);
    relativeLayout.setGravity(Gravity.CENTER);
    relativeLayout.setBackground(context.getResources().getDrawable(R.drawable.ripple));
    relativeLayout.setId(R.id.input_erase);

    ImageView eraseView = new ImageView(context);
    eraseView.setImageResource(R.drawable.ic_erase);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    eraseView.setLayoutParams(layoutParams);

    relativeLayout.addView(eraseView);
    relativeLayout.setOnClickListener(this);
    return relativeLayout;
}
 
Example 4
Source File: BGABanner.java    From JD-Test with Apache License 2.0 4 votes vote down vote up
private void initView(Context context) {
    RelativeLayout pointContainerRl = new RelativeLayout(context);
    if (Build.VERSION.SDK_INT >= 16) {
        pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
    } else {
        pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
    }
    pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
    LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
    // 处理圆点在顶部还是底部
    if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    } else {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    }
    addView(pointContainerRl, pointContainerLp);


    LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
    indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    if (mIsNumberIndicator) {
        mNumberIndicatorTv = new TextView(context);
        mNumberIndicatorTv.setId(R.id.banner_indicatorId);
        mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
        mNumberIndicatorTv.setSingleLine(true);
        mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
        mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
        mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
        mNumberIndicatorTv.setVisibility(View.INVISIBLE);
        if (mNumberIndicatorBackground != null) {
            if (Build.VERSION.SDK_INT >= 16) {
                mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
            } else {
                mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
            }
        }
        pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
    } else {
        mPointRealContainerLl = new LinearLayout(context);
        mPointRealContainerLl.setId(R.id.banner_indicatorId);
        mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
        mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);


        pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
    }

    LayoutParams tipLp = new LayoutParams(RMP, RWC);
    tipLp.addRule(CENTER_VERTICAL);
    mTipTv = new TextView(context);
    mTipTv.setGravity(Gravity.CENTER_VERTICAL);
    mTipTv.setSingleLine(true);
    mTipTv.setEllipsize(TextUtils.TruncateAt.END);
    mTipTv.setTextColor(mTipTextColor);
    mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
    pointContainerRl.addView(mTipTv, tipLp);

    int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    // 处理圆点在左边、右边还是水平居中
    if (horizontalGravity == Gravity.LEFT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
        mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    } else if (horizontalGravity == Gravity.RIGHT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    } else {
        indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    }

    showPlaceholder();
}
 
Example 5
Source File: BGABanner.java    From KUtils with Apache License 2.0 4 votes vote down vote up
private void initView(Context context) {
    RelativeLayout pointContainerRl = new RelativeLayout(context);
    if (Build.VERSION.SDK_INT >= 16) {
        pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
    } else {
        pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
    }
    pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
    LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
    // 处理圆点在顶部还是底部
    if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    } else {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    }
    addView(pointContainerRl, pointContainerLp);


    LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
    indicatorLp.addRule(CENTER_VERTICAL);
    if (mIsNumberIndicator) {
        mNumberIndicatorTv = new TextView(context);
        mNumberIndicatorTv.setId(R.id.banner_indicatorId);
        mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
        mNumberIndicatorTv.setSingleLine(true);
        mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
        mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
        mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
        mNumberIndicatorTv.setVisibility(View.INVISIBLE);
        if (mNumberIndicatorBackground != null) {
            if (Build.VERSION.SDK_INT >= 16) {
                mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
            } else {
                mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
            }
        }
        pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
    } else {
        mPointRealContainerLl = new LinearLayout(context);
        mPointRealContainerLl.setId(R.id.banner_indicatorId);
        mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
        mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);
        pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
    }

    LayoutParams tipLp = new LayoutParams(RMP, RWC);
    tipLp.addRule(CENTER_VERTICAL);
    mTipTv = new TextView(context);
    mTipTv.setGravity(Gravity.CENTER_VERTICAL);
    mTipTv.setSingleLine(true);
    mTipTv.setEllipsize(TextUtils.TruncateAt.END);
    mTipTv.setTextColor(mTipTextColor);
    mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
    pointContainerRl.addView(mTipTv, tipLp);

    int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    // 处理圆点在左边、右边还是水平居中
    if (horizontalGravity == Gravity.LEFT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
        mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    } else if (horizontalGravity == Gravity.RIGHT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    } else {
        indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    }

    showPlaceholder();
}
 
Example 6
Source File: BGABanner.java    From KUtils-master with Apache License 2.0 4 votes vote down vote up
private void initView(Context context) {
    RelativeLayout pointContainerRl = new RelativeLayout(context);
    if (Build.VERSION.SDK_INT >= 16) {
        pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
    } else {
        pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
    }
    pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
    LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
    // 处理圆点在顶部还是底部
    if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    } else {
        pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    }
    addView(pointContainerRl, pointContainerLp);


    LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
    indicatorLp.addRule(CENTER_VERTICAL);
    if (mIsNumberIndicator) {
        mNumberIndicatorTv = new TextView(context);
        mNumberIndicatorTv.setId(R.id.banner_indicatorId);
        mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
        mNumberIndicatorTv.setSingleLine(true);
        mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
        mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
        mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
        mNumberIndicatorTv.setVisibility(View.INVISIBLE);
        if (mNumberIndicatorBackground != null) {
            if (Build.VERSION.SDK_INT >= 16) {
                mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
            } else {
                mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
            }
        }
        pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
    } else {
        mPointRealContainerLl = new LinearLayout(context);
        mPointRealContainerLl.setId(R.id.banner_indicatorId);
        mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
        mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);
        pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
    }

    LayoutParams tipLp = new LayoutParams(RMP, RWC);
    tipLp.addRule(CENTER_VERTICAL);
    mTipTv = new TextView(context);
    mTipTv.setGravity(Gravity.CENTER_VERTICAL);
    mTipTv.setSingleLine(true);
    mTipTv.setEllipsize(TextUtils.TruncateAt.END);
    mTipTv.setTextColor(mTipTextColor);
    mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
    pointContainerRl.addView(mTipTv, tipLp);

    int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    // 处理圆点在左边、右边还是水平居中
    if (horizontalGravity == Gravity.LEFT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
        mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    } else if (horizontalGravity == Gravity.RIGHT) {
        indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    } else {
        indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
    }

    showPlaceholder();
}
 
Example 7
Source File: XBanner.java    From XBanner with Apache License 2.0 4 votes vote down vote up
private void initView() {

        /*设置指示器背景容器*/
        RelativeLayout pointContainerRl = new RelativeLayout(getContext());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
        } else {
            pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
        }

        /*设置内边距*/
        pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomPading, mPointContainerLeftRightPadding, mPointTopBottomPading);

        /*设定指示器容器布局及位置*/
        mPointContainerLp = new LayoutParams(RMP, RWC);
        mPointContainerLp.addRule(mPointContainerPosition);
        if (mIsClipChildrenMode) {
            mPointContainerLp.setMargins(mClipChildrenLeftRightMargin, 0, mClipChildrenLeftRightMargin, mClipChildrenTopBottomMargin);
        }
        addView(pointContainerRl, mPointContainerLp);
        mPointRealContainerLp = new LayoutParams(RWC, RWC);
        /*设置指示器容器*/
        if (mIsNumberIndicator) {
            mNumberIndicatorTv = new TextView(getContext());
            mNumberIndicatorTv.setId(R.id.xbanner_pointId);
            mNumberIndicatorTv.setGravity(Gravity.CENTER);
            mNumberIndicatorTv.setSingleLine(true);
            mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
            mNumberIndicatorTv.setTextColor(mTipTextColor);
            mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
            mNumberIndicatorTv.setVisibility(View.INVISIBLE);
            if (mNumberIndicatorBackground != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
                } else {
                    mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
                }
            }
            pointContainerRl.addView(mNumberIndicatorTv, mPointRealContainerLp);
        } else {
            mPointRealContainerLl = new LinearLayout(getContext());
            mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
            mPointRealContainerLl.setId(R.id.xbanner_pointId);
            pointContainerRl.addView(mPointRealContainerLl, mPointRealContainerLp);
        }

        /*设置指示器是否可见*/
        if (mPointRealContainerLl != null) {
            if (mPointsIsVisible) {
                mPointRealContainerLl.setVisibility(View.VISIBLE);
            } else {
                mPointRealContainerLl.setVisibility(View.GONE);
            }
        }

        /*设置提示语*/
        LayoutParams pointLp = new LayoutParams(RMP, RWC);
        pointLp.addRule(CENTER_VERTICAL);

        if (mIsShowTips) {
            mTipTv = new TextView(getContext());
            mTipTv.setGravity(Gravity.CENTER_VERTICAL);
            mTipTv.setSingleLine(true);
            if (mIsTipsMarquee) {
                mTipTv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
                mTipTv.setMarqueeRepeatLimit(3);
                mTipTv.setSelected(true);
            } else {
                mTipTv.setEllipsize(TextUtils.TruncateAt.END);
            }
            mTipTv.setTextColor(mTipTextColor);
            mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
            pointContainerRl.addView(mTipTv, pointLp);
        }

        /*设置指示器布局位置*/
        if (CENTER == mPointPosition) {
            mPointRealContainerLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
            pointLp.addRule(RelativeLayout.LEFT_OF, R.id.xbanner_pointId);
        } else if (LEFT == mPointPosition) {
            mPointRealContainerLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (mTipTv != null) {
                mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
            }
            pointLp.addRule(RelativeLayout.RIGHT_OF, R.id.xbanner_pointId);
        } else if (RIGHT == mPointPosition) {
            mPointRealContainerLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            pointLp.addRule(RelativeLayout.LEFT_OF, R.id.xbanner_pointId);
        }
        setBannerPlaceholderDrawable();
    }
 
Example 8
Source File: SearchBar.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
public SearchBar(Context context, AttributeSet attrs) {
	super(context, attrs);

	// 方式1获取属性
	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.SearchBar);

	hintString = a.getString(R.styleable.SearchBar_searchbar_hint);

	etBackground = a
			.getDrawable(R.styleable.SearchBar_searchbar_edittext_background);

	searchbarLogo = a.getDrawable(R.styleable.SearchBar_searchbar_logo);
	searchbarIcon = a.getDrawable(R.styleable.SearchBar_searchbar_icon);
	searchbarDeleteIcon = a
			.getDrawable(R.styleable.SearchBar_searchbar_delete_icon);

	hintTextColor = a.getColor(
			R.styleable.SearchBar_searchbar_hint_text_color, getResources()
					.getColor(R.color.gray));

	etTextColor = a.getColor(
			R.styleable.SearchBar_searchbar_edittext_text_color,
			getResources().getColor(R.color.gray));

	etTextSize = a.getDimension(
			R.styleable.SearchBar_searchbar_edittext_text_size, -1);

	a.recycle();

	View view = LayoutInflater.from(context).inflate(R.layout.search_bar,
			null);

	rlEditText = (RelativeLayout) view.findViewById(R.id.rlEditText);
	if (etBackground != null)
		rlEditText.setBackground(etBackground);

	ivSearchBarLogo = (ImageView) view.findViewById(R.id.ivSearchBarLogo);
	if (searchbarLogo != null)
		ivSearchBarLogo.setImageDrawable(searchbarLogo);
	else
		ivSearchBarLogo.setVisibility(View.GONE);

	ivSearchBarIcon = (ImageView) view.findViewById(R.id.ivSearchBarIcon);
	if (ivSearchBarIcon != null)
		ivSearchBarIcon.setImageDrawable(searchbarIcon);

	ivSearchbarDeleteIcon = (ImageView) view
			.findViewById(R.id.iv_searchbar_delete);
	if (ivSearchbarDeleteIcon != null)
		ivSearchbarDeleteIcon.setImageDrawable(searchbarDeleteIcon);

	etSearch = (EditText) view.findViewById(R.id.et_searchbar);

	etSearch.setTextColor(etTextColor);

	if (etTextSize != -1)
		etSearch.setTextSize(DensityUtils.px2dip(context, etTextSize));
	etSearch.setHintTextColor(hintTextColor);

	if (hintString != null)
		etSearch.setHint(hintString);
	else
		etSearch.setHint("");

	ivSearchbarDeleteIcon.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			etSearch.setText("");
		}
	});
	// 给编辑框添加文本改变事件
	etSearch.addTextChangedListener(new SearchBarTextWatcher(this));

	// 把获得的view加载到这个控件中
	addView(view);
}
 
Example 9
Source File: NoteAdapter.java    From Swiftnotes with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // Inflate custom note view if null
    if (convertView == null)
        convertView = this.inflater.inflate(R.layout.list_view_note, parent, false);

    // Initialize layout items
    RelativeLayout relativeLayout = (RelativeLayout) convertView.findViewById(R.id.relativeLayout);
    LayerDrawable roundedCard = (LayerDrawable) context.getResources().getDrawable(R.drawable.rounded_card);
    TextView titleView = (TextView) convertView.findViewById(R.id.titleView);
    TextView bodyView = (TextView) convertView.findViewById(R.id.bodyView);
    ImageButton favourite = (ImageButton) convertView.findViewById(R.id.favourite);

    // Get Note object at position
    JSONObject noteObject = getItem(position);

    if (noteObject != null) {
        // If noteObject not empty -> initialize variables
        String title = context.getString(R.string.note_title);
        String body = context.getString(R.string.note_body);
        String colour = String.valueOf(context.getResources().getColor(R.color.white));
        int fontSize = 18;
        Boolean hideBody = false;
        Boolean favoured = false;

        try {
            // Get noteObject data and store in variables
            title = noteObject.getString(NOTE_TITLE);
            body = noteObject.getString(NOTE_BODY);
            colour = noteObject.getString(NOTE_COLOUR);

            if (noteObject.has(NOTE_FONT_SIZE))
                fontSize = noteObject.getInt(NOTE_FONT_SIZE);

            if (noteObject.has(NOTE_HIDE_BODY))
                hideBody = noteObject.getBoolean(NOTE_HIDE_BODY);

            favoured = noteObject.getBoolean(NOTE_FAVOURED);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        // Set favourite image resource
        if (favoured)
            favourite.setImageResource(R.drawable.ic_fav);

        else
            favourite.setImageResource(R.drawable.ic_unfav);


        // If search or delete modes are active -> hide favourite button; Show otherwise
        if (searchActive || deleteActive)
            favourite.setVisibility(View.INVISIBLE);

        else
            favourite.setVisibility(View.VISIBLE);


        titleView.setText(title);

        // If hidBody is true -> hide body of note
        if (hideBody)
            bodyView.setVisibility(View.GONE);

        // Else -> set visible note body, text to normal and set text size to 'fontSize' as sp
        else {
            bodyView.setVisibility(View.VISIBLE);
            bodyView.setText(body);
            bodyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
        }

        // If current note is selected for deletion -> highlight
        if (checkedArray.contains(position)) {
            ((GradientDrawable) roundedCard.findDrawableByLayerId(R.id.card))
                    .setColor(context.getResources().getColor(R.color.theme_primary));
        }

        // If current note is not selected -> set background colour to normal
        else {
            ((GradientDrawable) roundedCard.findDrawableByLayerId(R.id.card))
                    .setColor(Color.parseColor(colour));
        }

        // Set note background style to rounded card
        relativeLayout.setBackground(roundedCard);

        final Boolean finalFavoured = favoured;
        favourite.setOnClickListener(new View.OnClickListener() {
            // If favourite button was clicked -> change that note to favourite or un-favourite
            @Override
            public void onClick(View v) {
                setFavourite(context, !finalFavoured, position);
            }
        });
    }

    return convertView;
}
 
Example 10
Source File: FragmentMap.java    From iGap-Android with GNU Affero General Public License v3.0 2 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle saveInctanceState) {
    super.onViewCreated(view, saveInctanceState);


    /* *//**//* itemIcon = (MaterialDesignTextView) view.findViewById(R.id.mf_icon);*/


    rvIcon = (RelativeLayout) view.findViewById(R.id.rv_icon);

    Drawable mDrawableSkip = ContextCompat.getDrawable(getContext(), R.drawable.ic_circle_shape);
    if (mDrawableSkip != null) {
        mDrawableSkip.setColorFilter(new PorterDuffColorFilter(Color.parseColor(G.appBarColor), PorterDuff.Mode.SRC_IN));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            rvIcon.setBackground(mDrawableSkip);
        }
    }


    imgProfile = (ImageView) view.findViewById(R.id.mf_imgProfile);

    rvSendPosition = (RelativeLayout) view.findViewById(R.id.mf_rv_send_position);
    rvSeePosition = (RelativeLayout) view.findViewById(R.id.mf_rv_see_position);

    rvSendPosition.setEnabled(false);

    accuracy = (TextView) view.findViewById(R.id.mf_txt_accuracy);
    accuracy.setText(getResources().getString(R.string.get_location_data));


    txtTitle = (TextView) view.findViewById(R.id.mf_txt_message);

    txtUserName = (TextView) view.findViewById(R.id.mf_txt_userName);
    txtDistance = (TextView) view.findViewById(R.id.mf_txt_distance);

    txtDistance.setText(getResources().getString(R.string.calculation));

    txtUserName.setTextColor(Color.parseColor(G.appBarColor));

    accuracy.setTextColor(Color.parseColor(G.appBarColor));
    txtDistance.setTextColor(Color.parseColor(G.appBarColor));


    //rvSendPosition.setBackgroundColor(Color.parseColor(G.appBarColor));
    txtTitle.setTextColor(Color.parseColor(G.appBarColor));

    fabOpenMap = (FloatingActionButton) view.findViewById(R.id.mf_fab_openMap);
    fabOpenMap.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom)));
    fabOpenMap.setColorFilter(Color.WHITE);

    bundle = getArguments();

    if (bundle != null) {

        latitude = bundle.getDouble(FragmentMap.Latitude);
        longitude = bundle.getDouble(FragmentMap.Longitude);

        mode = (Mode) bundle.getSerializable(PosoitionMode);
        if (G.onHelperSetAction != null) {
            G.onHelperSetAction.onAction(ProtoGlobal.ClientAction.SENDING_LOCATION);
        }

        initComponent(view, bundle.getInt("type", 0), bundle.getLong("roomId", 00), bundle.getString("senderId", null));
    } else {
        close();
    }
}