Java Code Examples for android.widget.LinearLayout.setBackgroundResource()

The following are Jave code examples for showing how to use setBackgroundResource() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ButterToast   File: ButterToast.java   View Source Code Vote up 6 votes
public static Toast custom(@NonNull Context context, CharSequence text, @Nullable Drawable icon,
                           @ColorInt int backgroundColor, int duration, @DrawableRes int resid,
                           @Nullable Typeface tp, float cornerRadius,
                           @ColorInt int textColor, float textSize) {
    Toast toast = new Toast(context);

    View layout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.toast_layout, null);
    LinearLayout ll = (LinearLayout) layout.findViewById(R.id.base_layout);
    ll.setBackgroundResource(resid);
    GradientDrawable gd = (GradientDrawable) ll.getBackground().getCurrent();
    gd.setColor(backgroundColor);
    gd.setCornerRadius(cornerRadius);
    TextView tv_message = (TextView) layout.findViewById(R.id.toast_text);
    tv_message.setTextSize(textSize);
    tv_message.setTypeface(tp == null ? DEFAULT_TYPEFACE : tp);
    tv_message.setTextColor(textColor);
    ImageView iv_toast_image = (ImageView) layout.findViewById(R.id.toast_image);
    if (icon != null) {
        iv_toast_image.setImageDrawable(icon);
    }
    tv_message.setText(text);
    toast.setView(layout);
    toast.setDuration(duration);
    return toast;
}
 
Example 2
Project: microMathematics   File: ExportToImage.java   View Source Code Vote up 6 votes
public void write(FormulaListView formulaListView, Bitmap.CompressFormat format) throws Exception
{
    final LinearLayout f = formulaListView.getList();
    Bitmap bitmap = null;
    try
    {
        bitmap = Bitmap.createBitmap(f.getMeasuredWidth(), f.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bitmap);
        f.setBackgroundColor(CompatUtils.getThemeColorAttr(f.getContext(), android.R.attr.windowBackground));
        f.draw(canvas);
    }
    catch (OutOfMemoryError e)
    {
        throw new Exception(e.getLocalizedMessage());
    }
    finally
    {
        f.setBackgroundResource(android.R.color.transparent);
    }
    bitmap.compress(format, 100, stream);
    stream.flush();
}
 
Example 3
Project: InstaBadge   File: DummyArrow.java   View Source Code Vote up 6 votes
public DummyArrow(Context context){
    this.context = context;

    bottom_arrow = new LinearLayout(context);
    scale = context.getResources().getDisplayMetrics().density;
    dpAsPixels = (int) (20 * scale + 0.5f);
    LinearLayout.LayoutParams arrow_params = new LinearLayout.LayoutParams(dpAsPixels, dpAsPixels, 1f);
    arrow_params.gravity = Gravity.CENTER_HORIZONTAL;
    bottom_arrow.setLayoutParams(arrow_params);
    bottom_arrow.setOrientation(LinearLayout.HORIZONTAL);

    bottom_arrow.setBackgroundResource(R.drawable.upper_traingle);

    value = bottom_arrow.getLayoutParams().height;

}
 
Example 4
Project: GongXianSheng   File: CustomBottomDialog.java   View Source Code Vote up 6 votes
private View addItemView(int rid, String text) {
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setId(rid);
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 44f)));
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundResource(R.drawable.base_item_bg_selector);
    linearLayout.setOnClickListener(this);
    TextView textView = new TextView(context);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    textView.setText(text);
    textView.setTextColor(context.getResources().getColor(R.color.bottom_dialog_textcolor));
    textView.setTextSize(16f);
    textView.setGravity(Gravity.CENTER);
    linearLayout.removeAllViews();
    linearLayout.addView(textView);
    return  linearLayout;
}
 
Example 5
Project: Huochexing12306   File: EditPage.java   View Source Code Vote up 6 votes
private LinearLayout getPageBody() {
	llBody = new LinearLayout(getContext());
	llBody.setId(2);
	int resId = getBitmapRes(activity, "edittext_back");
	if (resId > 0) {
		llBody.setBackgroundResource(resId);
	}
	llBody.setOrientation(LinearLayout.VERTICAL);
	RelativeLayout.LayoutParams lpBody = new RelativeLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpBody.addRule(RelativeLayout.ALIGN_LEFT, llTitle.getId());
	lpBody.addRule(RelativeLayout.BELOW, llTitle.getId());
	lpBody.addRule(RelativeLayout.ALIGN_RIGHT, llTitle.getId());
	if (!dialogMode) {
		lpBody.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
	}
	int dp_3 = dipToPx(getContext(), 3);
	lpBody.setMargins(dp_3, dp_3, dp_3, dp_3);
	llBody.setLayoutParams(lpBody);

	llBody.addView(getMainBody());
	llBody.addView(getSep());
	llBody.addView(getPlatformList());

	return llBody;
}
 
