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.niligo.prism.adapter.ItemAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (viewType) {
    case 0://from w w w .j a va  2  s  .  c  om
        View view = LayoutInflater.from(parent.getContext()).inflate(mCatLayoutId, parent, false);
        return new ViewHolder(view, true);
    case 1:
        view = LayoutInflater.from(parent.getContext()).inflate(mBulbLayoutId, parent, false);
        return new ViewHolder(view, false);
    }
    return null;
}

From source file:com.jigarmjoshi.ActFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_act, container, false);
    Utility.checkAndEnableLocation(container.getContext());

    // Gets the MapView from the XML layout and creates it
    mapView = (MapView) rootView.findViewById(R.id.mapviewAct);
    refreshMapButton = (Button) rootView.findViewById(R.id.refreshMapButton);

    mapView.onCreate(savedInstanceState);
    // Gets to GoogleMap from the MapView and does initialization stuff
    map = mapView.getMap();//from w  ww .ja v  a2 s .  c o m
    map.getUiSettings().setMyLocationButtonEnabled(true);
    // map.setMyLocationEnabled(true);
    mapView.refreshDrawableState();

    map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            String title = marker.getTitle();
            boolean validNumber = false;
            try {
                Long.parseLong(title);
                validNumber = true;
            } catch (Exception ex) {
                // this is current location marker
            }
            if (!validNumber) {
                return false;
            }
            Utility.createMapEntryDialog(rootView.getContext(), marker).show();
            return false;
        }
    });
    // Needs to call MapsInitializer before doing any CameraUpdateFactory
    // calls
    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (Exception ex) {
        Log.e(ActFragment.class.getName(), "failed to initialize map", ex);
    }
    Utility.focusAtCurrentLocation(map);

    refreshMapButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refreshMapButton.setText("loading..");
            refreshMapButton.refreshDrawableState();
            refreshMapButton.setEnabled(false);
            LatLngBounds latLngBounds = map.getProjection().getVisibleRegion().latLngBounds;
            RefreshMapAsyncTask refreshMapAsyncTask = new RefreshMapAsyncTask(refreshMapButton, map,
                    rootView.getContext(), mapView);
            refreshMapAsyncTask.execute(String.valueOf(latLngBounds.southwest.latitude),
                    String.valueOf(latLngBounds.southwest.longitude),
                    String.valueOf(latLngBounds.northeast.latitude),
                    String.valueOf(latLngBounds.northeast.longitude));

        }
    });

    return rootView;
}

From source file:com.tompee.funtablayout.PopTabAdapter.java

@Override
public PopTabAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    PopTabView itemView = new PopTabView(parent.getContext());
    itemView.setLayoutParams(createLayoutParamsForTabs(parent));
    ViewCompat.setPaddingRelative(itemView, mTabPaddingStart, mTabPaddingTop, mTabPaddingEnd,
            mTabPaddingBottom);/*from   w  w w.  j  av a  2  s.co m*/
    itemView.setBackgroundResource(mTabBackgroundResId);
    itemView.setIconDimension(mIconDimension);
    itemView.setTextAppearance(mTabTextAppearance);
    itemView.setMaxLines(MAX_TAB_TEXT_LINES);
    itemView.setTextColor(mTabIndicatorColor);
    itemView.setPopDuration(mPopDuration);
    return new ViewHolder(itemView);
}

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

