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:com.google.android.leanbackjank.presenter.CardPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    mDefaultBackgroundColor = ResourcesCompat.getColor(parent.getResources(), R.color.jank_blue, null);
    mSelectedBackgroundColor = ResourcesCompat.getColor(parent.getResources(), R.color.jank_red, null);

    ImageCardView cardView = new ImageCardView(parent.getContext()) {
        @Override// w w w  . ja va 2  s  .  co m
        public void setSelected(boolean selected) {
            findViewById(R.id.info_field)
                    .setBackgroundColor(selected ? mSelectedBackgroundColor : mDefaultBackgroundColor);
            super.setSelected(selected);
        }
    };

    cardView.setFocusable(true);
    cardView.setFocusableInTouchMode(true);
    return new ViewHolder(cardView);
}

From source file:com.tmendes.birthdaydroid.StatisticsFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_statistics, container, false);

    ctx = container.getContext();
    BirthDayDataList data = BirthDayDataList.getBirthDayDataList(this.ctx);
    DateFormatSymbols dfs = new DateFormatSymbols();

    int contactsCounter = data.getList().size();

    Map<Integer, Integer> ageStat = data.getAgeStats();
    Map<String, Integer> signStat = data.getSignStats();
    Map<Integer, Integer> monthStat = data.getMonthStats();
    Map<Integer, Integer> weekStat = data.getWeekStats();

    Button buttonAges = (Button) v.findViewById(R.id.buttonAges);
    Button buttonSign = (Button) v.findViewById(R.id.buttonSign);
    Button buttonMonth = (Button) v.findViewById(R.id.buttonMonth);
    Button buttonWeek = (Button) v.findViewById(R.id.buttonWeek);

    Iterator it;/*from  w  ww  . j a v a2  s.  co m*/

    it = ageStat.entrySet().iterator();

    String dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);

    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        int age = (int) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_int, number, age);
    }

    final String finalDialogDataAges = dialogData;
    buttonAges.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_age_title));
            alertDialog.setMessage(finalDialogDataAges);
            alertDialog.show();
        }

    });

    it = signStat.entrySet().iterator();
    dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        String sign = (String) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_string, number, sign);
    }

    final String finalDialogDataSign = dialogData;
    buttonSign.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_sign_title));
            alertDialog.setMessage(finalDialogDataSign);
            alertDialog.show();
        }

    });

    it = monthStat.entrySet().iterator();
    dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        int month = (int) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_string, number,
                dfs.getMonths()[month]);
    }

    final String finalDialogDataMonth = dialogData;
    buttonMonth.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_month_title));
            alertDialog.setMessage(finalDialogDataMonth);
            alertDialog.show();
        }

    });

    it = weekStat.entrySet().iterator();
    dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        int week = (int) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_string, number,
                dfs.getWeekdays()[week]);
    }

    final String finalDialogDataWeek = dialogData;
    buttonWeek.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_week_title));
            alertDialog.setMessage(finalDialogDataWeek);
            alertDialog.show();
        }

    });

    return v;

}

From source file:com.daniel.lupianez.casares.LayoutPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {

    //Get the resource id for that position
    int resourceId = layoutIds.get(position);
    //Inflate the view and add it to the container
    View view = View.inflate(container.getContext(), resourceId, null);

    //Tell the listener
    if ((view != null) && (onViewLoadedListener != null))
        onViewLoadedListener.onViewLoadedListener(this, view, position);

    //Add the view
    if (view != null)
        container.addView(view);/*from  w  w  w  .  j av  a2 s .  com*/

    //Finally, return the object
    return view;

}

From source file:com.repkap11.repcast.queue.ui.QueueListAdapter.java

@Override
public QueueItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View v = inflater.inflate(R.layout.queue_row, parent, false);
    return new QueueItemViewHolder(v);
}

From source file:com.tlongdev.bktf.adapter.BackpackAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v;//from   w ww . j  a  v  a 2s  . c  o m
    switch (viewType) {
    case VIEW_TYPE_ITEM:
        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_backpack, parent, false);
        break;
    case VIEW_TYPE_HEADER:
        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_backpack_header, parent, false);
        break;
    default:
        return null;
    }

    return new ViewHolder(v, viewType);

}