Example 6
Project: CustomShoppingCarDemo   File: GoodsAnimUtil.java   View Source Code Vote up 5 votes
private static ViewGroup createAnimLayout()
{
    ViewGroup rootView = (ViewGroup) mActivity.getWindow().getDecorView();
    LinearLayout animLayout = new LinearLayout(mActivity);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT ,
            LinearLayout.LayoutParams.MATCH_PARENT);
    animLayout.setLayoutParams(lp);
    animLayout.setBackgroundResource(android.R.color.transparent);
    rootView.addView(animLayout);
    return animLayout;
}
 
Example 7
Project: RLibrary   File: T.java   View Source Code Vote up 5 votes
private static View createToastView(Context context) {
        RelativeLayout root = new RelativeLayout(context);
        root.setTag("root");
        if (isSupport()) {
            root.setBackgroundResource(context.getResources().getIdentifier("colorAccent", "color", context.getPackageName()));
        }
        //root.setBackgroundColor(Color.RED);
        WindowManager.LayoutParams rootParams = new WindowManager.LayoutParams(-1, -2);
        rootParams.gravity = Gravity.TOP;
        root.setLayoutParams(rootParams);

        LinearLayout layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.HORIZONTAL);
        if (isSupport()) {
            layout.setBackgroundResource(context.getResources().getIdentifier("colorAccent", "color", context.getPackageName()));
        }
//        layout.setBackgroundResource(android.R.color.holo_red_dark);
//        layout.setVerticalGravity(Gravity.VERTICAL_GRAVITY_MASK);
        final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-2, -2);
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        layout.setLayoutParams(params);
        layout.setMinimumHeight(getMinHeight(context));

        ImageView imageView = new ImageView(context);
        imageView.setTag("image");
        imageView.setVisibility(View.GONE);

        TextView textView = new TextView(context);
        textView.setTag("text");
        textView.setTextColor(Color.WHITE);

        final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
        layoutParams.setMargins(getMinHeight(context, 10), 0, 0, 0);
        layoutParams.gravity = Gravity.CENTER_VERTICAL;

        layout.addView(imageView, layoutParams);
        layout.addView(textView, layoutParams);
        root.addView(layout);
        return root;
    }
 
Example 8
Project: MVP-Practice-Project-Template   File: MultiTypeActivity.java   View Source Code Vote up 5 votes
@Override
public void initViews() {
    builder = builder();
    if (builder == null) {
        throw new IllegalArgumentException("builder 不能为空");
    }
    magicIndicator = (MagicIndicator) findViewById(R.id.base_title_magic_indicator);
    mViewPager = (NoScrollViewPager) findViewById(R.id.base_title_view_pager);
    magicIndicatorParent = (LinearLayout) findViewById(R.id.base_title_magic_parent);
    cutOffRule = findViewById(R.id.base_title_cut_off_rule);

    magicIndicatorParent.setBackgroundResource(builder.getMultiTypeBgColor());

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            UIUtil.dip2px(mContext, builder.getTitleViewHeight()));
    layoutParams.setMargins(UIUtil.dip2px(mContext, builder.getHeadViewMarginsLeft()),
            UIUtil.dip2px(mContext, builder.getHeadViewMarginsTop()),
            UIUtil.dip2px(mContext, builder.getHeadViewMarginsRight()),
            UIUtil.dip2px(mContext, builder.getHeadViewMarginsBottom()));
    magicIndicator.setLayoutParams(layoutParams);
    magicIndicator.requestLayout();

    if (!builder.isShowCutOffRule()) {
        cutOffRule.setVisibility(View.GONE);
    }
    if (builder.getMultiTypeBodyBgColor() != 0) {
        mViewPager.setBackgroundResource(builder.getMultiTypeBodyBgColor());
    }
    mViewPager.setScroll(builder.isScroll());
    cutOffRule.setBackgroundResource(builder.getCutOffRuleColor());

}
 
