Example usage for android.view LayoutInflater getContext

List of usage examples for android.view LayoutInflater getContext

Introduction

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

Prototype

public Context getContext() 

Source Link

Document

Return the context we are running in, for access to resources, class loader, etc.

Usage

From source file:codingpractice.renard314.com.products.ProductGridAdapter.java

public ProductGridAdapter(LayoutInflater layoutInflater, Collection<Product> products) {
    mProducts.addAll(products);/*from www.  ja v  a  2 s. c o  m*/
    final Resources resources = layoutInflater.getContext().getResources();
    mDefaultBackgroundColor = resources.getColor(R.color.colorAccent);
    mDefaultTextColor = resources.getColor(R.color.primary_text_default_material_dark);
    this.mLayoutInflater = layoutInflater;
}

From source file:com.xengar.android.stocktracker.ui.StockFragment.java

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

    mContext = inflater.getContext();

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    // Get a reference to the RecyclerView, and attach this adapter to it.
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
    error = (TextView) rootView.findViewById(R.id.error);
    // Set the layout manager
    adapter = new StockAdapter(mContext, new StockAdapter.StockAdapterOnClickHandler() {
        @Override/* ww w. j  a  va 2  s  .c o  m*/
        public void onClick(String symbol, StockAdapter.StockViewHolder vh) {
            ((Callback) getActivity()).onItemSelected(Contract.Quote.makeUriForStock(symbol), vh);
            mPosition = vh.getAdapterPosition();
        }
    });
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setRefreshing(true);
    //onRefresh();

    long syncPeriod = PrefUtils.getSyncFrequency(mContext);
    QuoteSyncJob.initialize(mContext, syncPeriod);
    getLoaderManager().initLoader(STOCK_LOADER, null, this);

    new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            String symbol = adapter.getSymbolAtPosition(viewHolder.getAdapterPosition());
            PrefUtils.removeStock(getActivity(), symbol);
            mContext.getContentResolver().delete(Contract.Quote.makeUriForStock(symbol), null, null);
        }
    }).attachToRecyclerView(mRecyclerView);

    return rootView;
}

From source file:org.berlin_vegan.bvapp.fragments.LocationsOverview.LocationMapOverviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    mResourceProxy = new ResourceProxyImpl(inflater.getContext().getApplicationContext());
    mMapView = new MapView(inflater.getContext(), mResourceProxy);

    mMapView.getController().setInvertedTiles(false);

    mMapView.setTileSource(UiUtils.GOOGLE_MAPS_TILE);
    mMapView.setMultiTouchControls(true);

    mOverlayItemList = new ArrayList<>();

    // inner class seems HACKy here ....
    OnItemGestureListener<LocationOverlayItem> myOnItemGestureListener = new OnItemGestureListener<LocationOverlayItem>() {

        @Override//from  ww w .j  a  v  a  2  s  . com
        public boolean onItemLongPress(int arg0, LocationOverlayItem arg1) {
            // TODO
            return false;
        }

        @Override
        public boolean onItemSingleTapUp(int index, LocationOverlayItem item) {
            final Intent intent = new Intent(getContext(), LocationDetailActivity.class);
            intent.putExtra(LocationDetailActivity.EXTRA_LOCATION, item.getCorrespondingLocation());
            startActivity(intent);
            return true;
        }
    };

    mLocationOverlay = new ItemizedIconOverlay<>(getContext(), mOverlayItemList, myOnItemGestureListener);
    mMapView.getOverlays().add(mLocationOverlay);

    IMapController mapController = mMapView.getController();
    mapController.setZoom(10);

    // set Center of the map to Alex
    GeoPoint gPoint = new GeoPoint(52.521918, 13.413215);
    mapController.setCenter(gPoint);

    Locations locations = ((LocationsOverviewActivity) getActivity()).getLocations();

    for (int i = 0; i < locations.size(); i++) {
        Location location = locations.get(i);
        gPoint = new GeoPoint(location.getLatCoord(), location.getLongCoord());
        LocationOverlayItem mMarkerItem = new LocationOverlayItem(location.getName(),
                location.getVegan().toString(), gPoint, location);
        Drawable marker = getResources().getDrawable(R.mipmap.ic_map_pin_red);
        mMarkerItem.setMarker(marker);
        mLocationOverlay.addItem(mMarkerItem);
    }

    return mMapView;
}

