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:android.support.v7.internal.view.menu.SubMenuBuilder.java

public SubMenu setHeaderIcon(int iconRes) {
    super.setHeaderIconInt(ContextCompat.getDrawable(getContext(), iconRes));
    return this;
}

From source file:com.imageview.glide.ImageView.java

public void setErrorDrawable(@DrawableRes int resId) {
    if (resId != mErrorResource) {
        mErrorResource = resId;//w  w  w  .ja v a  2  s . co  m
        setErrorDrawable(ContextCompat.getDrawable(getContext(), resId));
    }
}

From source file:com.example.android.mediabrowserservice.QueueAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;/*from  w w  w . java  2s.c o  m*/

    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.media_list_item, parent, false);
        holder = new ViewHolder();
        holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
        holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
        holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    MediaSessionCompat.QueueItem item = getItem(position);
    holder.mTitleView.setText(item.getDescription().getTitle());
    if (item.getDescription().getDescription() != null) {
        holder.mDescriptionView.setText(item.getDescription().getDescription());
    }

    // If the itemId matches the active Id then use a different icon
    if (mActiveQueueItemId == item.getQueueId()) {
        holder.mImageView
                .setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_equalizer_white_24dp));
    } else {
        holder.mImageView
                .setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_play_arrow_white_24dp));
    }
    return convertView;
}

From source file:com.arsy.maps_library.MapRadar.java

public MapRadar(GoogleMap googleMap, LatLng latLng, Context context) {
    mGoogleMap = googleMap;/*from   ww  w.java  2s.co m*/
    mLatLng = latLng;
    mPrevLatLng = latLng;
    mOuterDrawable = (GradientDrawable) ContextCompat.getDrawable(context, R.drawable.background);
}

From source file:com.artemchep.horario.ui.fragments.details.DetailsHelper.java

void setAppBarBackgroundColor(@ColorInt int color) {
    color |= 0xFF000000; // ignore alpha bits
    final boolean isColorDark = ColorUtil.isColorDark(color);

    Drawable overflowIcon;/*from  w w w. j  a va 2  s .com*/
    if (isColorDark) {
        mCollapsingToolbar.setExpandedTitleColor(Color.WHITE);
        mCollapsingToolbar.setCollapsedTitleTextColor(Color.WHITE);
        overflowIcon = ContextCompat.getDrawable(mActivity, R.drawable.ic_dots_vertical_white_24dp);
        if (mSmartTabLayout != null) {
            mSmartTabLayout.setDefaultTabTextColor(Color.WHITE);
            mSmartTabLayout.setSelectedIndicatorColors(Color.WHITE);
        }
    } else {
        mCollapsingToolbar.setExpandedTitleColor(Color.BLACK);
        mCollapsingToolbar.setCollapsedTitleTextColor(Color.BLACK);
        overflowIcon = ContextCompat.getDrawable(mActivity, R.drawable.ic_dots_vertical_black_24dp);
        if (mSmartTabLayout != null) {
            mSmartTabLayout.setDefaultTabTextColor(Color.BLACK);
            mSmartTabLayout.setSelectedIndicatorColors(Color.BLACK);
        }
    }

    mCollapsingToolbar.setContentScrimColor(color);
    if (mBackdropToolbar != null) {
        mBackdropToolbar.setBackgroundColor(color);
    } else
        mAppBar.setBackgroundColor(color);
    mToolbar.setOverflowIcon(overflowIcon);

    if (mActivity.mContainers.hasSingleColumn()) {
        int iconRes;
        if (mActivity.mAppBar.hasGeneralToolbar()) {
            iconRes = isColorDark ? R.drawable.ic_close_white_24dp : R.drawable.ic_close_black_24dp;
        } else
            iconRes = isColorDark ? R.drawable.ic_backburger_white_24dp : R.drawable.ic_backburger_black_24dp;
        Drawable navIcon = ContextCompat.getDrawable(mActivity, iconRes);
        mToolbar.setNavigationIcon(navIcon);
    }

    MenuItem editItem = mToolbar.getMenu().findItem(R.id.action_edit);
    if (editItem != null) {
        Drawable editIcon = isColorDark ? ContextCompat.getDrawable(mActivity, R.drawable.ic_pencil_white_24dp)
                : ContextCompat.getDrawable(mActivity, R.drawable.ic_pencil_black_24dp);
        editItem.setIcon(editIcon);
    }

    MenuItem shareItem = mToolbar.getMenu().findItem(R.id.action_share);
    if (shareItem != null) {
        Drawable shareIcon = isColorDark
                ? ContextCompat.getDrawable(mActivity, R.drawable.ic_share_variant_white_24dp)
                : ContextCompat.getDrawable(mActivity, R.drawable.ic_share_variant_black_24dp);
        shareItem.setIcon(shareIcon);
    }
}