Example 9
Project: FancyToast-Android   File: FancyToast.java   View Source Code Vote up 5 votes
public static Toast makeText(Context context,String message,int duration,int type,boolean androidicon){
    Toast toast = new Toast(context);
    toast.setDuration(duration);
    View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false);
    TextView l1 = (TextView) layout.findViewById(R.id.toast_text);
    LinearLayout linearLayout=(LinearLayout) layout.findViewById(R.id.toast_type);
    ImageView img=(ImageView) layout.findViewById(R.id.toast_icon);
    ImageView img1=(ImageView) layout.findViewById(R.id.imageView4);
    l1.setText(message);
    if(androidicon==true)
    img1.setVisibility(View.VISIBLE);
    else if(androidicon==false)
    img1.setVisibility(View.GONE);
    if(type==1)
    { linearLayout.setBackgroundResource(R.drawable.success_shape);
      img.setImageResource(R.drawable.ic_check_black_24dp);
    }
    else if (type==2)
    { linearLayout.setBackgroundResource(R.drawable.warning_shape);
      img.setImageResource(R.drawable.ic_pan_tool_black_24dp);
    }
    else if (type==3)
    { linearLayout.setBackgroundResource(R.drawable.error_shape);
      img.setImageResource(R.drawable.ic_clear_black_24dp);
    }
    else if (type==4)
    { linearLayout.setBackgroundResource(R.drawable.info_shape);
      img.setImageResource(R.drawable.ic_info_outline_black_24dp);
    }
    else if (type==5)
    { linearLayout.setBackgroundResource(R.drawable.default_shape);
      img.setVisibility(View.GONE);
    }
    else if (type==6)
    { linearLayout.setBackgroundResource(R.drawable.confusing_shape);
      img.setImageResource(R.drawable.ic_refresh_black_24dp);
    }
    toast.setView(layout);
    return toast;
}
 
Example 10
Project: FancyToast-Android   File: FancyToast.java   View Source Code Vote up 5 votes
public static Toast makeText(Context context,String message,int duration,int type,int ImageResource){
    Toast toast = new Toast(context);
    View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false);
    TextView l1 = (TextView) layout.findViewById(R.id.toast_text);
    LinearLayout linearLayout=(LinearLayout) layout.findViewById(R.id.toast_type);
    ImageView img=(ImageView) layout.findViewById(R.id.toast_icon);
    l1.setText(message);
    if(type==1)
    { linearLayout.setBackgroundResource(R.drawable.success_shape);
      img.setImageResource(ImageResource);
    }
    else if (type==2)
    { linearLayout.setBackgroundResource(R.drawable.warning_shape);
      img.setImageResource(ImageResource);
    }
    else if (type==3)
    { linearLayout.setBackgroundResource(R.drawable.error_shape);
      img.setImageResource(ImageResource);
    }
    else if (type==4)
    { linearLayout.setBackgroundResource(R.drawable.info_shape);
      img.setImageResource(ImageResource);
    }
    else if (type==5)
    { linearLayout.setBackgroundResource(R.drawable.default_shape);
      img.setVisibility(View.GONE);
    }
    else if (type==6)
    { linearLayout.setBackgroundResource(R.drawable.confusing_shape);
      img.setImageResource(ImageResource);
    }
    toast.setView(layout);
    return toast;
}
 
Example 11
Project: InstaBadge   File: InstaBadgeView.java   View Source Code Vote up 5 votes
private void setupBottomArrow() {

        bottom_arrow = new LinearLayout(context);
        dpAsPixels = (int) (20 * scale + 0.5f);
        LayoutParams arrow_params = new LinearLayout.LayoutParams(dpAsPixels, dpAsPixels);
        arrow_params.gravity = Gravity.CENTER_HORIZONTAL;
        bottom_arrow.setLayoutParams(arrow_params);
        bottom_arrow.setOrientation(LinearLayout.HORIZONTAL);

        bottom_arrow.setBackgroundResource(R.drawable.triangle);
        addView(outer_container);
        addView(bottom_arrow);

    }
 
Example 12
Project: SScheduleView-Android   File: CustomSSViewAdapter.java   View Source Code Vote up 5 votes
/**
 * 第一行日期
 * @param weekDayName
 * @param dayName
 * @param firstRowHeight
 * @param isToday
 * @return
 */
