Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

private void setVolumeOrBrightnessInfo(String txt, @DrawableRes int drawableId) {
    centerInfo.setVisibility(View.VISIBLE);
    centerInfo.setText(txt);//from  w  w  w .  jav a2s .c  o m
    centerInfo.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
    centerInfo.setCompoundDrawablesWithIntrinsicBounds(null,
            ContextCompat.getDrawable(getContext(), drawableId), null, null);
}

From source file:android.support.design.widget.CollapsingToolbarLayout.java

/**
 * Set the drawable to use for the content scrim from resources.
 *
 * @param resId drawable resource id//from www  .j a v a  2  s  . com
 *
 * @attr ref R.styleable#CollapsingToolbarLayout_statusBarScrim
 * @see #getStatusBarScrim()
 */
public void setStatusBarScrimResource(@DrawableRes int resId) {
    setStatusBarScrim(ContextCompat.getDrawable(getContext(), resId));
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private void setChipDimensions(final Context context, final AttributeSet attrs) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecipientEditTextView, 0, 0);
    final Resources r = getContext().getResources();
    mChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_chipBackground);
    if (mChipBackground == null)
        mChipBackground = ContextCompat.getDrawable(context, R.drawable.circle_background_chips);
    mChipBackgroundPressed = a.getDrawable(R.styleable.RecipientEditTextView_chipBackgroundPressed);
    if (mChipBackgroundPressed == null)
        mChipBackgroundPressed = ContextCompat.getDrawable(context, R.drawable.chip_background_selected);
    mChipDelete = a.getDrawable(R.styleable.RecipientEditTextView_chipDelete);
    if (mChipDelete == null)
        mChipDelete = ContextCompat.getDrawable(context, R.drawable.chip_delete);
    mChipPadding = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipPadding, -1);
    if (mChipPadding == -1)
        mChipPadding = (int) r.getDimension(R.dimen.chip_padding);
    mAlternatesLayout = a.getResourceId(R.styleable.RecipientEditTextView_chipAlternatesLayout, -1);
    if (mAlternatesLayout == -1)
        mAlternatesLayout = R.layout.chips_alternate_item;
    mDefaultContactPhoto = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture);
    mMoreItem = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.more_item, null);
    mChipHeight = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipHeight, -1);
    if (mChipHeight == -1)
        mChipHeight = r.getDimension(R.dimen.chip_height);
    mChipFontSize = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipFontSize, -1);
    if (mChipFontSize == -1)
        mChipFontSize = r.getDimension(R.dimen.chip_text_size);
    mInvalidChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_invalidChipBackground);
    if (mInvalidChipBackground == null)
        mInvalidChipBackground = ContextCompat.getDrawable(context, R.drawable.chip_background_invalid);
    mLineSpacingExtra = r.getDimension(R.dimen.line_spacing_extra);
    mMaxLines = r.getInteger(R.integer.chips_max_lines);
    final TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    a.recycle();/*from ww  w .  j av a2s .c o m*/
}

From source file:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Center the selected place and change the pin
 * color to blue./*from   w  w w  . jav a 2 s.  com*/
 * @param p - the selected place
 */
