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

The following examples show how to use android.view.ViewGroup#getResources() . These examples are extracted from open source projects. 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 Project: tv-samples   File: GridItemPresenter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.grid_item_width);
    int height = res.getDimensionPixelSize(R.dimen.grid_item_height);

    view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(),
            R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 2
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    ImageView imageView =
            (ImageView)
                    LayoutInflater.from(parent.getContext())
                            .inflate(
                                    R.layout.lb_fullwidth_details_overview_logo,
                                    parent,
                                    false);

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.detail_thumb_width);
    int height = res.getDimensionPixelSize(R.dimen.detail_thumb_height);
    imageView.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    return new ViewHolder(imageView);
}
 
Example 3
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.grid_item_width);
    int height = res.getDimensionPixelSize(R.dimen.grid_item_height);

    view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(),
            R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 4
Source Project: tv-samples   File: VideoDetailsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    ImageView imageView = (ImageView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.lb_fullwidth_details_overview_logo, parent, false);

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.detail_thumb_width);
    int height = res.getDimensionPixelSize(R.dimen.detail_thumb_height);
    imageView.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    return new ViewHolder(imageView);
}
 
Example 5
Source Project: delion   File: PaymentRequestSection.java    License: Apache License 2.0 5 votes vote down vote up
private ImageView createAndAddChevron(ViewGroup parent) {
    Resources resources = parent.getResources();
    TintedDrawable chevron = TintedDrawable.constructTintedDrawable(
            resources, R.drawable.ic_expanded, R.color.payments_section_chevron);

    ImageView view = new ImageView(parent.getContext());
    view.setImageDrawable(chevron);

    // Wrap whatever image is passed in.
    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}
 
Example 6
private Button createAndAddEditButton(ViewGroup parent) {
    Resources resources = parent.getResources();
    Button view = DualControlLayout.createButtonForLayout(
            parent.getContext(), true, resources.getString(R.string.select), this);
    view.setId(R.id.payments_section);

    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}
 
Example 7
private ImageView createAndAddChevron(ViewGroup parent) {
    Resources resources = parent.getResources();
    TintedDrawable chevron = TintedDrawable.constructTintedDrawable(
            resources, R.drawable.ic_expanded, R.color.payments_section_chevron);

    ImageView view = new ImageView(parent.getContext());
    view.setImageDrawable(chevron);

    // Wrap whatever image is passed in.
    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}
 
Example 8
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    this.viewType = viewType;

    View view = getViewForType(viewType, inflater, parent);

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
Example 9
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    this.viewType = viewType;

    View view = getViewForType(viewType, inflater, parent);

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
Example 10
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    View view = getViewForType(viewType, inflater, parent);

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
Example 11
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    View view = getViewForType(viewType, inflater, parent);

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
Example 12
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    this.viewType = viewType;

    View view = getViewForType(viewType, inflater, parent);

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
Example 13
private Button createAndAddEditButton(ViewGroup parent) {
    Resources resources = parent.getResources();
    Button view = DualControlLayout.createButtonForLayout(
            parent.getContext(), true, resources.getString(R.string.choose), this);
    view.setId(R.id.payments_section);

    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}
 
Example 14
private ImageView createAndAddChevron(ViewGroup parent) {
    Resources resources = parent.getResources();
    TintedDrawable chevron = TintedDrawable.constructTintedDrawable(
            resources, R.drawable.ic_expanded, R.color.payments_section_chevron);

    ImageView view = new ImageView(parent.getContext());
    view.setImageDrawable(chevron);

    // Wrap whatever image is passed in.
    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}
 
Example 15
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	IconContextMenuItem item = (IconContextMenuItem) getItem(position);
	Resources res = parentActivity.getResources();
	
	if (convertView == null) {
       	TextView temp = new TextView(context);
       	AbsListView.LayoutParams param = new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, 
       																  AbsListView.LayoutParams.WRAP_CONTENT);
       	temp.setLayoutParams(param);
       	temp.setPadding((int)toPixel(res, 20), 2, (int)toPixel(res, 20), 2);
       	temp.setGravity(android.view.Gravity.CENTER_VERTICAL);
       	Theme th = context.getTheme();
		TypedValue tv = new TypedValue();
		
		if (th.resolveAttribute(android.R.attr.textAppearanceLargeInverse, tv, true)) {
			temp.setTextAppearance(context, tv.resourceId);
		}
       	
       	temp.setMinHeight(LIST_PREFERED_HEIGHT);
       	
       	temp.setCompoundDrawablePadding((int)toPixel(res, 14));
       	convertView = temp;
	}
	
	TextView textView = (TextView) convertView;
	textView.setTag(item);
	textView.setText(item.text);
	textView.setTextColor(Color.WHITE);
	textView.setTypeface(typeface);
	
	Bitmap bitmap = ((BitmapDrawable) item.image).getBitmap();
	Drawable d = new BitmapDrawable(parent.getResources(), Bitmap.createScaledBitmap(bitmap, LIST_PREFERED_HEIGHT, LIST_PREFERED_HEIGHT, true));
	textView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
      	
       return textView;
}
 
Example 16
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    ImageView imageView = (ImageView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.lb_fullwidth_details_overview_logo, parent, false);

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.detail_thumb_width);
    int height = res.getDimensionPixelSize(R.dimen.detail_thumb_height);
    imageView.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    return new ViewHolder(imageView);
}
 