From source file:cn.edu.wyu.documentviewer.RecentsCreateFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = inflater.getContext();

    final View view = inflater.inflate(R.layout.fragment_directory, container, false);

    mEmptyView = view.findViewById(android.R.id.empty);

    mListView = (ListView) view.findViewById(R.id.list);
    mListView.setOnItemClickListener(mItemListener);

    mAdapter = new DocumentStackAdapter();
    mListView.setAdapter(mAdapter);// w  ww  . ja v  a  2  s  . c  o  m

    final RootsCache roots = DocumentsApplication.getRootsCache(context);
    final State state = ((DocumentsActivity) getActivity()).getDisplayState();

    mCallbacks = new LoaderCallbacks<List<DocumentStack>>() {
        @Override
        public Loader<List<DocumentStack>> onCreateLoader(int id, Bundle args) {
            return new RecentsCreateLoader(context, roots, state);
        }

        @Override
        public void onLoadFinished(Loader<List<DocumentStack>> loader, List<DocumentStack> data) {
            mAdapter.swapStacks(data);

            // When launched into empty recents, show drawer
            if (mAdapter.isEmpty() && !state.stackTouched) {
                ((DocumentsActivity) context).setRootsDrawerOpen(true);
            }
        }

        @Override
        public void onLoaderReset(Loader<List<DocumentStack>> loader) {
            mAdapter.swapStacks(null);
        }
    };

    return view;
}

From source file:com.poguico.palmabici.map.StationMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mResourceProxy = new ResourceProxyImpl(inflater.getContext().getApplicationContext());
    mMapView = new MapView(inflater.getContext(), 256, mResourceProxy);
    mMapView.setUseSafeCanvas(true);//from w ww  .ja  va  2  s . com
    setHardwareAccelerationOff();
    return mMapView;
}

From source file:com.spoiledmilk.ibikecph.map.MapFragmentBase.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    LOG.d("MapFragment onCreateView");
    try {/*from   w  w w. j  av a  2 s .c o  m*/
        resourceProxy = new ResourceProxy(inflater.getContext().getApplicationContext());
        mapView = new MapView(inflater.getContext(), 256, resourceProxy);
        mapView.setMaxZoomLevel(20);
        mapView.setMinZoomLevel(6);
        mapView.getOverlayManager().defaultZoom = (int) IbikePreferences.DEFAULT_ZOOM_LEVEL;
    } catch (Exception e) {
        LOG.d(e.getLocalizedMessage());
    }
    mapView.setUseSafeCanvas(true);
    setHardwareAccelerationOff();
    mapView.addView(textStationInfo);
    return mapView;
}

From source file:androidx.navigation.fragment.NavHostFragment.java

@Nullable
@Override//  w w w .  j ava 2  s. c  om
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    FrameLayout frameLayout = new FrameLayout(inflater.getContext());
    // When added via XML, this has no effect (since this FrameLayout is given the ID
    // automatically), but this ensures that the View exists as part of this Fragment's View
    // hierarchy in cases where the NavHostFragment is added programmatically as is required
    // for child fragment transactions
    frameLayout.setId(getId());
    return frameLayout;
}

From source file:com.github.pockethub.ui.comment.CommentListAdapter.java

/**
 * Create list adapter//  ww w .j av a 2 s  .c  o m
 *
 * @param inflater
 * @param avatars
 * @param imageGetter
 */
public CommentListAdapter(LayoutInflater inflater, AvatarLoader avatars, HttpImageGetter imageGetter,
        Issue issue) {
    this(inflater, null, avatars, imageGetter, issue);
    this.context = inflater.getContext();
}

From source file:org.kde.kdeconnect.UserInterface.List.SmallEntryItem.java

@Override
public View inflateView(LayoutInflater layoutInflater) {
    View v = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);

    TextView titleView = (TextView) v.findViewById(android.R.id.text1);
    if (titleView != null) {
        titleView.setText(title);//from ww  w.j a  v  a 2s . c  o  m
        if (clickListener != null) {
            titleView.setOnClickListener(clickListener);
            v.setBackgroundDrawable(ContextCompat.getDrawable(layoutInflater.getContext(),
                    R.drawable.abc_list_selector_holo_dark));
        }
    }

    return v;
}

From source file:com.ixvil.android.BoxBonus.Fragments.ShopsListFragment.java

public void getAllShops(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    final RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.recycler_view, container, false);

    try {//from   ww w .j  a v  a  2 s  .  c  o m
        Ion.with(recyclerView.getContext())
                .load(inflater.getContext().getResources().getString(R.string.hostname) + "/json/getpartners")
                .asJsonObject().setCallback(new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                        if (e == null) {
                            JsonArray partnersJson = result.getAsJsonArray("data");
                            if (partnersJson != null) {
                                try {
                                    onFetchSuccess(partnersJson);
                                } catch (IOException e1) {
                                    e1.printStackTrace();
                                }
                            } else {
                                onFetchFailed(result.get("message").getAsString(), recyclerView.getContext());
                            }
                        } else {
                            onFetchFailed(e.getMessage().toString(), recyclerView.getContext());
                        }
                    }
                });
    } catch (Exception e) {
        onFetchFailed(e.getMessage().toString(), recyclerView.getContext());
    }

}