public View getWeekTitleView(String weekDayName,String dayName,int firstRowHeight,boolean isToday) {
    LinearLayout headViewCell = new LinearLayout(mContext);
    headViewCell.setBackgroundResource(R.drawable.head_view_back);
    headViewCell.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams tvLLP = new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            firstRowHeight / 2);

    TextView dayTV = new TextView(mContext);
    dayTV.setText(weekDayName);
    dayTV.setLayoutParams(tvLLP);
    dayTV.setGravity(Gravity.CENTER);
    dayTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
    headViewCell.addView(dayTV);

    TextView dateTV = new TextView(mContext);
    dateTV.setLayoutParams(tvLLP);
    dateTV.setText(dayName);
    dateTV.setGravity(Gravity.CENTER | Gravity.BOTTOM);
    dateTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    headViewCell.addView(dateTV);

    if (isToday) {
        headViewCell.setBackgroundColor(0x77069ee9);
        dateTV.setTextColor(Color.WHITE);
        dayTV.setTextColor(Color.WHITE);
    }
    return headViewCell;
}
 
Example 13
Project: HiBangClient   File: MessageItem.java   View Source Code Vote up 5 votes
protected void initViews(View view) {
		mLayoutTimeStampContainer = (RelativeLayout) view
				.findViewById(R.id.message_layout_timecontainer);
		mHtvTimeStampTime = (HandyTextView) view
				.findViewById(R.id.message_timestamp_htv_time);
		mHtvTimeStampDistance = (HandyTextView) view
				.findViewById(R.id.message_timestamp_htv_distance);

		mLayoutLeftContainer = (RelativeLayout) view
				.findViewById(R.id.message_layout_leftcontainer);
		mLayoutStatus = (LinearLayout) view
				.findViewById(R.id.message_layout_status);
		mHtvStatus = (HandyTextView) view.findViewById(R.id.message_htv_status);

		mLayoutMessageContainer = (LinearLayout) view
				.findViewById(R.id.message_layout_messagecontainer);
		mLayoutMessageContainer.setBackgroundResource(mBackground);

		mLayoutRightContainer = (LinearLayout) view
				.findViewById(R.id.message_layout_rightcontainer);
		mIvPhotoView = (ImageView) view.findViewById(R.id.message_iv_userphoto);
		onInitViews();
		
		mIvPhotoView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
//				mOnClickAvatarListener.onClick();
				
			}
		});
	}
 
Example 14
Project: PlusGram   File: SharedPhotoVideoCell.java   View Source Code Vote up 5 votes
public PhotoVideoView(Context context) {
    super(context);

    container = new FrameLayout(context);
    addView(container, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    imageView = new BackupImageView(context);
    imageView.getImageReceiver().setNeedsQualityThumb(true);
    imageView.getImageReceiver().setShouldGenerateQualityThumb(true);
    container.addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    videoInfoContainer = new LinearLayout(context);
    videoInfoContainer.setOrientation(LinearLayout.HORIZONTAL);
    videoInfoContainer.setBackgroundResource(R.drawable.phototime);
    videoInfoContainer.setPadding(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(3), 0);
    videoInfoContainer.setGravity(Gravity.CENTER_VERTICAL);
    container.addView(videoInfoContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 16, Gravity.BOTTOM | Gravity.LEFT));

    ImageView imageView1 = new ImageView(context);
    imageView1.setImageResource(R.drawable.ic_video);
    videoInfoContainer.addView(imageView1, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    videoTextView = new TextView(context);
    videoTextView.setTextColor(0xffffffff);
    videoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    videoTextView.setGravity(Gravity.CENTER_VERTICAL);
    videoInfoContainer.addView(videoTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 4, 0, 0, 1));

    selector = new View(context);
    selector.setBackgroundResource(R.drawable.list_selector);
    addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    checkBox = new CheckBox(context, R.drawable.round_check2);
    checkBox.setVisibility(INVISIBLE);
    addView(checkBox, LayoutHelper.createFrame(22, 22, Gravity.RIGHT | Gravity.TOP, 0, 2, 2, 0));
}
 