From source file:com.bilibili.magicasakura.widgets.AppCompatImageHelper.java

public void setImageResId(int resId) {
    if (mImageResId != resId) {
        resetTintResource(resId);/*from  ww  w  . ja  v a  2  s  .  c o  m*/

        if (resId != 0) {
            Drawable image = mTintManager.getDrawable(resId);
            setImageDrawable(image != null ? image : ContextCompat.getDrawable(mView.getContext(), resId));
        }
    }
}

From source file:cc.metapro.openct.customviews.DuringDialog.java

private void setViews(GridLayout gridLayout) {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 6; j++) {
            final int week = i * 6 + j + 1;
            final TextView textView = new TextView(getActivity());
            textView.setText(week + gridLayout.getContext().getString(R.string.week));
            textView.setGravity(Gravity.CENTER);
            if (DURING[week]) {
                textView.setBackground(/*from   w  w w.ja  v  a2s. co  m*/
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_blue));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
            } else {
                textView.setBackground(
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_grey));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.material_grey));
            }

            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DURING[week] = !DURING[week];
                }
            });
            GridLayout.Spec row = GridLayout.spec(i, 1, 1);
            GridLayout.Spec col = GridLayout.spec(j, 1, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
            gridLayout.addView(textView, params);
            selections[i][j] = textView;
        }
    }
}

From source file:com.geekandroid.sdk.sample.TabManagerSampleFragment.java

public View getItemIndicator(String text, int resId) {
    View view = null;/*w  ww.ja v  a 2  s  .co  m*/
    if (inflater == null) {
        inflater = LayoutInflater.from(getContext());
    }
    view = inflater.inflate(R.layout.item_main_tab, null);

    TextView textView = (TextView) view.findViewById(R.id.item_main_tab_view);
    textView.setText(text);

    Drawable drawable = ContextCompat.getDrawable(getContext(), resId);
    drawable.setBounds(0, 0, 60, 60);
    textView.setCompoundDrawablePadding(10);
    textView.setCompoundDrawables(null, drawable, null, null);

    return view;
}

From source file:com.hartcode.hartweather.list.WeatherItemViewHolder.java

public void bindData(@NonNull Model model, int position) {
    this.weatherIndex = position;
    this.model = model;

    Weather weather = model.getItem(position);
    this.txtCityName.setText(weather.cityName);

    String temp = String.format(this.view.getResources().getString(R.string.temp_format), (int) weather.temp,
            (char) 0x00B0);
    this.txtWeatherTemp.setText(temp);
    Drawable iconResource = ContextCompat.getDrawable(this.view.getContext(),
            resources.getIdentifier(resources.getString(R.string.weather_image_prefix) + weather.icon,
                    resources.getString(R.string.weather_image_resource_type),
                    this.view.getContext().getPackageName()));
    this.txtWeatherTemp.setCompoundDrawablesWithIntrinsicBounds(iconResource, null, null, null);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(weather.lastUpdate);
    SimpleDateFormat sdfDate = new SimpleDateFormat(resources.getString(R.string.simple_date_format),
            Locale.US);/*from   w w  w  .  j a v  a 2  s  .  c  o m*/
    String lastUpdate = String.format(resources.getString(R.string.last_update_format),
            sdfDate.format(calendar.getTime()));
    this.txtLastUpdate.setText(lastUpdate);
}

From source file:com.airbnb.rxgroups.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    startStop = (FloatingActionButton) findViewById(R.id.fab);
    lockUnlock = (FloatingActionButton) findViewById(R.id.fab_pause_resume);
    alarmOffDrawable = ContextCompat.getDrawable(this, R.drawable.ic_alarm_off_black_24dp);
    alarmDrawable = ContextCompat.getDrawable(this, R.drawable.ic_alarm_black_24dp);
    lockDrawable = ContextCompat.getDrawable(this, R.drawable.ic_lock_outline_black_24dp);
    unlockDrawable = ContextCompat.getDrawable(this, R.drawable.ic_lock_open_black_24dp);
    output = (TextView) findViewById(R.id.txt_output);
    setSupportActionBar(toolbar);/*from   w  ww  . j  a  v  a2 s  .  co m*/

    startStop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickStartStopTimer(v);
        }
    });
    lockUnlock.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickLockUnlockGroup(v);
        }
    });

    SampleApplication application = (SampleApplication) getApplication();
    ObservableManager manager = application.observableManager();
    groupLifecycleManager = GroupLifecycleManager.onCreate(manager, savedInstanceState, this);
    timerObservable = application.timerObservable();
    observableGroup = groupLifecycleManager.group();

    if (savedInstanceState != null && savedInstanceState.getBoolean(IS_RUNNING)) {
        isRunning = true;
        startStop.setImageDrawable(alarmOffDrawable);
    }
}