Java Code Examples for android.support.v4.content.ContextCompat.getDrawable()

The following are Jave code examples for showing how to use getDrawable() of the android.support.v4.content.ContextCompat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: easyfilemanager   File: IconUtils.java   Source Code and License Vote up 6 votes
public static Drawable loadMimeIcon(
        Context context, String mimeType, String authority, String docId, int mode) {

    if (Document.MIME_TYPE_DIR.equals(mimeType)) {
        if (MediaDocumentsProvider.AUTHORITY.equals(authority)) {
            if(docId.startsWith(MediaDocumentsProvider.TYPE_ALBUM)){
                return ContextCompat.getDrawable(context, R.drawable.ic_doc_album);
            }
            else if(docId.startsWith(MediaDocumentsProvider.TYPE_IMAGES_BUCKET)){
                return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
            }
            else if(docId.startsWith(MediaDocumentsProvider.TYPE_VIDEOS_BUCKET)){
                return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
            }
        }

        if (mode == DocumentsActivity.State.MODE_GRID) {
            return ContextCompat.getDrawable(context, R.drawable.ic_grid_folder);
        } else {
            return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
        }
    }

    return loadMimeIcon(context, mimeType);
}
 
Example 2
Project: duo-navigation-drawer   File: DuoMenuView.java   Source Code and License Vote up 6 votes
/**
 * Handles the background.
 */
private void handleBackground() {
    if (mMenuViewHolder.mMenuBackground == null) {
        return;
    }

    if (mBackgroundDrawableId != DEFAULT_DRAWABLE_ATTRIBUTE_VALUE) {
        Drawable backgroundDrawable = ContextCompat.getDrawable(getContext(), mBackgroundDrawableId);

        if (backgroundDrawable != null) {
            mMenuViewHolder.mMenuBackground.setImageDrawable(backgroundDrawable);
            return;
        }
    }

    mMenuViewHolder.mMenuBackground.setBackgroundColor(getPrimaryColor());
}
 
Example 3
Project: RackMonthPicker   File: MonthAdapter.java   Source Code and License Vote up 5 votes
private void setMonthBackgroundSelected(int color) {
    LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected);
    GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1);
    gradientDrawable.setColor(ContextCompat.getColor(context, color));
    layerDrawable.setDrawableByLayerId(1, gradientDrawable);

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable);
    states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default));
    layoutMain.setBackground(states);
}
 
Example 4
Project: Hitalk   File: XEditText.java   Source Code and License Vote up 5 votes
private void init() {
    if (getInputType() == InputType.TYPE_CLASS_NUMBER) { // if inputType="number", it can't insert separator.
        setInputType(InputType.TYPE_CLASS_PHONE);
    }

    mTextWatcher = new MyTextWatcher();
    this.addTextChangedListener(mTextWatcher);
    mRightMarkerDrawable = getCompoundDrawables()[2];
    if (customizeMarkerEnable && mRightMarkerDrawable != null) {
        setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1],
                null, getCompoundDrawables()[3]);
        setHasNoSeparator(true);
    }
    if (mRightMarkerDrawable == null) { // didn't customize Marker
        mRightMarkerDrawable = ContextCompat.getDrawable(getContext(), R.mipmap.indicator_input_error);
        DrawableCompat.setTint(mRightMarkerDrawable, getCurrentHintTextColor());
        if (mRightMarkerDrawable != null) {
            mRightMarkerDrawable.setBounds(0, 0, mRightMarkerDrawable.getIntrinsicWidth(),
                    mRightMarkerDrawable.getIntrinsicHeight());
        }
    }

    setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            hasFocused = hasFocus;
            markerFocusChangeLogic();
            iOSFocusChangeLogic();
        }
    });

    if (iOSStyleEnable) {
        initiOSObjects();
    }
    if (disableEmoji) {
        setFilters(new InputFilter[]{new EmojiExcludeFilter()});
    }
}
 
Example 5
Project: ZhaZhaShop   File: FloatingItemDecoration.java   Source Code and License Vote up 5 votes
/**
 * 自定义分割线
 *
 * @param context
 * @param drawableId 分割线图片
 */
public FloatingItemDecoration(Context context, @DrawableRes int drawableId) {
    mDivider = ContextCompat.getDrawable(context, drawableId);
    this.dividerHeight = mDivider.getIntrinsicHeight();
    this.dividerWidth = mDivider.getIntrinsicWidth();
    init(context);
}
 
Example 6
Project: simple-share-android   File: IconUtils.java   Source Code and License Vote up 5 votes
public static Drawable loadSchemeIcon(Context context, String type) {

        if (SERVER.equals(type)) {
            return ContextCompat.getDrawable(context, R.drawable.ic_connection_server);
        } else if (CLIENT.equals(type)) {
            return ContextCompat.getDrawable(context, R.drawable.ic_connection_network);
        } else {
            return ContextCompat.getDrawable(context, R.drawable.ic_connection_server);
        }
    }
 