Example 15
Project: BBSSDK-for-Android   File: BasePageWithTitle.java   View Source Code Vote up 5 votes
protected View onCreateView(Context context) {
		mainLayout = new LinearLayout(context);
		mainLayout.setBackgroundResource(ResHelper.getColorRes(context, "bbs_title_bg"));
		mainLayout.setOrientation(LinearLayout.VERTICAL);
		mainLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

		titleBar = new TitleBar(context) {
			@Override
			protected View getCenterView() {
				View centerview = getTitleCenterView();
				if (centerview == null) {
					return super.getCenterView();
				}
				return centerview;
			}
		};
		LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
		mainLayout.addView(titleBar, llp);

		vLine = new View(context);
		vLine.setBackgroundResource(ResHelper.getColorRes(context, "bbs_mainviewtitle_bg"));
		mainLayout.addView(vLine, ViewGroup.LayoutParams.MATCH_PARENT, ResHelper.dipToPx(context, 1) / 2);
		vLine.setVisibility(View.GONE);

		View contentView = onCreateContentView(context);
//		contentView.setBackgroundResource(ResHelper.getColorRes(context, "bbs_bg"));
		llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
		llp.weight = 1;
		mainLayout.addView(contentView, llp);

		titleBar.setOnClickListener(newTitleBarClickListener());
		return mainLayout;
	}
 
Example 16
Project: Days   File: MainActivity.java   View Source Code Vote up 4 votes
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    bg = (LinearLayout)findViewById(R.id.bg);
    preferences = getSharedPreferences("MY_PREFERENCE", Context.MODE_PRIVATE);
    editor = preferences.edit();

    if (id == R.id.nav_all) {
        setSimpleAdapter();
    } else if (id == R.id.nav_work) {
        setSimpleAdapterByTag(R.mipmap.icon_work);
    } else if (id == R.id.nav_study) {
        setSimpleAdapterByTag(R.mipmap.icon_study);
    } else if (id == R.id.nav_anniversary) {
        setSimpleAdapterByTag(R.mipmap.icon_love);
    } else if (id == R.id.nav_birthday) {
        setSimpleAdapterByTag(R.mipmap.icon_birthday);
    } else if (id == R.id.nav_life) {
        setSimpleAdapterByTag(R.mipmap.icon_life);
    } else if (id == R.id.nav_event) {
        setSimpleAdapterByTag(R.mipmap.icon_event);
    } else if (id == R.id.nav_change) {
        //更改背景
        bgNum = (bgNum+ 1)% 5;

        switch (bgNum) {
            case 1:
                bg.setBackgroundResource(R.mipmap.bg1);
                editor.putInt("bgNum",R.mipmap.bg1);
                editor.commit();
                break;
            case 2:
                bg.setBackgroundResource(R.mipmap.bg2);
                editor.putInt("bgNum",R.mipmap.bg2);
                editor.commit();
                break;
            case 3:
                bg.setBackgroundResource(R.mipmap.bg4);
                editor.putInt("bgNum",R.mipmap.bg4);
                editor.commit();
                break;
            case 4:
                bg.setBackgroundResource(R.mipmap.bg5);
                editor.putInt("bgNum",R.mipmap.bg5);
                editor.commit();
                break;
            case 0:
                bg.setBackgroundResource(R.mipmap.bg7);
                editor.putInt("bgNum",R.mipmap.bg7);
                editor.commit();
                break;
            default:
                break;
        }
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 17
Project: FabToast   File: FabToast.java   View Source Code Vote up 4 votes
public static Toast makeText(Context context,String toastMessage,int duration, int type, int pos){
    Toast toast = new Toast(context);
    toast.setDuration(duration);

    View layout = LayoutInflater.from(context).inflate(R.layout.fab_toast_layout, null, false);
    LinearLayout toastRoot = layout.findViewById(R.id.toast_root);
    LinearLayout imageWrapper = layout.findViewById(R.id.image_view_wrapper);
    ImageView image = layout.findViewById(R.id.image);

    TextView text = layout.findViewById(R.id.toast_text);

    switch (pos){
        case 2:
            toast.setGravity(Gravity.CENTER, 0, 0);
            break;
        case 3:
            toast.setGravity(Gravity.TOP, 0,0);
            break;
    }

    switch (type){
        case 1:
            toastRoot.setBackgroundResource(R.drawable.success_toast);
            imageWrapper.setBackgroundResource(R.drawable.success_round);
            image.setImageResource(R.drawable.ic_done_white_24dp);
            break;
        case 2:
            toastRoot.setBackgroundResource(R.drawable.info_toast);
            imageWrapper.setBackgroundResource(R.drawable.info_round);
            image.setImageResource(R.drawable.ic_info_outline_white_24dp);
            break;
        case 3:
            toastRoot.setBackgroundResource(R.drawable.error_toast);
            imageWrapper.setBackgroundResource(R.drawable.error_round);
            image.setImageResource(R.drawable.ic_close_white_24dp);
            break;
        case 4:
            toastRoot.setBackgroundResource(R.drawable.warning_toast);
            imageWrapper.setBackgroundResource(R.drawable.warning_round);
            image.setImageResource(R.drawable.ic_pan_tool_white_24dp);
            break;
    }

    text.setText(toastMessage);
    toast.setView(layout);
    return toast;
}
 
Example 18
Project: Closet   File: ClosetFragment.java   View Source Code Vote up 4 votes
private void setupUnitCategory(HomeCategoryEntity homeCategoryEntity, final int index) {
    MasterCategoryEntity categoryEntity = homeCategoryEntity.getCategoryEntity();
    String cateName = categoryEntity.getCateName();
    final int picResId = categoryEntity.getPicResId();
    final List<ProductEntity> productEntityList = homeCategoryEntity.getProductEntityList();

    LinearLayout unitContainer = new LinearLayout(getContext());
    unitContainer.setOrientation(LinearLayout.VERTICAL);
    unitContainer.setGravity(Gravity.CENTER_VERTICAL);
    unitContainer.setBackgroundResource(R.color.bg_default_category);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DisplayUtil.dip2px(getResources().getInteger(R.integer.category_unit_height), getContext()));
    layoutParams.gravity = Gravity.CENTER;
    unitContainer.setLayoutParams(layoutParams);

    final ImageView imgIcon = new ImageView(getAttachActivity());
    int length = DisplayUtil.dip2px(32, getAttachActivity());
    LinearLayout.LayoutParams iconLp = new LinearLayout.LayoutParams(length, length);
    iconLp.gravity = Gravity.CENTER_HORIZONTAL;
    imgIcon.setLayoutParams(iconLp);
    imgIcon.setImageResource(picResId);


    final TextView tvCategory = new TextView(getContext());
    LinearLayout.LayoutParams tvLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    tvLp.gravity = Gravity.CENTER_HORIZONTAL;
    tvCategory.setLayoutParams(tvLp);
    tvCategory.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
    tvCategory.setTextColor(getAttachActivity().getResources().getColor(R.color.font_red));
    tvCategory.setText(cateName);
    tvCategory.setVisibility(View.GONE);

    View lineView = new View(getContext());
    LinearLayout.LayoutParams lineLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
    lineView.setLayoutParams(lineLp);
    lineView.setBackgroundResource(R.color.line);

    mUnitCategoryLayoutList.add(unitContainer);
    mTvCategoryNameList.add(tvCategory);
    mImgCategoryIconList.add(imgIcon);

    unitContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            reactionToClickCategory(index, productEntityList);
        }
    });

    unitContainer.addView(imgIcon);
    unitContainer.addView(tvCategory);
    mContainerCategory.addView(unitContainer);
    mContainerCategory.addView(lineView);
}
 