@Override
public final void centerOnPlace(final Place p) {
    if (p.getLocation() == null) {
        return;
    }
    // Dismiss the route header view
    removeRouteHeaderView();

    // Keep track of centered place since
    // it will be needed to reset
    // the graphic if another place
    // is centered.
    mCenteredPlace = p;

    // Stop listening to navigation changes
    // while place is centered in map.
    removeNavigationChangedListener();
    final ListenableFuture<Boolean> viewCentered = mMapView.setViewpointCenterAsync(p.getLocation());
    viewCentered.addDoneListener(new Runnable() {
        @Override
        public void run() {
            // Once we've centered on a place, listen
            // for changes in viewpoint.
            if (mNavigationChangedListener == null) {
                setNavigationChangeListener();
            }
        }
    });
    // Change the pin icon
    clearCenteredPin();

    final List<Graphic> graphics = mGraphicOverlay.getGraphics();
    for (final Graphic g : graphics) {
        if (g.getGeometry().equals(p.getLocation())) {
            mCenteredGraphic = g;
            mCenteredGraphic.setZIndex(3);
            final BitmapDrawable pin = (BitmapDrawable) ContextCompat.getDrawable(getActivity(),
                    getPinForCenterPlace(p));
            final PictureMarkerSymbol pinSymbol = new PictureMarkerSymbol(pin);
            g.setSymbol(pinSymbol);
            break;
        }
    }
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * Divider/*  w  w w . ja  v  a 2  s .c  o  m*/
 *
 * @param divider Divider
 */
@SuppressWarnings("unused")
public void setDivider(@DrawableRes int divider) {
    setDivider(ContextCompat.getDrawable(getContext(), divider));
}

From source file:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Restore a pin to its default color//from   w  w  w  . ja v  a 2s.co  m
 */
private void clearCenteredPin() {
    if (mCenteredGraphic != null) {
        mCenteredGraphic.setZIndex(0);
        final BitmapDrawable oldPin = (BitmapDrawable) ContextCompat.getDrawable(getActivity(),
                getDrawableForPlace(mCenteredPlace));
        mCenteredGraphic.setSymbol(new PictureMarkerSymbol(oldPin));
    }
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * /*from w  ww .  ja v a2s .c  o m*/
 *
 * @param indicator 
 */
@SuppressWarnings("unused")
public void setIndicator(@DrawableRes int indicator) {
    setIndicator(ContextCompat.getDrawable(getContext(), indicator));
}

From source file:android.support.v17.leanback.app.BackgroundManager.java

/**
 * Returns the default drawable used as a dim layer.
 */
public Drawable getDefaultDimLayer() {
    return ContextCompat.getDrawable(mContext, R.color.lb_background_protection);
}

From source file:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Show the route//from   w  ww.  ja  v a2 s .com
 */
public final void displayRoute() {
    if (mRouteResult != null && mStart != null && mEnd != null) {
        final Route route;
        try {
            route = mRouteResult.getRoutes().get(0);
            if (route.getTotalLength() == 0.0) {
                throw new Exception("Can not find the Route");
            }
        } catch (final Exception e) {
            Toast.makeText(getActivity(),
                    "We're sorry, we couldn't find the route. Please make "
                            + "sure the Start and Destination are different or are connected by a road",
                    Toast.LENGTH_LONG).show();
            Log.e(MapFragment.TAG, e.getMessage());
            return;
        }

        // Clear all place graphics
        clearPlaceGraphicOverlay();

        if (mRouteOverlay == null) {
            mRouteOverlay = new GraphicsOverlay();
            mMapView.getGraphicsOverlays().add(mRouteOverlay);
        } else {
            // Clear any previous route
            mRouteOverlay.getGraphics().clear();
        }
        // Create polyline graphic of the full route
        final SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 6);
        final Graphic routeGraphic = new Graphic(route.getRouteGeometry(), lineSymbol);

        // Add the route graphic to the route layer
        mRouteOverlay.getGraphics().add(routeGraphic);
        // Add start and end pins
        final BitmapDrawable startPin = (BitmapDrawable) ContextCompat.getDrawable(getActivity(),
                R.drawable.route_pin_start);
        final BitmapDrawable endPin = (BitmapDrawable) ContextCompat.getDrawable(getActivity(),
                R.drawable.end_route_pin);
        // Current location from Google location services
        // needs a spatial reference before it can be added to map.
        final Point startPoint = new Point(mStart.getX(), mStart.getY(), mEnd.getSpatialReference());

        final Graphic begin = generateRoutePoints(startPoint, startPin);
        mRouteOverlay.getGraphics().add(begin);
        mRouteOverlay.getGraphics().add(generateRoutePoints(mEnd, endPin));

        // Zoom to the extent of the entire route with a padding
        final Envelope routingEnvelope = new Envelope(mStart.getX(), mStart.getY(), mEnd.getX(), mEnd.getY(),
                SpatialReferences.getWgs84());
        final Envelope projectedEnvelope = (Envelope) GeometryEngine.project(routingEnvelope,
                mMapView.getSpatialReference());
        mMapView.setViewpointGeometryAsync(projectedEnvelope, 100);

        // Get routing directions
        mRouteDirections = route.getDirectionManeuvers();

        // Show route header
        showRouteHeader(route.getTravelTime());

        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
        }
    } else {
        Log.i(TAG, "Route details haven't been set, no route to display");
    }
}

From source file:com.android.argb.edhlc.Utils.java

public static void expand(Context context, final CardView card, TextView title, ImageView selector,
        int minHeight, int maxHeight) {
    title.setTextColor(ContextCompat.getColor(context, R.color.accent_color_dark));

    Animation rotation = AnimationUtils.loadAnimation(context, R.anim.rotate_180_anticlockwise);
    selector.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.arrow_up));
    selector.setRotation(0);//w w  w .ja  va 2 s. com
    selector.startAnimation(rotation);
    selector.setColorFilter(ContextCompat.getColor(context, R.color.accent_color_dark));

    ValueAnimator anim = ValueAnimator.ofInt(minHeight, maxHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
            layoutParams.height = val;
            card.setLayoutParams(layoutParams);
            Utils.makeViewVisible(card);
        }
    });
    anim.start();
}