Example 7
Project: garras   File: PhotoFragment.java   Source Code and License Vote up 5 votes
private void setupData(Photos.User user) {
    if (null == getActivity()) return;
    mColorIcon = ContextCompat.getDrawable(getActivity(), R.mipmap.ic_fiber_manual_record_white_18dp);

    mUserTxt.setText(getString(R.string.by_photo, user.name));
    setTranslate(mUserTxt, DELAY * 4);
    try {
        Date createdAt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss-HH:mm", Locale.getDefault()).parse(mPhotos.created_at);
        mTitleTxt.setText(getString(R.string.shoot_at, new PrettyTime().format(createdAt)));
    } catch (ParseException e) {
        Timber.e(e);
    }

    RequestBuilder<Bitmap> bitmapRequestBuilder = GlideApp.with(getActivity())
            .asBitmap()
            .load(user.profile_image.large)
            .error(R.mipmap.bg_dark_avatar_male_big_normal)
            .placeholder(R.mipmap.bg_dark_avatar_male_big_normal)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .fallback(R.mipmap.bg_dark_avatar_male_big_normal);
    bitmapRequestBuilder.into(new CircularBitmapImageViewTarget(getActivity(), mUserAvatar));

    RxView.clicks(mUserAvatar).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
        @Override
        public void accept(Object o) throws Exception {
            if (null != mPhotos && null != mPhotos.user) {
                Request request = new Request(UserFragment.class);
                request.putExtra(UserFragment.EXTRA_USER_NAME_KEY, mPhotos.user.username);
                request.putExtra(UserFragment.EXTRA_NIKE_NAME_KEY, mPhotos.user.name);
                startFragment(request);
            }
        }
    });

    setTranslate(mUserTxt, DELAY * 4);
    setTranslate(mUserTxt, DELAY * 5);
}
 
Example 8
Project: Liz   File: ThemeHelper.java   Source Code and License Vote up 5 votes
public Drawable getPlaceHolder(){
	switch (baseTheme){
		case DARK:
			return ContextCompat.getDrawable(context, R.drawable.ic_empty);
		case AMOLED:
			return ContextCompat.getDrawable(context, R.drawable.ic_empty_amoled);
		case LIGHT:
			return ContextCompat.getDrawable(context, R.drawable.ic_empty_white);
	}
	return null;
}
 
Example 9
Project: OpenHub   File: ViewUtils.java   Source Code and License Vote up 5 votes
/**
 * Get bitmap from resource
 */