Example 19
Project: DateScroller   File: DateScroller.java   View Source Code Vote up 4 votes
private void init(Context context) {


        this.setOrientation(LinearLayout.VERTICAL);
        this.setGravity(Gravity.CENTER);
        this.setBackgroundResource(R.color.datescroller_check_border);

        //the content layout
        contentLinearLayout = new LinearLayout(getContext());
        LayoutParams contentParams = new LayoutParams(
                LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        int margin = DateScrollerUitls.dp2px(getContext(), 8);
        contentParams.topMargin = margin;
        contentParams.leftMargin = margin;
        contentParams.rightMargin = margin;
        contentParams.bottomMargin = margin;
        contentLinearLayout.setLayoutParams(contentParams);
        contentLinearLayout.setPadding(0, 0, DateScrollerUitls.dp2px(getContext(), 8), 0);
        contentLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
        contentLinearLayout.setBackgroundResource(R.drawable.shape_datescroller_bg);

        //today layout
        final LinearLayout todayLinearLayout = (LinearLayout) LayoutInflater.from(getContext())
                .inflate(R.layout.item_datescroller, null);
        LayoutParams todayParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        todayLinearLayout.setLayoutParams(todayParams);
        todayLinearLayout.setGravity(Gravity.CENTER);
        tvTodayDayOfWeek = (TextView) todayLinearLayout.findViewById(R.id.item_datescroller_dayOfWeek);
        tvTodayDayOfWeek.setText(getContext().getString(R.string.datescroller_today));
        tvTodayDayOfWeek.setPadding(DateScrollerUitls.dp2px(getContext(), 8), 0, 0, 0);


        //init today dayta
        todayDate = DateScrollerUitls.addDate(getContext(), calendar, 0);
        currentDate = todayDate;
        todayLinearLayout.setBackgroundResource(R.drawable.shape_datescroller_check_today_bg);

        todayLinearLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dateScollerView.setSelected(-1);
                todayLinearLayout.setBackgroundResource(R.drawable.shape_datescroller_check_today_bg);
                currentDate = todayDate;
                if (onItemClickListener != null)
                    onItemClickListener.onItemClick(currentDate);
            }
        });

        //diver
        View vDiver = new View(getContext());
        vDiver.setLayoutParams(new LayoutParams(DateScrollerUitls.dp2px(getContext(), 1), LayoutParams.MATCH_PARENT));
        vDiver.setBackgroundColor(Color.BLACK);


        contentLinearLayout.addView(todayLinearLayout);
        contentLinearLayout.addView(vDiver);

        dateScollerView = new DateScrollerView(getContext(), calendar);
        dateScollerView.setLayoutParams(
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        dateScollerView.setOnItemCheckListener(new DateScrollerView.OnItemCheckListener() {
            @Override
            public void onItemSelected(DateScrollerData datedata) {
                currentDate = datedata;
                if (onItemClickListener != null)
                    onItemClickListener.onItemClick(currentDate);
                todayLinearLayout.setBackgroundResource(0);
            }
        });
        contentLinearLayout.addView(dateScollerView);

        addView(contentLinearLayout);


    }
 