/**
 * {@inheritDoc}/*from   w  w w .  j a v a  2  s  .  c  om*/
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Context ctx = parent.getContext();
    assert ctx != null;

    View root = convertView;
    if (convertView == null) {
        // Create a new view (nothing to recycle)
        LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        root = inflater.inflate(R.layout.medium_card_two_lines, parent, false);
        assert root != null;

        ViewHolder holder = new ViewHolder();
        holder.vRoot = (ViewGroup) root;
        holder.ivCover = (AlbumArtImageView) root.findViewById(R.id.ivCover);
        holder.tvTitle = (TextView) root.findViewById(R.id.tvTitle);
        holder.tvSubTitle = (TextView) root.findViewById(R.id.tvSubTitle);
        holder.ivOfflineStatus = (ImageView) root.findViewById(R.id.ivOfflineStatus);

        root.setTag(holder);
    }

    // Fill in the fields
    final Playlist playlist = getItem(position);
    final ViewHolder tag = (ViewHolder) root.getTag();

    tag.playlist = playlist;

    if (playlist.isLoaded() || playlist.getName() != null) {
        tag.tvTitle.setText(playlist.getName());
        tag.tvSubTitle.setText(ctx.getResources().getQuantityString(R.plurals.songs_count,
                playlist.getSongsCount(), playlist.getSongsCount()));
        tag.ivCover.loadArtForPlaylist(playlist);

        tag.ivOfflineStatus.setVisibility(View.VISIBLE);
        switch (playlist.getOfflineStatus()) {
        case BoundEntity.OFFLINE_STATUS_NO:
            tag.ivOfflineStatus.setVisibility(View.GONE);
            break;

        case BoundEntity.OFFLINE_STATUS_DOWNLOADING:
            tag.ivOfflineStatus.setImageResource(R.drawable.ic_sync_in_progress);
            break;

        case BoundEntity.OFFLINE_STATUS_ERROR:
            tag.ivOfflineStatus.setImageResource(R.drawable.ic_sync_problem);
            break;

        case BoundEntity.OFFLINE_STATUS_PENDING:
            tag.ivOfflineStatus.setImageResource(R.drawable.ic_track_download_pending);
            break;

        case BoundEntity.OFFLINE_STATUS_READY:
            tag.ivOfflineStatus.setImageResource(R.drawable.ic_track_downloaded);
            break;
        }
    } else {
        tag.tvTitle.setText(R.string.loading);
        tag.tvSubTitle.setText(R.string.loading);
        tag.ivCover.setDefaultArt();
        tag.ivOfflineStatus.setVisibility(View.GONE);
    }

    return root;
}

From source file:com.quuzz.tbg.recyclerview.CustomAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    viewGroup.setClickable(true);/*from www. j a va 2  s .c o m*/
    // Create a new view.
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.text_row_item, viewGroup, false);

    return new ViewHolder(v, viewGroup);
}

From source file:com.lloydtorres.stately.region.RegionOverviewRecyclerAdapter.java

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    RecyclerView.ViewHolder viewHolder = null;
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());

    switch (viewType) {
    case REGION_QUICK_FACTS:
        View quickFactsCard = inflater.inflate(R.layout.card_region_quick_facts, parent, false);
        viewHolder = new RegionQuickFactsCard(quickFactsCard);
        break;//from w  w  w . j a v a 2 s . c om
    case REGION_FACTBOOK:
        View factbookCard = inflater.inflate(R.layout.card_region_generic, parent, false);
        viewHolder = new RegionFactbookCard(factbookCard);
        break;
    case REGION_TAGS:
        View tagsCard = inflater.inflate(R.layout.card_region_generic, parent, false);
        viewHolder = new RegionTagsCard(tagsCard);
        break;
    }

    return viewHolder;
}

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

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

From source file:com.vagabond.dealhunting.ui.DealAdapter.java

@Override
public DealAdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    if (viewGroup instanceof RecyclerView) {
        int layoutId = R.layout.list_item_deal;
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
        view.setFocusable(true);/*from w  w w  . j a v  a 2 s .com*/
        final DealAdapterViewHolder vh = new DealAdapterViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mClickHandler.onClick(mCursor, vh);
            }
        });
        return vh;
    } else {
        throw new RuntimeException("Not bound to RecyclerView");
    }
}

From source file:com.duanyl.recyclerviewsd.MyDraggableSwipeableItemAdapter.java

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View v = inflater.inflate((viewType == 0) ? R.layout.list_item : R.layout.list_item2, parent, false);
    return new MyViewHolder(v);
}

From source file:com.github.rubensousa.bottomsheetbuilder.adapter.BottomSheetItemAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (mMode == BottomSheetBuilder.MODE_GRID) {
        View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.bottomsheetbuilder_grid_adapter,
                parent, false);/*from  w w w  . j  av  a2 s.  c o m*/

        ViewGroup.LayoutParams layoutParams = layout.getLayoutParams();
        layoutParams.width = mItemWidth;
        layout.setLayoutParams(layoutParams);
        return new ItemViewHolder(layout);
    }

    if (mMode == BottomSheetBuilder.MODE_LIST) {

        if (viewType == TYPE_HEADER) {
            return new HeaderViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.bottomsheetbuilder_list_header, parent, false));
        }

        if (viewType == TYPE_ITEM) {
            return new ItemViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.bottomsheetbuilder_list_adapter, parent, false));
        }

        if (viewType == TYPE_DIVIDER) {
            return new DividerViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.bottomsheetbuilder_list_divider, parent, false));
        }

    }

    return new ViewHolder(LayoutInflater.from(parent.getContext())
            .inflate(R.layout.bottomsheetbuilder_list_adapter, parent, false));
}