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.baijiahulian.common.crop.utils.FrescoImageLoader.java

public void displayImage(Context context, String path, GFImageView imageView, int width, int height) {
    Resources resources = context.getResources();
    Drawable defaultDrawable = ContextCompat.getDrawable(context, R.drawable.common_crop_image_placeholder);
    //        imageView.setImageDrawable(defaultDrawable);
    imageView.setImageDrawable(null);/*w  w  w  .j  a  va  2 s.  c o m*/
    GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources).setFadeDuration(300)
            .setPlaceholderImage(defaultDrawable).setFailureImage(defaultDrawable)
            .setProgressBarImage(new ProgressBarDrawable()).build();
    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context);
    imageView.setOnImageViewListener(new GFImageView.OnImageViewListener() {
        @Override
        public void onDetach() {
            draweeHolder.onDetach();
        }

        @Override
        public void onAttach() {
            draweeHolder.onAttach();
        }

        @Override
        public boolean verifyDrawable(Drawable dr) {
            if (dr == draweeHolder.getHierarchy().getTopLevelDrawable()) {
                return true;
            }
            return false;
        }
    });
    Uri uri = new Uri.Builder().scheme(UriUtil.LOCAL_FILE_SCHEME).path(path).build();
    displayImage(uri, new ResizeOptions(width, height), imageView, draweeHolder);
}

From source file:android.support.v7.widget.AppCompatCheckBox.java

@Override
public void setButtonDrawable(@DrawableRes int resId) {
    setButtonDrawable(mDrawableManager != null ? mDrawableManager.getDrawable(getContext(), resId)
            : ContextCompat.getDrawable(getContext(), resId));
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_d_grid.RecyclerListViewFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new GridLayoutManager(getContext(), 3, GridLayoutManager.VERTICAL, false);

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
    // Start dragging after long press
    mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
    mRecyclerViewDragDropManager.setInitiateOnMove(false);
    mRecyclerViewDragDropManager.setLongPressTimeout(750);

    //adapter/*from   w  ww . ja  va 2s  .  c  o  m*/
    final MyDraggableItemAdapter myItemAdapter = new MyDraggableItemAdapter(getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);

    // additional decorations
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
        // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator(
                (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

From source file:com.grarak.kerneladiutor.fragments.tools.BuildpropFragment.java

@Override
protected Drawable getBottomFabDrawable() {
    Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(getActivity(), R.drawable.ic_add));
    DrawableCompat.setTint(drawable, Color.WHITE);
    return drawable;
}

From source file:com.fuzz.indicator.FrameAwareCutoutImageCell.java

@Override
@Nullable/* w ww  .  j  ava  2 s  .  c om*/
protected Drawable chooseDrawable(@NonNull CutoutViewLayoutParams lp) {
    Drawable chosen;
    if (lp.position <= -1 || latestResourceId != lp.indicatorDrawableId) {
        latestResourceId = lp.indicatorDrawableId;
        chosen = ContextCompat.getDrawable(itemView.getContext(), lp.indicatorDrawableId);
        if (chosen instanceof AnimationDrawable) {
            frames = (AnimationDrawable) chosen;
        } else {
            frames = null;
        }
    } else {
        chosen = itemView.getDrawable();
    }

    if (frames != null) {
        int frameIndex = lp.position % frames.getNumberOfFrames();
        chosen = frames.getFrame(frameIndex);
    }

    return chosen;
}

From source file:com.justplay1.shoppist.features.settings.widget.themedialog.ColorPickerSwatch.java

protected void setColor(int color) {
    Drawable[] colorDrawable = new Drawable[] {
            ContextCompat.getDrawable(getContext(), R.drawable.calendar_color_picker_swatch) };
    swatchImage.setImageDrawable(new ColorStateDrawable(colorDrawable, color));
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_d_staggered_grid.DraggableStaggeredGridExampleFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
    // Start dragging after long press
    mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
    mRecyclerViewDragDropManager.setInitiateOnMove(false);
    mRecyclerViewDragDropManager.setLongPressTimeout(750);

    //adapter/*from w  w  w .  j a v  a  2  s . c om*/
    final DraggableStaggeredGridExampleAdapter myItemAdapter = new DraggableStaggeredGridExampleAdapter(
            getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setHasFixedSize(false);

    // additional decorations
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
        // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator(
                (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.NotitieFragment.java

/**
 * Inflate the notitie_fragment layout containing the about text from strings resource
 * @param inflater LayoutInflator/*from  w  w w  .j a  va 2  s.  c  om*/
 * @param container ViewGroup
 * @param savedInstanceState Bundle
 * @return View
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // get the notitie fragment
    View view = inflater.inflate(R.layout.notitie_fragment, container, false);

    // bind the elements to the view
    ButterKnife.bind(this, view);

    // disable upper-casing the menu buttons
    mCancelButton.setTransformationMethod(null);
    mSaveButton.setTransformationMethod(null);

    // create the save progress dialog
    mProgressDialog = new ProgressDialog(getContext());
    mProgressDialog.setIndeterminate(true);
    mProgressDialog
            .setIndeterminateDrawable(ContextCompat.getDrawable(getContext(), R.drawable.progressbar_circle));
    mProgressDialog.setMessage(getString(R.string.notice_notitie_saving) + "...");
    mProgressDialog.setCancelable(false);

    return view;
}

From source file:com.grarak.kerneladiutor.fragments.tools.BackupFragment.java

@Override
protected Drawable getTopFabDrawable() {
    Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(getActivity(), R.drawable.ic_add));
    DrawableCompat.setTint(drawable, Color.WHITE);
    return drawable;
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_d_with_section.RecyclerListViewFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new LinearLayoutManager(getContext());

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));

    //adapter// w  ww. j  a v  a2s.  c o  m
    final MyDraggableWithSectionItemAdapter myItemAdapter = new MyDraggableWithSectionItemAdapter(
            getDataProvider());
    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);

    // additional decorations
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
        // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator(
                (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }
    mRecyclerView.addItemDecoration(new SimpleListDividerDecorator(
            ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true));

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
}