Example 20
Project: TaipeiTechRefined   File: CourseTableLayout.java   View Source Code Vote up 4 votes
private void initCourseTable() {
    courseContainer.removeAllViews();
    LayoutParams title_row_params = new LayoutParams(
            LayoutParams.MATCH_PARENT, ROW_HEIGHT / 2);
    LayoutParams row_params = new LayoutParams(LayoutParams.MATCH_PARENT,
            ROW_HEIGHT);
    LayoutParams cell_params = new LayoutParams(0,
            LayoutParams.MATCH_PARENT, 1f);
    LayoutParams title_col_params = new LayoutParams(0,
            LayoutParams.MATCH_PARENT, 0.5f);
    for (int i = 0; i < TABLE_ROW; i++) {
        LinearLayout table_row = new LinearLayout(getContext());
        table_row.setOrientation(LinearLayout.HORIZONTAL);
        table_row.setLayoutParams(i == 0 ? title_row_params : row_params);
        table_row.setGravity(Gravity.CENTER);
        table_row.setBackgroundResource(i % 2 != 0 ? R.color.cloud
                : R.color.white);
        for (int j = 0; j < TABLE_COL; j++) {
            CourseBlock table_cell = new CourseBlock(getContext());
            if (j == 0 && i > 0) {
                table_cell.setText(Integer.toHexString(i).toUpperCase(
                        Locale.US));
            }
            table_cell.setId(j != TABLE_COL - 1 ? i : 14);
            table_cell.setLayoutParams(j == 0 ? title_col_params
                    : cell_params);
            table_row.addView(table_cell);
        }
        courseContainer.addView(table_row);
    }
    LinearLayout title_row = (LinearLayout) courseContainer.getChildAt(0);
    CourseBlock text = (CourseBlock) title_row.getChildAt(1);
    text.setText(getContext().getString(R.string.mon));
    text = (CourseBlock) title_row.getChildAt(2);
    text.setText(getContext().getString(R.string.tue));
    text = (CourseBlock) title_row.getChildAt(3);
    text.setText(getContext().getString(R.string.wed));
    text = (CourseBlock) title_row.getChildAt(4);
    text.setText(getContext().getString(R.string.thu));
    text = (CourseBlock) title_row.getChildAt(5);
    text.setText(getContext().getString(R.string.fri));
    text = (CourseBlock) title_row.getChildAt(6);
    text.setText(getContext().getString(R.string.sat));
    text = (CourseBlock) title_row.getChildAt(7);
    text.setText(getContext().getString(R.string.sun));
}