Example 17
@Override
public Object instantiateItem(final ViewGroup container, int position) {
    if(mData != null && mData.size() > position){
        ZoomableDraweeView zoomableDraweeView = null;
        if(mImageViewList != null && mImageViewList.length > position && mImageViewList[position] != null){
            zoomableDraweeView = mImageViewList[position];

        }else{
            zoomableDraweeView = new ZoomableDraweeView(container.getContext());
            zoomableDraweeView.setAllowTouchInterceptionWhileZoomed(true);
            // needed for double tap to zoom
            zoomableDraweeView.setIsLongpressEnabled(false);
            zoomableDraweeView.setSwipeDownListener(mSwipeDownListener);
            final ZoomableDraweeView finalZoomableDraweeView = zoomableDraweeView;
            zoomableDraweeView.setTapListener(new DoubleTapGestureListener(finalZoomableDraweeView){
                @Override
                public boolean onSingleTapConfirmed(MotionEvent e) {
                    if(mItemClickListener != null){
                        mItemClickListener.onClick(finalZoomableDraweeView);
                    }
                    return super.onSingleTapConfirmed(e);
                }
            });
            DraweeController controller = Fresco.newDraweeControllerBuilder()
                    .setUri(mData.get(position % mData.size()))
                    .build();
            zoomableDraweeView.setController(controller);
            GenericDraweeHierarchyBuilder builder =
                    new GenericDraweeHierarchyBuilder(container.getResources());
            GenericDraweeHierarchy hierarchy = builder
                    .setFadeDuration(300).setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
                    .build();
            if(mPlaceholderImageResId > 0){
                hierarchy.setPlaceholderImage(mPlaceholderImageResId, ScalingUtils.ScaleType.FIT_CENTER);
            }
            if(mFailureImageResId > 0){
                hierarchy.setFailureImage(mFailureImageResId, ScalingUtils.ScaleType.FIT_CENTER);
            }
            zoomableDraweeView.setHierarchy(hierarchy);

            mImageViewList[position] = zoomableDraweeView;
        }
        container.addView(zoomableDraweeView);

        return zoomableDraweeView;
    }

    return null;
}
 
Example 18
Source Project: ResearchStack   File: DateQuestionBody.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    View view = inflater.inflate(R.layout.rsb_item_date_view, parent, false);

    TextView title = (TextView) view.findViewById(R.id.label);
    if (viewType == VIEW_TYPE_COMPACT) {
        title.setText(step.getTitle());
    } else {
        title.setVisibility(View.GONE);
    }

    TextView textView = (TextView) view.findViewById(R.id.value);
    textView.setSingleLine(true);
    if (step.getPlaceholder() != null) {
        textView.setHint(step.getPlaceholder());
    } else {
        if (format.getStyle() == AnswerFormat.DateAnswerStyle.Date) {
            textView.setHint(R.string.rsb_hint_step_body_date);
        } else if (format.getStyle() == AnswerFormat.DateAnswerStyle.TimeOfDay) {
            textView.setHint(R.string.rsb_hint_step_body_time);
        } else if (format.getStyle() == AnswerFormat.DateAnswerStyle.DateAndTime) {
            textView.setHint(R.string.rsb_hint_step_body_datetime);
        }
    }

    if (result.getResult() != null) {
        textView.setText(createFormattedResult());
    }

    textView.setOnFocusChangeListener((v, hasFocus) -> {
        if (hasFocus) {
            showDialog(textView);
        }
    });

    textView.setOnClickListener(v -> {
        if (v.isFocused()) {
            showDialog(textView);
        }
    });

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    view.setLayoutParams(layoutParams);

    return view;
}
 
Example 19
Source Project: ResearchStack   File: TextQuestionBody.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public View getBodyView(int viewType, LayoutInflater inflater, ViewGroup parent) {
    View body = inflater.inflate(R.layout.rsb_item_edit_text_compact, parent, false);

    editText = (EditText) body.findViewById(R.id.value);
    if (step.getPlaceholder() != null) {
        editText.setHint(step.getPlaceholder());
    } else {
        editText.setHint(R.string.rsb_hint_step_body_text);
    }

    TextView title = (TextView) body.findViewById(R.id.label);

    if (viewType == VIEW_TYPE_COMPACT) {
        title.setText(step.getTitle());
    } else {
        title.setVisibility(View.GONE);
    }

    // Restore previous result
    String stringResult = result.getResult();
    if (!TextUtils.isEmpty(stringResult)) {
        editText.setText(stringResult);
    }

    // Set result on text change
    RxTextView.textChanges(editText).subscribe(text -> {
        result.setResult(text.toString());
    });

    // Format EditText from TextAnswerFormat
    TextAnswerFormat format = (TextAnswerFormat) step.getAnswerFormat();

    editText.setSingleLine(!format.isMultipleLines());

    if (format.getMaximumLength() > TextAnswerFormat.UNLIMITED_LENGTH) {
        InputFilter.LengthFilter maxLengthFilter = new InputFilter.LengthFilter(format.getMaximumLength());
        InputFilter[] filters = ViewUtils.addFilter(editText.getFilters(), maxLengthFilter);
        editText.setFilters(filters);
    }

    Resources res = parent.getResources();
    LinearLayout.MarginLayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_left);
    layoutParams.rightMargin = res.getDimensionPixelSize(R.dimen.rsb_margin_right);
    body.setLayoutParams(layoutParams);

    return body;
}