From source file:com.google.sample.cast.refplayer.queue.ui.QueueListAdapter.java

@Override
public QueueItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View view = inflater.inflate(R.layout.cast_queue_row, parent, false);
    return new QueueItemViewHolder(view);
}

From source file:com.wii.sean.wiimmfiitus.adapters.CustomWiiCyclerViewAdapter.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v;//w ww. j  a va2 s  .  com
    RecyclerView.ViewHolder fvh = null;
    if (wiiList.get(0).getType() == DEFAULT_VIEW) {
        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.mii_license_card_default, parent, false);
        fvh = new DefaultFriendViewHolder(v, viewType);
    }
    if (wiiList.get(0).getType() == COMPACT_VIEW_DETAILED) {
        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.mii_license_card_compact_detailed, parent,
                false);
        fvh = new CompactFriendHolder(v, viewType);
    }
    return fvh;
}

From source file:com.fastbootmobile.encore.app.adapters.HistoryAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ProviderAggregator aggregator = ProviderAggregator.getDefault();
    ViewHolder tag;/* w  w  w.  ja v a  2 s . com*/

    if (convertView == null) {
        Context ctx = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(ctx);

        convertView = inflater.inflate(R.layout.item_history, parent, false);
        tag = new ViewHolder(convertView);

        tag.ivAlbumArt.setOnClickListener(mAlbumArtClickListener);
        tag.btnOverflow.setOnClickListener(mOverflowClickListener);
    } else {
        tag = (ViewHolder) convertView.getTag();
    }

    ListenLogger.LogEntry entry = getItem(position);
    Song song = aggregator.retrieveSong(entry.getReference(), entry.getIdentifier());

    tag.song = song;

    if (song != null) {
        if (song.isLoaded()) {
            tag.ivAlbumArt.loadArtForSong(song);
            tag.tvTitle.setText(song.getTitle());

            Artist artist = aggregator.retrieveArtist(song.getArtist(), song.getProvider());
            if (artist != null && artist.getName() != null && !artist.getName().isEmpty()) {
                tag.tvArtist.setText(artist.getName());
            } else if (artist != null) {
                tag.tvArtist.setText(R.string.loading);
            }
        } else {
            tag.tvTitle.setText(R.string.loading);
            tag.tvArtist.setText(null);
            tag.ivAlbumArt.setDefaultArt();
        }
    }

    tag.tvPlayDate.setText(sDateFormat.format(entry.getTimestamp()));
    return convertView;
}

From source file:com.ricardotrujillo.appstore.viewmodel.adapter.StoreRecyclerViewAdapter.java

@Override
public BindingHolder onCreateViewHolder(ViewGroup parent, int type) {

    LayoutInflater inflater = LayoutInflater.from(parent.getContext());

    StoreRowBinding binding = StoreRowBinding.inflate(inflater, parent, false);

    return new BindingHolder(binding.getRoot());
}

From source file:com.pedrogomez.renderers.VPRendererAdapter.java

/**
 * Main method of VPRendererAdapter. This method has the responsibility of update the
 * RendererBuilder values and create or recycle a new Renderer. Once the renderer has been
 * obtained the RendereBuilder will call the render method in the renderer and will return the
 * Renderer root view to the ViewPager./*from ww  w.  ja v  a  2s.c o m*/
 *
 * If RendererBuilder returns a null Renderer this method will throw a
 * NullRendererBuiltException.
 *
 * @param parent The containing View in which the page will be shown.
 * @param position to render.
 * @return view rendered.
 */
@Override
public Object instantiateItem(ViewGroup parent, int position) {
    T content = getItem(position);
    rendererBuilder.withContent(content);
    rendererBuilder.withParent(parent);
    rendererBuilder.withLayoutInflater(LayoutInflater.from(parent.getContext()));
    Renderer<T> renderer = rendererBuilder.build();
    if (renderer == null) {
        throw new NullRendererBuiltException("RendererBuilder have to return a not null Renderer");
    }
    updateRendererExtraValues(content, renderer, position);
    renderer.render();
    View view = renderer.getRootView();
    parent.addView(view);
    return view;
}