Example usage for android.view ViewGroup getContext

List of usage examples for android.view ViewGroup getContext

Introduction

In this page you can find the example usage for android.view ViewGroup getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:net.olejon.mdapp.LvhAdapter.java

@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.activity_lvh_card, viewGroup,
            false);/*  w w  w  . j a v  a  2s  .  c o m*/
    return new CategoryViewHolder(view);
}

From source file:com.example.android.leanback.CardPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    Log.d(TAG, "onCreateViewHolder");
    Context context = parent.getContext();
    if (mCardThemeResId != 0) {
        if (mContextThemeWrapper == null) {
            mContextThemeWrapper = new ContextThemeWrapper(context, mCardThemeResId);
        }/*  w ww. j a v  a  2 s  . c  om*/
        context = mContextThemeWrapper;
    }
    ImageCardView v = new ImageCardView(context);
    v.setFocusable(true);
    v.setFocusableInTouchMode(true);
    // Randomly makes image view crop as a square or just stretch to original
    // aspect ratio.
    if (sRand.nextBoolean()) {
        v.setMainImageAdjustViewBounds(false);
        v.setMainImageDimensions(getRowHeight(parent.getContext()), getRowHeight(parent.getContext()));
    } else {
        v.setMainImageAdjustViewBounds(true);
        v.setMainImageDimensions(LayoutParams.WRAP_CONTENT, getRowHeight(parent.getContext()));
    }
    return new ViewHolder(v);
}

From source file:com.example.nikhil.wikipediasearch.ImageAdapter.java

public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        view = new ImageView(parent.getContext());
        view.setPadding(6, 2, 6, 2);/* ww w  .  j  ava2 s .  co  m*/
        //view.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
        view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.Color_1));

        view.invalidate();
    }

    int width = parent.getContext().getResources().getDisplayMetrics().widthPixels;
    if (URLS[position] != null) {
        Picasso.with(parent.getContext()).load(URLS[position]).noFade().resize(width / 4, width / 4)
                .centerCrop().error(R.drawable.no_image).placeholder(R.drawable.loading_image)
                .into((ImageView) view);
    }

    view.setTag(position);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                int pos = (int) v.getTag();
                zoomImageFromThumb(v, pos);

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

    return view;
}

From source file:com.canyinghao.canadapter.CanRVFragmentAdapter.java

@Override
public final FragmentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = new FrameLayout(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    int id = Math.abs(new Random().nextInt());
    if (parent.getContext() instanceof Activity) {
        while (((Activity) parent.getContext()).getWindow().getDecorView().findViewById(id) != null) {
            id = Math.abs(new Random().nextInt());
        }// www  .  jav a  2  s  .  co m
    }
    view.setId(id);
    mIds.add(id);
    return new FragmentViewHolder(view);
}

From source file:com.yacorso.nowaste.views.adapters.FridgeFoodAdapter.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    mContext = parent.getContext();
    View view = LayoutInflater.from(mContext).inflate(R.layout.card_food_item, parent, false);
    RecyclerView.ViewHolder vh = new FridgeViewHolder(view);

    return vh;/*from  w  w  w .j  a v a  2s. c  om*/
}

From source file:com.google.samples.apps.topeka.adapter.ScoreAdapter.java

private View createView(ViewGroup parent) {
    View convertView;//w  w  w . j av  a 2s  .  c o m
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    ViewGroup scorecardItem = (ViewGroup) inflater.inflate(R.layout.item_scorecard, parent, false);
    convertView = scorecardItem;
    ViewHolder holder = new ViewHolder(scorecardItem);
    convertView.setTag(holder);
    return convertView;
}

From source file:com.rks.musicx.ui.adapters.AlbumListAdapter.java

@Override
public AlbumListAdapter.AlbumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(layoutID, parent, false);
    return new AlbumViewHolder(itemView);
}

From source file:com.shizhefei.view.multitype.provider.FragmentDataProvider.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int providerType) {
    ChildViewHeightLayout layout = new ChildViewHeightLayout(parent.getContext());
    layout.setLayoutParams(ViewUtils.getRightLayoutParams(parent, layoutWidth, layoutHeight));
    layout.setId(providerType);//from   w w w .j  av  a2 s . c o m
    return new FragmentViewHolder(layout) {
        @Override
        public String toString() {
            return "Fragment :" + super.toString();
        }
    };
}

From source file:com.shopify.buy.ui.ProductImagePagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    Context context = container.getContext();
    if (context != null) {
        View view = container.findViewWithTag(position);
        ImageView imageView = (ImageView) view.findViewById(R.id.image);
        Picasso.with(context).cancelRequest(imageView);
    }/*  w  w w  .  ja  va2 s. c  o m*/
    super.destroyItem(container, position, object);
}

From source file:com.aphidmobile.flip.demo.fragment.FlipTextViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    flipView = new FlipViewController(inflater.getContext());

    flipView.setAdapter(new BaseAdapter() {
        @Override//w w  w.j a v a2 s. c om
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            NumberTextView view;
            if (convertView == null) {
                final Context context = parent.getContext();
                view = new NumberTextView(context, position);
                view.setTextSize(context.getResources().getDimension(R.dimen.textSize));
            } else {
                view = (NumberTextView) convertView;
                view.setNumber(position);
            }

            return view;
        }
    });

    return flipView;
}