public static Bitmap getBitmapFromResource(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    if (drawable instanceof BitmapDrawable) {
        return BitmapFactory.decodeResource(context.getResources(), drawableId);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmapFromResource((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
Example 10
Project: GitHub   File: SupportDividerItemDecoration.java   Source Code and License Vote up 5 votes
public SupportDividerItemDecoration(Context context, int orientation, boolean dash) {
    if (dash) {
        mDivider = ContextCompat.getDrawable(context, R.drawable.shape_common_dash_divide);
    } else {
        final TypedArray a = context.obtainStyledAttributes(ATTRS);
        mDivider = a.getDrawable(0);
        a.recycle();
    }
    setOrientation(orientation);
}
 
Example 11
Project: CameraFragment   File: RecordButton.java   Source Code and License Vote up 5 votes
public RecordButton(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    takePhotoDrawable = ContextCompat.getDrawable(context, R.drawable.take_photo_button);
    startRecordDrawable = ContextCompat.getDrawable(context, R.drawable.start_video_record_button);
    stopRecordDrawable = ContextCompat.getDrawable(context, R.drawable.stop_button_background);

    if (Build.VERSION.SDK_INT > 15)
        setBackground(ContextCompat.getDrawable(context, R.drawable.circle_frame_background));
    else
        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.circle_frame_background));

    setOnClickListener(new OnClickListener() {
        private final static int CLICK_DELAY = 1000;

        private long lastClickTime = 0;

        @Override
        public void onClick(View view) {
            if (System.currentTimeMillis() - lastClickTime < CLICK_DELAY) {
                return;
            } else lastClickTime = System.currentTimeMillis();

            if(listener != null) {
                listener.onRecordButtonClicked();
            }
        }
    });
    setSoundEffectsEnabled(false);
    setIconPadding(iconPadding);

    displayPhotoState();
}
 
Example 12
Project: letv   File: ActionBarDrawerToggle.java   Source Code and License Vote up 5 votes
public void setHomeAsUpIndicator(int resId) {
    Drawable indicator = null;
    if (resId != 0) {
        indicator = ContextCompat.getDrawable(this.mActivity, resId);
    }
    setHomeAsUpIndicator(indicator);
}
 
Example 13
Project: Android-Wear-Projects   File: HeartBeatView.java   Source Code and License Vote up 4 votes
private void init() {
    //make this not mandatory
    heartDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_heart_red_24dp);
    setImageDrawable(heartDrawable);

}
 
Example 14
Project: boohee_v5.6   File: SubMenuBuilder.java   Source Code and License Vote up 4 votes
public SubMenu setHeaderIcon(int iconRes) {
    super.setHeaderIconInt(ContextCompat.getDrawable(getContext(), iconRes));
    return this;
}
 
Example 15
Project: MaterialChipsInput   File: ChipsInput.java   Source Code and License Vote up 4 votes
/**
 * Inflate the view according to attributes
 *
 * @param attrs the attributes
 */
private void init(AttributeSet attrs) {
    // inflate layout
    View rootView = inflate(getContext(), R.layout.chips_input, this);
    // butter knife
    ButterKnife.bind(this, rootView);

    // attributes
    if(attrs != null) {
        TypedArray a = mContext.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.ChipsInput,
                0, 0);

        try {
            // hint
            mHint = a.getString(R.styleable.ChipsInput_hint);
            mHintColor = a.getColorStateList(R.styleable.ChipsInput_hintColor);
            mTextColor = a.getColorStateList(R.styleable.ChipsInput_textColor);
            mMaxRows = a.getInteger(R.styleable.ChipsInput_maxRows, 2);
            setMaxHeight(ViewUtil.dpToPx((40 * mMaxRows) + 8));
            //setVerticalScrollBarEnabled(true);
            // chip label color
            mChipLabelColor = a.getColorStateList(R.styleable.ChipsInput_chip_labelColor);
            // chip avatar icon
            mChipHasAvatarIcon = a.getBoolean(R.styleable.ChipsInput_chip_hasAvatarIcon, true);
            // chip delete icon
            mChipDeletable = a.getBoolean(R.styleable.ChipsInput_chip_deletable, false);
            mChipDeleteIconColor = a.getColorStateList(R.styleable.ChipsInput_chip_deleteIconColor);
            int deleteIconId = a.getResourceId(R.styleable.ChipsInput_chip_deleteIcon, NONE);
            if(deleteIconId != NONE) mChipDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
            // chip background color
            mChipBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_chip_backgroundColor);
            // show chip detailed
            mShowChipDetailed = a.getBoolean(R.styleable.ChipsInput_showChipDetailed, true);
            // chip detailed text color
            mChipDetailedTextColor = a.getColorStateList(R.styleable.ChipsInput_chip_detailed_textColor);
            mChipDetailedBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_chip_detailed_backgroundColor);
            mChipDetailedDeleteIconColor = a.getColorStateList(R.styleable.ChipsInput_chip_detailed_deleteIconColor);
            // filterable list
            mFilterableListBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_filterable_list_backgroundColor);
            mFilterableListTextColor = a.getColorStateList(R.styleable.ChipsInput_filterable_list_textColor);
        }
        finally {
            a.recycle();
        }
    }

    // adapter
    mChipsAdapter = new ChipsAdapter(mContext, this, mRecyclerView);
    ChipsLayoutManager chipsLayoutManager = ChipsLayoutManager.newBuilder(mContext)
            .setOrientation(ChipsLayoutManager.HORIZONTAL)
            .build();
    mRecyclerView.setLayoutManager(chipsLayoutManager);
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setAdapter(mChipsAdapter);

    // set window callback
    // will hide DetailedOpenView and hide keyboard on touch outside
    Activity activity = ActivityUtil.scanForActivity(mContext);
    if(activity == null)
        throw new ClassCastException("android.view.Context cannot be cast to android.app.Activity");

    android.view.Window.Callback mCallBack = (activity).getWindow().getCallback();
    activity.getWindow().setCallback(new MyWindowCallback(mCallBack, activity));
}
 
Example 16
Project: GitHub   File: RecycleViewDivider.java   Source Code and License Vote up 4 votes
public RecycleViewDivider(Context context, int orientation, @DrawableRes int resId) {
    this(context, orientation, ContextCompat.getDrawable(context, resId));
}
 
Example 17
Project: Phoenix-for-VK   File: AudioRecyclerAdapter.java   Source Code and License Vote up 4 votes
public AudioRecyclerAdapter(Context context, List<Audio> data) {
    this.mContext = context;
    this.mData = data;
    this.unselectedDrawable = ContextCompat.getDrawable(context, R.drawable.circle_back_white);
    this.unselectedDrawable.setColorFilter(CurrentTheme.getIconColorActive(context), PorterDuff.Mode.MULTIPLY);
}
 
Example 18
Project: MiPushFramework   File: BottomNavigationItemView.java   Source Code and License Vote up 4 votes
public void setItemBackground(int background) {
    Drawable backgroundDrawable = background == 0
            ? null : ContextCompat.getDrawable(getContext(), background);
    ViewCompat.setBackground(this, backgroundDrawable);
}
 
Example 19
Project: Phoenix-for-VK   File: CircleCounterButton.java   Source Code and License Vote up 4 votes
public void setIcon(int res){
    this.mIcon = ContextCompat.getDrawable(getContext(), res);
    icon.setImageDrawable(mIcon);
}
 
Example 20
Project: VideoPlayer   File: RecycleViewDivider.java   Source Code and License Vote up 2 votes
/**
 * 自定义分割线
 *
 * @param context
 * @param orientation 列表方向
 * @param drawableId  分割线图片
 */
public RecycleViewDivider(Context context, int orientation, int drawableId) {
    this(context, orientation);
    mDivider = ContextCompat.getDrawable(context, drawableId);
    mDividerHeight = mDivider.getIntrinsicHeight();
}